Skip to content

Instantly share code, notes, and snippets.

@felipeg48
Forked from zaus/jquery.tinierpubsub.js
Created August 29, 2014 20:43
Show Gist options
  • Save felipeg48/a3f52747b09076868da9 to your computer and use it in GitHub Desktop.
Save felipeg48/a3f52747b09076868da9 to your computer and use it in GitHub Desktop.
/* jQuery Tinier Pub/Sub - v0.9 - 2013-02-11
* original by http://benalman.com/ 10/27/2011
* Original Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
// "topic" holder
var o = $({}); // use $('<b>') with Zepto, as it doesn't like {} ?
// attach each alias method
$.each(['on','off','trigger'], function(i,method) {
$[method] = function(topic, callbackOrArgs) {
o[method].apply(o, arguments);
}
});
}(jQuery));

Fork and "simplification" of jQuery Tiny Pubsub. Two alternate versions -- one with my preferred "on/off/go" syntax, the other with jQuery-standard "on/off/trigger".

Update: do is a reserved keyword, and even though it's a property it still chokes <IE9.

See testing at jsfiddle.

See original Tiny Pubsub by Ben Alman: gist repo.

/* jQuery Tinier Pub/Sub - v0.9b - @see https://gist.github.com/zaus/4756518 */
(function(e){var t=e({});e.each({on:0,off:0,"go":"trigger"},function(n,r){e[n]=function(e,i){t[r||n].apply(t,arguments)}})})(jQuery)
/* jQuery Tinier Pub/Sub - v0.9b - "on/off/do version" - 2013-02-11
* original by http://benalman.com/ 10/27/2011
* Original Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
// "topic" holder
var o = $({}); // use $('<b>') with Zepto, as it doesn't like {} ?
// attach each alias method
$.each({on:0,off:0,go:'trigger'}, function(alias,method) {
$[alias] = function(topic, callbackOrArgs) {
o[method || alias].apply(o, arguments);
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment