Created
September 28, 2012 21:35
-
-
Save joelpurra/3802197 to your computer and use it in GitHub Desktop.
Overriding $.publish() to capture the event for logging purposes. For use with jQuery pub/sub plugin by Peter Higgins.
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
/*! | |
* @license PubSubLogging | |
* Copyright © 2012 Joel Purra <http://joelpurra.se/> | |
* Released under MIT, BSD and GPL license. Comply with at least one. | |
* | |
* Overriding $.publish() to capture the event for logging purposes. | |
* | |
* For use with jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org) | |
* http://higginsforpresident.net/ | |
* https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js | |
* | |
* Usage: | |
* PubSubLogging.start(); | |
* PubSubLogging.stop(); | |
*/ | |
// | |
// https://gist.github.com/3802197 | |
// | |
/*jslint white: true, browser: true*/ | |
/*global jQuery, console*/ | |
var JoelPurra = JoelPurra || {}; | |
(function (namespace, $, console) { | |
namespace.PubSubLogging = namespace.PubSubLogging || {}; | |
var ns = namespace.PubSubLogging, | |
original = $.publish, | |
overridden = function (topic, args) { | |
console.log("$.publish", topic, args); | |
original.call($, topic, args); | |
}; | |
ns.stop = function () { | |
$.publish = original; | |
}; | |
ns.start = function () { | |
$.publish = overridden; | |
}; | |
} (JoelPurra, jQuery, console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment