Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $('#test').click(function(e) {
- alert('test');
- var events = $('#test').data("events");
- $('#test').unbind('click', events.click[0]);
- });
- });
- <a id="test">test</a>
- var ary_handlers = [ fn_highlight, fn_onpress, fn_cleanup ];
- for ( idx = 0; idx < ary_handlers.length; idx++ ){
- $('#test').bind('click.foobar',ary_handlers[idx]);
- }
- // and then later:
- $('#test').unbind('.foobar');
- var ary_handlers = [ fn_highlight, fn_onpress, fn_cleanup ];
- for ( idx = 0; idx < ary_handlers.length; idx++ ){
- $('#test').bind('click.ns_' + String(idx), ary_handlers[idx]);
- }
- // and then later you could pick off a specific one to unbind
- $('#test').unbind('.ns_2');
- (function($){
- function obj_copy(obj){
- var out = {};
- for (i in obj) {
- if (typeof obj[i] == 'object') {
- out[i] = this.copy(obj[i]);
- }
- else
- out[i] = obj[i];
- }
- return out;
- }
- $.fn.extend({
- storeEvents:function(){
- this.each(function(){
- $.data(this,'storedEvents',obj_copy($(this).data('events')));
- });
- return this;
- },
- restoreEvents:function(){
- this.each(function(){
- var events = $.data(this,'storedEvents');
- if (events){
- $(this).unbind();
- for (var type in events){
- for (var handler in events[type]){
- $.event.add(
- this,
- type,
- events[type][handler],
- events[type][handler].data);
- }
- }
- }
- });
- return this;
- }
- });
- })(jQuery);
Add Comment
Please, Sign In to add comment