Current Path : /home/user/web/pansionat-v-yaroslavle.ru/public_html/bitrix/js/main/phonenumber/ |
Current File : /home/user/web/pansionat-v-yaroslavle.ru/public_html/bitrix/js/main/phonenumber/phonenumber.min.js |
(function(){if(BX.PhoneNumber)return;var t;var e=null;var r=false;var n="/bitrix/js/main/phonenumber/metadata.json";var a={};var i;var o=3;var u=2;var s=17;var l=250;var h="+";var f="0-9";var m="-";var c="/";var p=".";var N="s";var b="()\\[\\]";var d="~";var v="["+h+f+"]";var g="[^"+f+"]+$";var y="["+f+"]{"+u+"}";var P=m+c+p+N+b+d;var B="["+h+"]{0,1}"+"(?:"+"["+P+"]*"+"["+f+"]"+"){3,}"+"["+P+f+"]*";var C="^(?:"+"^"+y+"$"+"|"+"^"+B+"$"+")$";var F=function(){if(r){var t=new BX.Promise;t.fulfill({codeToCountries:i,metadata:a});return t}else if(e){return e}else{e=new BX.Promise;BX.ajax.load({url:n,type:"json",callback:function(t){i=t.codeToCountries;a=t.metadata;t.metadata.forEach(function(t){a[t["id"]]=t});r=true;e.fulfill({codeToCountries:i,metadata:a})}});return e}};BX.PhoneNumber=function(){this.rawNumber=null;this.country=null;this.valid=false;this.countryCode=null;this.nationalNumber=null;this.numberType=null;this.extension=null;this.international=false;this.hadNationalPrefix=false};BX.PhoneNumber.Format={E164:"E.164",INTERNATIONAL:"International",NATIONAL:"National"};BX.PhoneNumber.getDefaultCountry=function(){return BX.message("phone_number_default_country")};BX.PhoneNumber.getIncompleteFormatter=function(t){var e=new BX.Promise;if(r){e.fulfill(new BX.PhoneNumber.IncompleteFormatter(t))}else{F().then(function(){e.fulfill(new BX.PhoneNumber.IncompleteFormatter(t))})}return e};BX.PhoneNumber.prototype.format=function(t,e){if(!this.valid)return this.rawNumber;if(!t)t=this.international?BX.PhoneNumber.Format.INTERNATIONAL:BX.PhoneNumber.Format.NATIONAL;return BX.PhoneNumberFormatter.format(this,t,e||this.hadNationalPrefix)};BX.PhoneNumber.prototype.getRawNumber=function(){return this.rawNumber};BX.PhoneNumber.prototype.setRawNumber=function(t){this.rawNumber=t};BX.PhoneNumber.prototype.getCountry=function(){return this.country};BX.PhoneNumber.prototype.setCountry=function(t){this.country=t};BX.PhoneNumber.prototype.isValid=function(){return this.valid};BX.PhoneNumber.prototype.setValid=function(t){this.valid=t};BX.PhoneNumber.prototype.getCountryCode=function(){return this.countryCode};BX.PhoneNumber.prototype.setCountryCode=function(t){this.countryCode=t};BX.PhoneNumber.prototype.getNationalNumber=function(){return this.nationalNumber};BX.PhoneNumber.prototype.setNationalNumber=function(t){this.nationalNumber=t};BX.PhoneNumber.prototype.getNumberType=function(){return this.numberType};BX.PhoneNumber.prototype.setNumberType=function(t){this.numberType=t};BX.PhoneNumber.prototype.getExtension=function(){return this.extension};BX.PhoneNumber.prototype.getExtension=function(t){this.extension=t};BX.PhoneNumber.prototype.isInternational=function(){return this.international};BX.PhoneNumber.prototype.setInternational=function(t){this.international=t};BX.PhoneNumber.prototype.setHadNationalPrefix=function(t){this.hadNationalPrefix=t};BX.PhoneNumberParser=function(){};BX.PhoneNumberParser.getInstance=function(){if(!(t instanceof BX.PhoneNumberParser))t=new BX.PhoneNumberParser;return t};BX.PhoneNumberParser.prototype.parse=function(t,e){var n=this;var a=new BX.Promise;if(!e)e=BX.PhoneNumber.getDefaultCountry();if(r){a.fulfill(n._realParse(t,e))}else{F().then(function(){a.fulfill(n._realParse(t,e))})}return a};BX.PhoneNumberParser.prototype._realParse=function(t,e){var r=new BX.PhoneNumber;r.setRawNumber(t);var n=S(t);if(!V(n)){return r}var a=M(n);if(a===false){return r}var i;var o=a["countryCode"];var u=a["localNumber"];var l;var h;if(o){l=true;h=j(o);i=null}else{i=e;h=Z(i);o=h["countryCode"];var f=q(u,h);l=f!==u;u=f}if(!h){return r}var m=K(u,h);var c=false;if(m!==u){c=G(m,h);if(c){u=m}}if(i===null){i=z(o,u);if(!i){return r}h=Z(i)}if(u.length>s){return r}var p=new RegExp("^(?:"+h["generalDesc"]["nationalNumberPattern"]+")$");if(!u.match(p)){return r}r.setCountry(i);r.setCountryCode(o);r.setNationalNumber(u);r.setNumberType(U(u,i));r.setInternational(l);r.setHadNationalPrefix(c);r.setValid(true);return r};BX.PhoneNumberFormatter={};BX.PhoneNumberFormatter.format=function(t,e,n){n=n===true;if(!(t instanceof BX.PhoneNumber)){throw new Error("number should be instance of BX.PhoneNumber")}if(!r){throw new Error("Metadata should be loaded prior to calling format")}if(!t.isValid())return t.getRawNumber();if(e===BX.PhoneNumber.Format.E164)return"+"+t.getCountryCode()+t.getNationalNumber();var i=a[t.getCountry()];var o=e===BX.PhoneNumber.Format.INTERNATIONAL;var u=this.selectFormatForNumber(t.getNationalNumber(),o,i);if(u){var s=this.formatNationalNumber(t.getNationalNumber(),o,i,u,n)}else{s=t.getNationalNumber()}if(e===BX.PhoneNumber.Format.INTERNATIONAL){return"+"+t.getCountryCode()+" "+s}else if(e===BX.PhoneNumber.Format.NATIONAL){return s}return t.getRawNumber()};BX.PhoneNumberFormatter.selectFormatForNumber=function(t,e,r){var n=BX.type.isArray(r["availableFormats"])?r["availableFormats"]:[];for(var a=0;a<n.length;a++){var i=n[a];if(e&&i.hasOwnProperty("intlFormat")&&i["intlFormat"]==="NA")continue;if(i.hasOwnProperty("leadingDigits")&&!at(t,i["leadingDigits"])){continue}var o=new RegExp("^"+i["pattern"]+"$");if(t.match(o)){return i}}return false};BX.PhoneNumberFormatter.formatNationalNumber=function(t,e,r,n,a){var i=n.hasOwnProperty("intlFormat")&&e?n["intlFormat"]:n["format"];var o=new RegExp(n["pattern"]);if(!e&&(a!==false||!rt(n,r))){var u=this.getNationalPrefixFormattingRule(r,n);if(u!=""){i=i.replace(new RegExp("(\\$\\d)"),u)}else{i=r["nationalPrefix"]+" "+i}}return t.replace(o,i)};BX.PhoneNumberFormatter.getNationalPrefixFormattingRule=function(t,e){var r=et(e,t);return r.replace("$NP",t["nationalPrefix"]).replace("$FG","$1")};BX.PhoneNumberFormatter.getNationalPrefixOptional=function(t,e){if(BX.type.isPlainObject(e)&&e.hasOwnProperty("nationalPrefixOptionalWhenFormatting"))return e["nationalPrefixOptionalWhenFormatting"];else if(t.hasOwnProperty("nationalPrefixOptionalWhenFormatting"))return t["nationalPrefixOptionalWhenFormatting"];else return false};var X="9";var x=new RegExp(X,"g");var w=15;var I=lt(X,w);var T="x";var R=new RegExp(T);var E=new RegExp(T,"g");var O=new RegExp("\\[([^\\[\\]])*\\]","g");var _=new RegExp("\\d(?=[^,}][^,}])","g");var D=new RegExp("^"+"["+P+"]*"+"(\\$\\d["+P+"]*)+"+"$");const A=3;const L="["+h+"]{0,1}"+"["+P+f+"]*";const $=new RegExp("^"+L+"$","i");BX.PhoneNumber.IncompleteFormatter=function(t){if(!r){throw new Error("Metadata is not loaded yet. Do not construct this class directly, use BX.PhoneNumber.getIncompleteFormatter instead")}this.defaultCountry=t||BX.PhoneNumber.getDefaultCountry();this.rawInput=null;this.country=null;this.countryCode=null;this.countryMetadata=null;this.nationalPrefix=null;this.nationalNumber=null;this.isInternational=false;this.hasNationalPrefix=false;this.hasPlusChar=false;this.formattedNumber=null};BX.PhoneNumber.IncompleteFormatter.prototype.format=function(t){this.resetState();var e=S(t);if(!e&&t[0]===h){this.rawInput=t;this.formattedNumber=t;return t}this.isInternational=e[0]===h;e=ot(e);this.rawInput=e;if(this.isInternational){this.hasPlusChar=true;this.rawInput=h+e}if(this.isInternational){this.extractCountryCode();if(!this.countryCode){return this.rawInput}this.findSuitableCountry()}else if(!this.defaultCountry){return this.rawInput}else{this.country=this.defaultCountry;this.countryMetadata=Z(this.country);this.nationalNumber=this.rawInput;this.extractNationalPrefix();if(!this.hasNationalPrefix){this.tryToStripCountryCode()}}var r=this.formatNationalNumber();if(r){return r}return this.rawInput};BX.PhoneNumber.IncompleteFormatter.prototype.extractCountryCode=function(){var t=M(this.rawInput);if(t&&t["countryCode"]){this.countryCode=t["countryCode"];this.nationalNumber=t["localNumber"]}};BX.PhoneNumber.IncompleteFormatter.prototype.tryToStripCountryCode=function(){var t=this.countryMetadata["countryCode"];var e;if(this.nationalNumber.indexOf(t)===0){e=this.nationalNumber.substr(t.length);if(H(e,this.countryMetadata,true,false)){this.isInternational=true;this.countryCode=t;this.nationalNumber=e}}};BX.PhoneNumber.IncompleteFormatter.prototype.extractNationalPrefix=function(){var t=K(this.nationalNumber,this.countryMetadata);if(t!==this.nationalNumber){if(!H(t,this.countryMetadata,false,true)){return false}this.hasNationalPrefix=true;this.nationalPrefix=this.nationalNumber.substr(0,this.nationalNumber.length-t.length);this.nationalNumber=t;return true}return false};BX.PhoneNumber.IncompleteFormatter.prototype.resetState=function(){this.country=null;this.country=null;this.countryCode=null;this.nationalPrefix=null;this.nationalNumber=null;this.isInternational=false;this.hasNationalPrefix=false;this.hasPlusChar=false;this.selectedFormat=null;this.formattedNumber=null;this.formattingTemplate=null};BX.PhoneNumber.IncompleteFormatter.prototype.findSuitableCountry=function(){var t=z(this.countryCode,this.nationalNumber);if(t)this.country=t;else this.country=Y(this.countryCode);this.countryMetadata=Z(this.country)};BX.PhoneNumber.IncompleteFormatter.prototype.formatNationalNumber=function(){if(this.isCompleteNumber()){return this.formatCompleteNumber(this.nationalNumber)}if(this.selectFormat()){this.formattedNumber=this.formatUsingTemplate();if(this.isInternational){return(this.hasPlusChar?h:"")+this.countryCode+" "+this.formattedNumber}else{return this.formattedNumber}}};BX.PhoneNumber.IncompleteFormatter.prototype.isCompleteNumber=function(){return U(this.nationalNumber,this.country)?true:false};BX.PhoneNumber.IncompleteFormatter.prototype.selectFormat=function(){var t=BX.type.isArray(this.countryMetadata["availableFormats"])?this.countryMetadata["availableFormats"]:[];for(var e=0;e<t.length;e++){var r=t[e];if(!this.isFormatSuitable(r))continue;if(r.hasOwnProperty("leadingDigits")&&!at(this.nationalNumber,r["leadingDigits"]))continue;if(!this.createFormattingTemplate(r))continue;this.selectedFormat=r;return true}return false};BX.PhoneNumber.IncompleteFormatter.prototype.createFormattingTemplate=function(t){var e=t["pattern"];if(e.indexOf("|")!==-1)return false;this.formattingTemplate="";var r=this.getFormattingTemplate(e,t);if(r){this.formattingTemplate=r;return true}return false};BX.PhoneNumber.IncompleteFormatter.prototype.getFormattingTemplate=function(t,e){var r=it(e,this.isInternational);var n=t.replace(O,"\\d");n=n.replace(_,"\\d");var a=I.match(new RegExp(n))[0];if(this.nationalNumber.length>a.length)return false;if(this.hasNationalPrefix){var i=et(e,this.countryMetadata);if(i){i=i.replace("$NP",this.nationalPrefix).replace("$FG","$1");r=r.replace(new RegExp("(\\$\\d)"),i)}else{r=this.nationalPrefix+" "+r}}var o=a.replace(new RegExp(n,"g"),r);o=o.replace(x,T);return o};BX.PhoneNumber.IncompleteFormatter.prototype.formatUsingTemplate=function(){if(!this.formattingTemplate)return false;var t=this.formattingTemplate;var e;for(var r=0;r<this.nationalNumber.length;r++){e=t.search(R);if(e===-1)return false;t=t.replace(R,this.nationalNumber[r])}t=this.closeLastBracket(t,e+1);return t};BX.PhoneNumber.IncompleteFormatter.prototype.closeLastBracket=function(t,e){var r=t.substr(e);var n=r.indexOf("(");var a=r.indexOf(")");if(a!==-1&&(n===-1||n>a)){e=e+a+1}return t.substr(0,e).replace(E," ")};BX.PhoneNumber.IncompleteFormatter.prototype.formatCompleteNumber=function(){if(!this.countryMetadata.hasOwnProperty("availableFormats"))return false;var t=BX.PhoneNumberFormatter.selectFormatForNumber(this.nationalNumber,this.isInternational,this.countryMetadata);if(!t)return false;var e=BX.PhoneNumberFormatter.formatNationalNumber(this.nationalNumber,this.isInternational,this.countryMetadata,t,this.hasNationalPrefix);if(this.isInternational){e=(this.hasPlusChar?h:"")+this.countryCode+" "+e}this.selectedFormat=t;return e};BX.PhoneNumber.IncompleteFormatter.prototype.isFormatSuitable=function(t){if(this.isInternational){return tt(t)?true:false}else{return!this.hasNationalPrefix||nt(t,this.countryMetadata)}};var k="[\\d+]";BX.PhoneNumber.Input=function(t){if(!BX.type.isDomNode(t.node)||t.node.nodeName!=="INPUT"||t.node.type!=="text"){throw new Error("params.node should be text input node")}this.inputNode=t.node;this.defaultCountry=t.defaultCountry||BX.PhoneNumber.getDefaultCountry();this.forceLeadingPlus=t.forceLeadingPlus===true;this.callbacks={initialize:BX.type.isFunction(t.onInitialize)?t.onInitialize:BX.DoNothing,change:BX.type.isFunction(t.onChange)?t.onChange:BX.DoNothing,countryChange:BX.type.isFunction(t.onCountryChange)?t.onCountryChange:BX.DoNothing};this.formatter=null;this._lastCaretPosition=null;this._digitsToTheLeft=0;this._digitsToTheRight=0;this._digitsCount=0;this._selectedDigitsBeforeAction=0;this._countryBefore="";this.init();this.bindEvents()};BX.PhoneNumber.Input.prototype.init=function(){var t=this;BX.PhoneNumber.getIncompleteFormatter(this.defaultCountry).then(function(e){t.formatter=e;if(t.inputNode.value){t.inputNode.value=t.formatter.format(t.inputNode.value)}t.callbacks.initialize()})};BX.PhoneNumber.Input.prototype.bindEvents=function(){this.inputNode.addEventListener("keydown",this._onKeyDown.bind(this));this.inputNode.addEventListener("input",this._onInput.bind(this))};BX.PhoneNumber.Input.prototype.getValue=function(){return W(this.inputNode.value)};BX.PhoneNumber.Input.prototype.getFormattedValue=function(){return this.inputNode.value};BX.PhoneNumber.Input.prototype.getCountry=function(){return this.formatter.country||this.formatter.defaultCountry};BX.PhoneNumber.Input.prototype.getCountryCode=function(){var t=Z(this.getCountry());return t?t["countryCode"]:false};BX.PhoneNumber.Input.prototype._onKeyDown=function(t){var e=this.inputNode.selectionEnd-this.inputNode.selectionStart;if(t.key===h){if(this.inputNode.selectionStart!==0){t.preventDefault();t.stopPropagation();return}}else if(t.key.length===1&&t.key.search(/\d/)!==0&&!t.ctrlKey){t.preventDefault();t.stopPropagation();return}var r=st(this.inputNode.value);this._lastCaretPosition=this.inputNode.selectionStart;this._digitsToTheLeft=ut(k,this.inputNode.value.substr(0,this._lastCaretPosition));this._digitsToTheRight=ut(k,this.inputNode.value.substr(this._lastCaretPosition));this._digitsCount=ut(k,this.inputNode.value);this._countryBefore=this.getCountry();if(e>0){var n=this.inputNode.value.substr(this.inputNode.selectionStart,e);this._selectedDigitsBeforeAction=ut(k,n)}else{this._selectedDigitsBeforeAction=0}var a=null;if(t.key==="Backspace"&&e===0){a=r[this._digitsToTheLeft-1]+1}if(t.key==="Delete"&&e===0&&this._digitsToTheRight>0){a=r[this._digitsToTheLeft]}if(a!==null){this.inputNode.setSelectionRange(a,a)}};BX.PhoneNumber.Input.prototype._onInput=function(t){var e=null;if(this.formatter){var r=this.formatter.format(this.inputNode.value);var n=st(r);var a=this._digitsCount;var i=this._selectedDigitsBeforeAction;var o=ut(k,r);var u=o-a;var s=u+i;if(this._lastCaretPosition!==null){switch(t.inputType){case"deleteContentBackward":if(u==-1)e=n[this._digitsToTheLeft+u-1]+1;else e=n[this._digitsToTheLeft];break;case"deleteContentForward":if(this._digitsToTheLeft===0){e=n[0]}else{e=n[this._digitsToTheLeft-1]+1}break;case"insertText":case"insertFromPaste":e=n[this._digitsToTheLeft-1+s]+1;break}this.inputNode.value=r;if(e!==null){this.inputNode.setSelectionRange(e,e)}this.callbacks.change({value:this.getValue(),formattedValue:this.getFormattedValue(),country:this.getCountry(),countryCode:this.getCountryCode()});if(this._countryBefore!==this.getCountry()){this.callbacks.countryChange({country:this.getCountry(),countryCode:this.getCountryCode()})}}}this._lastCaretPosition=null};var S=function(t){if(!t||t.length>l){return""}var e=t.search(new RegExp(v));if(e<0){return""}var r=t.substr(e);r=r.replace(new RegExp(g),"");return r};var M=function(t){t=W(t);if(!t)return false;if(t[0]!==h){return{countryCode:"",localNumber:t}}t=t.substr(1);if(t[0]==="0"){return false}for(var e=o;e>0;e--){var r=t.substr(0,e);if(J(r)){return{countryCode:r,localNumber:t.substr(e)}}}return false};var V=function(t){return t.length>=u&&t.search(new RegExp(C))!==-1};var W=function(t){if(!t)return"";var e=t[0]===h;t=ot(t);if(e)return h+t;else return t};var j=function(t){if(!J(t)){return false}var e=Q(t);return Z(e[0])};var z=function(t,e){if(!t||!e)return false;var r=Q(t);var n;var a;if(r.length===1){return r[0]}for(var i=0;i<r.length;i++){n=r[i];a=Z(n);if(a.hasOwnProperty("leadingDigits")){if(e.match(new RegExp(a["leadingDigits"]))){return n}}else if(U(e,n)){return n}}return false};var U=function(t,e){var r=Z(e);var n;if(!r)return false;if(r["generalDesc"]&&r["generalDesc"]["nationalNumberPattern"]){if(!t.match(new RegExp("^(?:"+r["generalDesc"]["nationalNumberPattern"]+")$")))return false}var a=["noInternationalDialling","areaCodeOptional","fixedLine","mobile","pager","tollFree","premiumRate","sharedCost","personalNumber","voip","uan","voicemail"];for(var i=0;i<a.length;i++){n=a[i];if(r[n]&&r[n]["nationalNumberPattern"]){if(t.match(new RegExp("^"+r[n]["nationalNumberPattern"]+"$"))){return n}}}return false};var K=function(t,e){var r=e.hasOwnProperty("nationalPrefixForParsing")?e["nationalPrefixForParsing"]:e["nationalPrefix"];if(t==""||r=="")return t;var n="^(?:"+r+")";var a=t.match(new RegExp(n));if(!a){return t}var i=e["nationalPrefixTransformRule"];var o;if(i&&a.length>1){o=t.replace(n,i)}else{o=t.substr(a[0].length)}return o};var G=function(t,e){var r=new RegExp("^(?:"+e["generalDesc"]["nationalNumberPattern"]+")$");if(t.match(r,t))return true;else return false};var H=function(t,e,r,n){if(!e["availableFormats"])return true;for(var a=0;a<e.availableFormats.length;a++){var i=e.availableFormats[a];if(r&&i["intlFormat"]==="NA")continue;if(n){var o=et(i,e);if(o&&o.search(/\$NP/)===-1)continue}if(i["leadingDigits"]&&!at(t,i["leadingDigits"]))continue;return true}return false};var q=function(t,e){var r=e["countryCode"];if(t.search(r)!==0)return t;var n=t.substr(r.length);var a=new RegExp("^(?:"+e["generalDesc"]["nationalNumberPattern"]+")$");if(t.match(a)&&!n.match(a)){return t}return n};var J=function(t){t=t.toString();return i.hasOwnProperty(t)};var Q=function(t){t=t.toString();return i.hasOwnProperty(t)?i[t]:[]};var Y=function(t){t=t.toString();return i.hasOwnProperty(t)?i[t][0]:false};var Z=function(t){t=t.toUpperCase();return a.hasOwnProperty(t)?a[t]:false};var tt=function(t){if(t.hasOwnProperty("intlFormat")){if(t["intlFormat"]==="NA")return false;else return t["intlFormat"]}return t["format"]};var et=function(t,e){if(t.hasOwnProperty("nationalPrefixFormattingRule"))return t["nationalPrefixFormattingRule"];else if(e.hasOwnProperty("nationalPrefixFormattingRule"))return e["nationalPrefixFormattingRule"];else return""};var rt=function(t,e){if(t.hasOwnProperty("nationalPrefixOptionalWhenFormatting"))return t["nationalPrefixOptionalWhenFormatting"];else if(e.hasOwnProperty("nationalPrefixOptionalWhenFormatting"))return e["nationalPrefixOptionalWhenFormatting"];else return false};var nt=function(t,e){var r=et(t,e);return!r||r.search(/\$NP/)!==-1};var at=function(t,e){var r;var n;if(BX.type.isArray(e)){for(var a=0;a<e.length;a++){r=new RegExp("^"+e[a]);n=t.match(r);if(n){return n}}}else{r=new RegExp("^"+e);n=t.match(r);if(n){return n}}return false};var it=function(t,e){if(e&&t.hasOwnProperty("intlFormat"))return t["intlFormat"];else return t["format"]};var ot=function(t){return t.replace(new RegExp("[^\\d]","g"),"")};var ut=function(t,e){var r=e.match(t instanceof RegExp?t:new RegExp(t,"g"));return r?r.length:0};var st=function(t){var e=/[\d+]/g;var r=[];var n;while((n=e.exec(t))!==null){r.push(n.index)}return r};function lt(t,e){var r="";if(e<=0)return"";for(var n=0;n<e;n++)r+=t;return r}})(); //# sourceMappingURL=phonenumber.map.js