@salla.sa/twilight-components 1.0.17 → 1.0.19

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