@salla.sa/twilight-components 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cjs/Helper-fcea994c.js +23 -0
  2. package/dist/cjs/index-714023c8.js +1653 -0
  3. package/dist/cjs/index.cjs.js +13 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/salla-branches.cjs.entry.js +92 -0
  6. package/dist/cjs/salla-button_5.cjs.entry.js +1727 -0
  7. package/dist/cjs/salla-localization.cjs.entry.js +82 -0
  8. package/dist/cjs/salla-login-c438bb35.js +128 -0
  9. package/dist/cjs/salla-offer.cjs.entry.js +79 -0
  10. package/dist/cjs/salla-product-availability.cjs.entry.js +75 -0
  11. package/dist/cjs/salla-rating.cjs.entry.js +195 -0
  12. package/dist/cjs/salla-search-45173394.js +85 -0
  13. package/dist/cjs/salla-search.cjs.entry.js +11 -0
  14. package/dist/cjs/twilight-components.cjs.js +19 -0
  15. package/dist/collection/Helpers/Helper.js +19 -0
  16. package/dist/collection/collection-manifest.json +22 -0
  17. package/dist/collection/components/generate-summary.js +35 -0
  18. package/dist/collection/components/salla-branches/salla-branches.css +12 -0
  19. package/dist/collection/components/salla-branches/salla-branches.js +233 -0
  20. package/dist/collection/components/salla-button/salla-button.css +3 -0
  21. package/dist/collection/components/salla-button/salla-button.js +246 -0
  22. package/dist/collection/components/salla-localization/salla-localization.js +208 -0
  23. package/dist/collection/components/salla-login/salla-login.css +3 -0
  24. package/dist/collection/components/salla-login/salla-login.js +380 -0
  25. package/dist/collection/components/salla-modal/salla-modal.js +477 -0
  26. package/dist/collection/components/salla-offer/offer-schema.js +1 -0
  27. package/dist/collection/components/salla-offer/salla-offer.js +110 -0
  28. package/dist/collection/components/salla-product-availability/salla-product-availability.js +331 -0
  29. package/dist/collection/components/salla-rating/order-feedback-response.js +1 -0
  30. package/dist/collection/components/salla-rating/salla-rating.css +7 -0
  31. package/dist/collection/components/salla-rating/salla-rating.js +277 -0
  32. package/dist/collection/components/salla-search/salla-search.css +24 -0
  33. package/dist/collection/components/salla-search/salla-search.js +143 -0
  34. package/dist/collection/components/salla-tel-input/salla-tel-input.js +121 -0
  35. package/dist/collection/components/salla-verify/salla-verify.js +280 -0
  36. package/dist/collection/index.js +2 -0
  37. package/dist/collection/interfaces/colors.js +1 -0
  38. package/dist/collection/interfaces/index.js +2 -0
  39. package/dist/collection/interfaces/ratio.js +1 -0
  40. package/dist/collection/plugins/tailwind-theme/generator.js +62 -0
  41. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  42. package/dist/{twilight-components → esm}/Helper-d07ebbc7.js +0 -0
  43. package/dist/esm/index-a1bf769d.js +1625 -0
  44. package/dist/esm/index.js +4 -0
  45. package/dist/esm/loader.js +17 -0
  46. package/dist/esm/polyfills/core-js.js +11 -0
  47. package/dist/esm/polyfills/css-shim.js +1 -0
  48. package/dist/esm/polyfills/dom.js +79 -0
  49. package/dist/esm/polyfills/es5-html-element.js +1 -0
  50. package/dist/esm/polyfills/index.js +34 -0
  51. package/dist/esm/polyfills/system.js +6 -0
  52. package/dist/{twilight-components → esm}/salla-branches.entry.js +2 -2
  53. package/dist/{twilight-components/salla-tel-input.entry.js → esm/salla-button_5.entry.js} +337 -35
  54. package/dist/{twilight-components → esm}/salla-localization.entry.js +1 -1
  55. package/dist/{twilight-components/salla-login-57b18c2c.js → esm/salla-login-dd957742.js} +26 -23
  56. package/dist/{twilight-components → esm}/salla-offer.entry.js +1 -1
  57. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +1 -1
  58. package/dist/{twilight-components → esm}/salla-rating.entry.js +71 -108
  59. package/dist/{twilight-components/salla-search-30fec1e8.js → esm/salla-search-5e691ebb.js} +15 -11
  60. package/dist/esm/salla-search.entry.js +3 -0
  61. package/dist/esm/twilight-components.js +17 -0
  62. package/dist/index.cjs.js +1 -0
  63. package/dist/index.js +1 -0
  64. package/dist/twilight-components/index.esm.js +1 -4
  65. package/dist/twilight-components/p-1a6d8171.entry.js +1 -0
  66. package/dist/twilight-components/p-1deb8111.entry.js +1 -0
  67. package/dist/twilight-components/p-3a4d963e.js +1 -0
  68. package/dist/twilight-components/p-47f17d3b.js +1 -0
  69. package/dist/twilight-components/p-5b2eb87d.entry.js +1 -0
  70. package/dist/twilight-components/p-6a5be894.js +1 -0
  71. package/dist/twilight-components/p-7fbdf746.entry.js +1 -0
  72. package/dist/twilight-components/p-7fe5d346.entry.js +1 -0
  73. package/dist/twilight-components/p-81a61f4e.js +1 -0
  74. package/dist/twilight-components/p-ce991664.entry.js +1 -0
  75. package/dist/twilight-components/p-da73fc9b.entry.js +1 -0
  76. package/dist/twilight-components/twilight-components.css +1 -3
  77. package/dist/twilight-components/twilight-components.esm.js +1 -125
  78. package/dist/types/components/salla-login/salla-login.d.ts +3 -3
  79. package/dist/types/components/salla-modal/salla-modal.d.ts +1 -0
  80. package/dist/types/components/salla-rating/salla-rating.d.ts +6 -23
  81. package/dist/types/components/salla-search/salla-search.d.ts +1 -1
  82. package/dist/types/components/salla-tel-input/salla-tel-input.d.ts +14 -0
  83. package/dist/types/components/salla-verify/salla-verify.d.ts +3 -1
  84. package/dist/types/components.d.ts +12 -35
  85. package/package.json +1 -1
  86. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  87. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  88. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  89. package/dist/twilight-components/index-9c087700.js +0 -3010
  90. package/dist/twilight-components/salla-button.entry.js +0 -75
  91. package/dist/twilight-components/salla-login.entry.js +0 -3
  92. package/dist/twilight-components/salla-modal.entry.js +0 -113
  93. package/dist/twilight-components/salla-search.entry.js +0 -3
  94. package/dist/twilight-components/salla-verify.entry.js +0 -114
  95. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -0,0 +1,1727 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-714023c8.js');
6
+ const Helper = require('./Helper-fcea994c.js');
7
+ const sallaLogin = require('./salla-login-c438bb35.js');
8
+
9
+ const sallaButtonCss = ":host{display:block}";
10
+
11
+ const SallaButton = class {
12
+ constructor(hostRef) {
13
+ index.registerInstance(this, hostRef);
14
+ this.btnStyle = 'primary';
15
+ this.loading = false;
16
+ this.disabled = false;
17
+ this.loaderPosition = 'before';
18
+ this.wide = false;
19
+ this.hostAttributes = {};
20
+ //============= Initiate Button Attributes =============//
21
+ for (let i = 0; i < this.host.attributes.length; i++) {
22
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
23
+ }
24
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
25
+ this.hostAttributes.class += ' s-button-btn btn--has-loading'
26
+ + ' s-button-' + this.btnStyle
27
+ + (this.wide ? ' s-button-wide ' : '')
28
+ + ' loader-' + this.loaderPosition
29
+ + (this.loaderPosition == 'before' ? ' s-button-loader-after' : '');
30
+ delete this.hostAttributes['btn-style'];
31
+ delete this.hostAttributes['id'];
32
+ if (this.wide) {
33
+ this.host.classList.add('s-button-wide');
34
+ }
35
+ }
36
+ async load() {
37
+ if (this.loaderPosition == 'center')
38
+ this.text.classList.add('s-button-hide');
39
+ this.host.setAttribute('loading', '');
40
+ return this.host;
41
+ }
42
+ async stop() {
43
+ this.host.removeAttribute('loading');
44
+ return this.host;
45
+ }
46
+ async disable() {
47
+ this.host.setAttribute('disabled', '');
48
+ }
49
+ async enable() {
50
+ this.host.removeAttribute('disabled');
51
+ }
52
+ handleVisible(newKind, oldKind) {
53
+ //todo::use united styles
54
+ this.btn.classList.remove('btn-' + oldKind);
55
+ this.btn.classList.add('btn-' + newKind);
56
+ }
57
+ handleLoading(newVal) {
58
+ //todo::use united styles
59
+ Helper.Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
60
+ }
61
+ render() {
62
+ return (
63
+ //TODO:: use HOST then fake button behaviours
64
+ index.h(index.Host, { class: "s-button-host-tag" }, index.h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes), index.h("span", { class: "s-button-text", ref: el => this.text = el }, index.h("slot", null)), this.loading ? index.h("span", { class: {
65
+ //todo::use united styles
66
+ 's-button-loader': true,
67
+ 's-button-loader-start': this.loaderPosition === 'start',
68
+ 's-button-loader-end': this.loaderPosition === 'end',
69
+ 's-button-loader-center': this.loaderPosition === 'center',
70
+ } }) : '')));
71
+ }
72
+ get host() { return index.getElement(this); }
73
+ static get watchers() { return {
74
+ "btnStyle": ["handleVisible"],
75
+ "loading": ["handleLoading"]
76
+ }; }
77
+ };
78
+ SallaButton.style = sallaButtonCss;
79
+
80
+ const SallaModal = class {
81
+ constructor(hostRef) {
82
+ index.registerInstance(this, hostRef);
83
+ this.modalOpened = index.createEvent(this, "modalOpened", 7);
84
+ this.modalClosed = index.createEvent(this, "modalClosed", 7);
85
+ var _a;
86
+ //todo:: unite three colors (error, success, primary) in one prop
87
+ this.error = false;
88
+ this.success = false;
89
+ this.primary = false;
90
+ this.isClosable = true;
91
+ this.width = 'md';
92
+ this.position = 'middel';
93
+ this.visible = false;
94
+ this.isLoading = false;
95
+ this.subTitleFirst = false;
96
+ this.subTitle = '';
97
+ this.icon = '';
98
+ this.imageIcon = '';
99
+ Helper.Helper.setHost(this.host);
100
+ salla.event.on('modal::open', btn => btn.dataset.target == this.host.id && this.show());
101
+ salla.event.on('modal::close', btn => btn.dataset.target == this.host.id && this.hide());
102
+ this.title = this.host.title;
103
+ this.host.removeAttribute('title');
104
+ (_a = Helper.Helper.getElement('[slot=body]')) === null || _a === void 0 ? void 0 : _a.classList.add('s-modal-body', 's-modal-' + this.width);
105
+ }
106
+ handleVisible(newValue) {
107
+ if (!newValue) {
108
+ this.toggleModal(false);
109
+ this.modalClosed.emit();
110
+ return;
111
+ }
112
+ this.host.classList.remove('hidden');
113
+ setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
114
+ this.modalOpened.emit();
115
+ }
116
+ async show() {
117
+ this.host.setAttribute('visible', '');
118
+ return this.host;
119
+ }
120
+ async hide() {
121
+ this.host.removeAttribute('visible');
122
+ return this.host;
123
+ }
124
+ async setTitle(title) {
125
+ this.title = title;
126
+ return this.host;
127
+ }
128
+ async loading() {
129
+ this.isLoading = true;
130
+ return this.host;
131
+ }
132
+ async stopLoading() {
133
+ this.isLoading = false;
134
+ return this.host;
135
+ }
136
+ toggleModal(isOpen) {
137
+ Helper.Helper
138
+ // .toggleElement(this.host.querySelector('.s-modal-body'), 's-modal-entering', 's-modal-leaving', () => isOpen)
139
+ .toggleElement(this.host.querySelector('[slot=body]') || this.host, 's-modal-entering', 's-modal-leaving', () => isOpen)
140
+ .toggleElement(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
141
+ //todo:: use united class names
142
+ .toggleElement(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
143
+ if (!isOpen) {
144
+ setTimeout(() => this.host.classList.add('hidden'), 350);
145
+ }
146
+ }
147
+ closeModal() {
148
+ if (!this.isClosable) {
149
+ return;
150
+ }
151
+ this.host.removeAttribute('visible');
152
+ }
153
+ //todo:: pref for each modal
154
+ render() {
155
+ this.host.id = this.host.id || 'salla-modal';
156
+ return (
157
+ //todo:: use suitable class name instead of hidden
158
+ index.h(index.Host, { class: 's-modal-container hidden', "aria-modal": "true", role: "dialog" }, index.h("div", { class: "s-modal-wrapper" }, index.h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), index.h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), index.h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.width, slot: "body" }, this.isLoading
159
+ ? index.h("span", null, "Loading...")
160
+ :
161
+ [index.h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
162
+ index.h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, index.h("span", { class: "sicon-cancel" }))
163
+ : '', this.error || this.success || this.icon
164
+ ? index.h("div", { class: {
165
+ 's-modal-icon': true,
166
+ 's-modal-bg-error': this.error,
167
+ 's-modal-bg-success': this.success,
168
+ 's-modal-bg-normal': !this.error && !this.success,
169
+ 's-modal-bg-primary': this.primary
170
+ } }, index.h("i", { class: {
171
+ [this.icon]: true,
172
+ 's-modal-text-error': this.error,
173
+ 's-modal-text-success': this.success,
174
+ } }))
175
+ : this.imageIcon ?
176
+ index.h("img", { class: "s-modal-header-img", src: this.imageIcon })
177
+ : '', this.title || this.subTitle ?
178
+ index.h("div", { class: "s-modal-header-content" }, index.h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.title }), index.h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle }))
179
+ : ''),
180
+ index.h("slot", null),
181
+ index.h("slot", { name: "footer" })
182
+ ]))));
183
+ }
184
+ get host() { return index.getElement(this); }
185
+ static get watchers() { return {
186
+ "visible": ["handleVisible"]
187
+ }; }
188
+ };
189
+
190
+ function createCommonjsModule(fn, basedir, module) {
191
+ return module = {
192
+ path: basedir,
193
+ exports: {},
194
+ require: function (path, base) {
195
+ return commonjsRequire();
196
+ }
197
+ }, fn(module, module.exports), module.exports;
198
+ }
199
+
200
+ function commonjsRequire () {
201
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
202
+ }
203
+
204
+ var intlTelInput$1 = createCommonjsModule(function (module) {
205
+ /*
206
+ * International Telephone Input v17.0.15
207
+ * https://github.com/jackocnr/intl-tel-input.git
208
+ * Licensed under the MIT license
209
+ */
210
+
211
+ // wrap in UMD
212
+ (function(factory) {
213
+ if (module.exports) module.exports = factory(); else window.intlTelInput = factory();
214
+ })(function(undefined$1) {
215
+ return function() {
216
+ // Array of country objects for the flag dropdown.
217
+ // Here is the criteria for the plugin to support a given country/territory
218
+ // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
219
+ // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes
220
+ // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
221
+ // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
222
+ // Each country array has the following information:
223
+ // [
224
+ // Country name,
225
+ // iso2 code,
226
+ // International dial code,
227
+ // Order (if >1 country with same dial code),
228
+ // Area codes
229
+ // ]
230
+ var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1", 5, [ "684" ] ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1", 6, [ "264" ] ], [ "Antigua and Barbuda", "ag", "1", 7, [ "268" ] ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Ascension Island", "ac", "247" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1", 8, [ "242" ] ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1", 9, [ "246" ] ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1", 10, [ "441" ] ], [ "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", "1", 11, [ "284" ] ], [ "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, [ "3", "4", "7" ] ], [ "Cayman Islands", "ky", "1", 12, [ "345" ] ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2, [ "89164" ] ], [ "Cocos (Keeling) Islands", "cc", "61", 1, [ "89162" ] ], [ "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", "1", 13, [ "767" ] ], [ "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" ], [ "Eswatini", "sz", "268" ], [ "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", "1", 14, [ "473" ] ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1", 15, [ "671" ] ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1, [ "1481", "7781", "7839", "7911" ] ], [ "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, [ "1624", "74576", "7524", "7924", "7624" ] ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1", 4, [ "876", "658" ] ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3, [ "1534", "7509", "7700", "7797", "7829", "7937" ] ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1, [ "33", "7" ] ], [ "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" ], [ "North Macedonia (Македонија)", "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, [ "269", "639" ] ], [ "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", "1", 16, [ "664" ] ], [ "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", "1", 17, [ "670" ] ], [ "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", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1", 18, [ "869" ] ], [ "Saint Lucia", "lc", "1", 19, [ "758" ] ], [ "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", "1", 20, [ "784" ] ], [ "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", "1", 21, [ "721" ] ], [ "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, [ "79" ] ], [ "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", "1", 22, [ "868" ] ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1", 23, [ "649" ] ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1", 24, [ "340" ] ], [ "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, [ "06698" ] ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1, [ "5288", "5289" ] ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1, [ "18" ] ] ];
231
+ // loop over all of the countries above, restructuring the data to be objects with named keys
232
+ for (var i = 0; i < allCountries.length; i++) {
233
+ var c = allCountries[i];
234
+ allCountries[i] = {
235
+ name: c[0],
236
+ iso2: c[1],
237
+ dialCode: c[2],
238
+ priority: c[3] || 0,
239
+ areaCodes: c[4] || null
240
+ };
241
+ }
242
+ function _classCallCheck(instance, Constructor) {
243
+ if (!(instance instanceof Constructor)) {
244
+ throw new TypeError("Cannot call a class as a function");
245
+ }
246
+ }
247
+ function _defineProperties(target, props) {
248
+ for (var i = 0; i < props.length; i++) {
249
+ var descriptor = props[i];
250
+ descriptor.enumerable = descriptor.enumerable || false;
251
+ descriptor.configurable = true;
252
+ if ("value" in descriptor) descriptor.writable = true;
253
+ Object.defineProperty(target, descriptor.key, descriptor);
254
+ }
255
+ }
256
+ function _createClass(Constructor, protoProps, staticProps) {
257
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
258
+ if (staticProps) _defineProperties(Constructor, staticProps);
259
+ return Constructor;
260
+ }
261
+ var intlTelInputGlobals = {
262
+ getInstance: function getInstance(input) {
263
+ var id = input.getAttribute("data-intl-tel-input-id");
264
+ return window.intlTelInputGlobals.instances[id];
265
+ },
266
+ instances: {},
267
+ // using a global like this allows us to mock it in the tests
268
+ documentReady: function documentReady() {
269
+ return document.readyState === "complete";
270
+ }
271
+ };
272
+ if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
273
+ // these vars persist through all instances of the plugin
274
+ var id = 0;
275
+ var defaults = {
276
+ // whether or not to allow the dropdown
277
+ allowDropdown: true,
278
+ // if there is just a dial code in the input: remove it on blur
279
+ autoHideDialCode: true,
280
+ // add a placeholder in the input with an example number for the selected country
281
+ autoPlaceholder: "polite",
282
+ // modify the parentClass
283
+ customContainer: "",
284
+ // modify the auto placeholder
285
+ customPlaceholder: null,
286
+ // append menu to specified element
287
+ dropdownContainer: null,
288
+ // don't display these countries
289
+ excludeCountries: [],
290
+ // format the input value during initialisation and on setNumber
291
+ formatOnDisplay: true,
292
+ // geoIp lookup function
293
+ geoIpLookup: null,
294
+ // inject a hidden input with this name, and on submit, populate it with the result of getNumber
295
+ hiddenInput: "",
296
+ // initial country
297
+ initialCountry: "",
298
+ // localized country names e.g. { 'de': 'Deutschland' }
299
+ localizedCountries: null,
300
+ // don't insert international dial codes
301
+ nationalMode: true,
302
+ // display only these countries
303
+ onlyCountries: [],
304
+ // number type to use for placeholders
305
+ placeholderNumberType: "MOBILE",
306
+ // the countries at the top of the list. defaults to united states and united kingdom
307
+ preferredCountries: [ "us", "gb" ],
308
+ // display the country dial code next to the selected flag so it's not part of the typed number
309
+ separateDialCode: false,
310
+ // specify the path to the libphonenumber script to enable validation/formatting
311
+ utilsScript: ""
312
+ };
313
+ // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
314
+ var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
315
+ // utility function to iterate over an object. can't use Object.entries or native forEach because
316
+ // of IE11
317
+ var forEachProp = function forEachProp(obj, callback) {
318
+ var keys = Object.keys(obj);
319
+ for (var i = 0; i < keys.length; i++) {
320
+ callback(keys[i], obj[keys[i]]);
321
+ }
322
+ };
323
+ // run a method on each instance of the plugin
324
+ var forEachInstance = function forEachInstance(method) {
325
+ forEachProp(window.intlTelInputGlobals.instances, function(key) {
326
+ window.intlTelInputGlobals.instances[key][method]();
327
+ });
328
+ };
329
+ // this is our plugin class that we will create an instance of
330
+ // eslint-disable-next-line no-unused-vars
331
+ var Iti = /*#__PURE__*/
332
+ function() {
333
+ function Iti(input, options) {
334
+ var _this = this;
335
+ _classCallCheck(this, Iti);
336
+ this.id = id++;
337
+ this.telInput = input;
338
+ this.activeItem = null;
339
+ this.highlightedItem = null;
340
+ // process specified options / defaults
341
+ // alternative to Object.assign, which isn't supported by IE11
342
+ var customOptions = options || {};
343
+ this.options = {};
344
+ forEachProp(defaults, function(key, value) {
345
+ _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
346
+ });
347
+ this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
348
+ }
349
+ _createClass(Iti, [ {
350
+ key: "_init",
351
+ value: function _init() {
352
+ var _this2 = this;
353
+ // if in nationalMode, disable options relating to dial codes
354
+ if (this.options.nationalMode) this.options.autoHideDialCode = false;
355
+ // if separateDialCode then doesn't make sense to A) insert dial code into input
356
+ // (autoHideDialCode), and B) display national numbers (because we're displaying the country
357
+ // dial code next to them)
358
+ if (this.options.separateDialCode) {
359
+ this.options.autoHideDialCode = this.options.nationalMode = false;
360
+ }
361
+ // we cannot just test screen size as some smartphones/website meta tags will report desktop
362
+ // resolutions
363
+ // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
364
+ // rest of these declarations
365
+ // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
366
+ this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
367
+ if (this.isMobile) {
368
+ // trigger the mobile dropdown css
369
+ document.body.classList.add("iti-mobile");
370
+ // on mobile, we want a full screen dropdown, so we must append it to the body
371
+ if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
372
+ }
373
+ // these promises get resolved when their individual requests complete
374
+ // this way the dev can do something like iti.promise.then(...) to know when all requests are
375
+ // complete
376
+ if (typeof Promise !== "undefined") {
377
+ var autoCountryPromise = new Promise(function(resolve, reject) {
378
+ _this2.resolveAutoCountryPromise = resolve;
379
+ _this2.rejectAutoCountryPromise = reject;
380
+ });
381
+ var utilsScriptPromise = new Promise(function(resolve, reject) {
382
+ _this2.resolveUtilsScriptPromise = resolve;
383
+ _this2.rejectUtilsScriptPromise = reject;
384
+ });
385
+ this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
386
+ } else {
387
+ // prevent errors when Promise doesn't exist
388
+ this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {};
389
+ this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {};
390
+ }
391
+ // in various situations there could be no country selected initially, but we need to be able
392
+ // to assume this variable exists
393
+ this.selectedCountryData = {};
394
+ // process all the data: onlyCountries, excludeCountries, preferredCountries etc
395
+ this._processCountryData();
396
+ // generate the markup
397
+ this._generateMarkup();
398
+ // set the initial state of the input value and the selected flag
399
+ this._setInitialState();
400
+ // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
401
+ this._initListeners();
402
+ // utils script, and auto country
403
+ this._initRequests();
404
+ }
405
+ }, {
406
+ key: "_processCountryData",
407
+ value: function _processCountryData() {
408
+ // process onlyCountries or excludeCountries array if present
409
+ this._processAllCountries();
410
+ // process the countryCodes map
411
+ this._processCountryCodes();
412
+ // process the preferredCountries
413
+ this._processPreferredCountries();
414
+ // translate countries according to localizedCountries option
415
+ if (this.options.localizedCountries) this._translateCountriesByLocale();
416
+ // sort countries by name
417
+ if (this.options.onlyCountries.length || this.options.localizedCountries) {
418
+ this.countries.sort(this._countryNameSort);
419
+ }
420
+ }
421
+ }, {
422
+ key: "_addCountryCode",
423
+ value: function _addCountryCode(iso2, countryCode, priority) {
424
+ if (countryCode.length > this.countryCodeMaxLen) {
425
+ this.countryCodeMaxLen = countryCode.length;
426
+ }
427
+ if (!this.countryCodes.hasOwnProperty(countryCode)) {
428
+ this.countryCodes[countryCode] = [];
429
+ }
430
+ // bail if we already have this country for this countryCode
431
+ for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
432
+ if (this.countryCodes[countryCode][i] === iso2) return;
433
+ }
434
+ // check for undefined as 0 is falsy
435
+ var index = priority !== undefined$1 ? priority : this.countryCodes[countryCode].length;
436
+ this.countryCodes[countryCode][index] = iso2;
437
+ }
438
+ }, {
439
+ key: "_processAllCountries",
440
+ value: function _processAllCountries() {
441
+ if (this.options.onlyCountries.length) {
442
+ var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
443
+ return country.toLowerCase();
444
+ });
445
+ this.countries = allCountries.filter(function(country) {
446
+ return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
447
+ });
448
+ } else if (this.options.excludeCountries.length) {
449
+ var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
450
+ return country.toLowerCase();
451
+ });
452
+ this.countries = allCountries.filter(function(country) {
453
+ return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
454
+ });
455
+ } else {
456
+ this.countries = allCountries;
457
+ }
458
+ }
459
+ }, {
460
+ key: "_translateCountriesByLocale",
461
+ value: function _translateCountriesByLocale() {
462
+ for (var i = 0; i < this.countries.length; i++) {
463
+ var iso = this.countries[i].iso2.toLowerCase();
464
+ if (this.options.localizedCountries.hasOwnProperty(iso)) {
465
+ this.countries[i].name = this.options.localizedCountries[iso];
466
+ }
467
+ }
468
+ }
469
+ }, {
470
+ key: "_countryNameSort",
471
+ value: function _countryNameSort(a, b) {
472
+ return a.name.localeCompare(b.name);
473
+ }
474
+ }, {
475
+ key: "_processCountryCodes",
476
+ value: function _processCountryCodes() {
477
+ this.countryCodeMaxLen = 0;
478
+ // here we store just dial codes
479
+ this.dialCodes = {};
480
+ // here we store "country codes" (both dial codes and their area codes)
481
+ this.countryCodes = {};
482
+ // first: add dial codes
483
+ for (var i = 0; i < this.countries.length; i++) {
484
+ var c = this.countries[i];
485
+ if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
486
+ this._addCountryCode(c.iso2, c.dialCode, c.priority);
487
+ }
488
+ // next: add area codes
489
+ // this is a second loop over countries, to make sure we have all of the "root" countries
490
+ // already in the map, so that we can access them, as each time we add an area code substring
491
+ // to the map, we also need to include the "root" country's code, as that also matches
492
+ for (var _i = 0; _i < this.countries.length; _i++) {
493
+ var _c = this.countries[_i];
494
+ // area codes
495
+ if (_c.areaCodes) {
496
+ var rootCountryCode = this.countryCodes[_c.dialCode][0];
497
+ // for each area code
498
+ for (var j = 0; j < _c.areaCodes.length; j++) {
499
+ var areaCode = _c.areaCodes[j];
500
+ // for each digit in the area code to add all partial matches as well
501
+ for (var k = 1; k < areaCode.length; k++) {
502
+ var partialDialCode = _c.dialCode + areaCode.substr(0, k);
503
+ // start with the root country, as that also matches this dial code
504
+ this._addCountryCode(rootCountryCode, partialDialCode);
505
+ this._addCountryCode(_c.iso2, partialDialCode);
506
+ }
507
+ // add the full area code
508
+ this._addCountryCode(_c.iso2, _c.dialCode + areaCode);
509
+ }
510
+ }
511
+ }
512
+ }
513
+ }, {
514
+ key: "_processPreferredCountries",
515
+ value: function _processPreferredCountries() {
516
+ this.preferredCountries = [];
517
+ for (var i = 0; i < this.options.preferredCountries.length; i++) {
518
+ var countryCode = this.options.preferredCountries[i].toLowerCase();
519
+ var countryData = this._getCountryData(countryCode, false, true);
520
+ if (countryData) this.preferredCountries.push(countryData);
521
+ }
522
+ }
523
+ }, {
524
+ key: "_createEl",
525
+ value: function _createEl(name, attrs, container) {
526
+ var el = document.createElement(name);
527
+ if (attrs) forEachProp(attrs, function(key, value) {
528
+ return el.setAttribute(key, value);
529
+ });
530
+ if (container) container.appendChild(el);
531
+ return el;
532
+ }
533
+ }, {
534
+ key: "_generateMarkup",
535
+ value: function _generateMarkup() {
536
+ // if autocomplete does not exist on the element and its form, then
537
+ // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
538
+ // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
539
+ // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
540
+ if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
541
+ this.telInput.setAttribute("autocomplete", "off");
542
+ }
543
+ // containers (mostly for positioning)
544
+ var parentClass = "iti";
545
+ if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
546
+ if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
547
+ if (this.options.customContainer) {
548
+ parentClass += " ";
549
+ parentClass += this.options.customContainer;
550
+ }
551
+ var wrapper = this._createEl("div", {
552
+ "class": parentClass
553
+ });
554
+ this.telInput.parentNode.insertBefore(wrapper, this.telInput);
555
+ this.flagsContainer = this._createEl("div", {
556
+ "class": "iti__flag-container"
557
+ }, wrapper);
558
+ wrapper.appendChild(this.telInput);
559
+ // selected flag (displayed to left of input)
560
+ this.selectedFlag = this._createEl("div", {
561
+ "class": "iti__selected-flag",
562
+ role: "combobox",
563
+ "aria-controls": "iti-".concat(this.id, "__country-listbox"),
564
+ "aria-owns": "iti-".concat(this.id, "__country-listbox"),
565
+ "aria-expanded": "false"
566
+ }, this.flagsContainer);
567
+ this.selectedFlagInner = this._createEl("div", {
568
+ "class": "iti__flag"
569
+ }, this.selectedFlag);
570
+ if (this.options.separateDialCode) {
571
+ this.selectedDialCode = this._createEl("div", {
572
+ "class": "iti__selected-dial-code"
573
+ }, this.selectedFlag);
574
+ }
575
+ if (this.options.allowDropdown) {
576
+ // make element focusable and tab navigable
577
+ this.selectedFlag.setAttribute("tabindex", "0");
578
+ this.dropdownArrow = this._createEl("div", {
579
+ "class": "iti__arrow"
580
+ }, this.selectedFlag);
581
+ // country dropdown: preferred countries, then divider, then all countries
582
+ this.countryList = this._createEl("ul", {
583
+ "class": "iti__country-list iti__hide",
584
+ id: "iti-".concat(this.id, "__country-listbox"),
585
+ role: "listbox",
586
+ "aria-label": "List of countries"
587
+ });
588
+ if (this.preferredCountries.length) {
589
+ this._appendListItems(this.preferredCountries, "iti__preferred", true);
590
+ this._createEl("li", {
591
+ "class": "iti__divider",
592
+ role: "separator",
593
+ "aria-disabled": "true"
594
+ }, this.countryList);
595
+ }
596
+ this._appendListItems(this.countries, "iti__standard");
597
+ // create dropdownContainer markup
598
+ if (this.options.dropdownContainer) {
599
+ this.dropdown = this._createEl("div", {
600
+ "class": "iti iti--container"
601
+ });
602
+ this.dropdown.appendChild(this.countryList);
603
+ } else {
604
+ this.flagsContainer.appendChild(this.countryList);
605
+ }
606
+ }
607
+ if (this.options.hiddenInput) {
608
+ var hiddenInputName = this.options.hiddenInput;
609
+ var name = this.telInput.getAttribute("name");
610
+ if (name) {
611
+ var i = name.lastIndexOf("[");
612
+ // if input name contains square brackets, then give the hidden input the same name,
613
+ // replacing the contents of the last set of brackets with the given hiddenInput name
614
+ if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
615
+ }
616
+ this.hiddenInput = this._createEl("input", {
617
+ type: "hidden",
618
+ name: hiddenInputName
619
+ });
620
+ wrapper.appendChild(this.hiddenInput);
621
+ }
622
+ }
623
+ }, {
624
+ key: "_appendListItems",
625
+ value: function _appendListItems(countries, className, preferred) {
626
+ // we create so many DOM elements, it is faster to build a temp string
627
+ // and then add everything to the DOM in one go at the end
628
+ var tmp = "";
629
+ // for each country
630
+ for (var i = 0; i < countries.length; i++) {
631
+ var c = countries[i];
632
+ var idSuffix = preferred ? "-preferred" : "";
633
+ // open the list item
634
+ tmp += "<li class='iti__country ".concat(className, "' tabIndex='-1' id='iti-").concat(this.id, "__item-").concat(c.iso2).concat(idSuffix, "' role='option' data-dial-code='").concat(c.dialCode, "' data-country-code='").concat(c.iso2, "' aria-selected='false'>");
635
+ // add the flag
636
+ tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
637
+ // and the country name and dial code
638
+ tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
639
+ tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
640
+ // close the list item
641
+ tmp += "</li>";
642
+ }
643
+ this.countryList.insertAdjacentHTML("beforeend", tmp);
644
+ }
645
+ }, {
646
+ key: "_setInitialState",
647
+ value: function _setInitialState() {
648
+ // fix firefox bug: when first load page (with input with value set to number with intl dial
649
+ // code) and initialising plugin removes the dial code from the input, then refresh page,
650
+ // and we try to init plugin again but this time on number without dial code so get grey flag
651
+ var attributeValue = this.telInput.getAttribute("value");
652
+ var inputValue = this.telInput.value;
653
+ var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
654
+ var val = useAttribute ? attributeValue : inputValue;
655
+ var dialCode = this._getDialCode(val);
656
+ var isRegionlessNanp = this._isRegionlessNanp(val);
657
+ var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
658
+ // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
659
+ // flag, else fall back to the default country
660
+ if (dialCode && !isRegionlessNanp) {
661
+ this._updateFlagFromNumber(val);
662
+ } else if (initialCountry !== "auto") {
663
+ // see if we should select a flag
664
+ if (initialCountry) {
665
+ this._setFlag(initialCountry.toLowerCase());
666
+ } else {
667
+ if (dialCode && isRegionlessNanp) {
668
+ // has intl dial code, is regionless nanp, and no initialCountry, so default to US
669
+ this._setFlag("us");
670
+ } else {
671
+ // no dial code and no initialCountry, so default to first in list
672
+ this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
673
+ if (!val) {
674
+ this._setFlag(this.defaultCountry);
675
+ }
676
+ }
677
+ }
678
+ // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
679
+ if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
680
+ this.telInput.value = "+".concat(this.selectedCountryData.dialCode);
681
+ }
682
+ }
683
+ // NOTE: if initialCountry is set to auto, that will be handled separately
684
+ // format - note this wont be run after _updateDialCode as that's only called if no val
685
+ if (val) this._updateValFromNumber(val);
686
+ }
687
+ }, {
688
+ key: "_initListeners",
689
+ value: function _initListeners() {
690
+ this._initKeyListeners();
691
+ if (this.options.autoHideDialCode) this._initBlurListeners();
692
+ if (this.options.allowDropdown) this._initDropdownListeners();
693
+ if (this.hiddenInput) this._initHiddenInputListener();
694
+ }
695
+ }, {
696
+ key: "_initHiddenInputListener",
697
+ value: function _initHiddenInputListener() {
698
+ var _this3 = this;
699
+ this._handleHiddenInputSubmit = function() {
700
+ _this3.hiddenInput.value = _this3.getNumber();
701
+ };
702
+ if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
703
+ }
704
+ }, {
705
+ key: "_getClosestLabel",
706
+ value: function _getClosestLabel() {
707
+ var el = this.telInput;
708
+ while (el && el.tagName !== "LABEL") {
709
+ el = el.parentNode;
710
+ }
711
+ return el;
712
+ }
713
+ }, {
714
+ key: "_initDropdownListeners",
715
+ value: function _initDropdownListeners() {
716
+ var _this4 = this;
717
+ // hack for input nested inside label (which is valid markup): clicking the selected-flag to
718
+ // open the dropdown would then automatically trigger a 2nd click on the input which would
719
+ // close it again
720
+ this._handleLabelClick = function(e) {
721
+ // if the dropdown is closed, then focus the input, else ignore the click
722
+ if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
723
+ };
724
+ var label = this._getClosestLabel();
725
+ if (label) label.addEventListener("click", this._handleLabelClick);
726
+ // toggle country dropdown on click
727
+ this._handleClickSelectedFlag = function() {
728
+ // only intercept this event if we're opening the dropdown
729
+ // else let it bubble up to the top ("click-off-to-close" listener)
730
+ // we cannot just stopPropagation as it may be needed to close another instance
731
+ if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
732
+ _this4._showDropdown();
733
+ }
734
+ };
735
+ this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
736
+ // open dropdown list if currently focused
737
+ this._handleFlagsContainerKeydown = function(e) {
738
+ var isDropdownHidden = _this4.countryList.classList.contains("iti__hide");
739
+ if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) {
740
+ // prevent form from being submitted if "ENTER" was pressed
741
+ e.preventDefault();
742
+ // prevent event from being handled again by document
743
+ e.stopPropagation();
744
+ _this4._showDropdown();
745
+ }
746
+ // allow navigation from dropdown to input on TAB
747
+ if (e.key === "Tab") _this4._closeDropdown();
748
+ };
749
+ this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
750
+ }
751
+ }, {
752
+ key: "_initRequests",
753
+ value: function _initRequests() {
754
+ var _this5 = this;
755
+ // if the user has specified the path to the utils script, fetch it on window.load, else resolve
756
+ if (this.options.utilsScript && !window.intlTelInputUtils) {
757
+ // if the plugin is being initialised after the window.load event has already been fired
758
+ if (window.intlTelInputGlobals.documentReady()) {
759
+ window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
760
+ } else {
761
+ // wait until the load event so we don't block any other requests e.g. the flags image
762
+ window.addEventListener("load", function() {
763
+ window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
764
+ });
765
+ }
766
+ } else this.resolveUtilsScriptPromise();
767
+ if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
768
+ }
769
+ }, {
770
+ key: "_loadAutoCountry",
771
+ value: function _loadAutoCountry() {
772
+ // 3 options:
773
+ // 1) already loaded (we're done)
774
+ // 2) not already started loading (start)
775
+ // 3) already started loading (do nothing - just wait for loading callback to fire)
776
+ if (window.intlTelInputGlobals.autoCountry) {
777
+ this.handleAutoCountry();
778
+ } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
779
+ // don't do this twice!
780
+ window.intlTelInputGlobals.startedLoadingAutoCountry = true;
781
+ if (typeof this.options.geoIpLookup === "function") {
782
+ this.options.geoIpLookup(function(countryCode) {
783
+ window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase();
784
+ // tell all instances the auto country is ready
785
+ // TODO: this should just be the current instances
786
+ // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
787
+ // away (e.g. if they have already done the geo ip lookup somewhere else). Using
788
+ // setTimeout means that the current thread of execution will finish before executing
789
+ // this, which allows the plugin to finish initialising.
790
+ setTimeout(function() {
791
+ return forEachInstance("handleAutoCountry");
792
+ });
793
+ }, function() {
794
+ return forEachInstance("rejectAutoCountryPromise");
795
+ });
796
+ }
797
+ }
798
+ }
799
+ }, {
800
+ key: "_initKeyListeners",
801
+ value: function _initKeyListeners() {
802
+ var _this6 = this;
803
+ // update flag on keyup
804
+ this._handleKeyupEvent = function() {
805
+ if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
806
+ _this6._triggerCountryChange();
807
+ }
808
+ };
809
+ this.telInput.addEventListener("keyup", this._handleKeyupEvent);
810
+ // update flag on cut/paste events (now supported in all major browsers)
811
+ this._handleClipboardEvent = function() {
812
+ // hack because "paste" event is fired before input is updated
813
+ setTimeout(_this6._handleKeyupEvent);
814
+ };
815
+ this.telInput.addEventListener("cut", this._handleClipboardEvent);
816
+ this.telInput.addEventListener("paste", this._handleClipboardEvent);
817
+ }
818
+ }, {
819
+ key: "_cap",
820
+ value: function _cap(number) {
821
+ var max = this.telInput.getAttribute("maxlength");
822
+ return max && number.length > max ? number.substr(0, max) : number;
823
+ }
824
+ }, {
825
+ key: "_initBlurListeners",
826
+ value: function _initBlurListeners() {
827
+ var _this7 = this;
828
+ // on blur or form submit: if just a dial code then remove it
829
+ this._handleSubmitOrBlurEvent = function() {
830
+ _this7._removeEmptyDialCode();
831
+ };
832
+ if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
833
+ this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
834
+ }
835
+ }, {
836
+ key: "_removeEmptyDialCode",
837
+ value: function _removeEmptyDialCode() {
838
+ if (this.telInput.value.charAt(0) === "+") {
839
+ var numeric = this._getNumeric(this.telInput.value);
840
+ // if just a plus, or if just a dial code
841
+ if (!numeric || this.selectedCountryData.dialCode === numeric) {
842
+ this.telInput.value = "";
843
+ }
844
+ }
845
+ }
846
+ }, {
847
+ key: "_getNumeric",
848
+ value: function _getNumeric(s) {
849
+ return s.replace(/\D/g, "");
850
+ }
851
+ }, {
852
+ key: "_trigger",
853
+ value: function _trigger(name) {
854
+ // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
855
+ var e = document.createEvent("Event");
856
+ e.initEvent(name, true, true);
857
+ // can bubble, and is cancellable
858
+ this.telInput.dispatchEvent(e);
859
+ }
860
+ }, {
861
+ key: "_showDropdown",
862
+ value: function _showDropdown() {
863
+ this.countryList.classList.remove("iti__hide");
864
+ this.selectedFlag.setAttribute("aria-expanded", "true");
865
+ this._setDropdownPosition();
866
+ // update highlighting and scroll to active list item
867
+ if (this.activeItem) {
868
+ this._highlightListItem(this.activeItem, false);
869
+ this._scrollTo(this.activeItem, true);
870
+ }
871
+ // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
872
+ this._bindDropdownListeners();
873
+ // update the arrow
874
+ this.dropdownArrow.classList.add("iti__arrow--up");
875
+ this._trigger("open:countrydropdown");
876
+ }
877
+ }, {
878
+ key: "_toggleClass",
879
+ value: function _toggleClass(el, className, shouldHaveClass) {
880
+ if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
881
+ }
882
+ }, {
883
+ key: "_setDropdownPosition",
884
+ value: function _setDropdownPosition() {
885
+ var _this8 = this;
886
+ if (this.options.dropdownContainer) {
887
+ this.options.dropdownContainer.appendChild(this.dropdown);
888
+ }
889
+ if (!this.isMobile) {
890
+ var pos = this.telInput.getBoundingClientRect();
891
+ // windowTop from https://stackoverflow.com/a/14384091/217866
892
+ var windowTop = window.pageYOffset || document.documentElement.scrollTop;
893
+ var inputTop = pos.top + windowTop;
894
+ var dropdownHeight = this.countryList.offsetHeight;
895
+ // dropdownFitsBelow = (dropdownBottom < windowBottom)
896
+ var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
897
+ var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
898
+ // by default, the dropdown will be below the input. If we want to position it above the
899
+ // input, we add the dropup class.
900
+ this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove);
901
+ // if dropdownContainer is enabled, calculate postion
902
+ if (this.options.dropdownContainer) {
903
+ // by default the dropdown will be directly over the input because it's not in the flow.
904
+ // If we want to position it below, we need to add some extra top value.
905
+ var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight;
906
+ // calculate placement
907
+ this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
908
+ this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
909
+ // close menu on window scroll
910
+ this._handleWindowScroll = function() {
911
+ return _this8._closeDropdown();
912
+ };
913
+ window.addEventListener("scroll", this._handleWindowScroll);
914
+ }
915
+ }
916
+ }
917
+ }, {
918
+ key: "_getClosestListItem",
919
+ value: function _getClosestListItem(target) {
920
+ var el = target;
921
+ while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
922
+ el = el.parentNode;
923
+ }
924
+ // if we reached the countryList element, then return null
925
+ return el === this.countryList ? null : el;
926
+ }
927
+ }, {
928
+ key: "_bindDropdownListeners",
929
+ value: function _bindDropdownListeners() {
930
+ var _this9 = this;
931
+ // when mouse over a list item, just highlight that one
932
+ // we add the class "highlight", so if they hit "enter" we know which one to select
933
+ this._handleMouseoverCountryList = function(e) {
934
+ // handle event delegation, as we're listening for this event on the countryList
935
+ var listItem = _this9._getClosestListItem(e.target);
936
+ if (listItem) _this9._highlightListItem(listItem, false);
937
+ };
938
+ this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
939
+ // listen for country selection
940
+ this._handleClickCountryList = function(e) {
941
+ var listItem = _this9._getClosestListItem(e.target);
942
+ if (listItem) _this9._selectListItem(listItem);
943
+ };
944
+ this.countryList.addEventListener("click", this._handleClickCountryList);
945
+ // click off to close
946
+ // (except when this initial opening click is bubbling up)
947
+ // we cannot just stopPropagation as it may be needed to close another instance
948
+ var isOpening = true;
949
+ this._handleClickOffToClose = function() {
950
+ if (!isOpening) _this9._closeDropdown();
951
+ isOpening = false;
952
+ };
953
+ document.documentElement.addEventListener("click", this._handleClickOffToClose);
954
+ // listen for up/down scrolling, enter to select, or letters to jump to country name.
955
+ // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
956
+ // just hit down and hold it to scroll down (no keyup event).
957
+ // listen on the document because that's where key events are triggered if no input has focus
958
+ var query = "";
959
+ var queryTimer = null;
960
+ this._handleKeydownOnDropdown = function(e) {
961
+ // prevent down key from scrolling the whole page,
962
+ // and enter key from submitting a form etc
963
+ e.preventDefault();
964
+ // up and down to navigate
965
+ if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") _this9._handleUpDownKey(e.key); else if (e.key === "Enter") _this9._handleEnterKey(); else if (e.key === "Escape") _this9._closeDropdown(); else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
966
+ // jump to countries that start with the query string
967
+ if (queryTimer) clearTimeout(queryTimer);
968
+ query += e.key.toLowerCase();
969
+ _this9._searchForCountry(query);
970
+ // if the timer hits 1 second, reset the query
971
+ queryTimer = setTimeout(function() {
972
+ query = "";
973
+ }, 1e3);
974
+ }
975
+ };
976
+ document.addEventListener("keydown", this._handleKeydownOnDropdown);
977
+ }
978
+ }, {
979
+ key: "_handleUpDownKey",
980
+ value: function _handleUpDownKey(key) {
981
+ var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
982
+ if (next) {
983
+ // skip the divider
984
+ if (next.classList.contains("iti__divider")) {
985
+ next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling;
986
+ }
987
+ this._highlightListItem(next, true);
988
+ }
989
+ }
990
+ }, {
991
+ key: "_handleEnterKey",
992
+ value: function _handleEnterKey() {
993
+ if (this.highlightedItem) this._selectListItem(this.highlightedItem);
994
+ }
995
+ }, {
996
+ key: "_searchForCountry",
997
+ value: function _searchForCountry(query) {
998
+ for (var i = 0; i < this.countries.length; i++) {
999
+ if (this._startsWith(this.countries[i].name, query)) {
1000
+ var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2));
1001
+ // update highlighting and scroll
1002
+ this._highlightListItem(listItem, false);
1003
+ this._scrollTo(listItem, true);
1004
+ break;
1005
+ }
1006
+ }
1007
+ }
1008
+ }, {
1009
+ key: "_startsWith",
1010
+ value: function _startsWith(a, b) {
1011
+ return a.substr(0, b.length).toLowerCase() === b;
1012
+ }
1013
+ }, {
1014
+ key: "_updateValFromNumber",
1015
+ value: function _updateValFromNumber(originalNumber) {
1016
+ var number = originalNumber;
1017
+ if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
1018
+ var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+");
1019
+ var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
1020
+ var format = useNational ? NATIONAL : INTERNATIONAL;
1021
+ number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
1022
+ }
1023
+ number = this._beforeSetNumber(number);
1024
+ this.telInput.value = number;
1025
+ }
1026
+ }, {
1027
+ key: "_updateFlagFromNumber",
1028
+ value: function _updateFlagFromNumber(originalNumber) {
1029
+ // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
1030
+ // with a +1 so _getDialCode will be able to extract the area code
1031
+ // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
1032
+ // from the number), that means we're initialising the plugin with a number that already has a
1033
+ // dial code, so fine to ignore this bit
1034
+ var number = originalNumber;
1035
+ var selectedDialCode = this.selectedCountryData.dialCode;
1036
+ var isNanp = selectedDialCode === "1";
1037
+ if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
1038
+ if (number.charAt(0) !== "1") number = "1".concat(number);
1039
+ number = "+".concat(number);
1040
+ }
1041
+ // update flag if user types area code for another country
1042
+ if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
1043
+ number = "+".concat(selectedDialCode).concat(number);
1044
+ }
1045
+ // try and extract valid dial code from input
1046
+ var dialCode = this._getDialCode(number, true);
1047
+ var numeric = this._getNumeric(number);
1048
+ var countryCode = null;
1049
+ if (dialCode) {
1050
+ var countryCodes = this.countryCodes[this._getNumeric(dialCode)];
1051
+ // check if the right country is already selected. this should be false if the number is
1052
+ // longer than the matched dial code because in this case we need to make sure that if
1053
+ // there are multiple country matches, that the first one is selected (note: we could
1054
+ // just check that here, but it requires the same loop that we already have later)
1055
+ var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
1056
+ var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
1057
+ // only update the flag if:
1058
+ // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
1059
+ // AND
1060
+ // B) the right country is not already selected
1061
+ if (!isRegionlessNanpNumber && !alreadySelected) {
1062
+ // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
1063
+ // non-empty index
1064
+ for (var j = 0; j < countryCodes.length; j++) {
1065
+ if (countryCodes[j]) {
1066
+ countryCode = countryCodes[j];
1067
+ break;
1068
+ }
1069
+ }
1070
+ }
1071
+ } else if (number.charAt(0) === "+" && numeric.length) {
1072
+ // invalid dial code, so empty
1073
+ // Note: use getNumeric here because the number has not been formatted yet, so could contain
1074
+ // bad chars
1075
+ countryCode = "";
1076
+ } else if (!number || number === "+") {
1077
+ // empty, or just a plus, so default
1078
+ countryCode = this.defaultCountry;
1079
+ }
1080
+ if (countryCode !== null) {
1081
+ return this._setFlag(countryCode);
1082
+ }
1083
+ return false;
1084
+ }
1085
+ }, {
1086
+ key: "_isRegionlessNanp",
1087
+ value: function _isRegionlessNanp(number) {
1088
+ var numeric = this._getNumeric(number);
1089
+ if (numeric.charAt(0) === "1") {
1090
+ var areaCode = numeric.substr(1, 3);
1091
+ return regionlessNanpNumbers.indexOf(areaCode) !== -1;
1092
+ }
1093
+ return false;
1094
+ }
1095
+ }, {
1096
+ key: "_highlightListItem",
1097
+ value: function _highlightListItem(listItem, shouldFocus) {
1098
+ var prevItem = this.highlightedItem;
1099
+ if (prevItem) prevItem.classList.remove("iti__highlight");
1100
+ this.highlightedItem = listItem;
1101
+ this.highlightedItem.classList.add("iti__highlight");
1102
+ if (shouldFocus) this.highlightedItem.focus();
1103
+ }
1104
+ }, {
1105
+ key: "_getCountryData",
1106
+ value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) {
1107
+ var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
1108
+ for (var i = 0; i < countryList.length; i++) {
1109
+ if (countryList[i].iso2 === countryCode) {
1110
+ return countryList[i];
1111
+ }
1112
+ }
1113
+ if (allowFail) {
1114
+ return null;
1115
+ }
1116
+ throw new Error("No country data for '".concat(countryCode, "'"));
1117
+ }
1118
+ }, {
1119
+ key: "_setFlag",
1120
+ value: function _setFlag(countryCode) {
1121
+ var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
1122
+ // do this first as it will throw an error and stop if countryCode is invalid
1123
+ this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
1124
+ // update the defaultCountry - we only need the iso2 from now on, so just store that
1125
+ if (this.selectedCountryData.iso2) {
1126
+ this.defaultCountry = this.selectedCountryData.iso2;
1127
+ }
1128
+ this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1129
+ // update the selected country's title attribute
1130
+ var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
1131
+ this.selectedFlag.setAttribute("title", title);
1132
+ if (this.options.separateDialCode) {
1133
+ var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
1134
+ this.selectedDialCode.innerHTML = dialCode;
1135
+ // offsetWidth is zero if input is in a hidden container during initialisation
1136
+ var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
1137
+ // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
1138
+ this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
1139
+ }
1140
+ // and the input's placeholder
1141
+ this._updatePlaceholder();
1142
+ // update the active list item
1143
+ if (this.options.allowDropdown) {
1144
+ var prevItem = this.activeItem;
1145
+ if (prevItem) {
1146
+ prevItem.classList.remove("iti__active");
1147
+ prevItem.setAttribute("aria-selected", "false");
1148
+ }
1149
+ if (countryCode) {
1150
+ // check if there is a preferred item first, else fall back to standard
1151
+ var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode));
1152
+ nextItem.setAttribute("aria-selected", "true");
1153
+ nextItem.classList.add("iti__active");
1154
+ this.activeItem = nextItem;
1155
+ this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id"));
1156
+ }
1157
+ }
1158
+ // return if the flag has changed or not
1159
+ return prevCountry.iso2 !== countryCode;
1160
+ }
1161
+ }, {
1162
+ key: "_getHiddenSelectedFlagWidth",
1163
+ value: function _getHiddenSelectedFlagWidth() {
1164
+ // to get the right styling to apply, all we need is a shallow clone of the container,
1165
+ // and then to inject a deep clone of the selectedFlag element
1166
+ var containerClone = this.telInput.parentNode.cloneNode();
1167
+ containerClone.style.visibility = "hidden";
1168
+ document.body.appendChild(containerClone);
1169
+ var flagsContainerClone = this.flagsContainer.cloneNode();
1170
+ containerClone.appendChild(flagsContainerClone);
1171
+ var selectedFlagClone = this.selectedFlag.cloneNode(true);
1172
+ flagsContainerClone.appendChild(selectedFlagClone);
1173
+ var width = selectedFlagClone.offsetWidth;
1174
+ containerClone.parentNode.removeChild(containerClone);
1175
+ return width;
1176
+ }
1177
+ }, {
1178
+ key: "_updatePlaceholder",
1179
+ value: function _updatePlaceholder() {
1180
+ var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite";
1181
+ if (window.intlTelInputUtils && shouldSetPlaceholder) {
1182
+ var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
1183
+ var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
1184
+ placeholder = this._beforeSetNumber(placeholder);
1185
+ if (typeof this.options.customPlaceholder === "function") {
1186
+ placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
1187
+ }
1188
+ this.telInput.setAttribute("placeholder", placeholder);
1189
+ }
1190
+ }
1191
+ }, {
1192
+ key: "_selectListItem",
1193
+ value: function _selectListItem(listItem) {
1194
+ // update selected flag and active list item
1195
+ var flagChanged = this._setFlag(listItem.getAttribute("data-country-code"));
1196
+ this._closeDropdown();
1197
+ this._updateDialCode(listItem.getAttribute("data-dial-code"), true);
1198
+ // focus the input
1199
+ this.telInput.focus();
1200
+ // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
1201
+ // inserting dial code), who try to put the cursor at the beginning the first time
1202
+ var len = this.telInput.value.length;
1203
+ this.telInput.setSelectionRange(len, len);
1204
+ if (flagChanged) {
1205
+ this._triggerCountryChange();
1206
+ }
1207
+ }
1208
+ }, {
1209
+ key: "_closeDropdown",
1210
+ value: function _closeDropdown() {
1211
+ this.countryList.classList.add("iti__hide");
1212
+ this.selectedFlag.setAttribute("aria-expanded", "false");
1213
+ // update the arrow
1214
+ this.dropdownArrow.classList.remove("iti__arrow--up");
1215
+ // unbind key events
1216
+ document.removeEventListener("keydown", this._handleKeydownOnDropdown);
1217
+ document.documentElement.removeEventListener("click", this._handleClickOffToClose);
1218
+ this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
1219
+ this.countryList.removeEventListener("click", this._handleClickCountryList);
1220
+ // remove menu from container
1221
+ if (this.options.dropdownContainer) {
1222
+ if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
1223
+ if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
1224
+ }
1225
+ this._trigger("close:countrydropdown");
1226
+ }
1227
+ }, {
1228
+ key: "_scrollTo",
1229
+ value: function _scrollTo(element, middle) {
1230
+ var container = this.countryList;
1231
+ // windowTop from https://stackoverflow.com/a/14384091/217866
1232
+ var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1233
+ var containerHeight = container.offsetHeight;
1234
+ var containerTop = container.getBoundingClientRect().top + windowTop;
1235
+ var containerBottom = containerTop + containerHeight;
1236
+ var elementHeight = element.offsetHeight;
1237
+ var elementTop = element.getBoundingClientRect().top + windowTop;
1238
+ var elementBottom = elementTop + elementHeight;
1239
+ var newScrollTop = elementTop - containerTop + container.scrollTop;
1240
+ var middleOffset = containerHeight / 2 - elementHeight / 2;
1241
+ if (elementTop < containerTop) {
1242
+ // scroll up
1243
+ if (middle) newScrollTop -= middleOffset;
1244
+ container.scrollTop = newScrollTop;
1245
+ } else if (elementBottom > containerBottom) {
1246
+ // scroll down
1247
+ if (middle) newScrollTop += middleOffset;
1248
+ var heightDifference = containerHeight - elementHeight;
1249
+ container.scrollTop = newScrollTop - heightDifference;
1250
+ }
1251
+ }
1252
+ }, {
1253
+ key: "_updateDialCode",
1254
+ value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) {
1255
+ var inputVal = this.telInput.value;
1256
+ // save having to pass this every time
1257
+ var newDialCode = "+".concat(newDialCodeBare);
1258
+ var newNumber;
1259
+ if (inputVal.charAt(0) === "+") {
1260
+ // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
1261
+ var prevDialCode = this._getDialCode(inputVal);
1262
+ if (prevDialCode) {
1263
+ // current number contains a valid dial code, so replace it
1264
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
1265
+ } else {
1266
+ // current number contains an invalid dial code, so ditch it
1267
+ // (no way to determine where the invalid dial code ends and the rest of the number begins)
1268
+ newNumber = newDialCode;
1269
+ }
1270
+ } else if (this.options.nationalMode || this.options.separateDialCode) {
1271
+ // don't do anything
1272
+ return;
1273
+ } else {
1274
+ // nationalMode is disabled
1275
+ if (inputVal) {
1276
+ // there is an existing value with no dial code: prefix the new dial code
1277
+ newNumber = newDialCode + inputVal;
1278
+ } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
1279
+ // no existing value and either they've just selected a list item, or autoHideDialCode is
1280
+ // disabled: insert new dial code
1281
+ newNumber = newDialCode;
1282
+ } else {
1283
+ return;
1284
+ }
1285
+ }
1286
+ this.telInput.value = newNumber;
1287
+ }
1288
+ }, {
1289
+ key: "_getDialCode",
1290
+ value: function _getDialCode(number, includeAreaCode) {
1291
+ var dialCode = "";
1292
+ // only interested in international numbers (starting with a plus)
1293
+ if (number.charAt(0) === "+") {
1294
+ var numericChars = "";
1295
+ // iterate over chars
1296
+ for (var i = 0; i < number.length; i++) {
1297
+ var c = number.charAt(i);
1298
+ // if char is number (https://stackoverflow.com/a/8935649/217866)
1299
+ if (!isNaN(parseInt(c, 10))) {
1300
+ numericChars += c;
1301
+ // if current numericChars make a valid dial code
1302
+ if (includeAreaCode) {
1303
+ if (this.countryCodes[numericChars]) {
1304
+ // store the actual raw string (useful for matching later)
1305
+ dialCode = number.substr(0, i + 1);
1306
+ }
1307
+ } else {
1308
+ if (this.dialCodes[numericChars]) {
1309
+ dialCode = number.substr(0, i + 1);
1310
+ // if we're just looking for a dial code, we can break as soon as we find one
1311
+ break;
1312
+ }
1313
+ }
1314
+ // stop searching as soon as we can - in this case when we hit max len
1315
+ if (numericChars.length === this.countryCodeMaxLen) {
1316
+ break;
1317
+ }
1318
+ }
1319
+ }
1320
+ }
1321
+ return dialCode;
1322
+ }
1323
+ }, {
1324
+ key: "_getFullNumber",
1325
+ value: function _getFullNumber() {
1326
+ var val = this.telInput.value.trim();
1327
+ var dialCode = this.selectedCountryData.dialCode;
1328
+ var prefix;
1329
+ var numericVal = this._getNumeric(val);
1330
+ if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
1331
+ // when using separateDialCode, it is visible so is effectively part of the typed number
1332
+ prefix = "+".concat(dialCode);
1333
+ } else {
1334
+ prefix = "";
1335
+ }
1336
+ return prefix + val;
1337
+ }
1338
+ }, {
1339
+ key: "_beforeSetNumber",
1340
+ value: function _beforeSetNumber(originalNumber) {
1341
+ var number = originalNumber;
1342
+ if (this.options.separateDialCode) {
1343
+ var dialCode = this._getDialCode(number);
1344
+ // if there is a valid dial code
1345
+ if (dialCode) {
1346
+ // in case _getDialCode returned an area code as well
1347
+ dialCode = "+".concat(this.selectedCountryData.dialCode);
1348
+ // a lot of numbers will have a space separating the dial code and the main number, and
1349
+ // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
1350
+ // rid of it
1351
+ // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
1352
+ var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
1353
+ number = number.substr(start);
1354
+ }
1355
+ }
1356
+ return this._cap(number);
1357
+ }
1358
+ }, {
1359
+ key: "_triggerCountryChange",
1360
+ value: function _triggerCountryChange() {
1361
+ this._trigger("countrychange");
1362
+ }
1363
+ }, {
1364
+ key: "handleAutoCountry",
1365
+ value: function handleAutoCountry() {
1366
+ if (this.options.initialCountry === "auto") {
1367
+ // we must set this even if there is an initial val in the input: in case the initial val is
1368
+ // invalid and they delete it - they should see their auto country
1369
+ this.defaultCountry = window.intlTelInputGlobals.autoCountry;
1370
+ // if there's no initial value in the input, then update the flag
1371
+ if (!this.telInput.value) {
1372
+ this.setCountry(this.defaultCountry);
1373
+ }
1374
+ this.resolveAutoCountryPromise();
1375
+ }
1376
+ }
1377
+ }, {
1378
+ key: "handleUtils",
1379
+ value: function handleUtils() {
1380
+ // if the request was successful
1381
+ if (window.intlTelInputUtils) {
1382
+ // if there's an initial value in the input, then format it
1383
+ if (this.telInput.value) {
1384
+ this._updateValFromNumber(this.telInput.value);
1385
+ }
1386
+ this._updatePlaceholder();
1387
+ }
1388
+ this.resolveUtilsScriptPromise();
1389
+ }
1390
+ }, {
1391
+ key: "destroy",
1392
+ value: function destroy() {
1393
+ var form = this.telInput.form;
1394
+ if (this.options.allowDropdown) {
1395
+ // make sure the dropdown is closed (and unbind listeners)
1396
+ this._closeDropdown();
1397
+ this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
1398
+ this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1399
+ // label click hack
1400
+ var label = this._getClosestLabel();
1401
+ if (label) label.removeEventListener("click", this._handleLabelClick);
1402
+ }
1403
+ // unbind hiddenInput listeners
1404
+ if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
1405
+ // unbind autoHideDialCode listeners
1406
+ if (this.options.autoHideDialCode) {
1407
+ if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
1408
+ this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
1409
+ }
1410
+ // unbind key events, and cut/paste events
1411
+ this.telInput.removeEventListener("keyup", this._handleKeyupEvent);
1412
+ this.telInput.removeEventListener("cut", this._handleClipboardEvent);
1413
+ this.telInput.removeEventListener("paste", this._handleClipboardEvent);
1414
+ // remove attribute of id instance: data-intl-tel-input-id
1415
+ this.telInput.removeAttribute("data-intl-tel-input-id");
1416
+ // remove markup (but leave the original input)
1417
+ var wrapper = this.telInput.parentNode;
1418
+ wrapper.parentNode.insertBefore(this.telInput, wrapper);
1419
+ wrapper.parentNode.removeChild(wrapper);
1420
+ delete window.intlTelInputGlobals.instances[this.id];
1421
+ }
1422
+ }, {
1423
+ key: "getExtension",
1424
+ value: function getExtension() {
1425
+ if (window.intlTelInputUtils) {
1426
+ return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
1427
+ }
1428
+ return "";
1429
+ }
1430
+ }, {
1431
+ key: "getNumber",
1432
+ value: function getNumber(format) {
1433
+ if (window.intlTelInputUtils) {
1434
+ var iso2 = this.selectedCountryData.iso2;
1435
+ return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
1436
+ }
1437
+ return "";
1438
+ }
1439
+ }, {
1440
+ key: "getNumberType",
1441
+ value: function getNumberType() {
1442
+ if (window.intlTelInputUtils) {
1443
+ return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
1444
+ }
1445
+ return -99;
1446
+ }
1447
+ }, {
1448
+ key: "getSelectedCountryData",
1449
+ value: function getSelectedCountryData() {
1450
+ return this.selectedCountryData;
1451
+ }
1452
+ }, {
1453
+ key: "getValidationError",
1454
+ value: function getValidationError() {
1455
+ if (window.intlTelInputUtils) {
1456
+ var iso2 = this.selectedCountryData.iso2;
1457
+ return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
1458
+ }
1459
+ return -99;
1460
+ }
1461
+ }, {
1462
+ key: "isValidNumber",
1463
+ value: function isValidNumber() {
1464
+ var val = this._getFullNumber().trim();
1465
+ var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
1466
+ return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
1467
+ }
1468
+ }, {
1469
+ key: "setCountry",
1470
+ value: function setCountry(originalCountryCode) {
1471
+ var countryCode = originalCountryCode.toLowerCase();
1472
+ // check if already selected
1473
+ if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
1474
+ this._setFlag(countryCode);
1475
+ this._updateDialCode(this.selectedCountryData.dialCode, false);
1476
+ this._triggerCountryChange();
1477
+ }
1478
+ }
1479
+ }, {
1480
+ key: "setNumber",
1481
+ value: function setNumber(number) {
1482
+ // we must update the flag first, which updates this.selectedCountryData, which is used for
1483
+ // formatting the number before displaying it
1484
+ var flagChanged = this._updateFlagFromNumber(number);
1485
+ this._updateValFromNumber(number);
1486
+ if (flagChanged) {
1487
+ this._triggerCountryChange();
1488
+ }
1489
+ }
1490
+ }, {
1491
+ key: "setPlaceholderNumberType",
1492
+ value: function setPlaceholderNumberType(type) {
1493
+ this.options.placeholderNumberType = type;
1494
+ this._updatePlaceholder();
1495
+ }
1496
+ } ]);
1497
+ return Iti;
1498
+ }();
1499
+ /********************
1500
+ * STATIC METHODS
1501
+ ********************/
1502
+ // get the country data object
1503
+ intlTelInputGlobals.getCountryData = function() {
1504
+ return allCountries;
1505
+ };
1506
+ // inject a <script> element to load utils.js
1507
+ var injectScript = function injectScript(path, handleSuccess, handleFailure) {
1508
+ // inject a new script element into the page
1509
+ var script = document.createElement("script");
1510
+ script.onload = function() {
1511
+ forEachInstance("handleUtils");
1512
+ if (handleSuccess) handleSuccess();
1513
+ };
1514
+ script.onerror = function() {
1515
+ forEachInstance("rejectUtilsScriptPromise");
1516
+ if (handleFailure) handleFailure();
1517
+ };
1518
+ script.className = "iti-load-utils";
1519
+ script.async = true;
1520
+ script.src = path;
1521
+ document.body.appendChild(script);
1522
+ };
1523
+ // load the utils script
1524
+ intlTelInputGlobals.loadUtils = function(path) {
1525
+ // 2 options:
1526
+ // 1) not already started loading (start)
1527
+ // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
1528
+ // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
1529
+ if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
1530
+ // only do this once
1531
+ window.intlTelInputGlobals.startedLoadingUtilsScript = true;
1532
+ // if we have promises, then return a promise
1533
+ if (typeof Promise !== "undefined") {
1534
+ return new Promise(function(resolve, reject) {
1535
+ return injectScript(path, resolve, reject);
1536
+ });
1537
+ }
1538
+ injectScript(path);
1539
+ }
1540
+ return null;
1541
+ };
1542
+ // default options
1543
+ intlTelInputGlobals.defaults = defaults;
1544
+ // version
1545
+ intlTelInputGlobals.version = "17.0.15";
1546
+ // convenience wrapper
1547
+ return function(input, options) {
1548
+ var iti = new Iti(input, options);
1549
+ iti._init();
1550
+ input.setAttribute("data-intl-tel-input-id", iti.id);
1551
+ window.intlTelInputGlobals.instances[iti.id] = iti;
1552
+ return iti;
1553
+ };
1554
+ }();
1555
+ });
1556
+ });
1557
+
1558
+ /**
1559
+ * Exposing intl-tel-input as a component
1560
+ */
1561
+ var intlTelInput = intlTelInput$1;
1562
+
1563
+ const SallaTelInput = class {
1564
+ constructor(hostRef) {
1565
+ index.registerInstance(this, hostRef);
1566
+ this.countryCode = "SA";
1567
+ this.countryKey = "+966";
1568
+ Helper.Helper.setHost(this.host);
1569
+ }
1570
+ async getValues() {
1571
+ this.phone = this.phoneInput.value;
1572
+ this.countryCode = this.countryCodeInput.value;
1573
+ this.countryKey = this.countryKeyInput.value;
1574
+ return { phone: this.phoneInput.value, countryCode: this.countryCodeInput.value, countryKey: this.countryKeyInput.value };
1575
+ }
1576
+ initTelInput() {
1577
+ salla.document.event.onKeyup('.tel-input', event => salla.helpers.digitsOnly(event.target));
1578
+ document.querySelectorAll('.tel-input').forEach((intlInput) => {
1579
+ salla.helpers.digitsOnly(intlInput);
1580
+ let iti = intlTelInput(intlInput, {
1581
+ initialCountry: intlInput.dataset.code || 'sa',
1582
+ preferredCountries: ['sa', 'ae', 'kw', 'bh', 'qa', 'iq', 'om', 'ye', 'eg', 'jo', 'sy', 'ps', 'sd', 'lb', 'dz', 'tn', 'ma', 'ly'],
1583
+ formatOnDisplay: false,
1584
+ separateDialCode: true,
1585
+ autoPlaceholder: 'aggressive',
1586
+ utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.min.js',
1587
+ });
1588
+ intlInput.addEventListener("countrychange", () => {
1589
+ let data = iti.getSelectedCountryData();
1590
+ this.host.querySelectorAll('.country_code').forEach((input) => input.value = data.iso2.toUpperCase());
1591
+ this.host.querySelectorAll('.country_key').forEach((input) => {
1592
+ input.value = ('+' + data.dialCode).replace('++', '+');
1593
+ });
1594
+ });
1595
+ });
1596
+ }
1597
+ render() {
1598
+ return (index.h(index.Host, null, index.h("input", { type: "tel", name: "mobile", "data-code": this.countryCode, value: this.phone, ref: el => this.phoneInput = el, class: "s-tel-input-control tel-input s-ltr" }), index.h("input", { type: "hidden", name: "country_code", value: this.countryCode, ref: el => this.countryCodeInput = el, class: "country_code" }), index.h("input", { type: "hidden", name: "country_key", value: this.countryKey, ref: el => this.countryKeyInput = el, class: "country_key" })));
1599
+ }
1600
+ componentDidRender() {
1601
+ this.initTelInput();
1602
+ }
1603
+ get host() { return index.getElement(this); }
1604
+ };
1605
+
1606
+ const SallaVerify = class {
1607
+ constructor(hostRef) {
1608
+ index.registerInstance(this, hostRef);
1609
+ this.verified = index.createEvent(this, "verified", 7);
1610
+ this.backClicked = index.createEvent(this, "backClicked", 7);
1611
+ this.url = 'profile/verify-mobile';
1612
+ this.by = 'sms';
1613
+ this.autoReload = true;
1614
+ Helper.Helper.setHost(this.host);
1615
+ if (this.withoutModal) {
1616
+ this.modal = { show: () => '', hide: () => '' };
1617
+ }
1618
+ else {
1619
+ salla.event.on('profile::verify.mobile', data => this.show(data));
1620
+ }
1621
+ }
1622
+ async getCode() {
1623
+ return this.code.value;
1624
+ }
1625
+ componentDidLoad() {
1626
+ Helper.Helper.on('input', '.s-verify-input', e => salla.helpers.digitsOnly(e.target));
1627
+ Helper.Helper.onKeyUp('.s-verify-input', event => {
1628
+ var _a, _b, _c, _d;
1629
+ let key = event.keyCode || event.charCode;
1630
+ if (event.target.value) {
1631
+ (_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
1632
+ (_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
1633
+ }
1634
+ else if ([8, 46].includes(key)) {
1635
+ (_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
1636
+ (_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
1637
+ }
1638
+ this.toggleOTPSubmit();
1639
+ });
1640
+ Helper.Helper.on('paste', '.s-verify-input', event => {
1641
+ let text = event.clipboardData.getData('text').toArabicDigits().replace(/[^0-9.]/g, '').replace('..', '.');
1642
+ this.otpInputs.forEach((input, i) => input.value = text[i] || '');
1643
+ this.toggleOTPSubmit();
1644
+ setTimeout(() => this.otpInputs[3].focus(), 100);
1645
+ });
1646
+ return this.modal.show();
1647
+ }
1648
+ async show(data) {
1649
+ this.data = data;
1650
+ this.resendTimer();
1651
+ this.otpInputs = document.querySelectorAll('.s-verify-input');
1652
+ this.reset();
1653
+ }
1654
+ toggleOTPSubmit() {
1655
+ let otp = [];
1656
+ this.otpInputs.forEach(input => input.value && otp.push(input.value));
1657
+ this.code.value = otp.join('');
1658
+ if (otp.length === 4) {
1659
+ this.btn.removeAttribute('disabled');
1660
+ this.btn.click();
1661
+ return;
1662
+ }
1663
+ this.btn.setAttribute('disabled', '');
1664
+ }
1665
+ reset() {
1666
+ this.otpInputs.forEach((input) => input.value = '');
1667
+ this.code.value = '';
1668
+ this.otpInputs[0].focus();
1669
+ }
1670
+ resendTimer() {
1671
+ Helper.Helper.showElement(this.resendMessage).hideElement(this.resend);
1672
+ let resendAfter = 30;
1673
+ let timerId = setInterval(() => {
1674
+ if (resendAfter === -1) {
1675
+ clearTimeout(timerId);
1676
+ Helper.Helper.hideElement(this.resendMessage).showElement(this.resend);
1677
+ }
1678
+ else {
1679
+ this.timer.innerHTML = `${resendAfter >= 10 ? resendAfter : '0' + resendAfter} : 00`;
1680
+ resendAfter--;
1681
+ }
1682
+ }, 1000);
1683
+ }
1684
+ resendCode() {
1685
+ return this.btn.stop()
1686
+ .then(() => this.btn.disable())
1687
+ .then(() => {
1688
+ this.otpInputs.forEach(input => input.value = '');
1689
+ this.otpInputs[0].focus();
1690
+ })
1691
+ .then(() => salla.api.auth.resend(Object.assign({ resend_by: this.by }, this.data)))
1692
+ .then(() => this.resendTimer())
1693
+ .catch(() => this.resendTimer());
1694
+ }
1695
+ submit() {
1696
+ return this.btn.load()
1697
+ .then(() => this.btn.disable())
1698
+ .then(() => salla.document.api.request(this.url, Object.assign({ code: this.code.value }, this.data)))
1699
+ .then(response => this.verified.emit(response))
1700
+ .then(() => this.btn.stop() && this.btn.disable())
1701
+ .then(() => this.modal.hide())
1702
+ .then(() => this.autoReload && window.location.reload())
1703
+ .catch(() => this.btn.stop() && this.btn.enable() && this.reset());
1704
+ }
1705
+ render() {
1706
+ return this.withoutModal ? this.myBody() :
1707
+ index.h("salla-modal", { id: "s-verify", ref: modal => this.modal = modal, title: salla.lang.get('pages.profile.verify_title') }, this.myBody());
1708
+ }
1709
+ myBody() {
1710
+ return [
1711
+ index.h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }),
1712
+ // <label class="s-verify-label">{salla.lang.get('pages.profile.verify_placeholder')}</label>,
1713
+ index.h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }),
1714
+ index.h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => index.h("input", { type: "text", maxlength: "1", class: "s-verify-input", required: true }))),
1715
+ index.h("div", { slot: "footer", class: "s-verify-footer" }, index.h("salla-button", { class: "s-verify-submit", disabled: true, onClick: () => this.submit(), ref: b => this.btn = b }, salla.lang.get('pages.profile.verify')), index.h("p", { class: "s-verify-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), index.h("b", { class: "s-verify-timer", ref: el => this.timer = el })), index.h("a", { href: "#", class: "s-verify-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit')), this.backText ?
1716
+ index.h("a", { href: "#", class: "s-verify-resend", onClick: () => this.backClicked.emit() }, this.backText)
1717
+ : '')
1718
+ ];
1719
+ }
1720
+ get host() { return index.getElement(this); }
1721
+ };
1722
+
1723
+ exports.salla_login = sallaLogin.SallaLogin;
1724
+ exports.salla_button = SallaButton;
1725
+ exports.salla_modal = SallaModal;
1726
+ exports.salla_tel_input = SallaTelInput;
1727
+ exports.salla_verify = SallaVerify;