msenkpiel
9/18/2014 - 7:01 AM

jQuery Plugin Pattern

jQuery Plugin Pattern

;
(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);