This file contains 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
// Array shuffle for MooTools | |
Array.implement({ | |
// don't remember where I saw this one-liner first... | |
shuffle: function(){ | |
for (var j, x, i = this.length; i; j = Math.floor(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x); | |
return this; | |
} |
This file contains 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 overloading based on the type of the first argument | |
Function.prototype.overload = function(types, pick){ | |
var self = this; | |
return function(){ | |
var type = (pick || typeOf).apply(this, arguments); | |
return (type && types[type] || self).apply(this, arguments); | |
}; | |
}; |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html;charset=utf-8"/> | |
<!-- Online here: http://ejohn.org/files/bugs/isObjectLiteral/ --> | |
<title>isObjectLiteral</title> | |
<style> | |
li { background: green; } li.FAIL { background: red; } | |
iframe { display: none; } | |
</style> |
This file contains 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
// add chrome to jQuery browser test | |
if ((jQuery.browser.chrome = /chrome/i.test(navigator.userAgent)) | |
jQuery.browser.version = navigator.userAgent.match(/chrome\/(\d+)/i)[1]; | |
// alternative I just thought of... | |
if (/chrome\/(\d+)/i.exec(navigator.userAgent)){ | |
jQuery.browser.chrome = true; | |
jQuery.browser.version = RegExp.$1; | |
} |
This file contains 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
// Static mutator to accept static methods to a Class | |
Class.Mutators.Static = function(methods){ | |
this.extend(methods); | |
}; |
This file contains 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
// adds in support for having just msxml.dll, see issue #739 on -core | |
Browser.Request = function(){ | |
return $try(function(){ | |
return new XMLHttpRequest(); | |
}, function(){ | |
return new ActiveXObject('MSXML2.XMLHTTP'); | |
}, function(){ | |
return new ActiveXObject('Microsoft.XMLHTTP'); | |
}); |
This file contains 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
// set the class of a jQuery collection | |
jQuery.fn.setClass = function(className){ | |
return this.each(function(){ | |
this.className = className || ''; | |
}); | |
}; |
This file contains 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
Request.Twitter = new Class({ | |
Extends: Request.JSONP, | |
options: { | |
linkify: true, | |
url: 'http://twitter.com/statuses/user_timeline/{term}.json', | |
data: { | |
count: 5 | |
} |
This file contains 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.stab(function(){ | |
Array.from(document.html.childNodes); | |
}, function(){ | |
var old = Array.from; | |
Array.from = function(item, slice){ | |
if (typeOf(item) == 'collection'){ | |
var l = item.length, array = new Array(l - slice), i = slice; | |
while (i++ < l) array[i - slice] = item[i]; | |
return array; | |
} |
This file contains 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
// Puncture a closure, absolute madness | |
Function.prototype.puncture = function(){ | |
var wormhole = function(__cmd__){ | |
return eval(__cmd__); | |
}; | |
var source = ('' + this).match(/function.+?\{([\s\S]*)\}/)[1]; | |
var fn = new Function('this.wormhole=' + wormhole + '\n' + source); |