<commit_before>'use strict';
/* globals django, _actions_icnt, interpolate, ngettext, gettext */
/* jshint eqeqeq: false */

/* OLD SCHOOL JAVASCRIPT HERE, WILL BE REPLACED SOON */
(function ($) {
    var lastChecked;

    $.fn.actions = function (opts) {
        var options = $.extend({}, $.fn.actions.defaults, opts);
        var actionCheckboxes = $(this);
        var list_editable_changed = false;
        var checker = function (checked) {
            if (checked) {
                showQuestion();
            } else {
                reset();
            }
            $(actionCheckboxes).prop('checked', checked)
                .parent().parent().toggleClass(options.selectedClass, checked);
        },
        updateCounter = function () {
            var sel = $(actionCheckboxes).filter(':checked').length;
            // _actions_icnt is defined in the generated HTML
            // and contains the total amount of objects in the queryset
            $(options.counterContainer).html(interpolate(
            ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
                sel: sel,
                cnt: _actions_icnt
            }, true));
            $(options.allToggle).prop('checked', function () {
                var value;
                if (sel == actionCheckboxes.length) {
                    value = true;
                    showQuestion();
                } else {
                    value = false;
                    clearAcross();
                }
                return value;
            });
        },
        showQuestion = function () {
            $(options.acrossClears).hide();
            $(options.acrossQuestions).show();
            $(options.allContainer).hide();
        },
        showClear = function () {
            $(options.acrossClears).show();
            $(options.acrossQuestions).hide();
            $(options.actionContainer).toggleClass(options.selectedClass);
            $(options.allContainer).show();
            $(options.counterContainer).hide();
        },
        reset = function () {
            $(options.acrossClears).hide();
            $(options.acrossQuestions).hide();
            $(options.allContainer).hide();
            $(options.counterContainer).show();
        },
        clearAcross = function () {
            reset();
            $(options.acrossInput).val(0);
            $(options.actionContainer).removeClass(options.selectedClass);
        };
        // Show counter by default
        $(options.counterContainer).show();
        // Check state of checkboxes and reinit state if needed
        $(this).filter(':checked').each(function () {
            $(this).parent().parent().toggleClass(options.selectedClass);
            updateCounter();
            if (parseInt($(options.acrossInput).val()) == 1) {
                showClear();
            }
        });
        $(options.allToggle).show().click(function () {
            checker($(this).prop('checked'));
            updateCounter();
        });
        $('a', options.acrossQuestions).click(function (event) {
            event.preventDefault();
            $(options.acrossInput).val(1);
            showClear();
        });
        $('a', options.acrossClears).click(function (event) {
            event.preventDefault();
            $(options.allToggle).prop('checked', false);
            clearAcross();
            checker(0);
            updateCounter();
        });
        lastChecked = null;
        $(actionCheckboxes).click(function (event) {
            var target;
            var inrange;

            if (!event) {
                event = window.event;
            }
            target = event.target ? event.target : event.srcElement;
            if (lastChecked && $.data(lastChecked) != $.data(target) && event.shiftKey === true) {
                inrange = false;
                $(lastChecked).prop('checked', target.checked)
                    .parent().parent().toggleClass(options.selectedClass, target.checked);
                $(actionCheckboxes).each(function () {
                    if ($.data(this) == $.data(lastChecked) || $.data(this) == $.data(target)) {
                        inrange = (inrange) ? false : true;
                    }
                    if (inrange) {
                        $(this).prop('checked', target.checked)
                            .parent().parent().toggleClass(options.selectedClass, target.checked);
                    }
                });
            }
            $(target).parent().parent().toggleClass(options.selectedClass, target.checked);
            lastChecked = target;
            updateCounter();
        });
        $('form#changelist-form table#result_list tr, .js-navigator-table tr').find('td:gt(0) :input').change(function () {
            list_editable_changed = true;
        });
        $('form#changelist-form button[name="index"], .js-navigator-form button[name="index"]').click(function () {
            if (list_editable_changed) {
                return confirm(gettext('You have unsaved changes on individual editable fields. ' +
                    'If you run an action, your unsaved changes will be lost.'));
            }
        });
        $('form#changelist-form input[name="_save"], .js-navigator-form input[name="_save"]').click(function () {
            var action_changed = false;
            $('select option:selected', options.actionContainer).each(function () {
                if ($(this).val()) {
                    action_changed = true;
                }
            });
            if (action_changed) {
                if (list_editable_changed) {
                    return confirm(gettext('You have selected an action, ' +
                        'but you haven&#39;t saved your changes to individual fields yet. ' +
                        'Please click OK to save. ' +
                        'You&#39;ll need to re-run the action.'));
                } else {
                    return confirm(gettext('You have selected an action, and you haven&#39;t made any ' +
                        'changes on individual fields. ' +
                        'You&#39;re probably looking for the Go button rather than the Save button.'));
                }
            }
        });
    };
    /* Setup plugin defaults */<commit_msg>JS styling fixes<commit_after>'use strict';
/* globals django, _actions_icnt, interpolate, ngettext, gettext */
/* jshint eqeqeq: false */

/* OLD SCHOOL JAVASCRIPT HERE, WILL BE REPLACED SOON */
(function ($) {
    var lastChecked;

    $.fn.actions = function (opts) {
        var options = $.extend({}, $.fn.actions.defaults, opts);
        var actionCheckboxes = $(this);
        var list_editable_changed = false;
        var checker = function (checked) {
            if (checked) {
                showQuestion();
            } else {
                reset();
            }
            $(actionCheckboxes).prop('checked', checked)
                .parent().parent().toggleClass(options.selectedClass, checked);
        },
        showQuestion = function () {
            $(options.acrossClears).hide();
            $(options.acrossQuestions).show();
            $(options.allContainer).hide();
        },
        showClear = function () {
            $(options.acrossClears).show();
            $(options.acrossQuestions).hide();
            $(options.actionContainer).toggleClass(options.selectedClass);
            $(options.allContainer).show();
            $(options.counterContainer).hide();
        },
        reset = function () {
            $(options.acrossClears).hide();
            $(options.acrossQuestions).hide();
            $(options.allContainer).hide();
            $(options.counterContainer).show();
        },
        clearAcross = function () {
            reset();
            $(options.acrossInput).val(0);
            $(options.actionContainer).removeClass(options.selectedClass);
        },
        updateCounter = function () {
            var sel = $(actionCheckboxes).filter(':checked').length;
            // _actions_icnt is defined in the generated HTML
            // and contains the total amount of objects in the queryset
            $(options.counterContainer).html(interpolate(
            ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
                sel: sel,
                cnt: _actions_icnt
            }, true));
            $(options.allToggle).prop('checked', function () {
                var value;
                if (sel == actionCheckboxes.length) {
                    value = true;
                    showQuestion();
                } else {
                    value = false;
                    clearAcross();
                }
                return value;
            });
        };
        // Show counter by default
        $(options.counterContainer).show();
        // Check state of checkboxes and reinit state if needed
        $(this).filter(':checked').each(function () {
            $(this).parent().parent().toggleClass(options.selectedClass);
            updateCounter();
            if (parseInt($(options.acrossInput).val()) == 1) {
                showClear();
            }
        });
        $(options.allToggle).show().click(function () {
            checker($(this).prop('checked'));
            updateCounter();
        });
        $('a', options.acrossQuestions).click(function (event) {
            event.preventDefault();
            $(options.acrossInput).val(1);
            showClear();
        });
        $('a', options.acrossClears).click(function (event) {
            event.preventDefault();
            $(options.allToggle).prop('checked', false);
            clearAcross();
            checker(0);
            updateCounter();
        });
        lastChecked = null;
        $(actionCheckboxes).click(function (event) {
            var target;
            var inrange;

            if (!event) {
                event = window.event;
            }
            target = event.target ? event.target : event.srcElement;
            if (lastChecked && $.data(lastChecked) != $.data(target) && event.shiftKey === true) {
                inrange = false;
                $(lastChecked).prop('checked', target.checked)
                    .parent().parent().toggleClass(options.selectedClass, target.checked);
                $(actionCheckboxes).each(function () {
                    if ($.data(this) == $.data(lastChecked) || $.data(this) == $.data(target)) {
                        inrange = (inrange) ? false : true;
                    }
                    if (inrange) {
                        $(this).prop('checked', target.checked)
                            .parent().parent().toggleClass(options.selectedClass, target.checked);
                    }
                });
            }
            $(target).parent().parent().toggleClass(options.selectedClass, target.checked);
            lastChecked = target;
            updateCounter();
        });
        $('form#changelist-form table#result_list tr, .js-navigator-table tr')
            .find('td:gt(0) :input').change(function () {
            list_editable_changed = true;
        });
        $('form#changelist-form button[name="index"], .js-navigator-form button[name="index"]')
            .click(function () {
            if (list_editable_changed) {
                return confirm(gettext('You have unsaved changes on individual editable fields. ' +
                    'If you run an action, your unsaved changes will be lost.'));
            }
        });
        $('form#changelist-form input[name="_save"], .js-navigator-form input[name="_save"]').click(function () {
            var action_changed = false;
            $('select option:selected', options.actionContainer).each(function () {
                if ($(this).val()) {
                    action_changed = true;
                }
            });
            if (action_changed) {
                if (list_editable_changed) {
                    return confirm(gettext('You have selected an action, ' +
                        'but you haven&#39;t saved your changes to individual fields yet. ' +
                        'Please click OK to save. ' +
                        'You&#39;ll need to re-run the action.'));
                } else {
                    return confirm(gettext('You have selected an action, and you haven&#39;t made any ' +
                        'changes on individual fields. ' +
                        'You&#39;re probably looking for the Go button rather than the Save button.'));
                }
            }
        });
    };
    /* Setup plugin defaults */
{'fraction_non_alphanumeric': 0.13618094412483253, 'fraction_numerical': 0.0020490188352116005, 'mean_word_length': 1.602009432027886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4318449', 'n_tokens_mistral': 3195, 'n_tokens_neox': 3070, 'n_words': 650}