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
/* | |
* A simple JavaScript inheritance system | |
* (Like Prototype's `Class.create()`, only without the crazy method wrapping and function decompilation) | |
* | |
* Usage | |
* var A = Class.create({ | |
* // `$init` is the constructor | |
* $init: function(x, y) { | |
* this.x = x; | |
* this.y = y; |
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-Resizing Textareas (jQuery v1.7+) | |
* Based on: http://phaistonian.pblogs.gr/expanding-textareas-the-easy-and-clean-way.html | |
* | |
* Usage: | |
* // Direct binding | |
* $("textarea").autoResize(); | |
* | |
* // Delegated binding | |
* $.autoResize("textarea"); |
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
/** | |
* underscore.js mixin to create an arguments signature | |
* | |
* Usage: | |
* switch(_.signature(arguments)) { | |
* case "*": | |
* ... | |
* case "object": | |
* case "object *": | |
* ... |
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(replace) { | |
var escape = [/[\-\[\]\/\\{}()*+?.^$|]/g, '\\$&']; | |
RegExp.Safe = function(pattern, flags) { | |
return new RegExp(replace.apply(String(pattern), escape), flags); | |
} | |
}(String.prototype.replace)); |
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() { | |
function extendPrototype(Obj) { | |
return function(method, fn) { | |
if (!(method in Obj.prototype)) Obj.prototype[method] = _.isFunction(fn) ? fn : function() { | |
return _[method].apply(null, [this].concat(_.toArray(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
// deparam | |
// | |
// Inverse of $.param() | |
// | |
// Taken from jquery-bbq by Ben Alman | |
// https://github.com/cowboy/jquery-bbq/blob/master/jquery.ba-bbq.js | |
var isArray = Array.isArray || function(obj) { | |
return Object.prototype.toString.call(obj) == '[object 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
// 1234567890 => "1,234,567,890" | |
function formatNumber(n) { | |
var a = [], s = String(n), i = l = s.length; | |
while (i--) a.push(s[i]), i && (l - i) % 3 === 0 && a.push(","); | |
return a.reverse().join(""); | |
} |
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
Object.defineProperty(Object, "extend", { | |
enumerable: false, | |
value: function extend(obj) { | |
Array.prototype.slice.call(arguments, 1).forEach(function(current) { | |
Object.getOwnPropertyNames(current).forEach(function(key) { | |
Object.defineProperty(obj, key, Object.getOwnPropertyDescriptor(current, key)); | |
}); | |
}); | |
return obj; | |
} |
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
var encodeImage = (function() { | |
var DEFAULT_IMAGE = 'data:image/png;base64,', | |
prefix = "_", | |
cache = {}; | |
function encode(url, callback) { | |
var key = prefix + url, value = cache[key]; | |
if (value) { | |
callback(value); | |
} else { |
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
var shadowWrap = (function() { | |
var createShadowRoot = Element.prototype.createShadowRoot || Element.prototype.webkitCreateShadowRoot; | |
function createWrapper(content) { | |
var wrapper = document.createElement("shadow-wrap"); | |
var shadowRoot = createShadowRoot.call(wrapper); | |
wrapper.resetStyleInheritance = true; | |
switch (typeof content) { | |
case "string": |
OlderNewer