<commit_before>/* Set caret at end of text in given elem */
function setCaretAtEnd(elem) {
    var range;
    var caretPos = $(elem).val().length;

    if (elem.createTextRange) {
        range = elem.createTextRange();
        range.move('character', caretPos);
        range.select();
    } else {
        elem.focus();
        if (elem.selectionStart !== undefined) {
            elem.setSelectionRange(caretPos, caretPos);
        }
    }
}

if (typeof String.prototype.startsWith != 'function') {
    String.prototype.startsWith = function(str) {
        return this.substring(0, str.length) === str;
    }
}

if (typeof String.prototype.endsWith != 'function') {
    String.prototype.endsWith = function(str) {
        return this.substring(this.length - str.length, this.length ) === str;
    }
}

(function($, window, document, undefined){
    var truncatedFields;

    window.HLApp = {
        config: {
            phoneInputFields: 'input[name^="phone"]',
            countryPrefix: '+31',
            truncateFields: '.truncate',
            truncateToken: '&nbsp;(&hellip;)',
            toastrPosition: 'toast-bottom-right',
            contactField: '#id_contact',
            quickContactField: '#id_case_quickbutton_contact',
            accountField: '#id_account',
            quickAccountField: '#id_case_quickbutton_account',
            contactJsonUrl: "/contacts/json_works_at/"
        },

        init: function(config) {
            // Setup config
            var self = this;
            if ($.isPlainObject(config)) {
                $.extend(self.config, config);
            }

            self.initListeners();
            self.resetTruncateFields();
            self.initToastr();
            self.initDatePicker();
            self.initModalSpinner();
        },

        initListeners: function() {
            var self = this,
                cf = self.config;
            $('body')
                .on('blur', cf.phoneInputFields, function() {
                    // Format phonenumbers for every phone input field
                    self.formatPhoneNumber.call(self, this);
                })
                .on('change', cf.contactField, function() {
                    self.changedAccount(cf.contactField, cf.accountField);
                })
                .on('change', cf.quickContactField, function() {
                    self.changedAccount(cf.quickContactField, cf.quickAccountField);
                })
                .on('change', cf.accountField, function() {
                    self.changedContact(cf.contactField, cf.accountField);
                })
                .on('change', cf.quickAccountField, function() {
                    self.changedContact(cf.quickContactField, cf.quickAccountField);
                })
                .on('hidden.bs.modal', '.modal', function() {
                    // remove any results from other modals
                    $(this).find('[data-async-response]').html('');
                })
                .on('hide.bs.modal', '.modal', function() {
                    // remove focus from element that triggered modal
                    $(':focus').blur();
                })
                .on('click', '[data-source]', function(event) {
                    self.openModalWithRemoteContent.call(this, event);
                })
                .on('submit', 'form[data-async]', function(event) {
                    self.submitAjaxForm.call(self, this, event);
                })
                .on('shown.bs.tab', '[data-toggle="tab"]', function(e) {
                    // update address bar with target
                    // - this helps showing the correct tab immediately on page load after
                    // trying to post a form but receiving errors for instance
                    window.location.hash = e.target.hash;
                });

            $(window).on('resize', function() {
                self.truncateFields();
            });

            // submit forms with other elements
            $('[data-form-submit]').on('click', function(event) {
                $($(this).data('form-selector')).submit();
                event.preventDefault();
            });
        },

        formatPhoneNumber: function(phoneNumberInput) {
            // Format telephone number
            var $phoneNumberInput = $(phoneNumberInput);
            var phone = $phoneNumberInput.val();
            if (phone.match(/[a-z]|[A-Z]/)) {
                // if letters are found, skip formatting: it may not be a phone field after all
                return false;
            }

            phone = phone
                .replace("(0)","")
                .replace(/\s|\(|\-|\)|\.|x|:|\*/g, "")
                .replace(/^00/,"+");

            if (phone.length == 0) {
                return false;
            }

            if (!phone.startsWith('+')) {
                if (phone.startsWith('0')) {
                    phone = phone.substring(1);
                }
                phone = this.config.countryPrefix + phone;
            }
            $phoneNumberInput.val(phone);
        },

        setupTruncate: function() {
            truncatedFields = $(this.config.truncateFields);
        },

        truncateFields: function() {
            truncatedFields.truncate({
                token: this.config.truncateToken
            });
        },

        resetTruncateFields: function() {
            this.setupTruncate();
            this.truncateFields();
        },

        initToastr: function() {
            toastr.options = {
                closeButton: true,
                positionClass: this.config.toastrPosition<commit_msg>quickfix numbers starting "+310" should have "0" removed<commit_after>/* Set caret at end of text in given elem */
function setCaretAtEnd(elem) {
    var range;
    var caretPos = $(elem).val().length;

    if (elem.createTextRange) {
        range = elem.createTextRange();
        range.move('character', caretPos);
        range.select();
    } else {
        elem.focus();
        if (elem.selectionStart !== undefined) {
            elem.setSelectionRange(caretPos, caretPos);
        }
    }
}

if (typeof String.prototype.startsWith != 'function') {
    String.prototype.startsWith = function(str) {
        return this.substring(0, str.length) === str;
    }
}

if (typeof String.prototype.endsWith != 'function') {
    String.prototype.endsWith = function(str) {
        return this.substring(this.length - str.length, this.length ) === str;
    }
}

(function($, window, document, undefined){
    var truncatedFields;

    window.HLApp = {
        config: {
            phoneInputFields: 'input[name^="phone"]',
            countryPrefix: '+31',
            truncateFields: '.truncate',
            truncateToken: '&nbsp;(&hellip;)',
            toastrPosition: 'toast-bottom-right',
            contactField: '#id_contact',
            quickContactField: '#id_case_quickbutton_contact',
            accountField: '#id_account',
            quickAccountField: '#id_case_quickbutton_account',
            contactJsonUrl: "/contacts/json_works_at/"
        },

        init: function(config) {
            // Setup config
            var self = this;
            if ($.isPlainObject(config)) {
                $.extend(self.config, config);
            }

            self.initListeners();
            self.resetTruncateFields();
            self.initToastr();
            self.initDatePicker();
            self.initModalSpinner();
        },

        initListeners: function() {
            var self = this,
                cf = self.config;
            $('body')
                .on('blur', cf.phoneInputFields, function() {
                    // Format phonenumbers for every phone input field
                    self.formatPhoneNumber.call(self, this);
                })
                .on('change', cf.contactField, function() {
                    self.changedAccount(cf.contactField, cf.accountField);
                })
                .on('change', cf.quickContactField, function() {
                    self.changedAccount(cf.quickContactField, cf.quickAccountField);
                })
                .on('change', cf.accountField, function() {
                    self.changedContact(cf.contactField, cf.accountField);
                })
                .on('change', cf.quickAccountField, function() {
                    self.changedContact(cf.quickContactField, cf.quickAccountField);
                })
                .on('hidden.bs.modal', '.modal', function() {
                    // remove any results from other modals
                    $(this).find('[data-async-response]').html('');
                })
                .on('hide.bs.modal', '.modal', function() {
                    // remove focus from element that triggered modal
                    $(':focus').blur();
                })
                .on('click', '[data-source]', function(event) {
                    self.openModalWithRemoteContent.call(this, event);
                })
                .on('submit', 'form[data-async]', function(event) {
                    self.submitAjaxForm.call(self, this, event);
                })
                .on('shown.bs.tab', '[data-toggle="tab"]', function(e) {
                    // update address bar with target
                    // - this helps showing the correct tab immediately on page load after
                    // trying to post a form but receiving errors for instance
                    window.location.hash = e.target.hash;
                });

            $(window).on('resize', function() {
                self.truncateFields();
            });

            // submit forms with other elements
            $('[data-form-submit]').on('click', function(event) {
                $($(this).data('form-selector')).submit();
                event.preventDefault();
            });
        },

        formatPhoneNumber: function(phoneNumberInput) {
            // Format telephone number
            var $phoneNumberInput = $(phoneNumberInput);
            var phone = $phoneNumberInput.val();
            if (phone.match(/[a-z]|[A-Z]/)) {
                // if letters are found, skip formatting: it may not be a phone field after all
                return false;
            }

            phone = phone
                .replace("(0)","")
                .replace(/\s|\(|\-|\)|\.|x|:|\*/g, "")
                .replace(/^00/,"+");

            if (phone.length == 0) {
                return false;
            }

            if (!phone.startsWith('+')) {
                if (phone.startsWith('0')) {
                    phone = phone.substring(1);
                }
                phone = this.config.countryPrefix + phone;
            }

            if (phone.startsWith('+310')) {
                phone = '+31' + phone.substring(4);
            }
            $phoneNumberInput.val(phone);
        },

        setupTruncate: function() {
            truncatedFields = $(this.config.truncateFields);
        },

        truncateFields: function() {
            truncatedFields.truncate({
                token: this.config.truncateToken
            });
        },

        resetTruncateFields: function() {
            this.setupTruncate();
            this.truncateFields();
        },

        initToastr: function() {
            toastr.options = {
                closeButton: true,
                positionClass: this.config.toastrPosition
{'fraction_non_alphanumeric': 0.13142757538783337, 'fraction_numerical': 0.002440299808262158, 'mean_word_length': 1.5109409190371992, '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': '3690002', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2859, 'n_words': 573}