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
// 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
<!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
// 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
// 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
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 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
String.implement({ | |
truncate: function(max, trail, separator){ | |
var s = this.trim(); | |
if (s.length <= max) return s; | |
separator = $pick(separator, ' '); | |
if (separator) | |
s = s.substr(0, max + 1).substr(0, s.lastIndexOf(separator)); | |
else | |
s = s.substr(0, max); |
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
// inspired by jQuery watch: http://plugins.jquery.com/files/jquery-watch.js.txt | |
(function(){ | |
var watch = Object.prototype.watch, | |
unwatch = Object.prototype.unwatch, | |
watched = [], | |
timer; | |
Object.watch = function(obj, prop, fn){ |
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 BINDING | |
Function.prototype.bind = function(bind, args){ | |
var self = this.unbind(); | |
if (args != null) args = $splat(args); | |
var fn = function(){ | |
return self.apply(bind, args || 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
// Auto-updating Date stuff | |
Date.pretty = new Class({ | |
Implements: Options, | |
options: { | |
interval: 60000, | |
threshold: '24 hours' | |
}, |