/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
( function( $ ) { // Global variables var i, j; // Default settings var settings = { "property" : 'value' }; // Methods var methods = { init: function(options) { // Capture $(this) global as a local variable var $this = $(this); // Extend settings with provided options if( options ) { $.extend(settings, options); } // Example method call $this.pluginName('methodTwo'); $this.pluginName('methodThree'); }, methodTwo: function() { }, methodThree: function() { } }; // Plugin namespace initialization $.fn.pluginName = function(methd) { 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.pluginName' ); } } // Standalone functions function doThis(property) { return 1; } } (jQuery) );