<commit_before>import { Delegate } from 'dom-delegate';
import { addClass, removeClass, select, nodesToArray } from '@pod-point/dom-ops';

const HAS_CONTENT = 'has-content';
const HAS_ERROR = 'has-error';
const HAS_FOCUS = 'has-focus';

class FormFields {
    constructor(root = document.body) {
        this.bindEvents(root);
        this.checkAllFieldsForContent();
    }

    checkAllFieldsForContent() {
        var inputs = nodesToArray(select('input'));

        if (inputs.length) {
            inputs.forEach(input => this.checkForContent(input));
        }
    }

    checkForContent(element) {
        var container = this.getInputContainer(element),
            callback = (element.value) ? addClass : removeClass;

        callback(container, HAS_CONTENT);
    }

    checkForErrors(element) {
        removeClass(this.getInputContainer(element), HAS_ERROR);
    }

    bindEvents(root) {
        var listener = new Delegate(root);

        // Listen to change because of password managers etc
        listener.on('change', 'input, textarea', (event, element) => {
            this.checkForContent(element);
            this.checkForErrors(element);
            this.giveFocus(element);
        });

        // Text input focus handler
        listener.on('focus', 'input, textarea', (event, element) => this.giveFocus(element));

        // Text input focusout handler
        listener.on('focusout', 'input, textarea', (event, element) => {
            this.checkForContent(element);
            this.checkForErrors(element);
            this.removeFocus(element);
        });

        listener.on('input', 'textarea', (event, element) => {
            var scrollHeight = element.scrollHeight;

            if (scrollHeight > parseInt(window.getComputedStyle(element, null).height)) {
                element.style.height = scrollHeight + 'px';
            }
        });
    }

    getInputContainer(element) {
        return element.parentNode;
    }

    removeFocus(element) {
        removeClass(this.getInputContainer(element), HAS_FOCUS);
    }

    giveFocus(element) {
        addClass(this.getInputContainer(element), HAS_FOCUS);
    }
}

export default {
    init: function() {
        new FormFields();
    }
};<commit_msg>eslint for-fields.js bar one error no-new<commit_after>import { Delegate } from 'dom-delegate';
import { addClass, removeClass, select, nodesToArray } from '@pod-point/dom-ops';

const HAS_CONTENT = 'has-content';
const HAS_ERROR = 'has-error';
const HAS_FOCUS = 'has-focus';

class FormFields {

    constructor(root = document.body) {
        this.bindEvents(root);
        this.checkAllFieldsForContent();
    }

    checkAllFieldsForContent() {
        const inputs = nodesToArray(select('input'));

        if (inputs.length) {
            inputs.forEach(input => this.checkForContent(input));
        }
    }

    checkForContent(element) {
        const container = this.getInputContainer(element);
        const callback = (element.value) ? addClass : removeClass;

        callback(container, HAS_CONTENT);
    }

    checkForErrors(element) {
        removeClass(this.getInputContainer(element), HAS_ERROR);
    }

    bindEvents(root) {
        const listener = new Delegate(root);

        // Listen to change because of password managers etc
        listener.on('change', 'input, textarea', (event, element) => {
            this.checkForContent(element);
            this.checkForErrors(element);
            this.giveFocus(element);
        });

        // Text input focus handler
        listener.on('focus', 'input, textarea', (event, element) => this.giveFocus(element));

        // Text input focusout handler
        listener.on('focusout', 'input, textarea', (event, element) => {
            this.checkForContent(element);
            this.checkForErrors(element);
            this.removeFocus(element);
        });

        listener.on('input', 'textarea', (event, element) => {
            const scrollHeight = element.scrollHeight;
            const formEl = element;

            if (scrollHeight > parseInt(window.getComputedStyle(formEl, null).height, 0)) {
                formEl.style.height = `${scrollHeight}px`;
            }
        });
    }

    static getInputContainer(element) {
        return element.parentNode;
    }

    removeFocus(element) {
        removeClass(this.getInputContainer(element), HAS_FOCUS);
    }

    giveFocus(element) {
        addClass(this.getInputContainer(element), HAS_FOCUS);
    }
}

export default {
    init: () => {
        new FormFields();
    },
};
{'fraction_non_alphanumeric': 0.12480874316939891, 'fraction_numerical': 0.0002185792349726776, 'mean_word_length': 2.52, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '112587', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1254, 'n_words': 247}