The user can provide a JSON object to configure the plugin when they initialise it. I want those options to be available whenever a plugin action is performed.
I have read the plugin documentation but I'd like to get confirmation that I am going about this the right way.
Plugin is initialised with:
$(selector).hide_and_peek("init", {options:here});
And individual methods may be called with:
$(selector).hide_and_peek("action", {options:here});
Here's the plugin definition:
(function( $ ) {
// Plugin definition.
$.fn.hide_and_peek = function(action, options ) {
//define plugin defaults.
$.fn.hide_and_peek.defaults = {
peek_offset: -10,
peek_position: "bottom",
default_shown: true,
peek_show_duration:1000,
peek_hide_duration:1000,
center: true
};
//check to see if options are provided and extend if required.
$.fn.hide_and_peek.custom = function(){
if(typeof options === "undefined"){
return $.fn.hide_and_peek.custom;
}else{
return $.fn.extend($.fn.hide_and_peek.custom,options);
}
}();
//merge defaults and custom options
var oOptions = $.fn.extend({}, $.fn.hide_and_peek.defaults, $.fn.hide_and_peek.custom);
// *snip* Plugin implementation
})( jQuery );