Skip to content

Instantly share code, notes, and snippets.

@JawsomeJason
Created August 4, 2012 04:10
Show Gist options
  • Save JawsomeJason/3254344 to your computer and use it in GitHub Desktop.
Save JawsomeJason/3254344 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
"use strict";
/* boilerplate from: http://stefangabos.ro/jquery/jquery-plugin-boilerplate/ */
( function( $ ) {
$.fn.pluginName = function( method ) {
var methods = {
// constructor
init : function( options ) {
this.pluginName.settings = $.extend({}, this.pluginName.defaults, options);
return this.each( function() {
var $element = $(this),
element = this;
// code goes here
} );
}/*,
// public methods called via $.fn.pluginName( "method_name" [, argument]* )
foo_public_method: function() {
// code goes here
}
*/
}
var helpers = {
/* private helpers */
};
if ( methods[ method ] && method !== "init" ) {
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 in pluginName plugin!' );
}
};
// global defaults
$.fn.pluginName.defaults = {};
// global settings
$.fn.pluginName.settings = {};
} )( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment