Last active
October 13, 2015 18:08
-
-
Save morningtoast/4235585 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
| jQuery(function($){ | |
| function debug(str) { | |
| if (settings.debug) { console.log(str); } | |
| } | |
| // Helper methods | |
| var helper = { | |
| }; | |
| // Main methods | |
| var methods = { | |
| // Initial plugin, runs if parameter to plugin does not match another method | |
| "init" : function(options) { | |
| settings = { | |
| } | |
| // Override/combine variables with any that have been passed | |
| if (options) { $.extend(settings, options); } | |
| // Handling of targeted element; loop through each match | |
| return this.each(function() { | |
| // Do stuff here on the matched elements | |
| }); // End each() | |
| return(true); | |
| } | |
| } | |
| // Plugin namespace and attachment - Syntax: $(element).kickappsVideo({options}); | |
| $.fn.MYPLUGINNAME = function(methodOrOptions) { | |
| if ( methods[methodOrOptions] ) { | |
| return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 )); | |
| } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) { | |
| // Default to "init" | |
| return methods.init.apply( this, arguments ); | |
| } else { | |
| $.error( 'Method ' + method + ' does not exist' ); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment