<commit_before>/* Copyright (c) 2010, Sage Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define('Sage/Platform/Mobile/Fields/PhoneField', ['Sage/Platform/Mobile/Fields/TextField'], function() {
    var control = dojo.declare('Sage.Platform.Mobile.Fields.PhoneField', [Sage.Platform.Mobile.Fields.TextField], {
        /*
            {0}: original value
            {1}: cleaned value
            {2}: entire match (against clean value)
            {3..n}: match groups (against clean value)
        */
        formatters: [{
            test: /^\+.*/,
            format: '${0}'
        },{
            test: /^(\d{3})(\d{3,4})$/,
            format: '${3}-${4}'
        },{
            test: /^(\d{3})(\d{3})(\d{2,4})$/, // 555 555 5555
            format: '(${3})-${4}-${5}'
        },{
            test: /^(\d{3})(\d{3})(\d{2,4})([^0-9]{1,}.*)$/, // 555 555 5555x
            format: '(${3})-${4}-${5}${6}'
        },{
            test: /^(\d{11,})(.*)$/,
            format: '${1}'
        }],

        /* Currently only iOS supports non-numbers when a tel field has a default value
            http://code.google.com/p/android/issues/detail?id=19724
         */
        inputType: dojo.isSafari ? 'tel' : 'text',

        onBlur: function() {
            this.inherited(arguments);

            // temporarily added: http://code.google.com/p/android/issues/detail?id=14519
            this.inputNode.value = this.formatNumberForDisplay(this.inputNode.value, this.getValue());
        },
        getValue: function() {
            var value = dojo.attr(this.inputNode, 'value');


            if (/^\+/.test(value)) return value;

            return value.replace(/[^0-9x]/ig, "");
        },
        setValue: function(val, initial) {
            if (initial) this.originalValue = val;
            
            this.previousValue = false;

            dojo.attr(this.inputNode, 'value', this.formatNumberForDisplay(val) || '');
            this.inputNode.value = this.formatNumberForDisplay(val) || '';
        },
        formatNumberForDisplay: function(number, clean) {
            if (typeof clean === 'undefined') clean = number;

            for (var i = 0; i < this.formatters.length; i++)
            {
                var formatter = this.formatters[i],
                    match;
                if ((match = formatter.test.exec(clean)))
                {
                    return dojo.string.substitute(formatter.format, [number, clean].concat(match));
                    /*
                    return String.format.apply(String, [formatter.format, number, clean].concat(match));
                    */<commit_msg>fixed set value to dojo widget set<commit_after>/* Copyright (c) 2010, Sage Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define('Sage/Platform/Mobile/Fields/PhoneField', ['Sage/Platform/Mobile/Fields/TextField'], function() {
    var control = dojo.declare('Sage.Platform.Mobile.Fields.PhoneField', [Sage.Platform.Mobile.Fields.TextField], {
        /*
            {0}: original value
            {1}: cleaned value
            {2}: entire match (against clean value)
            {3..n}: match groups (against clean value)
        */
        formatters: [{
            test: /^\+.*/,
            format: '${0}'
        },{
            test: /^(\d{3})(\d{3,4})$/,
            format: '${3}-${4}'
        },{
            test: /^(\d{3})(\d{3})(\d{2,4})$/, // 555 555 5555
            format: '(${3})-${4}-${5}'
        },{
            test: /^(\d{3})(\d{3})(\d{2,4})([^0-9]{1,}.*)$/, // 555 555 5555x
            format: '(${3})-${4}-${5}${6}'
        },{
            test: /^(\d{11,})(.*)$/,
            format: '${1}'
        }],

        /* Currently only iOS supports non-numbers when a tel field has a default value
            http://code.google.com/p/android/issues/detail?id=19724
         */
        inputType: dojo.isSafari ? 'tel' : 'text',

        onBlur: function() {
            this.inherited(arguments);

            // temporarily added: http://code.google.com/p/android/issues/detail?id=14519
            this.set('inputValue', this.formatNumberForDisplay(this.inputNode.value, this.getValue()));
        },
        getValue: function() {
            var value = dojo.attr(this.inputNode, 'value');


            if (/^\+/.test(value)) return value;

            return value.replace(/[^0-9x]/ig, "");
        },
        setValue: function(val, initial) {
            if (initial) this.originalValue = val;
            
            this.previousValue = false;

            dojo.attr(this.inputNode, 'value', this.formatNumberForDisplay(val) || '');
            this.inputNode.value = this.formatNumberForDisplay(val) || '';
        },
        formatNumberForDisplay: function(number, clean) {
            if (typeof clean === 'undefined') clean = number;

            for (var i = 0; i < this.formatters.length; i++)
            {
                var formatter = this.formatters[i],
                    match;
                if ((match = formatter.test.exec(clean)))
                {
                    return dojo.string.substitute(formatter.format, [number, clean].concat(match));
{'fraction_non_alphanumeric': 0.15787786504247475, 'fraction_numerical': 0.02308062189453438, 'mean_word_length': 1.9686013320647002, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4193745', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1745, 'n_words': 449}