1//https://github.com/mareczek/international-phone-number 2; 3(function (angular) { 4 "use strict"; 5 angular.module("phone", []).constant('ipnConfig', { 6 allowExtensions: false, 7 autoHideDialCode: true, 8 autoPlaceholder: true, 9 defaultCountry: "", 10 geoIpLookup: true, 11 nationalMode: false, 12 numberType: "MOBILE", 13 onlyCountries: void 0, 14 preferredCountries: ['us', 'gb'], 15 skipUtilScriptDownload: true, 16 utilsScript: "" 17 }).directive('phone', [ 18 '$timeout', 'ipnConfig', function ($timeout, ipnConfig) { 19 return { 20 restrict: 'A', 21 require: '^ngModel', 22 scope: { 23 ngModel: '=', 24 country: '=', 25 updateField: '&', 26 international: '@', 27 validation: '@', 28 initial: '@', 29 initialCountry: '@', 30 preferredCountries: '@', 31 field: '=', 32 registerControl: '&' 33 }, 34 link: function (scope, element, attrs, ctrl) { 35 angular.merge(ipnConfig, { 36 customPlaceholder: function (selectedCountryPlaceholder, selectedCountryData) { 37 return (dnnsf.localization.phone && dnnsf.localization.phone.placeholder || "") + selectedCountryPlaceholder; 38 }, 39 nationalMode: scope.international !== 'True', 40 initialCountry: scope.initialCountry.toLowerCase(), 41 preferredCountries: scope.preferredCountries.toLowerCase().split(',') 42 }); 43 44 var validation = scope.validation === 'True'; 45 var handleWhatsSupposedToBeAnArray, options, watchOnce, customErrors; 46 47 if (dnnsf.localization.phone) { 48 customErrors = [ 49 "", 50 dnnsf.localization.phone.invalidCountryCode, 51 dnnsf.localization.phone.numberTooShort, 52 dnnsf.localization.phone.numberTooLong, 53 dnnsf.localization.phone.notPhoneNumber 54 ] 55 } else { 56 customErrors = [ 57 "", 58 "Invalid country code.", 59 "Number is too short.", 60 "Number is too long.", 61 "Input is not a phone number." 62 ] 63 } 64 65 if (ctrl) { 66 if (element.val() !== '') { 67 $timeout(function () { 68 element.intlTelInput('setNumber', element.val()); 69 return ctrl.$setViewValue(element.val()); 70 }, 0); 71 } 72 } 73 handleWhatsSupposedToBeAnArray = function (value) { 74 if (value instanceof Array) { 75 return value; 76 } else { 77 return value.toString().replace(/[ ]/g, '').split(','); 78 } 79 }; 80 options = angular.copy(ipnConfig); 81 82 if(attrs.placeholderOption == 'removeplaceholder') { 83 options.autoPlaceholder = false; 84 } 85 86 angular.forEach(options, function (value, key) { 87 var option; 88 if (!(attrs.hasOwnProperty(key) && angular.isDefined(attrs[key]))) { 89 return; 90 } 91 option = attrs[key]; 92 if (key === 'preferredCountries') { 93 return options.preferredCountries = handleWhatsSupposedToBeAnArray(option); 94 } else if (key === 'onlyCountries') { 95 return options.onlyCountries = handleWhatsSupposedToBeAnArray(option); 96 } else if (typeof value === "boolean") { 97 return options[key] = option === "true"; 98 } else { 99 return options[key] = option; 100 } 101 }); 102 watchOnce = scope.$watch('ngModel', function (newValue) { 103 return scope.$$postDigest(function () { 104 if (newValue !== null && newValue !== void 0 && newValue.length > 0) { 105 if (newValue[0] !== '+') { 106 newValue = '+' + newValue; 107 } 108 ctrl.$modelValue = newValue; 109 } 110 element.intlTelInput(options); 111 112 if(attrs.removeflag == 'True') { 113 $(element).css('padding-left', '6px'); 114 $(element).siblings().css('display', 'none'); 115 } 116 117 if (validation && scope.initial) { 118 ctrl.ngModel = scope.initial; 119 var initialError = element.intlTelInput('getValidationError'); 120 if (initialError !== 0) { 121 displayError(customErrors[initialError]); 122 } 123 } 124 if (!(options.skipUtilScriptDownload || attrs.skipUtilScriptDownload !== void 0 || options.utilsScript)) { 125 element.intlTelInput('loadUtils', '/js/utils.js'); 126 } 127 return watchOnce(); 128 }); 129 }); 130 scope.$watch('country', function (newValue) { 131 if (newValue !== null && newValue !== void 0 && newValue !== '') { 132 return element.intlTelInput("selectCountry", newValue); 133 } 134 }); 135 ctrl.$formatters.push(function (value) { 136 if (!value) { 137 return value; 138 } 139 element.intlTelInput('setNumber', value); 140 return element.val(); 141 }); 142 ctrl.$validators.internationalPhoneNumber = function (value) { 143 var selectedCountry, errorMessage; 144 selectedCountry = element.intlTelInput("get
144SelectedCountryData"); 145 if (!value || (selectedCountry && selectedCountry.dialCode === value) || element.intlTelInput("getValidationError") === 0) { 146 element.closest('.field-container').removeClass("has-error"); 147 element.closest('.field-container').find('.phone-text-danger').remove(); 148 return true; 149 } else { 150 if (validation) { 151 var errorNumber = element.intlTelInput("getValidationError"); 152 if (typeof errorNumber === 'number') { 153 element.closest('.field-container').addClass("has-error"); 154 errorMessage = customErrors[errorNumber]; 155 displayError(errorMessage); 156 } 157 } 158 return false; 159 } 160 }; 161 function displayError(errMsg) { 162 var err = element.closest('.field-container').find('.phone-text-danger'); 163 if (err.length) { 164 err.text(errMsg); 165 err.show(); 166 } 167 else { 168 element.closest('.field-container').addClass("has-error"); 169 var spanError = document.createElement("span"); 170 spanError.className = "phone-text-danger"; 171 element.closest('.field-container').append(spanError); 172 $(spanError).text(errMsg); 173 } 174 } 175 scope.$watch(function () { 176 return element.intlTelInput('getNumber'); 177 }, function (newVal) { 178 if (typeof element.intlTelInput('getNumber') !== 'object') { 179 scope.ngModel = element.intlTelInput('getNumber'); 180 element.intlTelInput('setNumber', scope.ngModel); 181 } 182 }); 183 184 scope.registerControl({ 185 control: { 186 field: scope.field, 187 onSubmit: function (fnCallWhenDone, fnCallOnError) { 188 if (validation && element.val()) { 189 var submitError = element.intlTelInput("getValidationError"); 190 if (submitError !== 0) { 191 displayError(""); 192 return fnCallOnError('\n' + scope.field.TitleCompacted + ': ' + customErrors[submitError] + '\n'); 193 } 194 } 195 fnCallWhenDone && fnCallWhenDone(); 196 }, 197 getValue: function () { 198 return element.intlTelInput('getNumber'); 199 } 200 } 201 }); 202 203 } 204 }; 205 } 206 ]); 207 208})(window.dnnsfAngular15 || window.angular);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.