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 $E(tag, props) { | |
if (typeof props == 'string') | |
props = { style : props }; | |
if (typeof tag == 'string') { | |
var id = tag.match(/#([\w-]+)/); | |
var classes = tag.match(/(?:\.[\w-]+)+/); | |
tag = tag.replace(/[#.].*/, ''); | |
props = props || {}; | |
if (id) props.id = id[1]; | |
if (classes) props['class'] = classes[0].replace(/\./g, ' '); |
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
Native.implement([Element, Window, Document, Events], { | |
oneEvent : function(type, fn) { | |
return this.addEvent(type, function() { | |
this.removeEvent(type, arguments.callee); | |
return fn.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
Element.Events.clickout = { | |
base : 'click', | |
condition : function(event){ | |
event.stopPropagation(); // stop event bubbling to the body | |
return false; // never run handler when clicking on element | |
}, | |
onAdd : function(fn){ | |
this.getDocument().addEvent('click', fn); | |
}, | |
onRemove : function(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
Class.Mutators.BindAll = function(self, bool) { | |
if (!bool) return self; | |
var init = self.initialize; | |
var exclude = arguments.callee.exclude; | |
self.initialize = function() { | |
for (var method in this) { | |
if (typeof this[method] != 'function' || exclude.contains(method)) | |
continue; |
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
Class.Initializers = {}; | |
Class.Mutators.initialize = function(initialize){ | |
return function(){ | |
this._init_ = initialize; | |
for (var modifier in Class.Initializers) { | |
if (!this[modifier]) continue; | |
this[modifier] = Class.Initializers[modifier].call(this, this[modifier]); |
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' | |
}, |
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
// 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
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
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 }; |
OlderNewer