Skip to content

Instantly share code, notes, and snippets.

@bsnux
Created February 5, 2013 10:33
Show Gist options
  • Save bsnux/4713599 to your computer and use it in GitHub Desktop.
Save bsnux/4713599 to your computer and use it in GitHub Desktop.
Simple skeleton for creating a jQuery plugin
(function( $ ){
/* Global variables for the plugin */
var defaults = {
timeout: 15
};
var settings = {};
var form;
/* Private method */
function deleteLocalStorage(form) {
}
/* Event handlers */
var eventHandlers = {
submit: function(e) {
}
};
/* Public methods */
var methods = {
init : function(options) {
// Binding events
$(this).bind('submit', eventHandlers.submit);
},
getDatafromLocal : function() {
},
clean: function() {
}
};
$.fn.pluginName = function(method) {
if (methods[method]) {
return methods[method].apply( this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.pluginName' );
}
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment