<commit_before>//import EVENTS     from '../../constants/common_events.constants';

export function jfField($timeout, JFrogEventBus, $rootScope) {
    return {
        restrict: 'E',
        require: '^form',
        scope: {
            animated: '@',
            validations: '@',
            autofocus: '=',
            invalidateOnSubmit: '@',
            alwaysShowErrors: '@',
            dontValidateDisabled: '@',
            delayedInit: '=',
            dontPushDownErrors: '='
        },
        transclude: true,
        templateUrl: 'directives/jf_field/jf_field.html',
        link: function jfInputTextLink(scope, element, attrs, form) {

            if (!scope.validations) scope.validations = 'common';

            let EVENTS = JFrogEventBus.getEventsDefinition();

            let inputElement;
            let inputName;
            let init = ()=>{
                inputElement = $(element.find('input')[0]);
                if (!inputElement.length) {
                    inputElement = $(element.find('textarea')[0]);
                }
                inputName = inputElement.attr('name');
                scope.formField = form[inputName];
                if (scope.formField) scope.formField.initialValue = true;
                scope.form = form;
                scope.$watch(()=>scope.autofocus, ()=>focusInput());
                JFrogEventBus.registerOnScope(scope, EVENTS.FORM_SUBMITTED, _onFormSubmitted);
                JFrogEventBus.registerOnScope(scope, EVENTS.FORM_CLEAR_FIELD_VALIDATION, force => {
                    _onBlur(force);
                    if (scope.formField) scope.formField.preventShowErrors = true;
                });

                scope.$on('$destroy', () => {
                    inputElement.off('blur');
                    inputElement.off('keyup');
                    inputElement.off('keydown');
                    inputElement.off('focus');
                });

                inputElement.on('keydown', () => _onKeyDown());

                if (!scope.invalidateOnSubmit && scope.validations) {
                    inputElement.on('blur', () => _onBlur());
                    inputElement.on('keyup', () => _onKeyUp());
                }
                if (scope.invalidateOnSubmit || scope.validations) {
                    inputElement.on('focus', () => _onFocus());
                }

                if (scope.dontValidateDisabled) {
                    $rootScope.$watch(() => inputElement[0].disabled, () => _onDisabledChanged(inputElement[0].disabled));
                }
                focusInput();
            };

            if (scope.delayedInit) {
                $timeout(()=>init());
            }
            else {
                init();
            }


            function focusInput() {
                if (scope.autofocus && scope.autofocus != 'false') {
                    $timeout(() => {
                        if (inputElement.scrollParent()) {
                            var y = inputElement.scrollParent().scrollTop();
                            inputElement.focus();
                            inputElement.scrollParent().scrollTop(y);
                        }
                        else {
                            inputElement.focus();
                        }
                    });
                }
            }
            function _onDisabledChanged(disabled) {
                if (disabled) {<commit_msg>jf_field safety check<commit_after>//import EVENTS     from '../../constants/common_events.constants';

export function jfField($timeout, JFrogEventBus, $rootScope) {
    return {
        restrict: 'E',
        require: '^form',
        scope: {
            animated: '@',
            validations: '@',
            autofocus: '=',
            invalidateOnSubmit: '@',
            alwaysShowErrors: '@',
            dontValidateDisabled: '@',
            delayedInit: '=',
            dontPushDownErrors: '='
        },
        transclude: true,
        templateUrl: 'directives/jf_field/jf_field.html',
        link: function jfInputTextLink(scope, element, attrs, form) {

            if (!scope.validations) scope.validations = 'common';

            let EVENTS = JFrogEventBus.getEventsDefinition();

            let inputElement;
            let inputName;
            let init = ()=>{
                inputElement = $(element.find('input')[0]);
                if (!inputElement.length) {
                    inputElement = $(element.find('textarea')[0]);
                }
                inputName = inputElement.attr('name');
                scope.formField = form[inputName];
                if (scope.formField) scope.formField.initialValue = true;
                scope.form = form;
                scope.$watch(()=>scope.autofocus, ()=>focusInput());
                JFrogEventBus.registerOnScope(scope, EVENTS.FORM_SUBMITTED, _onFormSubmitted);
                JFrogEventBus.registerOnScope(scope, EVENTS.FORM_CLEAR_FIELD_VALIDATION, force => {
                    _onBlur(force);
                    if (scope.formField) scope.formField.preventShowErrors = true;
                });

                scope.$on('$destroy', () => {
                    inputElement.off('blur');
                    inputElement.off('keyup');
                    inputElement.off('keydown');
                    inputElement.off('focus');
                });

                inputElement.on('keydown', () => _onKeyDown());

                if (!scope.invalidateOnSubmit && scope.validations) {
                    inputElement.on('blur', () => _onBlur());
                    inputElement.on('keyup', () => _onKeyUp());
                }
                if (scope.invalidateOnSubmit || scope.validations) {
                    inputElement.on('focus', () => _onFocus());
                }

                if (scope.dontValidateDisabled) {
                    $rootScope.$watch(() => inputElement[0].disabled, () => _onDisabledChanged(inputElement[0].disabled));
                }
                focusInput();
            };

            if (scope.delayedInit) {
                $timeout(()=>init());
            }
            else {
                init();
            }


            function focusInput() {
                if (scope.autofocus && scope.autofocus != 'false') {
                    $timeout(() => {
                        if (inputElement.scrollParent && inputElement.scrollParent()) {
                            var y = inputElement.scrollParent().scrollTop();
                            inputElement.focus();
                            inputElement.scrollParent().scrollTop(y);
                        }
                        else {
                            inputElement.focus();
                        }
                    });
                }
            }
            function _onDisabledChanged(disabled) {
                if (disabled) {
{'fraction_non_alphanumeric': 0.12679321837414867, 'fraction_numerical': 0.0011592522822779308, 'mean_word_length': 1.344429347826087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '803245', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1655, 'n_words': 253}