Created
February 5, 2013 10:33
-
-
Save bsnux/4713599 to your computer and use it in GitHub Desktop.
Simple skeleton for creating a jQuery plugin
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
(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