Created
May 13, 2009 19:24
-
-
Save ncr/111231 to your computer and use it in GitHub Desktop.
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($){ | |
$.fn.button = function(){ | |
return this.each(function(){ | |
var e = $(this) | |
e.bind("on", function(on_event){ | |
e.trigger("before_on", on_event) | |
if(!on_event.isImmediatePropagationStopped()){ | |
if(!e.data("on")){ | |
e.data("on", true) | |
e.trigger("toggle", {from: false, to: true}) | |
} | |
} | |
return false | |
}).click(function(){ | |
e.trigger("on") | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function($){ | |
$.fn.toggle_button = function(){ | |
return this.each(function(){ | |
var e = $(this) | |
e.bind("on", function(on_event){ | |
e.trigger("before_on", on_event) | |
if(!on_event.isImmediatePropagationStopped()){ | |
if(!e.data("on")){ | |
e.data("on", true) | |
e.trigger("toggle", {from: false, to: true}) | |
} | |
} | |
return false | |
}).bind("off", function(){ | |
if(e.data("on")){ | |
e.data("on", false) | |
e.trigger("toggle", {from: true, to: false}) | |
} | |
return false | |
}).click(function(){ | |
if(e.data("on")){ | |
e.trigger("off") | |
} else { | |
e.trigger("on") | |
} | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function($){ | |
$.fn.exclusive = function(){ | |
var els = this | |
return this.each(function(){ | |
var e = $(this) | |
e.bind("on", function(){ | |
els.not(e).trigger("off") | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function($){ | |
$.fn.box = function(klass){ | |
return this.each(function(){ | |
var e = $(this) | |
e.bind("on", function(){ | |
e.show() | |
return false | |
}).bind("off", function(){ | |
e.find("> ." + klass).trigger("off") | |
e.hide() | |
return false | |
}).addClass(klass) | |
}) | |
} | |
})(jQuery); | |
(function($){ | |
$.fn.cache = function(callback){ | |
return this.each(function(){ | |
var e = $(this) | |
e.bind("init", function(){ | |
e.data("cached", true) | |
callback() | |
return false | |
}).bind("invalidate", function(){ | |
e.data("cached", false) | |
return false | |
}).bind("on", function(){ | |
if(!e.data("cached")) { | |
e.trigger("init") | |
} | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function($){ | |
$.fn.join_handlers = function(event_types){ | |
var els = this | |
return this.each(function(i){ | |
var e = $(this) | |
$.each(event_types.split(/\s+/), function(ignored, event_type){ | |
e.bind(event_type, function(ignored, first){ | |
var next = els[i + 1] || els[0] | |
if(first) { | |
if(first != next) { | |
$(next).trigger(event_type, first) | |
} | |
} else { | |
$(next).trigger(event_type, e.context) | |
} | |
return false | |
}) | |
}) | |
}) | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment