Revisions
-
isao revised this gist
Apr 21, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * (removed pre 1.4.3 support, added $.pubsubdebug()) */ (function($){ -
isao revised this gist
Apr 21, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * (removed pre 1.4.3 support, add $.pubsubdebug()) */ (function($){ -
isao revised this gist
Apr 21, 2011 . 2 changed files with 22 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,48 +1,52 @@ /*! * jQuery Tiny Pub/Sub - v0.6 - 1/10/2011 * http://benalman.com/ see https://gist.github.com/661855 * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * (tweaked to remove pre 1.4.3 support, add $.pubsubdebug()) */ (function($){ // object on which to bind, unbind and trigger handlers. reqs jQuery 1.4.3+ var o = $({}); // Subscribe to a topic. Works just like bind, except the passed handler // is wrapped in a function so that the event object can be stripped out. // Even though the event object might be useful, it is unnecessary and // will only complicate things in the future should the user decide to move // to a non-$.event-based pub/sub implementation. $.subscribe = function(topic, fn) { // Call fn, stripping out the 1st argument (the event object) function wrapper() { return fn.apply(this, Array.prototype.slice.call(arguments, 1)); } // Add .guid property to function to allow it to be easily unbound // reqs jQuery 1.4+ wrapper.guid = fn.guid = fn.guid || $.guid++; // Bind the handler. o.bind(topic, wrapper); }; // Unsubscribe from a topic. Works exactly like unbind $.unsubscribe = function() { o.unbind.apply(o, arguments); }; // Publish a topic. Works exactly like trigger $.publish = function() { o.trigger.apply(o, arguments); }; // for debugging $.pubsubdebug = function() { return o; }; })(jQuery); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +0,0 @@ -
cowboy revised this gist
Jan 10, 2011 . 2 changed files with 24 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /*! * jQuery Tiny Pub/Sub - v0.6 - 1/10/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -9,22 +9,38 @@ (function($){ // Create a "dummy" jQuery object on which to bind, unbind and trigger event // handlers. Note that $({}) works in jQuery 1.4.3+, but because .unbind on // a "plain object" throws errors in older versions of jQuery, an element is // used here. var o = $('<b/>'); // Subscribe to a topic. Works just like bind, except the passed handler // is wrapped in a function so that the event object can be stripped out. // Even though the event object might be useful, it is unnecessary and // will only complicate things in the future should the user decide to move // to a non-$.event-based pub/sub implementation. $.subscribe = function( topic, fn ) { // Call fn, stripping out the 1st argument (the event object). function wrapper() { return fn.apply( this, Array.prototype.slice.call( arguments, 1 ) ); } // Add .guid property to function to allow it to be easily unbound. Note // that $.guid is new in jQuery 1.4+, and $.event.guid was used before. wrapper.guid = fn.guid = fn.guid || ( $.guid ? $.guid++ : $.event.guid++ ); // Bind the handler. o.bind( topic, wrapper ); }; // Unsubscribe from a topic. Works exactly like unbind. $.unsubscribe = function() { o.unbind.apply( o, arguments ); }; // Publish a topic. Works exactly like trigger. $.publish = function() { o.trigger.apply( o, arguments ); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ /* * jQuery Tiny Pub/Sub - v0.6 - 1/10/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){var a=$("<b/>");$.subscribe=function(b,c){function d(){return c.apply(this,Array.prototype.slice.call(arguments,1))}d.guid=c.guid=c.guid||($.guid?$.guid++:$.event.guid++);a.bind(b,d)};$.unsubscribe=function(){a.unbind.apply(a,arguments)};$.publish=function(){a.trigger.apply(a,arguments)}})(jQuery); -
cowboy revised this gist
Jan 10, 2011 . 2 changed files with 8 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /*! * jQuery Tiny Pub/Sub - v0.5 - 1/9/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -11,19 +11,14 @@ var o = $({}); $.subscribe = function( topic, fn ) { function handle() { return fn.apply( this, Array.prototype.slice.call( arguments, 1 ) ); } handle.guid = fn.guid = fn.guid || handle.guid || $.guid++; o.bind( topic, handle ); }; $.unsubscribe = function() { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ /* * jQuery Tiny Pub/Sub - v0.5 - 1/9/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){var o=$({});$.subscribe=function(topic,fn){function handle(){return fn.apply(this,Array.prototype.slice.call(arguments,1))}handle.guid=fn.guid=fn.guid||handle.guid||$.guid++;o.bind(topic,handle)};$.unsubscribe=function(){o.unbind.apply(o,arguments)};$.publish=function(){o.trigger.apply(o,arguments)}})(jQuery); -
cowboy revised this gist
Jan 10, 2011 . 2 changed files with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ }; $.unsubscribe = function() { o.unbind.apply( o, arguments ); }; $.publish = function() { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ /* * jQuery Tiny Pub/Sub - v0.4 - 1/4/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){var o=$({});$.subscribe=function(type,data,fn){if($.isFunction(data)||data===false){fn=data;data=undefined}function proxy(){return fn.apply(this,Array.prototype.slice.call(arguments,1))}proxy.guid=fn.guid=fn.guid||proxy.guid||$.guid++;o.bind(type,data,proxy)};$.unsubscribe=function(){o.unbind.apply(o,arguments)};$.publish=function(){o.trigger.apply(o,arguments)}})(jQuery); -
cowboy revised this gist
Jan 5, 2011 . 1 changed file with 22 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,37 @@ /*! * jQuery Tiny Pub/Sub - v0.4 - 1/4/2011 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){ var o = $({}); $.subscribe = function( type, data, fn ) { if ( $.isFunction( data ) || data === false ) { fn = data; data = undefined; } function proxy() { return fn.apply( this, Array.prototype.slice.call( arguments, 1 ) ); }; proxy.guid = fn.guid = fn.guid || proxy.guid || $.guid++; o.bind( type, data, proxy ); }; $.unsubscribe = function() { o.unbind.apply( o, arguments ); // Seems to be broken in jQuery 1.4.4 (?) }; $.publish = function() { o.trigger.apply( o, arguments ); }; })(jQuery); -
cowboy revised this gist
Nov 15, 2010 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /*! * jQuery Tiny Pub/Sub - v0.3 - 11/4/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -11,15 +11,15 @@ var o = $({}); $.subscribe = function() { o.bind.apply( o, arguments ); }; $.unsubscribe = function() { o.unbind.apply( o, arguments ); }; $.publish = function() { o.trigger.apply( o, arguments ); }; -
cowboy revised this gist
Nov 4, 2010 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /*! * jQuery Tiny Pub/Sub - v0.3pre - 11/4/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -9,18 +9,18 @@ (function($){ var o = $({}); $.subscribe = function(){ o.bind.apply( o, arguments ); }; $.unsubscribe = function(){ o.unbind.apply( o, arguments ); }; $.publish = function(){ o.trigger.apply( o, arguments ); }; })(jQuery); -
cowboy revised this gist
Nov 3, 2010 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /*! * jQuery Tiny Pub/Sub - v0.2pre - 11/3/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman @@ -15,12 +15,12 @@ w.bind.apply( w, arguments ); }; $.unsubscribe = function(){ w.unbind.apply( w, arguments ); }; $.publish = function(){ w.trigger.apply( w, arguments ); }; })(jQuery); -
cowboy created this gist
Nov 3, 2010 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ /*! * jQuery Tiny Pub/Sub - v0.1pre - 11/3/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){ var w = $(window); $.subscribe = function(){ w.bind.apply( w, arguments ); }; $.publish = function(){ w.trigger.apply( w, arguments ); }; $.unpublish = function(){ w.unbind.apply( w, arguments ); }; })(jQuery);