Skip to content

Instantly share code, notes, and snippets.

@zholmquist
Created August 28, 2009 14:59
Show Gist options
  • Save zholmquist/177016 to your computer and use it in GitHub Desktop.
Save zholmquist/177016 to your computer and use it in GitHub Desktop.
/*
jQuery publish/subscribe by Mark Meyer
- http://markdotmeyer.blogspot.com/2008/09/jquery-publish-subscribe.html
jQuery unsubscribe by Zach Holmquist
*/
jQuery.subscribe = function( eventName, obj, method ){
$(window).bind( eventName, function() {
obj[method].apply( obj, Array.prototype.slice.call( arguments, 1 ) );
});
return jQuery;
}
jQuery.publish = function(eventName){
$( window ).trigger( eventName, Array.prototype.slice.call( arguments, 1 ) );
return jQuery;
}
jQuery.unsubscribe = function( eventName ){
$(window).unbind( eventName );
return jQuery;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment