intl_phone_picker 0.0.7.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,1183 +2,8 @@
2
2
  //= require intlTelInputCore
3
3
 
4
4
  /*
5
- International Telephone Input v6.0.4
6
- https://github.com/Bluefieldscom/intl-tel-input.git
7
- */
8
- // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
9
- (function(factory) {
10
- if (typeof define === "function" && define.amd) {
11
- define([ "jquery" ], function($) {
12
- factory($, window, document);
13
- });
14
- } else {
15
- factory(jQuery, window, document);
16
- }
17
- })(function($, window, document, undefined) {
18
- "use strict";
19
- // these vars persist through all instances of the plugin
20
- var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling
21
- defaults = {
22
- // typing digits after a valid number will be added to the extension part of the number
23
- allowExtensions: false,
24
- // automatically format the number according to the selected country
25
- autoFormat: true,
26
- // if there is just a dial code in the input: remove it on blur, and re-add it on focus
27
- autoHideDialCode: true,
28
- // add or remove input placeholder with an example number for the selected country
29
- autoPlaceholder: true,
30
- // default country
31
- defaultCountry: "",
32
- // geoIp lookup function
33
- geoIpLookup: null,
34
- // don't insert international dial codes
35
- nationalMode: true,
36
- // number type to use for placeholders
37
- numberType: "MOBILE",
38
- // display only these countries
39
- onlyCountries: [],
40
- // the countries at the top of the list. defaults to united states and united kingdom
41
- preferredCountries: [ "us", "gb" ],
42
- // specify the path to the libphonenumber script to enable validation/formatting
43
- utilsScript: ""
44
- }, keys = {
45
- UP: 38,
46
- DOWN: 40,
47
- ENTER: 13,
48
- ESC: 27,
49
- PLUS: 43,
50
- A: 65,
51
- Z: 90,
52
- ZERO: 48,
53
- NINE: 57,
54
- SPACE: 32,
55
- BSPACE: 8,
56
- TAB: 9,
57
- DEL: 46,
58
- CTRL: 17,
59
- CMD1: 91,
60
- // Chrome
61
- CMD2: 224
62
- }, windowLoaded = false;
63
- // keep track of if the window.load event has fired as impossible to check after the fact
64
- $(window).load(function() {
65
- windowLoaded = true;
66
- });
67
- function Plugin(element, options) {
68
- this.element = element;
69
- this.options = $.extend({}, defaults, options);
70
- this._defaults = defaults;
71
- // event namespace
72
- this.ns = "." + pluginName + id++;
73
- // Chrome, FF, Safari, IE9+
74
- this.isGoodBrowser = Boolean(element.setSelectionRange);
75
- this.hadInitialPlaceholder = Boolean($(element).attr("placeholder"));
76
- this._name = pluginName;
77
- }
78
- Plugin.prototype = {
79
- _init: function() {
80
- // if in nationalMode, disable options relating to dial codes
81
- if (this.options.nationalMode) {
82
- this.options.autoHideDialCode = false;
83
- }
84
- // IE Mobile doesn't support the keypress event (see issue 68) which makes autoFormat impossible
85
- if (navigator.userAgent.match(/IEMobile/i)) {
86
- this.options.autoFormat = false;
87
- }
88
- // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions
89
- // Note: for some reason jasmine fucks up if you put this in the main Plugin function with the rest of these declarations
90
- // Note: to target Android Mobiles (and not Tablets), we must find "Android" and "Mobile"
91
- this.isMobile = /Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
92
- // we return these deferred objects from the _init() call so they can be watched, and then we resolve them when each specific request returns
93
- // Note: again, jasmine had a spazz when I put these in the Plugin function
94
- this.autoCountryDeferred = new $.Deferred();
95
- this.utilsScriptDeferred = new $.Deferred();
96
- // process all the data: onlyCountries, preferredCountries etc
97
- this._processCountryData();
98
- // generate the markup
99
- this._generateMarkup();
100
- // set the initial state of the input value and the selected flag
101
- this._setInitialState();
102
- // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
103
- this._initListeners();
104
- // utils script, and auto country
105
- this._initRequests();
106
- // return the deferreds
107
- return [ this.autoCountryDeferred, this.utilsScriptDeferred ];
108
- },
109
- /********************
110
- * PRIVATE METHODS
111
- ********************/
112
- // prepare all of the country data, including onlyCountries and preferredCountries options
113
- _processCountryData: function() {
114
- // set the instances country data objects
115
- this._setInstanceCountryData();
116
- // set the preferredCountries property
117
- this._setPreferredCountries();
118
- },
119
- // add a country code to this.countryCodes
120
- _addCountryCode: function(iso2, dialCode, priority) {
121
- if (!(dialCode in this.countryCodes)) {
122
- this.countryCodes[dialCode] = [];
123
- }
124
- var index = priority || 0;
125
- this.countryCodes[dialCode][index] = iso2;
126
- },
127
- // process onlyCountries array if present, and generate the countryCodes map
128
- _setInstanceCountryData: function() {
129
- var i;
130
- // process onlyCountries option
131
- if (this.options.onlyCountries.length) {
132
- // standardise case
133
- for (i = 0; i < this.options.onlyCountries.length; i++) {
134
- this.options.onlyCountries[i] = this.options.onlyCountries[i].toLowerCase();
135
- }
136
- // build instance country array
137
- this.countries = [];
138
- for (i = 0; i < allCountries.length; i++) {
139
- if ($.inArray(allCountries[i].iso2, this.options.onlyCountries) != -1) {
140
- this.countries.push(allCountries[i]);
141
- }
142
- }
143
- } else {
144
- this.countries = allCountries;
145
- }
146
- // generate countryCodes map
147
- this.countryCodes = {};
148
- for (i = 0; i < this.countries.length; i++) {
149
- var c = this.countries[i];
150
- this._addCountryCode(c.iso2, c.dialCode, c.priority);
151
- // area codes
152
- if (c.areaCodes) {
153
- for (var j = 0; j < c.areaCodes.length; j++) {
154
- // full dial code is country code + dial code
155
- this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]);
156
- }
157
- }
158
- }
159
- },
160
- // process preferred countries - iterate through the preferences,
161
- // fetching the country data for each one
162
- _setPreferredCountries: function() {
163
- this.preferredCountries = [];
164
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
165
- var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true);
166
- if (countryData) {
167
- this.preferredCountries.push(countryData);
168
- }
169
- }
170
- },
171
- // generate all of the markup for the plugin: the selected flag overlay, and the dropdown
172
- _generateMarkup: function() {
173
- // telephone input
174
- this.telInput = $(this.element);
175
- // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can easily put the plugin in an inconsistent state e.g. the wrong flag selected for the autocompleted number, which on submit could mean the wrong number is saved (esp in nationalMode)
176
- this.telInput.attr("autocomplete", "off");
177
- // containers (mostly for positioning)
178
- this.telInput.wrap($("<div>", {
179
- "class": "intl-tel-input"
180
- }));
181
- this.flagsContainer = $("<div>", {
182
- "class": "flag-dropdown"
183
- }).insertBefore(this.telInput);
184
- // currently selected flag (displayed to left of input)
185
- var selectedFlag = $("<div>", {
186
- // make element focusable and tab naviagable
187
- tabindex: "0",
188
- "class": "selected-flag"
189
- }).appendTo(this.flagsContainer);
190
- this.selectedFlagInner = $("<div>", {
191
- "class": "iti-flag"
192
- }).appendTo(selectedFlag);
193
- // CSS triangle
194
- $("<div>", {
195
- "class": "arrow"
196
- }).appendTo(selectedFlag);
197
- // country list
198
- // mobile is just a native select element
199
- // desktop is a proper list containing: preferred countries, then divider, then all countries
200
- if (this.isMobile) {
201
- this.countryList = $("<select>", {
202
- "class": "iti-mobile-select"
203
- }).appendTo(this.flagsContainer);
204
- } else {
205
- this.countryList = $("<ul>", {
206
- "class": "country-list v-hide"
207
- }).appendTo(this.flagsContainer);
208
- if (this.preferredCountries.length && !this.isMobile) {
209
- this._appendListItems(this.preferredCountries, "preferred");
210
- $("<li>", {
211
- "class": "divider"
212
- }).appendTo(this.countryList);
213
- }
214
- }
215
- this._appendListItems(this.countries, "");
216
- if (!this.isMobile) {
217
- // now we can grab the dropdown height, and hide it properly
218
- this.dropdownHeight = this.countryList.outerHeight();
219
- this.countryList.removeClass("v-hide").addClass("hide");
220
- // this is useful in lots of places
221
- this.countryListItems = this.countryList.children(".country");
222
- }
223
- },
224
- // add a country <li> to the countryList <ul> container
225
- // UPDATE: if isMobile, add an <option> to the countryList <select> container
226
- _appendListItems: function(countries, className) {
227
- // we create so many DOM elements, it is faster to build a temp string
228
- // and then add everything to the DOM in one go at the end
229
- var tmp = "";
230
- // for each country
231
- for (var i = 0; i < countries.length; i++) {
232
- var c = countries[i];
233
- if (this.isMobile) {
234
- tmp += "<option data-dial-code='" + c.dialCode + "' value='" + c.iso2 + "'>";
235
- tmp += c.name + " +" + c.dialCode;
236
- tmp += "</option>";
237
- } else {
238
- // open the list item
239
- tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>";
240
- // add the flag
241
- tmp += "<div class='flag'><div class='iti-flag " + c.iso2 + "'></div></div>";
242
- // and the country name and dial code
243
- tmp += "<span class='country-name'>" + c.name + "</span>";
244
- tmp += "<span class='dial-code'>+" + c.dialCode + "</span>";
245
- // close the list item
246
- tmp += "</li>";
247
- }
248
- }
249
- this.countryList.append(tmp);
250
- },
251
- // set the initial state of the input value and the selected flag
252
- _setInitialState: function() {
253
- var val = this.telInput.val();
254
- // if there is a number, and it's valid, we can go ahead and set the flag, else fall back to default
255
- if (this._getDialCode(val)) {
256
- this._updateFlagFromNumber(val, true);
257
- } else if (this.options.defaultCountry != "auto") {
258
- // check the defaultCountry option, else fall back to the first in the list
259
- if (this.options.defaultCountry) {
260
- this.options.defaultCountry = this._getCountryData(this.options.defaultCountry.toLowerCase(), false, false);
261
- } else {
262
- this.options.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0] : this.countries[0];
263
- }
264
- this._selectFlag(this.options.defaultCountry.iso2);
265
- // if empty, insert the default dial code (this function will check !nationalMode and !autoHideDialCode)
266
- if (!val) {
267
- this._updateDialCode(this.options.defaultCountry.dialCode, false);
268
- }
269
- }
270
- // format
271
- if (val) {
272
- // this wont be run after _updateDialCode as that's only called if no val
273
- this._updateVal(val);
274
- }
275
- },
276
- // initialise the main event listeners: input keyup, and click selected flag
277
- _initListeners: function() {
278
- var that = this;
279
- this._initKeyListeners();
280
- // autoFormat prevents the change event from firing, so we need to check for changes between focus and blur in order to manually trigger it
281
- if (this.options.autoHideDialCode || this.options.autoFormat) {
282
- this._initFocusListeners();
283
- }
284
- if (this.isMobile) {
285
- this.countryList.on("change" + this.ns, function(e) {
286
- that._selectListItem($(this).find("option:selected"));
287
- });
288
- } else {
289
- // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again
290
- var label = this.telInput.closest("label");
291
- if (label.length) {
292
- label.on("click" + this.ns, function(e) {
293
- // if the dropdown is closed, then focus the input, else ignore the click
294
- if (that.countryList.hasClass("hide")) {
295
- that.telInput.focus();
296
- } else {
297
- e.preventDefault();
298
- }
299
- });
300
- }
301
- // toggle country dropdown on click
302
- var selectedFlag = this.selectedFlagInner.parent();
303
- selectedFlag.on("click" + this.ns, function(e) {
304
- // only intercept this event if we're opening the dropdown
305
- // else let it bubble up to the top ("click-off-to-close" listener)
306
- // we cannot just stopPropagation as it may be needed to close another instance
307
- if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) {
308
- that._showDropdown();
309
- }
310
- });
311
- }
312
- // open dropdown list if currently focused
313
- this.flagsContainer.on("keydown" + that.ns, function(e) {
314
- var isDropdownHidden = that.countryList.hasClass("hide");
315
- if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) {
316
- // prevent form from being submitted if "ENTER" was pressed
317
- e.preventDefault();
318
- // prevent event from being handled again by document
319
- e.stopPropagation();
320
- that._showDropdown();
321
- }
322
- // allow navigation from dropdown to input on TAB
323
- if (e.which == keys.TAB) {
324
- that._closeDropdown();
325
- }
326
- });
327
- },
328
- _initRequests: function() {
329
- var that = this;
330
- // if the user has specified the path to the utils script, fetch it on window.load
331
- if (this.options.utilsScript) {
332
- // if the plugin is being initialised after the window.load event has already been fired
333
- if (windowLoaded) {
334
- this.loadUtils();
335
- } else {
336
- // wait until the load event so we don't block any other requests e.g. the flags image
337
- $(window).load(function() {
338
- that.loadUtils();
339
- });
340
- }
341
- } else {
342
- this.utilsScriptDeferred.resolve();
343
- }
344
- if (this.options.defaultCountry == "auto") {
345
- this._loadAutoCountry();
346
- } else {
347
- this.autoCountryDeferred.resolve();
348
- }
349
- },
350
- _loadAutoCountry: function() {
351
- var that = this;
352
- // check for cookie
353
- var cookieAutoCountry = $.cookie ? $.cookie("itiAutoCountry") : "";
354
- if (cookieAutoCountry) {
355
- $.fn[pluginName].autoCountry = cookieAutoCountry;
356
- }
357
- // 3 options:
358
- // 1) already loaded (we're done)
359
- // 2) not already started loading (start)
360
- // 3) already started loading (do nothing - just wait for loading callback to fire)
361
- if ($.fn[pluginName].autoCountry) {
362
- this.autoCountryLoaded();
363
- } else if (!$.fn[pluginName].startedLoadingAutoCountry) {
364
- // don't do this twice!
365
- $.fn[pluginName].startedLoadingAutoCountry = true;
366
- if (typeof this.options.geoIpLookup === "function") {
367
- this.options.geoIpLookup(function(countryCode) {
368
- $.fn[pluginName].autoCountry = countryCode.toLowerCase();
369
- if ($.cookie) {
370
- $.cookie("itiAutoCountry", $.fn[pluginName].autoCountry, {
371
- path: "/"
372
- });
373
- }
374
- // tell all instances the auto country is ready
375
- // TODO: this should just be the current instances
376
- $(".intl-tel-input input").intlTelInput("autoCountryLoaded");
377
- });
378
- }
379
- }
380
- },
381
- _initKeyListeners: function() {
382
- var that = this;
383
- if (this.options.autoFormat) {
384
- // format number and update flag on keypress
385
- // use keypress event as we want to ignore all input except for a select few keys,
386
- // but we dont want to ignore the navigation keys like the arrows etc.
387
- // NOTE: no point in refactoring this to only bind these listeners on focus/blur because then you would need to have those 2 listeners running the whole time anyway...
388
- this.telInput.on("keypress" + this.ns, function(e) {
389
- // 32 is space, and after that it's all chars (not meta/nav keys)
390
- // this fix is needed for Firefox, which triggers keypress event for some meta/nav keys
391
- // Update: also ignore if this is a metaKey e.g. FF and Safari trigger keypress on the v of Ctrl+v
392
- // Update: also ignore if ctrlKey (FF on Windows/Ubuntu)
393
- // Update: also check that we have utils before we do any autoFormat stuff
394
- if (e.which >= keys.SPACE && !e.ctrlKey && !e.metaKey && window.intlTelInputUtils && !that.telInput.prop("readonly")) {
395
- e.preventDefault();
396
- // allowed keys are just numeric keys and plus
397
- // we must allow plus for the case where the user does select-all and then hits plus to start typing a new number. we could refine this logic to first check that the selection contains a plus, but that wont work in old browsers, and I think it's overkill anyway
398
- var isAllowedKey = e.which >= keys.ZERO && e.which <= keys.NINE || e.which == keys.PLUS, input = that.telInput[0], noSelection = that.isGoodBrowser && input.selectionStart == input.selectionEnd, max = that.telInput.attr("maxlength"), val = that.telInput.val(), // assumes that if max exists, it is >0
399
- isBelowMax = max ? val.length < max : true;
400
- // first: ensure we dont go over maxlength. we must do this here to prevent adding digits in the middle of the number
401
- // still reformat even if not an allowed key as they could by typing a formatting char, but ignore if there's a selection as doesn't make sense to replace selection with illegal char and then immediately remove it
402
- if (isBelowMax && (isAllowedKey || noSelection)) {
403
- var newChar = isAllowedKey ? String.fromCharCode(e.which) : null;
404
- that._handleInputKey(newChar, true, isAllowedKey);
405
- // if something has changed, trigger the input event (which was otherwised squashed by the preventDefault)
406
- if (val != that.telInput.val()) {
407
- that.telInput.trigger("input");
408
- }
409
- }
410
- if (!isAllowedKey) {
411
- that._handleInvalidKey();
412
- }
413
- }
414
- });
415
- }
416
- // handle cut/paste event (now supported in all major browsers)
417
- this.telInput.on("cut" + this.ns + " paste" + this.ns, function() {
418
- // hack because "paste" event is fired before input is updated
419
- setTimeout(function() {
420
- if (that.options.autoFormat && window.intlTelInputUtils) {
421
- var cursorAtEnd = that.isGoodBrowser && that.telInput[0].selectionStart == that.telInput.val().length;
422
- that._handleInputKey(null, cursorAtEnd);
423
- that._ensurePlus();
424
- } else {
425
- // if no autoFormat, just update flag
426
- that._updateFlagFromNumber(that.telInput.val());
427
- }
428
- });
429
- });
430
- // handle keyup event
431
- // if autoFormat enabled: we use keyup to catch delete events (after the fact)
432
- // if no autoFormat, this is used to update the flag
433
- this.telInput.on("keyup" + this.ns, function(e) {
434
- // the "enter" key event from selecting a dropdown item is triggered here on the input, because the document.keydown handler that initially handles that event triggers a focus on the input, and so the keyup for that same key event gets triggered here. weird, but just make sure we dont bother doing any re-formatting in this case (we've already done preventDefault in the keydown handler, so it wont actually submit the form or anything).
435
- // ALSO: ignore keyup if readonly
436
- if (e.which == keys.ENTER || that.telInput.prop("readonly")) {} else if (that.options.autoFormat && window.intlTelInputUtils) {
437
- // cursorAtEnd defaults to false for bad browsers else they would never get a reformat on delete
438
- var cursorAtEnd = that.isGoodBrowser && that.telInput[0].selectionStart == that.telInput.val().length;
439
- if (!that.telInput.val()) {
440
- // if they just cleared the input, update the flag to the default
441
- that._updateFlagFromNumber("");
442
- } else if (e.which == keys.DEL && !cursorAtEnd || e.which == keys.BSPACE) {
443
- // if delete in the middle: reformat with no suffix (no need to reformat if delete at end)
444
- // if backspace: reformat with no suffix (need to reformat if at end to remove any lingering suffix - this is a feature)
445
- // important to remember never to add suffix on any delete key as can fuck up in ie8 so you can never delete a formatting char at the end
446
- that._handleInputKey();
447
- }
448
- that._ensurePlus();
449
- } else {
450
- // if no autoFormat, just update flag
451
- that._updateFlagFromNumber(that.telInput.val());
452
- }
453
- });
454
- },
455
- // prevent deleting the plus (if not in nationalMode)
456
- _ensurePlus: function() {
457
- if (!this.options.nationalMode) {
458
- var val = this.telInput.val(), input = this.telInput[0];
459
- if (val.charAt(0) != "+") {
460
- // newCursorPos is current pos + 1 to account for the plus we are about to add
461
- var newCursorPos = this.isGoodBrowser ? input.selectionStart + 1 : 0;
462
- this.telInput.val("+" + val);
463
- if (this.isGoodBrowser) {
464
- input.setSelectionRange(newCursorPos, newCursorPos);
465
- }
466
- }
467
- }
468
- },
469
- // alert the user to an invalid key event
470
- _handleInvalidKey: function() {
471
- var that = this;
472
- this.telInput.trigger("invalidkey").addClass("iti-invalid-key");
473
- setTimeout(function() {
474
- that.telInput.removeClass("iti-invalid-key");
475
- }, 100);
476
- },
477
- // when autoFormat is enabled: handle various key events on the input:
478
- // 1) adding a new number character, which will replace any selection, reformat, and preserve the cursor position
479
- // 2) reformatting on backspace/delete
480
- // 3) cut/paste event
481
- _handleInputKey: function(newNumericChar, addSuffix, isAllowedKey) {
482
- var val = this.telInput.val(), cleanBefore = this._getClean(val), originalLeftChars, // raw DOM element
483
- input = this.telInput[0], digitsOnRight = 0;
484
- if (this.isGoodBrowser) {
485
- // cursor strategy: maintain the number of digits on the right. we use the right instead of the left so that A) we dont have to account for the new digit (or multiple digits if paste event), and B) we're always on the right side of formatting suffixes
486
- digitsOnRight = this._getDigitsOnRight(val, input.selectionEnd);
487
- // if handling a new number character: insert it in the right place
488
- if (newNumericChar) {
489
- // replace any selection they may have made with the new char
490
- val = val.substr(0, input.selectionStart) + newNumericChar + val.substring(input.selectionEnd, val.length);
491
- } else {
492
- // here we're not handling a new char, we're just doing a re-format (e.g. on delete/backspace/paste, after the fact), but we still need to maintain the cursor position. so make note of the char on the left, and then after the re-format, we'll count in the same number of digits from the right, and then keep going through any formatting chars until we hit the same left char that we had before.
493
- // UPDATE: now have to store 2 chars as extensions formatting contains 2 spaces so you need to be able to distinguish
494
- originalLeftChars = val.substr(input.selectionStart - 2, 2);
495
- }
496
- } else if (newNumericChar) {
497
- val += newNumericChar;
498
- }
499
- // update the number and flag
500
- this.setNumber(val, null, addSuffix, true, isAllowedKey);
501
- // update the cursor position
502
- if (this.isGoodBrowser) {
503
- var newCursor;
504
- val = this.telInput.val();
505
- // if it was at the end, keep it there
506
- if (!digitsOnRight) {
507
- newCursor = val.length;
508
- } else {
509
- // else count in the same number of digits from the right
510
- newCursor = this._getCursorFromDigitsOnRight(val, digitsOnRight);
511
- // but if delete/paste etc, keep going left until hit the same left char as before
512
- if (!newNumericChar) {
513
- newCursor = this._getCursorFromLeftChar(val, newCursor, originalLeftChars);
514
- }
515
- }
516
- // set the new cursor
517
- input.setSelectionRange(newCursor, newCursor);
518
- }
519
- },
520
- // we start from the position in guessCursor, and work our way left until we hit the originalLeftChars or a number to make sure that after reformatting the cursor has the same char on the left in the case of a delete etc
521
- _getCursorFromLeftChar: function(val, guessCursor, originalLeftChars) {
522
- for (var i = guessCursor; i > 0; i--) {
523
- var leftChar = val.charAt(i - 1);
524
- if ($.isNumeric(leftChar) || val.substr(i - 2, 2) == originalLeftChars) {
525
- return i;
526
- }
527
- }
528
- return 0;
529
- },
530
- // after a reformat we need to make sure there are still the same number of digits to the right of the cursor
531
- _getCursorFromDigitsOnRight: function(val, digitsOnRight) {
532
- for (var i = val.length - 1; i >= 0; i--) {
533
- if ($.isNumeric(val.charAt(i))) {
534
- if (--digitsOnRight === 0) {
535
- return i;
536
- }
537
- }
538
- }
539
- return 0;
540
- },
541
- // get the number of numeric digits to the right of the cursor so we can reposition the cursor correctly after the reformat has happened
542
- _getDigitsOnRight: function(val, selectionEnd) {
543
- var digitsOnRight = 0;
544
- for (var i = selectionEnd; i < val.length; i++) {
545
- if ($.isNumeric(val.charAt(i))) {
546
- digitsOnRight++;
547
- }
548
- }
549
- return digitsOnRight;
550
- },
551
- // listen for focus and blur
552
- _initFocusListeners: function() {
553
- var that = this;
554
- if (this.options.autoHideDialCode) {
555
- // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click
556
- this.telInput.on("mousedown" + this.ns, function(e) {
557
- if (!that.telInput.is(":focus") && !that.telInput.val()) {
558
- e.preventDefault();
559
- // but this also cancels the focus, so we must trigger that manually
560
- that.telInput.focus();
561
- }
562
- });
563
- }
564
- this.telInput.on("focus" + this.ns, function(e) {
565
- var value = that.telInput.val();
566
- // save this to compare on blur
567
- that.telInput.data("focusVal", value);
568
- // on focus: if empty, insert the dial code for the currently selected flag
569
- if (that.options.autoHideDialCode && !value && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) {
570
- that._updateVal("+" + that.selectedCountryData.dialCode, null, true);
571
- // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one
572
- that.telInput.one("keypress.plus" + that.ns, function(e) {
573
- if (e.which == keys.PLUS) {
574
- // if autoFormat is enabled, this key event will have already have been handled by another keypress listener (hence we need to add the "+"). if disabled, it will be handled after this by a keyup listener (hence no need to add the "+").
575
- var newVal = that.options.autoFormat && window.intlTelInputUtils ? "+" : "";
576
- that.telInput.val(newVal);
577
- }
578
- });
579
- // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that
580
- setTimeout(function() {
581
- var input = that.telInput[0];
582
- if (that.isGoodBrowser) {
583
- var len = that.telInput.val().length;
584
- input.setSelectionRange(len, len);
585
- }
586
- });
587
- }
588
- });
589
- this.telInput.on("blur" + this.ns, function() {
590
- if (that.options.autoHideDialCode) {
591
- // on blur: if just a dial code then remove it
592
- var value = that.telInput.val(), startsPlus = value.charAt(0) == "+";
593
- if (startsPlus) {
594
- var numeric = that._getNumeric(value);
595
- // if just a plus, or if just a dial code
596
- if (!numeric || that.selectedCountryData.dialCode == numeric) {
597
- that.telInput.val("");
598
- }
599
- }
600
- // remove the keypress listener we added on focus
601
- that.telInput.off("keypress.plus" + that.ns);
602
- }
603
- // if autoFormat, we must manually trigger change event if value has changed
604
- if (that.options.autoFormat && window.intlTelInputUtils && that.telInput.val() != that.telInput.data("focusVal")) {
605
- that.telInput.trigger("change");
606
- }
607
- });
608
- },
609
- // extract the numeric digits from the given string
610
- _getNumeric: function(s) {
611
- return s.replace(/\D/g, "");
612
- },
613
- _getClean: function(s) {
614
- var prefix = s.charAt(0) == "+" ? "+" : "";
615
- return prefix + this._getNumeric(s);
616
- },
617
- // show the dropdown
618
- _showDropdown: function() {
619
- this._setDropdownPosition();
620
- // update highlighting and scroll to active list item
621
- var activeListItem = this.countryList.children(".active");
622
- if (activeListItem.length) {
623
- this._highlightListItem(activeListItem);
624
- }
625
- // show it
626
- this.countryList.removeClass("hide");
627
- if (activeListItem.length) {
628
- this._scrollTo(activeListItem);
629
- }
630
- // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
631
- this._bindDropdownListeners();
632
- // update the arrow
633
- this.selectedFlagInner.children(".arrow").addClass("up");
634
- },
635
- // decide where to position dropdown (depends on position within viewport, and scroll)
636
- _setDropdownPosition: function() {
637
- var inputTop = this.telInput.offset().top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom)
638
- dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
639
- // dropdownHeight - 1 for border
640
- var cssTop = !dropdownFitsBelow && dropdownFitsAbove ? "-" + (this.dropdownHeight - 1) + "px" : "";
641
- this.countryList.css("top", cssTop);
642
- },
643
- // we only bind dropdown listeners when the dropdown is open
644
- _bindDropdownListeners: function() {
645
- var that = this;
646
- // when mouse over a list item, just highlight that one
647
- // we add the class "highlight", so if they hit "enter" we know which one to select
648
- this.countryList.on("mouseover" + this.ns, ".country", function(e) {
649
- that._highlightListItem($(this));
650
- });
651
- // listen for country selection
652
- this.countryList.on("click" + this.ns, ".country", function(e) {
653
- that._selectListItem($(this));
654
- });
655
- // click off to close
656
- // (except when this initial opening click is bubbling up)
657
- // we cannot just stopPropagation as it may be needed to close another instance
658
- var isOpening = true;
659
- $("html").on("click" + this.ns, function(e) {
660
- if (!isOpening) {
661
- that._closeDropdown();
662
- }
663
- isOpening = false;
664
- });
665
- // listen for up/down scrolling, enter to select, or letters to jump to country name.
666
- // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
667
- // just hit down and hold it to scroll down (no keyup event).
668
- // listen on the document because that's where key events are triggered if no input has focus
669
- var query = "", queryTimer = null;
670
- $(document).on("keydown" + this.ns, function(e) {
671
- // prevent down key from scrolling the whole page,
672
- // and enter key from submitting a form etc
673
- e.preventDefault();
674
- if (e.which == keys.UP || e.which == keys.DOWN) {
675
- // up and down to navigate
676
- that._handleUpDownKey(e.which);
677
- } else if (e.which == keys.ENTER) {
678
- // enter to select
679
- that._handleEnterKey();
680
- } else if (e.which == keys.ESC) {
681
- // esc to close
682
- that._closeDropdown();
683
- } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
684
- // upper case letters (note: keyup/keydown only return upper case letters)
685
- // jump to countries that start with the query string
686
- if (queryTimer) {
687
- clearTimeout(queryTimer);
688
- }
689
- query += String.fromCharCode(e.which);
690
- that._searchForCountry(query);
691
- // if the timer hits 1 second, reset the query
692
- queryTimer = setTimeout(function() {
693
- query = "";
694
- }, 1e3);
695
- }
696
- });
697
- },
698
- // highlight the next/prev item in the list (and ensure it is visible)
699
- _handleUpDownKey: function(key) {
700
- var current = this.countryList.children(".highlight").first();
701
- var next = key == keys.UP ? current.prev() : current.next();
702
- if (next.length) {
703
- // skip the divider
704
- if (next.hasClass("divider")) {
705
- next = key == keys.UP ? next.prev() : next.next();
706
- }
707
- this._highlightListItem(next);
708
- this._scrollTo(next);
709
- }
710
- },
711
- // select the currently highlighted item
712
- _handleEnterKey: function() {
713
- var currentCountry = this.countryList.children(".highlight").first();
714
- if (currentCountry.length) {
715
- this._selectListItem(currentCountry);
716
- }
717
- },
718
- // find the first list item whose name starts with the query string
719
- _searchForCountry: function(query) {
720
- for (var i = 0; i < this.countries.length; i++) {
721
- if (this._startsWith(this.countries[i].name, query)) {
722
- var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
723
- // update highlighting and scroll
724
- this._highlightListItem(listItem);
725
- this._scrollTo(listItem, true);
726
- break;
727
- }
728
- }
729
- },
730
- // check if (uppercase) string a starts with string b
731
- _startsWith: function(a, b) {
732
- return a.substr(0, b.length).toUpperCase() == b;
733
- },
734
- // update the input's value to the given val
735
- // if autoFormat=true, format it first according to the country-specific formatting rules
736
- // Note: preventConversion will be false (i.e. we allow conversion) on init and when dev calls public method setNumber
737
- _updateVal: function(val, format, addSuffix, preventConversion, isAllowedKey) {
738
- var formatted;
739
- if (this.options.autoFormat && window.intlTelInputUtils && this.selectedCountryData) {
740
- if (typeof format == "number" && intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2)) {
741
- // if user specified a format, and it's a valid number, then format it accordingly
742
- formatted = intlTelInputUtils.formatNumberByType(val, this.selectedCountryData.iso2, format);
743
- } else if (!preventConversion && this.options.nationalMode && val.charAt(0) == "+" && intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2)) {
744
- // if nationalMode and we have a valid intl number, convert it to ntl
745
- formatted = intlTelInputUtils.formatNumberByType(val, this.selectedCountryData.iso2, intlTelInputUtils.numberFormat.NATIONAL);
746
- } else {
747
- // else do the regular AsYouType formatting
748
- formatted = intlTelInputUtils.formatNumber(val, this.selectedCountryData.iso2, addSuffix, this.options.allowExtensions, isAllowedKey);
749
- }
750
- // ensure we dont go over maxlength. we must do this here to truncate any formatting suffix, and also handle paste events
751
- var max = this.telInput.attr("maxlength");
752
- if (max && formatted.length > max) {
753
- formatted = formatted.substr(0, max);
754
- }
755
- } else {
756
- // no autoFormat, so just insert the original value
757
- formatted = val;
758
- }
759
- this.telInput.val(formatted);
760
- },
761
- // check if need to select a new flag based on the given number
762
- _updateFlagFromNumber: function(number, updateDefault) {
763
- // if we're in nationalMode and we're on US/Canada, make sure the number starts with a +1 so _getDialCode will be able to extract the area code
764
- // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag from the number), that means we're initialising the plugin with a number that already has a dial code, so fine to ignore this bit
765
- if (number && this.options.nationalMode && this.selectedCountryData && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
766
- if (number.charAt(0) != "1") {
767
- number = "1" + number;
768
- }
769
- number = "+" + number;
770
- }
771
- // try and extract valid dial code from input
772
- var dialCode = this._getDialCode(number), countryCode = null;
773
- if (dialCode) {
774
- // check if one of the matching countries is already selected
775
- var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && $.inArray(this.selectedCountryData.iso2, countryCodes) != -1;
776
- // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list
777
- if (!alreadySelected || this._isUnknownNanp(number, dialCode)) {
778
- // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
779
- for (var j = 0; j < countryCodes.length; j++) {
780
- if (countryCodes[j]) {
781
- countryCode = countryCodes[j];
782
- break;
783
- }
784
- }
785
- }
786
- } else if (number.charAt(0) == "+" && this._getNumeric(number).length) {
787
- // invalid dial code, so empty
788
- // Note: use getNumeric here because the number has not been formatted yet, so could contain bad shit
789
- countryCode = "";
790
- } else if (!number || number == "+") {
791
- // empty, or just a plus, so default
792
- countryCode = this.options.defaultCountry.iso2;
793
- }
794
- if (countryCode !== null) {
795
- this._selectFlag(countryCode, updateDefault);
796
- }
797
- },
798
- // check if the given number contains an unknown area code from the North American Numbering Plan i.e. the only dialCode that could be extracted was +1 but the actual number's length is >=4
799
- _isUnknownNanp: function(number, dialCode) {
800
- return dialCode == "+1" && this._getNumeric(number).length >= 4;
801
- },
802
- // remove highlighting from other list items and highlight the given item
803
- _highlightListItem: function(listItem) {
804
- this.countryListItems.removeClass("highlight");
805
- listItem.addClass("highlight");
806
- },
807
- // find the country data for the given country code
808
- // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
809
- _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
810
- var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
811
- for (var i = 0; i < countryList.length; i++) {
812
- if (countryList[i].iso2 == countryCode) {
813
- return countryList[i];
814
- }
815
- }
816
- if (allowFail) {
817
- return null;
818
- } else {
819
- throw new Error("No country data for '" + countryCode + "'");
820
- }
821
- },
822
- // select the given flag, update the placeholder and the active list item
823
- _selectFlag: function(countryCode, updateDefault) {
824
- // do this first as it will throw an error and stop if countryCode is invalid
825
- this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
826
- // update the "defaultCountry" - we only need the iso2 from now on, so just store that
827
- if (updateDefault && this.selectedCountryData.iso2) {
828
- // can't just make this equal to selectedCountryData as would be a ref to that object
829
- this.options.defaultCountry = {
830
- iso2: this.selectedCountryData.iso2
831
- };
832
- }
833
- this.selectedFlagInner.attr("class", "iti-flag " + countryCode);
834
- // update the selected country's title attribute
835
- var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown";
836
- this.selectedFlagInner.parent().attr("title", title);
837
- // and the input's placeholder
838
- this._updatePlaceholder();
839
- if (this.isMobile) {
840
- this.countryList.val(countryCode);
841
- } else {
842
- // update the active list item
843
- this.countryListItems.removeClass("active");
844
- if (countryCode) {
845
- this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
846
- }
847
- }
848
- },
849
- // update the input placeholder to an example number from the currently selected country
850
- _updatePlaceholder: function() {
851
- if (window.intlTelInputUtils && !this.hadInitialPlaceholder && this.options.autoPlaceholder && this.selectedCountryData) {
852
- var iso2 = this.selectedCountryData.iso2, numberType = intlTelInputUtils.numberType[this.options.numberType || "FIXED_LINE"], placeholder = iso2 ? intlTelInputUtils.getExampleNumber(iso2, this.options.nationalMode, numberType) : "";
853
- this.telInput.attr("placeholder", placeholder);
854
- }
855
- },
856
- // called when the user selects a list item from the dropdown
857
- _selectListItem: function(listItem) {
858
- var countryCodeAttr = this.isMobile ? "value" : "data-country-code";
859
- // update selected flag and active list item
860
- this._selectFlag(listItem.attr(countryCodeAttr), true);
861
- if (!this.isMobile) {
862
- this._closeDropdown();
863
- }
864
- this._updateDialCode(listItem.attr("data-dial-code"), true);
865
- // always fire the change event as even if nationalMode=true (and we haven't updated the input val), the system as a whole has still changed - see country-sync example. think of it as making a selection from a select element.
866
- this.telInput.trigger("change");
867
- // focus the input
868
- this.telInput.focus();
869
- // fix for FF and IE11 (with nationalMode=false i.e. auto inserting dial code), who try to put the cursor at the beginning the first time
870
- if (this.isGoodBrowser) {
871
- var len = this.telInput.val().length;
872
- this.telInput[0].setSelectionRange(len, len);
873
- }
874
- },
875
- // close the dropdown and unbind any listeners
876
- _closeDropdown: function() {
877
- this.countryList.addClass("hide");
878
- // update the arrow
879
- this.selectedFlagInner.children(".arrow").removeClass("up");
880
- // unbind key events
881
- $(document).off(this.ns);
882
- // unbind click-off-to-close
883
- $("html").off(this.ns);
884
- // unbind hover and click listeners
885
- this.countryList.off(this.ns);
886
- },
887
- // check if an element is visible within it's container, else scroll until it is
888
- _scrollTo: function(element, middle) {
889
- var container = this.countryList, containerHeight = container.height(), containerTop = container.offset().top, containerBottom = containerTop + containerHeight, elementHeight = element.outerHeight(), elementTop = element.offset().top, elementBottom = elementTop + elementHeight, newScrollTop = elementTop - containerTop + container.scrollTop(), middleOffset = containerHeight / 2 - elementHeight / 2;
890
- if (elementTop < containerTop) {
891
- // scroll up
892
- if (middle) {
893
- newScrollTop -= middleOffset;
894
- }
895
- container.scrollTop(newScrollTop);
896
- } else if (elementBottom > containerBottom) {
897
- // scroll down
898
- if (middle) {
899
- newScrollTop += middleOffset;
900
- }
901
- var heightDifference = containerHeight - elementHeight;
902
- container.scrollTop(newScrollTop - heightDifference);
903
- }
904
- },
905
- // replace any existing dial code with the new one (if not in nationalMode)
906
- // also we need to know if we're focusing for a couple of reasons e.g. if so, we want to add any formatting suffix, also if the input is empty and we're not in nationalMode, then we want to insert the dial code
907
- _updateDialCode: function(newDialCode, focusing) {
908
- var inputVal = this.telInput.val(), newNumber;
909
- // save having to pass this every time
910
- newDialCode = "+" + newDialCode;
911
- if (this.options.nationalMode && inputVal.charAt(0) != "+") {
912
- // if nationalMode, we just want to re-format
913
- newNumber = inputVal;
914
- } else if (inputVal) {
915
- // if the previous number contained a valid dial code, replace it
916
- // (if more than just a plus character)
917
- var prevDialCode = this._getDialCode(inputVal);
918
- if (prevDialCode.length > 1) {
919
- newNumber = inputVal.replace(prevDialCode, newDialCode);
920
- } else {
921
- // if the previous number didn't contain a dial code, we should persist it
922
- var existingNumber = inputVal.charAt(0) != "+" ? $.trim(inputVal) : "";
923
- newNumber = newDialCode + existingNumber;
924
- }
925
- } else {
926
- newNumber = !this.options.autoHideDialCode || focusing ? newDialCode : "";
927
- }
928
- this._updateVal(newNumber, null, focusing);
929
- },
930
- // try and extract a valid international dial code from a full telephone number
931
- // Note: returns the raw string inc plus character and any whitespace/dots etc
932
- _getDialCode: function(number) {
933
- var dialCode = "";
934
- // only interested in international numbers (starting with a plus)
935
- if (number.charAt(0) == "+") {
936
- var numericChars = "";
937
- // iterate over chars
938
- for (var i = 0; i < number.length; i++) {
939
- var c = number.charAt(i);
940
- // if char is number
941
- if ($.isNumeric(c)) {
942
- numericChars += c;
943
- // if current numericChars make a valid dial code
944
- if (this.countryCodes[numericChars]) {
945
- // store the actual raw string (useful for matching later)
946
- dialCode = number.substr(0, i + 1);
947
- }
948
- // longest dial code is 4 chars
949
- if (numericChars.length == 4) {
950
- break;
951
- }
952
- }
953
- }
954
- }
955
- return dialCode;
956
- },
957
- /********************
958
- * PUBLIC METHODS
959
- ********************/
960
- // this is called when the geoip call returns
961
- autoCountryLoaded: function() {
962
- if (this.options.defaultCountry == "auto") {
963
- this.options.defaultCountry = $.fn[pluginName].autoCountry;
964
- this._setInitialState();
965
- this.autoCountryDeferred.resolve();
966
- }
967
- },
968
- // remove plugin
969
- destroy: function() {
970
- if (!this.isMobile) {
971
- // make sure the dropdown is closed (and unbind listeners)
972
- this._closeDropdown();
973
- }
974
- // key events, and focus/blur events if autoHideDialCode=true
975
- this.telInput.off(this.ns);
976
- if (this.isMobile) {
977
- // change event on select country
978
- this.countryList.off(this.ns);
979
- } else {
980
- // click event to open dropdown
981
- this.selectedFlagInner.parent().off(this.ns);
982
- // label click hack
983
- this.telInput.closest("label").off(this.ns);
984
- }
985
- // remove markup
986
- var container = this.telInput.parent();
987
- container.before(this.telInput).remove();
988
- },
989
- // extract the phone number extension if present
990
- getExtension: function() {
991
- return this.telInput.val().split(" ext. ")[1] || "";
992
- },
993
- // format the number to the given type
994
- getNumber: function(type) {
995
- if (window.intlTelInputUtils) {
996
- return intlTelInputUtils.formatNumberByType(this.telInput.val(), this.selectedCountryData.iso2, type);
997
- }
998
- return "";
999
- },
1000
- // get the type of the entered number e.g. landline/mobile
1001
- getNumberType: function() {
1002
- if (window.intlTelInputUtils) {
1003
- return intlTelInputUtils.getNumberType(this.telInput.val(), this.selectedCountryData.iso2);
1004
- }
1005
- return -99;
1006
- },
1007
- // get the country data for the currently selected flag
1008
- getSelectedCountryData: function() {
1009
- // if this is undefined, the plugin will return it's instance instead, so in that case an empty object makes more sense
1010
- return this.selectedCountryData || {};
1011
- },
1012
- // get the validation error
1013
- getValidationError: function() {
1014
- if (window.intlTelInputUtils) {
1015
- return intlTelInputUtils.getValidationError(this.telInput.val(), this.selectedCountryData.iso2);
1016
- }
1017
- return -99;
1018
- },
1019
- // validate the input val - assumes the global function isValidNumber (from utilsScript)
1020
- isValidNumber: function() {
1021
- var val = $.trim(this.telInput.val()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
1022
- if (window.intlTelInputUtils) {
1023
- return intlTelInputUtils.isValidNumber(val, countryCode);
1024
- }
1025
- return false;
1026
- },
1027
- // load the utils script
1028
- loadUtils: function(path) {
1029
- var that = this;
1030
- var utilsScript = path || this.options.utilsScript;
1031
- if (!$.fn[pluginName].loadedUtilsScript && utilsScript) {
1032
- // don't do this twice! (dont just check if the global intlTelInputUtils exists as if init plugin multiple times in quick succession, it may not have finished loading yet)
1033
- $.fn[pluginName].loadedUtilsScript = true;
1034
- // dont use $.getScript as it prevents caching
1035
- $.ajax({
1036
- url: utilsScript,
1037
- success: function() {
1038
- // tell all instances the utils are ready
1039
- $(".intl-tel-input input").intlTelInput("utilsLoaded");
1040
- },
1041
- complete: function() {
1042
- that.utilsScriptDeferred.resolve();
1043
- },
1044
- dataType: "script",
1045
- cache: true
1046
- });
1047
- } else {
1048
- this.utilsScriptDeferred.resolve();
1049
- }
1050
- },
1051
- // update the selected flag, and update the input val accordingly
1052
- selectCountry: function(countryCode) {
1053
- countryCode = countryCode.toLowerCase();
1054
- // check if already selected
1055
- if (!this.selectedFlagInner.hasClass(countryCode)) {
1056
- this._selectFlag(countryCode, true);
1057
- this._updateDialCode(this.selectedCountryData.dialCode, false);
1058
- }
1059
- },
1060
- // set the input value and update the flag
1061
- setNumber: function(number, format, addSuffix, preventConversion, isAllowedKey) {
1062
- // ensure starts with plus
1063
- if (!this.options.nationalMode && number.charAt(0) != "+") {
1064
- number = "+" + number;
1065
- }
1066
- // we must update the flag first, which updates this.selectedCountryData, which is used later for formatting the number before displaying it
1067
- this._updateFlagFromNumber(number);
1068
- this._updateVal(number, format, addSuffix, preventConversion, isAllowedKey);
1069
- },
1070
- // this is called when the utils are ready
1071
- utilsLoaded: function() {
1072
- // if autoFormat is enabled and there's an initial value in the input, then format it
1073
- if (this.options.autoFormat && this.telInput.val()) {
1074
- this._updateVal(this.telInput.val());
1075
- }
1076
- this._updatePlaceholder();
1077
- }
1078
- };
1079
- // adapted to allow public functions
1080
- // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
1081
- $.fn[pluginName] = function(options) {
1082
- var args = arguments;
1083
- // Is the first parameter an object (options), or was omitted,
1084
- // instantiate a new instance of the plugin.
1085
- if (options === undefined || typeof options === "object") {
1086
- var deferreds = [];
1087
- this.each(function() {
1088
- if (!$.data(this, "plugin_" + pluginName)) {
1089
- var instance = new Plugin(this, options);
1090
- var instanceDeferreds = instance._init();
1091
- // we now have 2 deffereds: 1 for auto country, 1 for utils script
1092
- deferreds.push(instanceDeferreds[0]);
1093
- deferreds.push(instanceDeferreds[1]);
1094
- $.data(this, "plugin_" + pluginName, instance);
1095
- }
1096
- });
1097
- // return the promise from the "master" deferred object that tracks all the others
1098
- return $.when.apply(null, deferreds);
1099
- } else if (typeof options === "string" && options[0] !== "_") {
1100
- // If the first parameter is a string and it doesn't start
1101
- // with an underscore or "contains" the `init`-function,
1102
- // treat this as a call to a public method.
1103
- // Cache the method call to make it possible to return a value
1104
- var returns;
1105
- this.each(function() {
1106
- var instance = $.data(this, "plugin_" + pluginName);
1107
- // Tests that there's already a plugin-instance
1108
- // and checks that the requested public method exists
1109
- if (instance instanceof Plugin && typeof instance[options] === "function") {
1110
- // Call the method of our plugin instance,
1111
- // and pass it the supplied arguments.
1112
- returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
1113
- }
1114
- // Allow instances to be destroyed via the 'destroy' method
1115
- if (options === "destroy") {
1116
- $.data(this, "plugin_" + pluginName, null);
1117
- }
1118
- });
1119
- // If the earlier cached method gives a value back return the value,
1120
- // otherwise return this to preserve chainability.
1121
- return returns !== undefined ? returns : this;
1122
- }
1123
- };
1124
- /********************
1125
- * STATIC METHODS
1126
- ********************/
1127
- // get the country data object
1128
- $.fn[pluginName].getCountryData = function() {
1129
- return allCountries;
1130
- };
1131
- $.fn[pluginName].version = "6.0.4";
1132
- // Tell JSHint to ignore this warning: "character may get silently deleted by one or more browsers"
1133
- // jshint -W100
1134
- // Array of country objects for the flag dropdown.
1135
- // Each contains a name, country code (ISO 3166-1 alpha-2) and dial code.
1136
- // Originally from https://github.com/mledoze/countries
1137
- // then modified using the following JavaScript (NOW OUT OF DATE):
1138
- /*
1139
- var result = [];
1140
- _.each(countries, function(c) {
1141
- // ignore countries without a dial code
1142
- if (c.callingCode[0].length) {
1143
- result.push({
1144
- // var locals contains country names with localised versions in brackets
1145
- n: _.findWhere(locals, {
1146
- countryCode: c.cca2
1147
- }).name,
1148
- i: c.cca2.toLowerCase(),
1149
- d: c.callingCode[0]
1150
- });
1151
- }
1152
- });
1153
- JSON.stringify(result);
1154
- */
1155
- // then with a couple of manual re-arrangements to be alphabetical
1156
- // then changed Kazakhstan from +76 to +7
1157
- // and Vatican City from +379 to +39 (see issue 50)
1158
- // and Caribean Netherlands from +5997 to +599
1159
- // and Curacao from +5999 to +599
1160
- // Removed: Åland Islands, Christmas Island, Cocos Islands, Guernsey, Isle of Man, Jersey, Kosovo, Mayotte, Pitcairn Islands, South Georgia, Svalbard, Western Sahara
1161
- // Update: converted objects to arrays to save bytes!
1162
- // Update: added "priority" for countries with the same dialCode as others
1163
- // Update: added array of area codes for countries with the same dialCode as others
1164
- // So each country array has the following information:
1165
- // [
1166
- // Country name,
1167
- // iso2 code,
1168
- // International dial code,
1169
- // Order (if >1 country with same dial code),
1170
- // Area codes (if >1 country with same dial code)
1171
- // ]
1172
- var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1684" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1264" ], [ "Antigua and Barbuda", "ag", "1268" ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61" ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1242" ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1246" ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1441" ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1284" ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1 ], [ "Cayman Islands", "ky", "1345" ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Colombia", "co", "57" ], [ "Comoros (‫جزر القمر‬‎)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1767" ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (‫مصر‬‎)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358" ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (‫ایران‬‎)", "ir", "98" ], [ "Iraq (‫العراق‬‎)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (日本)", "jp", "81" ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1 ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kuwait (‫الكويت‬‎)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (‫لبنان‬‎)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (‫ليبيا‬‎)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "Macedonia (FYROM) (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (‫موريتانيا‬‎)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1664" ], [ "Morocco (‫المغرب‬‎)", "ma", "212" ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1670" ], [ "Norway (Norge)", "no", "47" ], [ "Oman (‫عُمان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262" ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy (Saint-Barthélemy)", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫المملكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44" ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna", "wf", "681" ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ] ];
1173
- // loop over all of the countries above
1174
- for (var i = 0; i < allCountries.length; i++) {
1175
- var c = allCountries[i];
1176
- allCountries[i] = {
1177
- name: c[0],
1178
- iso2: c[1],
1179
- dialCode: c[2],
1180
- priority: c[3] || 0,
1181
- areaCodes: c[4] || null
1182
- };
1183
- }
1184
- });
5
+ * International Telephone Input v10.0.2
6
+ * https://github.com/jackocnr/intl-tel-input.git
7
+ * Licensed under the MIT license
8
+ */
9
+ !function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b,window,document)}):"object"==typeof module&&module.exports?module.exports=a(require("jquery"),window,document):a(jQuery,window,document)}(function(a,b,c,d){"use strict";function e(b,c){this.a=a(b),this.b=a.extend({},h,c),this.ns="."+f+g++,this.d=Boolean(b.setSelectionRange),this.e=Boolean(a(b).attr("placeholder"))}var f="intlTelInput",g=1,h={allowDropdown:!0,autoHideDialCode:!0,autoPlaceholder:"polite",customPlaceholder:null,dropdownContainer:"",excludeCountries:[],formatOnDisplay:!0,geoIpLookup:null,initialCountry:"",nationalMode:!0,onlyCountries:[],placeholderNumberType:"MOBILE",preferredCountries:["us","gb"],separateDialCode:!1,utilsScript:""},i={b:38,c:40,d:13,e:27,f:43,A:65,Z:90,j:32,k:9},j=["800","822","833","844","855","866","877","880","881","882","883","884","885","886","887","888","889"];a(b).on("load",function(){a.fn[f].windowLoaded=!0}),e.prototype={_a:function(){return this.b.nationalMode&&(this.b.autoHideDialCode=!1),this.b.separateDialCode&&(this.b.autoHideDialCode=this.b.nationalMode=!1),this.g=/Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),this.g&&(a("body").addClass("iti-mobile"),this.b.dropdownContainer||(this.b.dropdownContainer="body")),this.h=new a.Deferred,this.i=new a.Deferred,this._b(),this._f(),this._h(),this._i(),this._i2(),[this.h,this.i]},_b:function(){this._d(),this._d2(),this._e()},_c:function(a,b,c){b in this.q||(this.q[b]=[]);var d=c||0;this.q[b][d]=a},_c2:function(b,c){var d;for(d=0;d<b.length;d++)b[d]=b[d].toLowerCase();for(this.p=[],d=0;d<k.length;d++)c(a.inArray(k[d].iso2,b))&&this.p.push(k[d])},_d:function(){this.b.onlyCountries.length?this._c2(this.b.onlyCountries,function(a){return a!=-1}):this.b.excludeCountries.length?this._c2(this.b.excludeCountries,function(a){return a==-1}):this.p=k},_d2:function(){this.q={};for(var a=0;a<this.p.length;a++){var b=this.p[a];if(this._c(b.iso2,b.dialCode,b.priority),b.areaCodes)for(var c=0;c<b.areaCodes.length;c++)this._c(b.iso2,b.dialCode+b.areaCodes[c])}},_e:function(){this.preferredCountries=[];for(var a=0;a<this.b.preferredCountries.length;a++){var b=this.b.preferredCountries[a].toLowerCase(),c=this._y(b,!1,!0);c&&this.preferredCountries.push(c)}},_f:function(){this.a.attr("autocomplete","off");var b="intl-tel-input";this.b.allowDropdown&&(b+=" allow-dropdown"),this.b.separateDialCode&&(b+=" separate-dial-code"),this.a.wrap(a("<div>",{"class":b})),this.k=a("<div>",{"class":"flag-container"}).insertBefore(this.a);var c=a("<div>",{"class":"selected-flag"});c.appendTo(this.k),this.l=a("<div>",{"class":"iti-flag"}).appendTo(c),this.b.separateDialCode&&(this.t=a("<div>",{"class":"selected-dial-code"}).appendTo(c)),this.b.allowDropdown?(c.attr("tabindex","0"),a("<div>",{"class":"iti-arrow"}).appendTo(c),this.m=a("<ul>",{"class":"country-list hide"}),this.preferredCountries.length&&(this._g(this.preferredCountries,"preferred"),a("<li>",{"class":"divider"}).appendTo(this.m)),this._g(this.p,""),this.o=this.m.children(".country"),this.b.dropdownContainer?this.dropdown=a("<div>",{"class":"intl-tel-input iti-container"}).append(this.m):this.m.appendTo(this.k)):this.o=a()},_g:function(a,b){for(var c="",d=0;d<a.length;d++){var e=a[d];c+="<li class='country "+b+"' data-dial-code='"+e.dialCode+"' data-country-code='"+e.iso2+"'>",c+="<div class='flag-box'><div class='iti-flag "+e.iso2+"'></div></div>",c+="<span class='country-name'>"+e.name+"</span>",c+="<span class='dial-code'>+"+e.dialCode+"</span>",c+="</li>"}this.m.append(c)},_h:function(){var a=this.a.val();this._af(a)&&!this._isRegionlessNanp(a)?this._v(a):"auto"!==this.b.initialCountry&&(this.b.initialCountry?this._z(this.b.initialCountry.toLowerCase()):(this.j=this.preferredCountries.length?this.preferredCountries[0].iso2:this.p[0].iso2,a||this._z(this.j)),a||this.b.nationalMode||this.b.autoHideDialCode||this.b.separateDialCode||this.a.val("+"+this.s.dialCode)),a&&this._u(a)},_i:function(){this._j(),this.b.autoHideDialCode&&this._l(),this.b.allowDropdown&&this._i1()},_i1:function(){var a=this,b=this.a.closest("label");b.length&&b.on("click"+this.ns,function(b){a.m.hasClass("hide")?a.a.focus():b.preventDefault()});var c=this.l.parent();c.on("click"+this.ns,function(b){!a.m.hasClass("hide")||a.a.prop("disabled")||a.a.prop("readonly")||a._n()}),this.k.on("keydown"+a.ns,function(b){var c=a.m.hasClass("hide");!c||b.which!=i.b&&b.which!=i.c&&b.which!=i.j&&b.which!=i.d||(b.preventDefault(),b.stopPropagation(),a._n()),b.which==i.k&&a._ac()})},_i2:function(){var c=this;this.b.utilsScript?a.fn[f].windowLoaded?a.fn[f].loadUtils(this.b.utilsScript,this.i):a(b).on("load",function(){a.fn[f].loadUtils(c.b.utilsScript,c.i)}):this.i.resolve(),"auto"===this.b.initialCountry?this._i3():this.h.resolve()},_i3:function(){a.fn[f].autoCountry?this.handleAutoCountry():a.fn[f].startedLoadingAutoCountry||(a.fn[f].startedLoadingAutoCountry=!0,"function"==typeof this.b.geoIpLookup&&this.b.geoIpLookup(function(b){a.fn[f].autoCountry=b.toLowerCase(),setTimeout(function(){a(".intl-tel-input input").intlTelInput("handleAutoCountry")})}))},_j:function(){var a=this;this.a.on("keyup"+this.ns,function(){a._v(a.a.val())&&a._triggerCountryChange()}),this.a.on("cut"+this.ns+" paste"+this.ns,function(){setTimeout(function(){a._v(a.a.val())&&a._triggerCountryChange()})})},_j2:function(a){var b=this.a.attr("maxlength");return b&&a.length>b?a.substr(0,b):a},_l:function(){var b=this;this.a.on("mousedown"+this.ns,function(a){b.a.is(":focus")||b.a.val()||(a.preventDefault(),b.a.focus())}),this.a.on("focus"+this.ns,function(a){b.a.val()||b.a.prop("readonly")||!b.s.dialCode||(b.a.val("+"+b.s.dialCode),b.a.one("keypress.plus"+b.ns,function(a){a.which==i.f&&b.a.val("")}),setTimeout(function(){var a=b.a[0];if(b.d){var c=b.a.val().length;a.setSelectionRange(c,c)}}))});var c=this.a.prop("form");c&&a(c).on("submit"+this.ns,function(){b._removeEmptyDialCode()}),this.a.on("blur"+this.ns,function(){b._removeEmptyDialCode()})},_removeEmptyDialCode:function(){var a=this.a.val(),b="+"==a.charAt(0);if(b){var c=this._m(a);c&&this.s.dialCode!=c||this.a.val("")}this.a.off("keypress.plus"+this.ns)},_m:function(a){return a.replace(/\D/g,"")},_n:function(){this._o();var a=this.m.children(".active");a.length&&(this._x(a),this._ad(a)),this._p(),this.l.children(".iti-arrow").addClass("up")},_o:function(){var c=this;if(this.b.dropdownContainer&&this.dropdown.appendTo(this.b.dropdownContainer),this.n=this.m.removeClass("hide").outerHeight(),!this.g){var d=this.a.offset(),e=d.top,f=a(b).scrollTop(),g=e+this.a.outerHeight()+this.n<f+a(b).height(),h=e-this.n>f;if(this.m.toggleClass("dropup",!g&&h),this.b.dropdownContainer){var i=!g&&h?0:this.a.innerHeight();this.dropdown.css({top:e+i,left:d.left}),a(b).on("scroll"+this.ns,function(){c._ac()})}}},_p:function(){var b=this;this.m.on("mouseover"+this.ns,".country",function(c){b._x(a(this))}),this.m.on("click"+this.ns,".country",function(c){b._ab(a(this))});var d=!0;a("html").on("click"+this.ns,function(a){d||b._ac(),d=!1});var e="",f=null;a(c).on("keydown"+this.ns,function(a){a.preventDefault(),a.which==i.b||a.which==i.c?b._q(a.which):a.which==i.d?b._r():a.which==i.e?b._ac():(a.which>=i.A&&a.which<=i.Z||a.which==i.j)&&(f&&clearTimeout(f),e+=String.fromCharCode(a.which),b._s(e),f=setTimeout(function(){e=""},1e3))})},_q:function(a){var b=this.m.children(".highlight").first(),c=a==i.b?b.prev():b.next();c.length&&(c.hasClass("divider")&&(c=a==i.b?c.prev():c.next()),this._x(c),this._ad(c))},_r:function(){var a=this.m.children(".highlight").first();a.length&&this._ab(a)},_s:function(a){for(var b=0;b<this.p.length;b++)if(this._t(this.p[b].name,a)){var c=this.m.children("[data-country-code="+this.p[b].iso2+"]").not(".preferred");this._x(c),this._ad(c,!0);break}},_t:function(a,b){return a.substr(0,b.length).toUpperCase()==b},_u:function(a){if(this.b.formatOnDisplay&&b.intlTelInputUtils&&this.s){var c=this.b.separateDialCode||!this.b.nationalMode&&"+"==a.charAt(0)?intlTelInputUtils.numberFormat.INTERNATIONAL:intlTelInputUtils.numberFormat.NATIONAL;a=intlTelInputUtils.formatNumber(a,this.s.iso2,c)}a=this._ah(a),this.a.val(a)},_v:function(b){b&&this.b.nationalMode&&this.s&&"1"==this.s.dialCode&&"+"!=b.charAt(0)&&("1"!=b.charAt(0)&&(b="1"+b),b="+"+b);var c=this._af(b),d=null,e=this._m(b);if(c){var f=this.q[this._m(c)],g=this.s&&a.inArray(this.s.iso2,f)!=-1,h="+1"==c&&e.length>=4;if((!g||h)&&!this._isRegionlessNanp(e))for(var i=0;i<f.length;i++)if(f[i]){d=f[i];break}}else"+"==b.charAt(0)&&e.length?d="":b&&"+"!=b||(d=this.j);return null!==d&&this._z(d)},_isRegionlessNanp:function(a){var b=this._m(a);if("1"==b.charAt(0)){var c=b.substr(1,3);return j.indexOf(c)>-1}return!1},_x:function(a){this.o.removeClass("highlight"),a.addClass("highlight")},_y:function(a,b,c){for(var d=b?k:this.p,e=0;e<d.length;e++)if(d[e].iso2==a)return d[e];if(c)return null;throw new Error("No country data for '"+a+"'")},_z:function(a){var b=this.s&&this.s.iso2?this.s:{};this.s=a?this._y(a,!1,!1):{},this.s.iso2&&(this.j=this.s.iso2),this.l.attr("class","iti-flag "+a);var c=a?this.s.name+": +"+this.s.dialCode:"Unknown";if(this.l.parent().attr("title",c),this.b.separateDialCode){var d=this.s.dialCode?"+"+this.s.dialCode:"",e=this.a.parent();b.dialCode&&e.removeClass("iti-sdc-"+(b.dialCode.length+1)),d&&e.addClass("iti-sdc-"+d.length),this.t.text(d)}return this._aa(),this.o.removeClass("active"),a&&this.o.find(".iti-flag."+a).first().closest(".country").addClass("active"),b.iso2!==a},_aa:function(){var a="aggressive"===this.b.autoPlaceholder||!this.e&&(this.b.autoPlaceholder===!0||"polite"===this.b.autoPlaceholder);if(b.intlTelInputUtils&&a&&this.s){var c=intlTelInputUtils.numberType[this.b.placeholderNumberType],d=this.s.iso2?intlTelInputUtils.getExampleNumber(this.s.iso2,this.b.nationalMode,c):"";d=this._ah(d),"function"==typeof this.b.customPlaceholder&&(d=this.b.customPlaceholder(d,this.s)),this.a.attr("placeholder",d)}},_ab:function(a){var b=this._z(a.attr("data-country-code"));if(this._ac(),this._ae(a.attr("data-dial-code"),!0),this.a.focus(),this.d){var c=this.a.val().length;this.a[0].setSelectionRange(c,c)}b&&this._triggerCountryChange()},_ac:function(){this.m.addClass("hide"),this.l.children(".iti-arrow").removeClass("up"),a(c).off(this.ns),a("html").off(this.ns),this.m.off(this.ns),this.b.dropdownContainer&&(this.g||a(b).off("scroll"+this.ns),this.dropdown.detach())},_ad:function(a,b){var c=this.m,d=c.height(),e=c.offset().top,f=e+d,g=a.outerHeight(),h=a.offset().top,i=h+g,j=h-e+c.scrollTop(),k=d/2-g/2;if(h<e)b&&(j-=k),c.scrollTop(j);else if(i>f){b&&(j+=k);var l=d-g;c.scrollTop(j-l)}},_ae:function(a,b){var c,d=this.a.val();if(a="+"+a,"+"==d.charAt(0)){var e=this._af(d);c=e?d.replace(e,a):a}else{if(this.b.nationalMode||this.b.separateDialCode)return;if(d)c=a+d;else{if(!b&&this.b.autoHideDialCode)return;c=a}}this.a.val(c)},_af:function(b){var c="";if("+"==b.charAt(0))for(var d="",e=0;e<b.length;e++){var f=b.charAt(e);if(a.isNumeric(f)&&(d+=f,this.q[d]&&(c=b.substr(0,e+1)),4==d.length))break}return c},_ag:function(){var a,b=this.a.val(),c=this.s.dialCode;return a=this.b.separateDialCode?"+"+c:c&&"1"==c.charAt(0)&&4==c.length&&c.substr(1)!=b.substr(0,3)?c.substr(1):"",a+b},_ah:function(a){if(this.b.separateDialCode){var b=this._af(a);if(b){null!==this.s.areaCodes&&(b="+"+this.s.dialCode);var c=" "===a[b.length]||"-"===a[b.length]?b.length+1:b.length;a=a.substr(c)}}return this._j2(a)},_triggerCountryChange:function(){this.a.trigger("countrychange",this.s)},handleAutoCountry:function(){"auto"===this.b.initialCountry&&(this.j=a.fn[f].autoCountry,this.a.val()||this.setCountry(this.j),this.h.resolve())},handleUtils:function(){b.intlTelInputUtils&&(this.a.val()&&this._u(this.a.val()),this._aa()),this.i.resolve()},destroy:function(){if(this.allowDropdown&&(this._ac(),this.l.parent().off(this.ns),this.a.closest("label").off(this.ns)),this.b.autoHideDialCode){var b=this.a.prop("form");b&&a(b).off(this.ns)}this.a.off(this.ns);var c=this.a.parent();c.before(this.a).remove()},getExtension:function(){return b.intlTelInputUtils?intlTelInputUtils.getExtension(this._ag(),this.s.iso2):""},getNumber:function(a){return b.intlTelInputUtils?intlTelInputUtils.formatNumber(this._ag(),this.s.iso2,a):""},getNumberType:function(){return b.intlTelInputUtils?intlTelInputUtils.getNumberType(this._ag(),this.s.iso2):-99},getSelectedCountryData:function(){return this.s||{}},getValidationError:function(){return b.intlTelInputUtils?intlTelInputUtils.getValidationError(this._ag(),this.s.iso2):-99},isValidNumber:function(){var c=a.trim(this._ag()),d=this.b.nationalMode?this.s.iso2:"";return b.intlTelInputUtils?intlTelInputUtils.isValidNumber(c,d):null},setCountry:function(a){a=a.toLowerCase(),this.l.hasClass(a)||(this._z(a),this._ae(this.s.dialCode,!1),this._triggerCountryChange())},setNumber:function(a){var b=this._v(a);this._u(a),b&&this._triggerCountryChange()}},a.fn[f]=function(b){var c=arguments;if(b===d||"object"==typeof b){var g=[];return this.each(function(){if(!a.data(this,"plugin_"+f)){var c=new e(this,b),d=c._a();g.push(d[0]),g.push(d[1]),a.data(this,"plugin_"+f,c)}}),a.when.apply(null,g)}if("string"==typeof b&&"_"!==b[0]){var h;return this.each(function(){var d=a.data(this,"plugin_"+f);d instanceof e&&"function"==typeof d[b]&&(h=d[b].apply(d,Array.prototype.slice.call(c,1))),"destroy"===b&&a.data(this,"plugin_"+f,null)}),h!==d?h:this}},a.fn[f].getCountryData=function(){return k},a.fn[f].loadUtils=function(b,c){a.fn[f].loadedUtilsScript?c&&c.resolve():(a.fn[f].loadedUtilsScript=!0,a.ajax({type:"GET",url:b,complete:function(){a(".intl-tel-input input").intlTelInput("handleUtils")},dataType:"script",cache:!0}))},a.fn[f].version="10.0.2",a.fn[f].defaults=h;for(var k=[["Afghanistan (‫افغانستان‬‎)","af","93"],["Albania (Shqipëri)","al","355"],["Algeria (‫الجزائر‬‎)","dz","213"],["American Samoa","as","1684"],["Andorra","ad","376"],["Angola","ao","244"],["Anguilla","ai","1264"],["Antigua and Barbuda","ag","1268"],["Argentina","ar","54"],["Armenia (Հայաստան)","am","374"],["Aruba","aw","297"],["Australia","au","61",0],["Austria (Österreich)","at","43"],["Azerbaijan (Azərbaycan)","az","994"],["Bahamas","bs","1242"],["Bahrain (‫البحرين‬‎)","bh","973"],["Bangladesh (বাংলাদেশ)","bd","880"],["Barbados","bb","1246"],["Belarus (Беларусь)","by","375"],["Belgium (België)","be","32"],["Belize","bz","501"],["Benin (Bénin)","bj","229"],["Bermuda","bm","1441"],["Bhutan (འབྲུག)","bt","975"],["Bolivia","bo","591"],["Bosnia and Herzegovina (Босна и Херцеговина)","ba","387"],["Botswana","bw","267"],["Brazil (Brasil)","br","55"],["British Indian Ocean Territory","io","246"],["British Virgin Islands","vg","1284"],["Brunei","bn","673"],["Bulgaria (България)","bg","359"],["Burkina Faso","bf","226"],["Burundi (Uburundi)","bi","257"],["Cambodia (កម្ពុជា)","kh","855"],["Cameroon (Cameroun)","cm","237"],["Canada","ca","1",1,["204","226","236","249","250","289","306","343","365","387","403","416","418","431","437","438","450","506","514","519","548","579","581","587","604","613","639","647","672","705","709","742","778","780","782","807","819","825","867","873","902","905"]],["Cape Verde (Kabu Verdi)","cv","238"],["Caribbean Netherlands","bq","599",1],["Cayman Islands","ky","1345"],["Central African Republic (République centrafricaine)","cf","236"],["Chad (Tchad)","td","235"],["Chile","cl","56"],["China (中国)","cn","86"],["Christmas Island","cx","61",2],["Cocos (Keeling) Islands","cc","61",1],["Colombia","co","57"],["Comoros (‫جزر القمر‬‎)","km","269"],["Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)","cd","243"],["Congo (Republic) (Congo-Brazzaville)","cg","242"],["Cook Islands","ck","682"],["Costa Rica","cr","506"],["Côte d’Ivoire","ci","225"],["Croatia (Hrvatska)","hr","385"],["Cuba","cu","53"],["Curaçao","cw","599",0],["Cyprus (Κύπρος)","cy","357"],["Czech Republic (Česká republika)","cz","420"],["Denmark (Danmark)","dk","45"],["Djibouti","dj","253"],["Dominica","dm","1767"],["Dominican Republic (República Dominicana)","do","1",2,["809","829","849"]],["Ecuador","ec","593"],["Egypt (‫مصر‬‎)","eg","20"],["El Salvador","sv","503"],["Equatorial Guinea (Guinea Ecuatorial)","gq","240"],["Eritrea","er","291"],["Estonia (Eesti)","ee","372"],["Ethiopia","et","251"],["Falkland Islands (Islas Malvinas)","fk","500"],["Faroe Islands (Føroyar)","fo","298"],["Fiji","fj","679"],["Finland (Suomi)","fi","358",0],["France","fr","33"],["French Guiana (Guyane française)","gf","594"],["French Polynesia (Polynésie française)","pf","689"],["Gabon","ga","241"],["Gambia","gm","220"],["Georgia (საქართველო)","ge","995"],["Germany (Deutschland)","de","49"],["Ghana (Gaana)","gh","233"],["Gibraltar","gi","350"],["Greece (Ελλάδα)","gr","30"],["Greenland (Kalaallit Nunaat)","gl","299"],["Grenada","gd","1473"],["Guadeloupe","gp","590",0],["Guam","gu","1671"],["Guatemala","gt","502"],["Guernsey","gg","44",1],["Guinea (Guinée)","gn","224"],["Guinea-Bissau (Guiné Bissau)","gw","245"],["Guyana","gy","592"],["Haiti","ht","509"],["Honduras","hn","504"],["Hong Kong (香港)","hk","852"],["Hungary (Magyarország)","hu","36"],["Iceland (Ísland)","is","354"],["India (भारत)","in","91"],["Indonesia","id","62"],["Iran (‫ایران‬‎)","ir","98"],["Iraq (‫العراق‬‎)","iq","964"],["Ireland","ie","353"],["Isle of Man","im","44",2],["Israel (‫ישראל‬‎)","il","972"],["Italy (Italia)","it","39",0],["Jamaica","jm","1876"],["Japan (日本)","jp","81"],["Jersey","je","44",3],["Jordan (‫الأردن‬‎)","jo","962"],["Kazakhstan (Казахстан)","kz","7",1],["Kenya","ke","254"],["Kiribati","ki","686"],["Kosovo","xk","383"],["Kuwait (‫الكويت‬‎)","kw","965"],["Kyrgyzstan (Кыргызстан)","kg","996"],["Laos (ລາວ)","la","856"],["Latvia (Latvija)","lv","371"],["Lebanon (‫لبنان‬‎)","lb","961"],["Lesotho","ls","266"],["Liberia","lr","231"],["Libya (‫ليبيا‬‎)","ly","218"],["Liechtenstein","li","423"],["Lithuania (Lietuva)","lt","370"],["Luxembourg","lu","352"],["Macau (澳門)","mo","853"],["Macedonia (FYROM) (Македонија)","mk","389"],["Madagascar (Madagasikara)","mg","261"],["Malawi","mw","265"],["Malaysia","my","60"],["Maldives","mv","960"],["Mali","ml","223"],["Malta","mt","356"],["Marshall Islands","mh","692"],["Martinique","mq","596"],["Mauritania (‫موريتانيا‬‎)","mr","222"],["Mauritius (Moris)","mu","230"],["Mayotte","yt","262",1],["Mexico (México)","mx","52"],["Micronesia","fm","691"],["Moldova (Republica Moldova)","md","373"],["Monaco","mc","377"],["Mongolia (Монгол)","mn","976"],["Montenegro (Crna Gora)","me","382"],["Montserrat","ms","1664"],["Morocco (‫المغرب‬‎)","ma","212",0],["Mozambique (Moçambique)","mz","258"],["Myanmar (Burma) (မြန်မာ)","mm","95"],["Namibia (Namibië)","na","264"],["Nauru","nr","674"],["Nepal (नेपाल)","np","977"],["Netherlands (Nederland)","nl","31"],["New Caledonia (Nouvelle-Calédonie)","nc","687"],["New Zealand","nz","64"],["Nicaragua","ni","505"],["Niger (Nijar)","ne","227"],["Nigeria","ng","234"],["Niue","nu","683"],["Norfolk Island","nf","672"],["North Korea (조선 민주주의 인민 공화국)","kp","850"],["Northern Mariana Islands","mp","1670"],["Norway (Norge)","no","47",0],["Oman (‫عُمان‬‎)","om","968"],["Pakistan (‫پاکستان‬‎)","pk","92"],["Palau","pw","680"],["Palestine (‫فلسطين‬‎)","ps","970"],["Panama (Panamá)","pa","507"],["Papua New Guinea","pg","675"],["Paraguay","py","595"],["Peru (Perú)","pe","51"],["Philippines","ph","63"],["Poland (Polska)","pl","48"],["Portugal","pt","351"],["Puerto Rico","pr","1",3,["787","939"]],["Qatar (‫قطر‬‎)","qa","974"],["Réunion (La Réunion)","re","262",0],["Romania (România)","ro","40"],["Russia (Россия)","ru","7",0],["Rwanda","rw","250"],["Saint Barthélemy (Saint-Barthélemy)","bl","590",1],["Saint Helena","sh","290"],["Saint Kitts and Nevis","kn","1869"],["Saint Lucia","lc","1758"],["Saint Martin (Saint-Martin (partie française))","mf","590",2],["Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)","pm","508"],["Saint Vincent and the Grenadines","vc","1784"],["Samoa","ws","685"],["San Marino","sm","378"],["São Tomé and Príncipe (São Tomé e Príncipe)","st","239"],["Saudi Arabia (‫المملكة العربية السعودية‬‎)","sa","966"],["Senegal (Sénégal)","sn","221"],["Serbia (Србија)","rs","381"],["Seychelles","sc","248"],["Sierra Leone","sl","232"],["Singapore","sg","65"],["Sint Maarten","sx","1721"],["Slovakia (Slovensko)","sk","421"],["Slovenia (Slovenija)","si","386"],["Solomon Islands","sb","677"],["Somalia (Soomaaliya)","so","252"],["South Africa","za","27"],["South Korea (대한민국)","kr","82"],["South Sudan (‫جنوب السودان‬‎)","ss","211"],["Spain (España)","es","34"],["Sri Lanka (ශ්‍රී ලංකාව)","lk","94"],["Sudan (‫السودان‬‎)","sd","249"],["Suriname","sr","597"],["Svalbard and Jan Mayen","sj","47",1],["Swaziland","sz","268"],["Sweden (Sverige)","se","46"],["Switzerland (Schweiz)","ch","41"],["Syria (‫سوريا‬‎)","sy","963"],["Taiwan (台灣)","tw","886"],["Tajikistan","tj","992"],["Tanzania","tz","255"],["Thailand (ไทย)","th","66"],["Timor-Leste","tl","670"],["Togo","tg","228"],["Tokelau","tk","690"],["Tonga","to","676"],["Trinidad and Tobago","tt","1868"],["Tunisia (‫تونس‬‎)","tn","216"],["Turkey (Türkiye)","tr","90"],["Turkmenistan","tm","993"],["Turks and Caicos Islands","tc","1649"],["Tuvalu","tv","688"],["U.S. Virgin Islands","vi","1340"],["Uganda","ug","256"],["Ukraine (Україна)","ua","380"],["United Arab Emirates (‫الإمارات العربية المتحدة‬‎)","ae","971"],["United Kingdom","gb","44",0],["United States","us","1",0],["Uruguay","uy","598"],["Uzbekistan (Oʻzbekiston)","uz","998"],["Vanuatu","vu","678"],["Vatican City (Città del Vaticano)","va","39",1],["Venezuela","ve","58"],["Vietnam (Việt Nam)","vn","84"],["Wallis and Futuna","wf","681"],["Western Sahara (‫الصحراء الغربية‬‎)","eh","212",1],["Yemen (‫اليمن‬‎)","ye","967"],["Zambia","zm","260"],["Zimbabwe","zw","263"],["Åland Islands","ax","358",1]],l=0;l<k.length;l++){var m=k[l];k[l]={name:m[0],iso2:m[1],dialCode:m[2],priority:m[3]||0,areaCodes:m[4]||null}}});