<commit_before>// CHARACTER LIMITER
// Use the class name of .js-limit-chars-x on the input
// The 'x' will be the character limit

/*jshint browser: true */
(function () {
    "use strict";

    var root = this,
        $ = root.jQuery;

    if (typeof GOVUK === 'undefined') {
        root.GOVUK = {};
    }

    var limitChars = function (containerSelector) {
        var limitElement = $(containerSelector).find("[class*='js-limit-chars-']");

        limitElement.on('keyup input paste change', function (event) {
            // Get the classes
            var elClass = $(event.target).attr('class');
            // Get the limiter value (the 'x')
            var charsLimit = elClass.substr(elClass.indexOf("limit-chars-")+12,1);
            // The amount of chars in the input
            var chars = $(event.target).val().length;

            if(chars <= charsLimit){
                return true;
            } else {
                var str = $(event.target).val();
                str = str.substring(0, str.length - 1);
                $(event.target).val(str);
            }

        }).trigger('keyup');
    };

    root.GOVUK.limitChars = limitChars;

}).call(this);<commit_msg>DDPB-243 js tweaks after review<commit_after>// CHARACTER LIMITER
// Use the class name of .js-limit-chars-x on the input
// The 'x' will be the character limit

/*jshint browser: true */
(function () {
    "use strict";

    var root = this,
        $ = root.jQuery;

    if (typeof GOVUK === 'undefined') {
        root.GOVUK = {};
    }

    var limitChars = function (containerSelector) {
        var limitElement = $(containerSelector).find("[class*='js-limit-chars-']");

        limitElement.on('keyup input paste change', function (event) {
            var $this = $(event.target);
            // Get the classes
            var elClass = $this.attr('class');
            // Get the limiter value (the 'x')
            var charsLimit = parseInt(elClass.substr(elClass.indexOf("limit-chars-")+12,1));
            // The amount of chars in the input
            var chars = $this.val().length;

            if(chars <= charsLimit){
                return true;
            } else {
                var str = $this.val();
                str = str.substring(0, str.length - 1);
                $this.val(str);
            }

        }).trigger('keyup');
    };

    root.GOVUK.limitChars = limitChars;

}).call(this);
{'fraction_non_alphanumeric': 0.14575569358178053, 'fraction_numerical': 0.005383022774327122, 'mean_word_length': 1.8524203069657614, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5832943', 'n_tokens_mistral': 726, 'n_tokens_neox': 685, 'n_words': 184}