<commit_before>/*!
 * jQuery Plugin Creator @VERSION
 * https://github.com/OOPMan/jquery-plugin-creator
 *
 * Copyright 2014 <NAME>
 * Released under the MIT license.
 * http://github.com/OOPMan/jquery-plugin-creator/LICENSE
 *
 */
/**
 * TODO: Add checks to prevent over-writing plugins
 * TODO: Add ability to not specify plugin name and have a randomly generated name assigned
 */
"use strict";
(function () {
    /**
     *
     * @param {jQuery} jQuery
     * @returns {{addPlugin: addPlugin}}
     */
    function pluginCreatorFactory(jQuery) {
        var $ = jQuery,
            noOp = jQuery.noop,
            scopeName = "jquery-plugincreator-",
            /**
             *
             * @param {function} childMember
             * @param {function} parentMember
             * @returns {function}
             */
            parentWrapper = function (childMember, parentMember) {
                var parentMember = (parentMember == childMember ? noOp : parentMember);
                function parentGenerator (self) {
                    var _super = parentMember;
                    if (_super._isParentGenerator) _super = _super(self);
                    else _super = function () {
                        return parentMember.apply(self, arguments);
                    };
                    return function () {
                        var args = $.makeArray(arguments);
                        args.push(_super);
                        return childMember.apply(self, args);
                    };
                }
                parentGenerator._isParentGenerator = true;
                return parentGenerator;
            },
            /**
             *
             * @param {Object} childMembers
             * @param {Object} parentMembers
             * @param {Object} [self]
             * @returns {Object}
             */
            wrapParents = function (childMembers, parentMembers, self) {
                var childMembers = $.extend(true, {}, childMembers),
                    parentMembers = $.extend(true, {}, parentMembers);
                for (var memberName in parentMembers) {
                    if (childMembers[memberName]) {
                        if (typeof childMembers[memberName] == "function" && !childMembers[memberName]._isParentGenerator) {
                            childMembers[memberName] = parentWrapper(childMembers[memberName], parentMembers[memberName]);
                            if (self) childMembers[memberName] = childMembers[memberName](self);
                        }
                    } else {
                        childMembers[memberName] = parentMembers[memberName];
                    }
                }
                return childMembers;
            },
            /**
             *
             * @type {{addPlugin: addPlugin}}
             */
            pluginCreator = {
                /**
                 * Adds a new stateful plugin to jQuery.
                 *
                 * A stateful plugin consists of the following optional components:
                 * - An object defining default properties to be associated with a plugin instance via its options member
                 * - An object defining member functions and values to be associated with a plugin instances prototype.
                 *
                 * @param {string} name
                 * @param {Object} [defaults]
                 * @param {Object} [members]
                 * @return {string}
                 */
                addPlugin: function (name, defaults, members) {
                    var defaults = $.extend(true, {}, defaults || {}),
                        baseMembers = {
                            /**
                             * Default init function. Does nothing.
                             */
                            init: noOp,
                            /**
                             *
                             * @returns {Object}
                             */
                            getInstance: function () {
                                return this;
                            },
                            /**
                             *
                             * @param {Object} [options]
                             * @returns {Object}
                             */
                            update: function (options) {
                                $.extend(true, this.options, options || {});
                                return this.options;
                            },
                            /**
                             *
                             * @param {Object} members
                             * @returns {boolean}
                             */
                            extend: function (members) {
                                return $.extend(true, this, wrapParents(members, this, this));
                            },
                            /**
                             * Destructor function, performs the following:
                             *
                             * 1: Triggers a scopeName + name + ".destroy" (E.g. "jquery-plugincreator-myPlugin.destroy") event on the jQuery context (I.e. $(this) ) for the plugin instance.
                             * 2: Removes the scopeName + name (E.g. "jquery-plugincreator-myPlugin") class from the element linked to the plugin instance.
                             * 3: Removes the scopeName + name (E.g. "jquery-plugincreator-myPlugin") data value from the element linked to the plugin instance.
                             * 4: Removes the "data-" + scopeName + name (E.g. "data-jquery-plugincreator-myPlugin") attribute from the element linked to the plugin instance.
                             */
                            destroy: function () {
                                this.context
                                    .trigger(scopeName + name + ".destroy")
                                    .removeClass(scopeName + name)
                                    .removeData(scopeName + name)
                                    .removeAttr("data-" + scopeName + name);
                            }
                        },
                        members = $.isArray(members) ? members : [wrapParents(members, wrapParents(baseMembers, baseMembers))];

                    /**
                     * This function is used to instantiate an instance of the plugin on a given element.
                     *
                     * @param {Object} element
                     * @param {Object} [options]
                     * @param {Array} [initArguments]
                     */
                    function instantiatePlugin(element, options, initArguments) {
                        var options = options || {},
                            prototype = $.extend(true, {}, members[0]);

                        function pluginConstructor () {
                            this.element = element;
                            this.context = $(element).addClass(scopeName + name);
                            this.options = $.extend(true, {}, defaults, options);
                            for (var memberName in prototype) {
                                if (typeof prototype[memberName] == "function" && prototype[memberName]._isParentGenerator) {
                                    prototype[memberName] = prototype[memberName](this);
                                }
                            }
                            $.extend(true, this, prototype);
                            this.init.apply(this, initArguments);
                        }
                        $.data(element, scopeName + name, new pluginConstructor());
                    }

                    /**
                     * A function to handle the actual process of instantiating a plugin instance or calling a method on
                     * a given plugin instance.
                     *
                     * @param {Object} self
                     * @param {Object|String} options
                     * @param {Array} args
                     * @returns {*}
                     */
                    function processPluginCall(self, options, args) {
                        var instance = $.data(self, scopeName + name);
                        if (instance) {
                            if (typeof options == "string" && typeof instance[options] == "function") { // call a method on the instance
                                return instance[options].apply(instance, args.slice(1));
                            } else if (typeof instance.update == "function" && $.isPlainObject(options)) { // call update on the instance
                                return instance.update.apply(instance, args);
                            } else {
                                throw options + " is not a member of " + self;
                            }
                        } else {
                            return instantiatePlugin(self, options, args.slice(1));
                        }
                    }

                    /**
                     *
                     * @param {Object|string} options
                     * @returns {jQuery}
                     */
                    $.fn[name] = function(options) {
                        var args = $.makeArray(arguments);
                        if (this.length === 1) {
                            return processPluginCall(this[0], options, args);
                        } else {
                            if (options === "map") {
                                return this.map(function () {
                                    return processPluginCall(this, args[1], args.slice(2));
                                });
                            } else {
                                return this.each(function () {<commit_msg>Allow plugin call on single element selection to return the selection if the plugin call does not return an actual result in order to preserve the selection chain effect.<commit_after>/*!
 * jQuery Plugin Creator @VERSION
 * https://github.com/OOPMan/jquery-plugin-creator
 *
 * Copyright 2014 <NAME>
 * Released under the MIT license.
 * http://github.com/OOPMan/jquery-plugin-creator/LICENSE
 *
 */
/**
 * TODO: Add checks to prevent over-writing plugins
 * TODO: Add ability to not specify plugin name and have a randomly generated name assigned
 */
"use strict";
(function () {
    /**
     *
     * @param {jQuery} jQuery
     * @returns {{addPlugin: addPlugin}}
     */
    function pluginCreatorFactory(jQuery) {
        var $ = jQuery,
            noOp = jQuery.noop,
            scopeName = "jquery-plugincreator-",
            /**
             *
             * @param {function} childMember
             * @param {function} parentMember
             * @returns {function}
             */
            parentWrapper = function (childMember, parentMember) {
                var parentMember = (parentMember == childMember ? noOp : parentMember);
                function parentGenerator (self) {
                    var _super = parentMember;
                    if (_super._isParentGenerator) _super = _super(self);
                    else _super = function () {
                        return parentMember.apply(self, arguments);
                    };
                    return function () {
                        var args = $.makeArray(arguments);
                        args.push(_super);
                        return childMember.apply(self, args);
                    };
                }
                parentGenerator._isParentGenerator = true;
                return parentGenerator;
            },
            /**
             *
             * @param {Object} childMembers
             * @param {Object} parentMembers
             * @param {Object} [self]
             * @returns {Object}
             */
            wrapParents = function (childMembers, parentMembers, self) {
                var childMembers = $.extend(true, {}, childMembers),
                    parentMembers = $.extend(true, {}, parentMembers);
                for (var memberName in parentMembers) {
                    if (childMembers[memberName]) {
                        if (typeof childMembers[memberName] == "function" && !childMembers[memberName]._isParentGenerator) {
                            childMembers[memberName] = parentWrapper(childMembers[memberName], parentMembers[memberName]);
                            if (self) childMembers[memberName] = childMembers[memberName](self);
                        }
                    } else {
                        childMembers[memberName] = parentMembers[memberName];
                    }
                }
                return childMembers;
            },
            /**
             *
             * @type {{addPlugin: addPlugin}}
             */
            pluginCreator = {
                /**
                 * Adds a new stateful plugin to jQuery.
                 *
                 * A stateful plugin consists of the following optional components:
                 * - An object defining default properties to be associated with a plugin instance via its options member
                 * - An object defining member functions and values to be associated with a plugin instances prototype.
                 *
                 * @param {string} name
                 * @param {Object} [defaults]
                 * @param {Object} [members]
                 * @return {string}
                 */
                addPlugin: function (name, defaults, members) {
                    var defaults = $.extend(true, {}, defaults || {}),
                        baseMembers = {
                            /**
                             * Default init function. Does nothing.
                             */
                            init: noOp,
                            /**
                             *
                             * @returns {Object}
                             */
                            getInstance: function () {
                                return this;
                            },
                            /**
                             *
                             * @param {Object} [options]
                             * @returns {Object}
                             */
                            update: function (options) {
                                $.extend(true, this.options, options || {});
                                return this.options;
                            },
                            /**
                             *
                             * @param {Object} members
                             * @returns {boolean}
                             */
                            extend: function (members) {
                                return $.extend(true, this, wrapParents(members, this, this));
                            },
                            /**
                             * Destructor function, performs the following:
                             *
                             * 1: Triggers a scopeName + name + ".destroy" (E.g. "jquery-plugincreator-myPlugin.destroy") event on the jQuery context (I.e. $(this) ) for the plugin instance.
                             * 2: Removes the scopeName + name (E.g. "jquery-plugincreator-myPlugin") class from the element linked to the plugin instance.
                             * 3: Removes the scopeName + name (E.g. "jquery-plugincreator-myPlugin") data value from the element linked to the plugin instance.
                             * 4: Removes the "data-" + scopeName + name (E.g. "data-jquery-plugincreator-myPlugin") attribute from the element linked to the plugin instance.
                             */
                            destroy: function () {
                                this.context
                                    .trigger(scopeName + name + ".destroy")
                                    .removeClass(scopeName + name)
                                    .removeData(scopeName + name)
                                    .removeAttr("data-" + scopeName + name);
                            }
                        },
                        members = $.isArray(members) ? members : [wrapParents(members, wrapParents(baseMembers, baseMembers))];

                    /**
                     * This function is used to instantiate an instance of the plugin on a given element.
                     *
                     * @param {Object} element
                     * @param {Object} [options]
                     * @param {Array} [initArguments]
                     */
                    function instantiatePlugin(element, options, initArguments) {
                        var options = options || {},
                            prototype = $.extend(true, {}, members[0]);

                        function pluginConstructor () {
                            this.element = element;
                            this.context = $(element).addClass(scopeName + name);
                            this.options = $.extend(true, {}, defaults, options);
                            for (var memberName in prototype) {
                                if (typeof prototype[memberName] == "function" && prototype[memberName]._isParentGenerator) {
                                    prototype[memberName] = prototype[memberName](this);
                                }
                            }
                            $.extend(true, this, prototype);
                            this.init.apply(this, initArguments);
                        }
                        $.data(element, scopeName + name, new pluginConstructor());
                    }

                    /**
                     * A function to handle the actual process of instantiating a plugin instance or calling a method on
                     * a given plugin instance.
                     *
                     * @param {Object} self
                     * @param {Object|String} options
                     * @param {Array} args
                     * @returns {*}
                     */
                    function processPluginCall(self, options, args) {
                        var instance = $.data(self, scopeName + name);
                        if (instance) {
                            if (typeof options == "string" && typeof instance[options] == "function") { // call a method on the instance
                                return instance[options].apply(instance, args.slice(1));
                            } else if (typeof instance.update == "function" && $.isPlainObject(options)) { // call update on the instance
                                return instance.update.apply(instance, args);
                            } else {
                                throw options + " is not a member of " + self;
                            }
                        } else {
                            return instantiatePlugin(self, options, args.slice(1));
                        }
                    }

                    /**
                     *
                     * @param {Object|string} options
                     * @returns {jQuery}
                     */
                    $.fn[name] = function(options) {
                        var args = $.makeArray(arguments);
                        if (this.length === 1) {
                            return processPluginCall(this[0], options, args) || this;
                        } else {
                            if (options === "map") {
                                return this.map(function () {
                                    return processPluginCall(this, args[1], args.slice(2));
                                });
                            } else {
                                return this.each(function () {
{'fraction_non_alphanumeric': 0.08847829352561214, 'fraction_numerical': 0.0015021781583295778, 'mean_word_length': 0.990829346092504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070069', 'n_tokens_mistral': 4192, 'n_tokens_neox': 3975, 'n_words': 1101}