This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ensureArray = function(obj) { | |
return (obj instanceof Array) ? obj : (typeof obj !== 'undefined') ? [obj] : []; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery plugin Textmate snippet | |
(function (\$) { | |
/** | |
* ${10:plugin} | |
*/ | |
\$.fn.${10:plugin} = function(cfg) { | |
if (this.length === 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stress (fn /*, n */) { | |
var n = arguments[1] || 1000, | |
i, t, | |
s = new Date(); | |
for (i = 0; i < n; i++) { | |
fn(); | |
}; | |
t = ((new Date()) - s); | |
return { | |
handler: fn, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty strings are truthy-falsy... | |
var EMPTY = ""; | |
EMPTY == true; // false | |
EMPTY == false; // true | |
// ...but non-empty strings are NOT. | |
var NON_EMPTY = "hello, world"; | |
NON_EMPTY == true; // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.useJsonpCallback = (jQuery.support.jsonpCallback = parseFloat(jQuery.fn.jquery) >= 1.4) ? jQuery.noop : function () { | |
var cfg = this, jsonp = cfg.dataType === 'script' && cfg.jsonpCallback; | |
if (jsonp && !window[jsonp]) { | |
window[jsonp] = function (data) { | |
cfg.success.call(cfg, data, 'success'); | |
try { | |
delete window[jsonp]; | |
} catch (ie6) { | |
// cannot delete window properties in IE6 | |
window[jsonp] = undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// punch | |
jQuery.punch = function (obj, method, fn) { | |
var hasOwnMethod = obj.hasOwnProperty(method), | |
original = obj[method]; | |
obj[method] = function () { | |
Array.prototype.unshift.call(arguments, $.proxy(original, this)); | |
return fn.apply(this, arguments); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// everyone's new favorite closure pattern: | |
(function(window,document,undefined){ ... })(this,this.document); | |
// minified: | |
(function(b,a,c){ ... })(this,this.document); | |
// which means all uses of window/document/undefined inside the closure | |
// will be single-lettered, so big gains in minification. | |
// it also will speed up scope chain traversal a tiny tiny little bit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.expando = (function (re) { | |
return function () { | |
var prop, elem = this.get(0); | |
for (prop in elem) { | |
if (re.test(prop)) { | |
return elem[prop]; | |
} | |
} | |
}; | |
})(/^jQuery\d{13}$/); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
/** | |
* Add live and die to the jQuery root | |
*/ | |
$.extend({ | |
live: function( selector, type, data, fn, thisObject ) { | |
if ( jQuery.isFunction( data ) ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.hoverClass = function(className) { | |
return this.each(function() { | |
var $this = $(this); | |
$this.hover(function() { | |
$this.addClass(className); | |
}, function() { | |
$this.removeClass(className); | |
}); | |
}); | |
}; |