Skip to content

Instantly share code, notes, and snippets.

View appden's full-sized avatar

Scott Kyle appden

View GitHub Profile
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]);
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;
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){
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);
});
}
});
/*
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, ' ');