Created
August 28, 2009 14:59
-
-
Save zholmquist/177016 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
/* | |
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