Skip to content

Instantly share code, notes, and snippets.

@chicagoworks
chicagoworks / jquery.offspring.js
Created January 3, 2011 20:05
jquery.offspring.js: perform the same duty as children but includes free floating 'text' nodes
//perform the same duty as children but includes free floating 'text' nodes
jQuery.fn.extend({
offspring: function() {
return jQuery(
jQuery.map( this, function(n){
return jQuery.grep(n.childNodes, function(n) {
return n.nodeType == 1 || n.nodeType == 3;
});
})
);
@chicagoworks
chicagoworks / jqueryui-dialog-message.js
Created December 28, 2010 21:56
jQuery UI dialog extension to set the message body of the dialog similar to the way dialog title is set.
var __setOption = $.ui.dialog.prototype._setOption;
$.extend($.ui.dialog.prototype, {
_setOption : function (key, value) {
var self = this,
uiDialog = self.uiDialog;
if (key === 'message') {
self.element.html("" + (value || ' '));
}
__setOption.apply(self, arguments);
}
@chicagoworks
chicagoworks / jqueryui-tabs-activate.js
Created December 28, 2010 21:54
jQueryui tabs extension. $(el).tabs('activate', tab) is a mix of tabs('add') and tabs('select'). If the tab exists it is selected, if not it iis created. $(el).tabs(close) removes the tab but selects the tab to the left instead of the tab to the r
(function($) {
$.fn.extend($.ui.tabs.prototype, {
//use the same signature as add
activate : function(url, label, index) {
console.log(index)
var self = this,
index = index || self.anchors.length - 1;
//loop thru the tab.anchors collection and look for tab with a matching href
//If tab is local then compare the URL with the anchor or hash (eg #anchor5)
//If the tab is remote then compare the URL with .data('href.tabs')
@chicagoworks
chicagoworks / development-sidebar.html
Created December 28, 2010 13:49
Sidebar for firefox to help when developing sites, debugging code etc.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta http-equiv="expires" content="-1"/>
<meta http-equiv="pragma" content="no-cache"/>
<title>Scenario Runner</title>
<link href="/public/stylesheets/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
@chicagoworks
chicagoworks / rsa-encrypt-decrypt-roundtrip-test.asp
Created December 28, 2010 13:42
Port of the RSA algo to javascript and vb-script. Used to for low-level encryption on non-https site.
<%
REM: An excerpt from RSA Security site FAW "Is RSA patented?"
REM: http://www.rsasecurity.com/rsalabs/faq/6-3-1.html
REM: The patent for the RSA algorithm (U.S. Patent 4,405,829) was issued on September 20, 1983,
REM: exclusively licensed to RSA Security Inc. by the Massachusetts Institute of Technology,
REM: with an expiration date of September 20, 2000. RSA Security maintained a standard,
REM: royalty-based licensing policy that could be modified for special circumstances.
REM: In the U.S., a license has been needed to ëëmake, use or sellíí products that included
REM: the RSA algorithm. However, RSA Security has long allowed free non-commercial use of
REM: the RSA algorithm, with written permission, for academic or university research purposes.
@chicagoworks
chicagoworks / jQuery-hasEvent-test.html
Created December 28, 2010 13:31
jQuery plugin to check if elements have a given event. Updated to work with .live() and .delegate() events.
<body>
<div id="wrapper" class="great-grand-parent">
<div class="grand-parent">
<div class="parent">
<button id="foo" class="button">foo (click)</button>
<button id="bar" class="button">bar (live click)</button>
<button id="baz" class="button">baz (#wrapper delegate)</button>
</div>
@chicagoworks
chicagoworks / ie-fix-flicker.js
Created December 26, 2010 17:22
Fix flicker of background images in IE
//==== Fix flicker of background images in IE
//http://ajaxian.com/archives/no-more-ie6-background-flicker
//http://support.microsoft.com/?scid=kb;en-us;823727&spid=2073&sid=global
//http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=1&postId=1104
//Executes proprietary command to force IE to cache all background images which prevents the browser from fetching the same image repeatedly when using CSS hover background repositioning
if($.browser.msie && parseInt($.browser.version) === 6) {
try {
document.execCommand("BackgroundImageCache",false,true);
} catch(e) {
@chicagoworks
chicagoworks / array-prototype.js
Created December 26, 2010 17:09
Array object additions
//implement shift and unshift on Array prototype
//http://www.javascriptkit.com/javatutors/oopjs2.shtml
if(!Array.prototype.shift) { // if this method does not exist..
Array.prototype.shift = function(){
firstElement = this[0];
this.reverse();
this.length = Math.max(this.length-1,0);
this.reverse();
@chicagoworks
chicagoworks / string-prototype.js
Created December 26, 2010 17:08
String object additions
//==== General Enhancements to Javascript ===========================================================
// Replace repeated spaces, newlines and tabs with a single space
String.prototype.normalize = function() {return this.replace(/^\s*|\s(?=\s)|\s*$/g, "");}
//http://www.somacon.com/p355.php
//Trim: Strip leading and trailing white-space
//NOTE: can also use jQuery.trim
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
@chicagoworks
chicagoworks / window.location.query
Created December 25, 2010 16:00
load and parse querystring, then append to name/values to window.location.query
(function() {
var arr = decodeURIComponent(window.location.search.substr(1)).replace(/\+/g," ").split('&'), p;
window.location.query = {};
for (var i = 0; i < arr.length; i++) {
p = arr[i].split('=');
window.location.query[p[0]] = p[1];
}
})();