Skip to content

Instantly share code, notes, and snippets.

@joecritch
Created April 19, 2011 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joecritch/929505 to your computer and use it in GitHub Desktop.
Save joecritch/929505 to your computer and use it in GitHub Desktop.
Callbacks
// 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