Created
August 4, 2012 04:10
-
-
Save JawsomeJason/3254344 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
This file contains hidden or 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
"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