Skip to content

Instantly share code, notes, and snippets.

@joelpurra
Created September 28, 2012 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelpurra/3802197 to your computer and use it in GitHub Desktop.
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.
/*!
* @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