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
Element.implement({ | |
// truncates element text to fit its width | |
truncate: function(trail){ | |
var text = this.get('text').trim(); | |
if (!text) return; | |
trail = trail || '...'; | |
var style = this.style; | |
var styles = { overflow: style.overflow, 'white-space': style.whiteSpace, padding: style.padding, margin: style.margin }; |
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
// 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 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
<!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 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.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 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
Class.Mutators.jQuery = function(name){ | |
var self = this; | |
jQuery.fn[name] = function(arg){ | |
var instance = this.data(name); | |
if ($type(arg) == 'string'){ | |
var prop = instance[arg]; | |
if ($type(prop) == 'function'){ | |
var returns = prop.apply(instance, Array.slice(arguments, 1)); | |
return (returns == instance) ? this : returns; | |
} else if (arguments.length == 1){ |