Created
November 24, 2012 20:15
-
-
Save estevesd/4141249 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
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
| /*! | |
| * PLUGIN_NAME v@PLUGIN_VERSION | |
| * PLUGIN_SITE_PATH | |
| * PLUGIN_REPO_PATH | |
| * | |
| * Copyright 2012 | |
| * Released under the MIT license. | |
| * PLUGIN_LICENSE_PATH | |
| * | |
| * Date: @PLUGIN_DATE | |
| */ | |
| (function( $ ){ | |
| window.PLUGIN_NAME = {}; | |
| PLUGIN_NAME.settings = { | |
| debug: false | |
| } | |
| var methods = { | |
| init : function( options ) { | |
| settings = $.extend(PLUGIN_NAME.settings, options); | |
| debug('GOING TO INIT', this, settings); | |
| return this.each(function() { | |
| debug('INIT', this, settings) | |
| }); | |
| }, | |
| destroy : function () { | |
| return this.each(function(){ | |
| debug('DESTROY PLUGIN_NAME', this); | |
| }) | |
| } | |
| }, | |
| debug = function () { | |
| var output = false, | |
| lastArgument = arguments[arguments.length - 1]; | |
| if ( typeof lastArgument === 'object' && lastArgument.tmpl) { | |
| output = lastArgument.debug; | |
| } else { | |
| output = PLUGIN_NAME.settings.debug; | |
| } | |
| if (output) console.log.apply(console, arguments); | |
| }; | |
| $.fn.PLUGIN_NAME = 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.PLUGIN_NAME' ); | |
| } | |
| }; | |
| })( jQuery ); | |
| // // Set global settings | |
| // PLUGIN_NAME.settings = {...}; | |
| // PLUGIN_NAME.settings.debug = true; | |
| // // Call the init method | |
| // $('div').PLUGIN_NAME()); | |
| // // Call the init method with options | |
| // $('div').PLUGIN_NAME({ | |
| // foo : true | |
| // }); | |
| // // Destroy functionality | |
| // $('div').PLUGIN_NAME('destroy'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment