Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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);
Advertisement
Add Comment
Please, Sign In to add comment