Created
April 19, 2011 20:13
-
-
Save joecritch/929505 to your computer and use it in GitHub Desktop.
Callbacks
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
// add a "fire" variable, below the self variable, that will cover both the current instance and the root variable. | |
var self = this, | |
fire = root.add(self); | |
///////////////////////// | |
// then insert calls to the custom functions in all the necessary places, e.g. in the slide function -- | |
$.extend(self, { | |
slide: function(where) { | |
// Trigger the callback. You can also pass custom data into trigger events. Very useful for callbacks. | |
fire.trigger("onSlide", [where]); | |
} | |
}); | |
///////////////////////// | |
// callbacks -- add these after you extend self with your public methods. | |
$.each(['onSlide', 'anotherCallback', 'yetAnotherCallback'], function(i, name) { | |
// configuration | |
if ($.isFunction(conf[name])) { | |
$(self).bind(name, conf[name]); | |
} | |
self[name] = function(fn) { | |
if (fn) { $(self).bind(name, fn); } | |
return self; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment