Created
May 7, 2013 16:40
-
-
Save garystorey/5534087 to your computer and use it in GitHub Desktop.
A basic setup for a jQuery plugin
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
| //PLUGINNAME === Pluginname (UpperCase first letter) | |
| //PLUGIN === pluginname (all lowercase) | |
| var PLUGINNAME = function( $elm, options ) { | |
| this.debug = false; | |
| this.$el = $elm; | |
| this.options = jQuery.extend( true, {}, $.fn.PLUGIN.defaults, options ); | |
| this.$el.data('PLUGINNAME', this); | |
| }; | |
| PLUGINNAME.prototype = { | |
| init : function () { }, | |
| destroy : function () { } | |
| }; | |
| jQuery.fn.PLUGIN = function( options ){ | |
| if ( typeof options !== 'string' ) { | |
| return this.each( function () { | |
| var obj = new PLUGINNAME( jQuery( this ), options ); | |
| obj.init(); | |
| }); | |
| } else { | |
| PLUGINNAME = $(this).data('PLUGINNAME'); | |
| if ( PLUGINNAME !== null ) { | |
| switch( options ) { | |
| case 'init': | |
| PLUGINNAME.init(); | |
| break; | |
| case 'destroy': | |
| PLUGINNAME.destroy(); | |
| break; | |
| } | |
| } | |
| } | |
| }; | |
| jQuery.fn.PLUGIN.defaults = { | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment