Reputation: 6812
I'm using sidr, a jQuery plugin for sliding in side menus. It offers a couple of public methods, and I want to extend it with a "destroy" method, which would remove the instance of the plugin.
I want to be able to call $.sidr('destroy', mySidrInstance)
just as I already can call $.sidr('open', mySidrInstance)
Here are the public methods
// Sidr public methods
var methods = {
open: function(name, callback) {
privateMethods.execute('open', name, callback);
},
close: function(name, callback) {
privateMethods.execute('close', name, callback);
},
toggle: function(name, callback) {
privateMethods.execute('toggle', name, callback);
},
destroy: function() {
// I want to create this. What should I write here?
}
};
$.sidr = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
}
else if ( typeof method === 'function' || typeof method === 'string' || ! method ) {
return methods.toggle.apply( this, arguments );
}
else {
$.error( 'Method ' + method + ' does not exist on jQuery.sidr' );
}
};
Upvotes: 1
Views: 1578