| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 
 | (function($) {
 
	//	Static private vars
	var pluginName = 'boilerplate',
		pStatic = {
			//	Static public vars
			foo: 'bar'
		};
 
	$[pluginName] = function(element, options) {
 
		// Private vars
		var
		plugin		= this,
		$element	= $(element),
		element		= element,
		defaults	= {
			foo: 'bar',
			onFoo: function() {}
		},
 
		// Private methods
		privateMethod = function() {
			// code goes here
		};
 
		// Public methods
		plugin.methods = {
			init: function() {
				plugin.settings = $.extend({}, defaults, options);
				// code goes here
			},
			publicMethod: function() {
				// code goes here
			}
		};
 
		// Public vars
		plugin.settings	= {};
		plugin.static	= pStatic;
 
		plugin.methods.init();
 
	}
 
	$.fn[pluginName] = function(options) {
		var	args	=	arguments;
        return this.each(function() {
        	var	i	=	$(this);
            if (undefined == (plugin = i.data(pluginName))) {
                var plugin = new $[pluginName](this, options);
                i.data(pluginName, plugin);
            } else if (plugin.methods[options]) {
            	plugin.methods[options].apply( plugin, Array.prototype.slice.call( args, 1 ));
            }
        });
 
	}
 
})(jQuery); | 
Partager