<commit_before>/**
 * Patterns depends - show/hide/disable content based on form status
 *
 * Copyright 2012-2013 <NAME>
 * Copyright 2012-2013 Simplon B.V. - Simplon B.V. - <NAME>
 */
define([
    "jquery",
    "../registry",
    "../core/logger",
    "../lib/dependshandler",
    "../core/parser"
], function($, patterns, logging, DependsHandler, Parser) {
    var log = logging.getLogger("depends"),
        parser = new Parser("depends");

    parser.add_argument("condition");
    parser.add_argument("action", "show", ["show", "enable"]);
    parser.add_argument("transition", "none", ["none", "css", "fade", "slide"]);
    parser.add_argument("effect-duration", "fast");
    parser.add_argument("effect-easing", "swing");

    var depends = {
        name: "depends",
        trigger: ".pat-depends",
        jquery_plugin: true,

        transitions: {
            none: {hide: "hide", show: "show"},
            fade: {hide: "fadeOut", show: "fadeIn"},
            slide: {hide: "slideUp", show: "slideDown"}
        },

        init: function($el, opts) {
            return $el.each(function() {
                var slave = this,
                    $slave = $(this),
                    options = parser.parse($slave, opts),
                    handler, state;

                try {
                    handler=new DependsHandler($slave, options.condition);
                } catch (e) {
                    log.error("Invalid condition: " + e.message);
                    return;
                }

                state=handler.evaluate();
                switch (options.action) {
                    case "show":
                        if (state)
                            $slave.show();
                        else
                            $slave.hide();
                        break;
                    case "enable":
                        if (state)
                            depends._enable($slave);
                        else
                            depends._disable($slave);
                        break;
                }

                var data = {handler: handler,
                            options: options,
                            slave: slave};

                handler.getAllInputs().each(function() {
                    if (this.form) {
                        var $form = $(this.form),
                            slaves = $form.data("patDepends.slaves");
                        if (!slaves) {
                            slaves=[data];
                            $form.on("reset.pat-depends", depends.onReset);
                        } else if (slaves.indexOf(data)===-1)
                            slaves.push(data);
                        $form.data("patDepends.slaves", slaves);
                    }
                    $(this).on("change.pat-depends", null, data, depends.onChange);
                });
            });
        },

        onReset: function(event) {
            var slaves = $(this).data("patDepends.slaves"),
                i;

            setTimeout(function() {
                for (i=0; i<slaves.length; i++) {
                    event.data=slaves[i];
                    depends.onChange(event);
                }
            }, 50);
        },

        _enable: function($slave) {
            if ($slave.is(":input"))
                $slave[0].disabled=null;
            else if ($slave.is("a"))
                $slave.off("click.patternDepends");
            $slave.removeClass("disabled");
        },

        _disable: function($slave) {
            if ($slave.is(":input"))
                $slave[0].disabled="disabled";
            else if ($slave.is("a"))
                $slave.on("click.patternDepends", depends.blockDefault);
            $slave.addClass("disabled");
        },

        _hide_or_show: function($slave, new_state, options) {
            var duration = (options.transition==="css" || options.transition==="none") ? null : options.effect.duration;

            $slave.removeClass("visible hidden in-progress");
            var onComplete = function() {
                $slave
                    .removeClass("in-progress")
                    .addClass(new_state ? "visible" : "hidden");
            };
            if (!duration) {
                if (options.transition!=="css")
                    $slave[new_state ? "show" : "hide"]();
                onComplete();
            } else {
                var t = depends.transitions[options.transition];
                $slave.addClass("in-progress");
                $slave[new_state ? t.show : t.hide]({
                    duration: duration,
                    easing: options.effect.easing,
                    complete: onComplete
                });
            }
        },

        onChange: function(event) {
            var handler = event.data.handler,
                options = event.data.options,
                slave = event.data.slave,
                $slave = $(slave),
                state = handler.evaluate(),
                duration = (options.transition==="css" || options.transition==="none") ? null : options.effect.duration;
<commit_msg>Fix jshint error.<commit_after>/**
 * Patterns depends - show/hide/disable content based on form status
 *
 * Copyright 2012-2013 <NAME>
 * Copyright 2012-2013 Simplon B.V. - Simplon B.V. - <NAME>
 */
define([
    "jquery",
    "../registry",
    "../core/logger",
    "../lib/dependshandler",
    "../core/parser"
], function($, patterns, logging, DependsHandler, Parser) {
    var log = logging.getLogger("depends"),
        parser = new Parser("depends");

    parser.add_argument("condition");
    parser.add_argument("action", "show", ["show", "enable"]);
    parser.add_argument("transition", "none", ["none", "css", "fade", "slide"]);
    parser.add_argument("effect-duration", "fast");
    parser.add_argument("effect-easing", "swing");

    var depends = {
        name: "depends",
        trigger: ".pat-depends",
        jquery_plugin: true,

        transitions: {
            none: {hide: "hide", show: "show"},
            fade: {hide: "fadeOut", show: "fadeIn"},
            slide: {hide: "slideUp", show: "slideDown"}
        },

        init: function($el, opts) {
            return $el.each(function() {
                var slave = this,
                    $slave = $(this),
                    options = parser.parse($slave, opts),
                    handler, state;

                try {
                    handler=new DependsHandler($slave, options.condition);
                } catch (e) {
                    log.error("Invalid condition: " + e.message);
                    return;
                }

                state=handler.evaluate();
                switch (options.action) {
                    case "show":
                        if (state)
                            $slave.show();
                        else
                            $slave.hide();
                        break;
                    case "enable":
                        if (state)
                            depends._enable($slave);
                        else
                            depends._disable($slave);
                        break;
                }

                var data = {handler: handler,
                            options: options,
                            slave: slave};

                handler.getAllInputs().each(function() {
                    if (this.form) {
                        var $form = $(this.form),
                            slaves = $form.data("patDepends.slaves");
                        if (!slaves) {
                            slaves=[data];
                            $form.on("reset.pat-depends", depends.onReset);
                        } else if (slaves.indexOf(data)===-1)
                            slaves.push(data);
                        $form.data("patDepends.slaves", slaves);
                    }
                    $(this).on("change.pat-depends", null, data, depends.onChange);
                });
            });
        },

        onReset: function(event) {
            var slaves = $(this).data("patDepends.slaves"),
                i;

            setTimeout(function() {
                for (i=0; i<slaves.length; i++) {
                    event.data=slaves[i];
                    depends.onChange(event);
                }
            }, 50);
        },

        _enable: function($slave) {
            if ($slave.is(":input"))
                $slave[0].disabled=null;
            else if ($slave.is("a"))
                $slave.off("click.patternDepends");
            $slave.removeClass("disabled");
        },

        _disable: function($slave) {
            if ($slave.is(":input"))
                $slave[0].disabled="disabled";
            else if ($slave.is("a"))
                $slave.on("click.patternDepends", depends.blockDefault);
            $slave.addClass("disabled");
        },

        _hide_or_show: function($slave, new_state, options) {
            var duration = (options.transition==="css" || options.transition==="none") ? null : options.effect.duration;

            $slave.removeClass("visible hidden in-progress");
            var onComplete = function() {
                $slave
                    .removeClass("in-progress")
                    .addClass(new_state ? "visible" : "hidden");
            };
            if (!duration) {
                if (options.transition!=="css")
                    $slave[new_state ? "show" : "hide"]();
                onComplete();
            } else {
                var t = depends.transitions[options.transition];
                $slave.addClass("in-progress");
                $slave[new_state ? t.show : t.hide]({
                    duration: duration,
                    easing: options.effect.easing,
                    complete: onComplete
                });
            }
        },

        onChange: function(event) {
            var handler = event.data.handler,
                options = event.data.options,
                slave = event.data.slave,
                $slave = $(slave),
                state = handler.evaluate();

{'fraction_non_alphanumeric': 0.13731666502608525, 'fraction_numerical': 0.004331134954227778, 'mean_word_length': 1.245303867403315, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3993107', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2489, 'n_words': 489}