Skip to content

Instantly share code, notes, and snippets.

View appden's full-sized avatar

Scott Kyle appden

View GitHub Profile
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){
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;
}
<!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>
// 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;
}
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 };