Created
September 18, 2014 07:01
-
-
Save msenkpiel/69189be33e3666276b1c to your computer and use it in GitHub Desktop.
jQuery Plugin Pattern
This file contains 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
; | |
(function ($, window, document, undefined) { | |
'use strict'; | |
var pluginName = 'plugin', | |
defaults = { | |
propertyName: "value" | |
}; | |
function Plugin(element, options) { | |
var plugin = this; | |
plugin.element = element; | |
plugin.settings = $.extend({}, defaults, options); | |
plugin._defaults = defaults; | |
plugin._name = pluginName; | |
var init = function () { | |
console.log('init plugin - element:', plugin.element); | |
}; | |
var privateMethod = function () { | |
}; | |
plugin.publicMethod = function () { | |
}; | |
init(); | |
} | |
$.fn[pluginName] = function (options) { | |
var p = new Plugin(this, options); | |
$(this).data(pluginName, p); | |
return p; | |
}; | |
})(jQuery, window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment