Extending a jquery plugins event callback

Posted by Greg J on Stack Overflow See other posts from Stack Overflow or by Greg J
Published on 2012-04-09T23:25:56Z Indexed on 2012/04/09 23:29 UTC
Read the original article Hit count: 268

I'm extending the functionality of a jquery plugin (foo) with another jquery plugin (bar).

Essentially, the first plugin specifies an onReady():

var foo = $.foo({ onReady: function() { alert('foo'); }});

Foo is sent to bar as a parameter to bar:

var bar = $.bar(foo);

I want bar to be able to hook into foo's onReady event:

(function($) {
  $.extend({
    bar: function(foo) {
      var foo = foo;
      // How to do alert('bar') when foo.onready is called?
    }
  });
})(jQuery);

I can override foo's onready event:

foo.onready = function() { alert('bar'); }

But I don't want to override it, I want to extend it so that I'll see both alerts when foo is ready.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-plugins