@salla.sa/twilight-components 1.6.2 → 1.6.4

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 (152) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/salla-button_27.cjs.entry.js +27879 -0
  3. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +26 -0
  4. package/dist/cjs/salla-scopes.cjs.entry.js +9 -6
  5. package/dist/cjs/salla-select.cjs.entry.js +159 -0
  6. package/dist/cjs/twilight-components.cjs.js +1 -1
  7. package/dist/collection/assets/svg/caret-down.svg +0 -1
  8. package/dist/collection/assets/svg/images.svg +0 -1
  9. package/dist/collection/collection-manifest.json +5 -0
  10. package/dist/collection/components/salla-datetime-picker/interfaces.js +4 -0
  11. package/dist/collection/components/salla-datetime-picker/salla-datetime-picker.css +13 -0
  12. package/dist/collection/components/salla-datetime-picker/salla-datetime-picker.js +1374 -0
  13. package/dist/collection/components/salla-file-upload/interfaces.js +42 -0
  14. package/dist/collection/components/salla-file-upload/salla-file-upload.css +219 -0
  15. package/dist/collection/components/salla-file-upload/salla-file-upload.js +1435 -0
  16. package/dist/collection/components/salla-gifting/gift-schema.js +4 -0
  17. package/dist/collection/components/salla-gifting/intefaces.js +4 -0
  18. package/dist/collection/components/salla-gifting/salla-gifting.css +20 -0
  19. package/dist/collection/components/salla-gifting/salla-gifting.js +564 -0
  20. package/dist/collection/components/salla-localization-modal/salla-localization-modal.js +23 -13
  21. package/dist/collection/components/salla-login-modal/salla-login-modal.js +46 -28
  22. package/dist/collection/components/salla-loyalty/salla-loyalty-prize-item.css +3 -0
  23. package/dist/collection/components/salla-loyalty/salla-loyalty-prize-item.js +69 -0
  24. package/dist/collection/components/salla-loyalty/salla-loyalty.css +0 -4
  25. package/dist/collection/components/salla-loyalty/salla-loyalty.js +29 -16
  26. package/dist/collection/components/salla-modal/salla-modal.css +6 -1
  27. package/dist/collection/components/salla-offer-modal/salla-offer-modal.js +37 -13
  28. package/dist/collection/components/salla-product-size-guide/salla-product-size-guide.js +23 -8
  29. package/dist/collection/components/salla-rating-modal/salla-rating-modal.js +87 -64
  30. package/dist/collection/components/salla-scopes/salla-scopes.js +11 -7
  31. package/dist/collection/components/salla-search/salla-search.js +1 -1
  32. package/dist/collection/components/salla-select/salla-select.css +86 -0
  33. package/dist/collection/components/salla-select/salla-select.js +610 -0
  34. package/dist/collection/components/salla-tel-input/interfaces.js +4 -0
  35. package/dist/collection/components/salla-tel-input/salla-tel-input.css +1 -2
  36. package/dist/collection/components/salla-tel-input/salla-tel-input.js +32 -3
  37. package/dist/collection/components/salla-verify/salla-verify.js +1 -1
  38. package/dist/collection/global/app.js +15 -12
  39. package/dist/components/_commonjsHelpers.js +24 -0
  40. package/dist/{esm/salla-social-share.entry.js → components/anime.es.js} +1 -132
  41. package/dist/components/index.d.ts +5 -0
  42. package/dist/components/index.js +5 -0
  43. package/dist/components/salla-datetime-picker.d.ts +11 -0
  44. package/dist/components/salla-datetime-picker.js +9 -0
  45. package/dist/components/salla-datetime-picker2.js +2876 -0
  46. package/dist/components/salla-file-upload.d.ts +11 -0
  47. package/dist/components/salla-file-upload.js +9 -0
  48. package/dist/components/salla-file-upload2.js +14623 -0
  49. package/dist/components/salla-gifting.d.ts +11 -0
  50. package/dist/components/salla-gifting.js +499 -0
  51. package/dist/components/salla-localization-modal.js +31 -16
  52. package/dist/components/salla-login-modal.js +35 -19
  53. package/dist/components/salla-loyalty-prize-item.d.ts +11 -0
  54. package/dist/components/salla-loyalty-prize-item.js +42 -0
  55. package/dist/components/salla-loyalty.js +28 -17
  56. package/dist/components/salla-modal2.js +1 -1
  57. package/dist/components/salla-offer-modal.js +42 -12
  58. package/dist/components/salla-product-size-guide.js +21 -6
  59. package/dist/components/salla-rating-modal.js +47 -19
  60. package/dist/components/salla-scopes.js +10 -6
  61. package/dist/components/salla-search.js +1 -1
  62. package/dist/components/salla-select.d.ts +11 -0
  63. package/dist/components/salla-select.js +199 -0
  64. package/dist/components/salla-social-share.js +1 -1308
  65. package/dist/components/salla-swiper2.js +9 -9
  66. package/dist/components/salla-tel-input2.js +15 -18
  67. package/dist/components/salla-verify2.js +1 -1
  68. package/dist/esm/loader.js +1 -1
  69. package/dist/esm/salla-button_27.entry.js +27849 -0
  70. package/dist/esm/salla-loyalty-prize-item.entry.js +22 -0
  71. package/dist/esm/salla-scopes.entry.js +9 -6
  72. package/dist/esm/salla-select.entry.js +155 -0
  73. package/dist/esm/twilight-components.js +1 -1
  74. package/dist/twilight-components/p-49125b6a.entry.js +4 -0
  75. package/dist/twilight-components/p-9a25753c.entry.js +4 -0
  76. package/dist/twilight-components/p-b7b9439d.entry.js +22 -0
  77. package/dist/twilight-components/p-df1eb1e5.entry.js +4 -0
  78. package/dist/twilight-components/twilight-components.esm.js +1 -1
  79. package/dist/types/components/salla-datetime-picker/interfaces.d.ts +8 -0
  80. package/dist/types/components/salla-datetime-picker/salla-datetime-picker.d.ts +250 -0
  81. package/dist/types/components/salla-file-upload/interfaces.d.ts +766 -0
  82. package/dist/types/components/salla-file-upload/salla-file-upload.d.ts +267 -0
  83. package/dist/types/components/salla-gifting/gift-schema.d.ts +20 -0
  84. package/dist/types/components/salla-gifting/intefaces.d.ts +18 -0
  85. package/dist/types/components/salla-gifting/salla-gifting.d.ts +98 -0
  86. package/dist/types/components/salla-localization-modal/salla-localization-modal.d.ts +3 -2
  87. package/dist/types/components/salla-login-modal/salla-login-modal.d.ts +13 -3
  88. package/dist/types/components/salla-loyalty/salla-loyalty-prize-item.d.ts +8 -0
  89. package/dist/types/components/salla-loyalty/salla-loyalty.d.ts +2 -0
  90. package/dist/types/components/salla-offer-modal/salla-offer-modal.d.ts +3 -1
  91. package/dist/types/components/salla-product-size-guide/salla-product-size-guide.d.ts +4 -0
  92. package/dist/types/components/salla-rating-modal/salla-rating-modal.d.ts +3 -2
  93. package/dist/types/components/salla-scopes/salla-scopes.d.ts +1 -0
  94. package/dist/types/components/salla-select/salla-select.d.ts +110 -0
  95. package/dist/types/components/salla-tel-input/interfaces.d.ts +4 -0
  96. package/dist/types/components/salla-tel-input/salla-tel-input.d.ts +3 -0
  97. package/dist/types/components.d.ts +1253 -10
  98. package/package.json +9 -3
  99. package/dist/cjs/Helper-8ae6a805.js +0 -28
  100. package/dist/cjs/arrow-right-3d137e4c.js +0 -13
  101. package/dist/cjs/cancel-ae668d91.js +0 -13
  102. package/dist/cjs/check-circle2-1aac98d1.js +0 -13
  103. package/dist/cjs/mail-2db058ee.js +0 -13
  104. package/dist/cjs/salla-button_10.cjs.entry.js +0 -2584
  105. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +0 -93
  106. package/dist/cjs/salla-list-tile_2.cjs.entry.js +0 -80
  107. package/dist/cjs/salla-loyalty.cjs.entry.js +0 -229
  108. package/dist/cjs/salla-product-availability.cjs.entry.js +0 -128
  109. package/dist/cjs/salla-product-size-guide.cjs.entry.js +0 -52
  110. package/dist/cjs/salla-quantity-input.cjs.entry.js +0 -101
  111. package/dist/cjs/salla-rating-modal.cjs.entry.js +0 -169
  112. package/dist/cjs/salla-rating-stars.cjs.entry.js +0 -83
  113. package/dist/cjs/salla-social-share.cjs.entry.js +0 -1447
  114. package/dist/cjs/salla-swiper.cjs.entry.js +0 -5023
  115. package/dist/cjs/salla-tab-content_3.cjs.entry.js +0 -159
  116. package/dist/cjs/star2-8288e6e1.js +0 -13
  117. package/dist/esm/Helper-e1d414a5.js +0 -26
  118. package/dist/esm/arrow-right-1c3e04f2.js +0 -11
  119. package/dist/esm/cancel-41a92070.js +0 -11
  120. package/dist/esm/check-circle2-f6e5f685.js +0 -11
  121. package/dist/esm/mail-9d5204c6.js +0 -11
  122. package/dist/esm/salla-button_10.entry.js +0 -2571
  123. package/dist/esm/salla-infinite-scroll.entry.js +0 -89
  124. package/dist/esm/salla-list-tile_2.entry.js +0 -75
  125. package/dist/esm/salla-loyalty.entry.js +0 -225
  126. package/dist/esm/salla-product-availability.entry.js +0 -124
  127. package/dist/esm/salla-product-size-guide.entry.js +0 -48
  128. package/dist/esm/salla-quantity-input.entry.js +0 -97
  129. package/dist/esm/salla-rating-modal.entry.js +0 -165
  130. package/dist/esm/salla-rating-stars.entry.js +0 -79
  131. package/dist/esm/salla-swiper.entry.js +0 -5019
  132. package/dist/esm/salla-tab-content_3.entry.js +0 -153
  133. package/dist/esm/star2-b134fc74.js +0 -11
  134. package/dist/twilight-components/p-0d498694.entry.js +0 -4
  135. package/dist/twilight-components/p-14f0ff17.entry.js +0 -4
  136. package/dist/twilight-components/p-335abbbb.entry.js +0 -4
  137. package/dist/twilight-components/p-4cafb11b.entry.js +0 -4
  138. package/dist/twilight-components/p-5e63e308.entry.js +0 -4
  139. package/dist/twilight-components/p-5fb32395.entry.js +0 -4
  140. package/dist/twilight-components/p-648e74e5.entry.js +0 -4
  141. package/dist/twilight-components/p-6a3adf55.entry.js +0 -4
  142. package/dist/twilight-components/p-6da4bb74.entry.js +0 -4
  143. package/dist/twilight-components/p-897b2018.js +0 -4
  144. package/dist/twilight-components/p-93708e1e.js +0 -4
  145. package/dist/twilight-components/p-9d236cf4.entry.js +0 -4
  146. package/dist/twilight-components/p-9d2ca9c8.js +0 -4
  147. package/dist/twilight-components/p-af7d5660.js +0 -4
  148. package/dist/twilight-components/p-bdbd2386.entry.js +0 -4
  149. package/dist/twilight-components/p-cac3db69.entry.js +0 -4
  150. package/dist/twilight-components/p-d914a212.js +0 -4
  151. package/dist/twilight-components/p-dace8e6d.js +0 -4
  152. package/dist/twilight-components/p-f9253fda.entry.js +0 -4
@@ -1,2571 +0,0 @@
1
- /*!
2
- * Crafted with ❤ by Salla
3
- */
4
- import { r as registerInstance, h, H as Host, g as getElement, c as createEvent } from './index-4e30ffd0.js';
5
- import { H as Helper } from './Helper-e1d414a5.js';
6
- import { e as email } from './mail-9d5204c6.js';
7
- import { A as ArrowRightIcon } from './arrow-right-1c3e04f2.js';
8
- import { C as Cancel } from './cancel-41a92070.js';
9
- import { C as CheckCircle2 } from './check-circle2-f6e5f685.js';
10
- import { S as Search } from './search-19ea3313.js';
11
-
12
- const sallaButtonCss = "";
13
-
14
- const SallaButton = class {
15
- constructor(hostRef) {
16
- registerInstance(this, hostRef);
17
- this.hostAttributes = {};
18
- /**
19
- * Button Type
20
- */
21
- this.shape = 'btn';
22
- /**
23
- * Button Color
24
- */
25
- this.color = 'primary';
26
- /**
27
- * Button Fill
28
- */
29
- this.fill = 'solid';
30
- /**
31
- * Button Size
32
- */
33
- this.size = 'medium';
34
- /**
35
- * Button Width
36
- */
37
- this.width = 'normal';
38
- /**
39
- * Is the button currently loading
40
- */
41
- this.loading = false;
42
- /**
43
- * Is the button currently disabled
44
- */
45
- this.disabled = false;
46
- /**
47
- * If there is need to change loader position, pass the position
48
- */
49
- this.loaderPosition = 'after';
50
- }
51
- /**
52
- * Run loading animation
53
- */
54
- async load() {
55
- if (this.loaderPosition == 'center')
56
- this.text.classList.add('s-button-hide');
57
- this.host.setAttribute('loading', '');
58
- return this.host;
59
- }
60
- /**
61
- * Stop loading animation
62
- */
63
- async stop() {
64
- this.host.removeAttribute('loading');
65
- this.host.querySelector('button').removeAttribute('loading');
66
- if (this.loaderPosition == 'center')
67
- this.text.classList.remove('s-button-hide');
68
- return this.host;
69
- }
70
- /**
71
- * Changing the body of the button
72
- * @param html
73
- */
74
- async setText(html) {
75
- this.text.innerHTML = html;
76
- return this.host;
77
- }
78
- /**
79
- * Add `disabled` attribute
80
- */
81
- async disable() {
82
- this.host.setAttribute('disabled', '');
83
- return this.host;
84
- }
85
- /**
86
- * Remove `disabled` attribute
87
- */
88
- async enable() {
89
- this.host.removeAttribute('disabled');
90
- return this.host;
91
- }
92
- getBtnAttributes() {
93
- for (let i = 0; i < this.host.attributes.length; i++) {
94
- if (!['color', 'fill', 'size', 'width', 'id'].includes(this.host.attributes[i].name)) {
95
- this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
96
- }
97
- }
98
- this.hostAttributes.type = this.hostAttributes.type || 'button';
99
- this.hostAttributes.class +=
100
- ' s-button-element s-button-' + this.shape
101
- + ' s-button-' + (this.fill == "none" ? 'fill-none' : this.fill)
102
- + (this.size != "medium" ? ' s-button-' + this.size : '')
103
- + (this.width != "normal" ? ' s-button-' + this.width : '')
104
- + (this.shape == "link" ? ' s-button-' + this.color + '-link' : '')
105
- + (this.shape != "link" && this.fill != 'outline' ? ' s-button-' + this.color : '')
106
- + (this.fill == 'outline' ? ' s-button-' + this.color + '-outline' : '')
107
- + (this.disabled ? ' s-button-disabled ' : '')
108
- + (this.shape == 'icon' ? ' s-button-loader-center' : ' s-button-loader-' + this.loaderPosition);
109
- return this.hostAttributes;
110
- }
111
- button() {
112
- return (h("button", Object.assign({}, this.getBtnAttributes(), { disabled: this.disabled }), h("span", { class: "s-button-text", ref: el => this.text = el }, h("slot", null)), this.loading ? h("span", { class: "s-button-loader" }) : ''));
113
- }
114
- render() {
115
- return (h(Host, { class: "s-button-wrap" }, this.href ? h("a", { href: this.href }, this.button()) : this.button()));
116
- }
117
- get host() { return getElement(this); }
118
- };
119
- SallaButton.style = sallaButtonCss;
120
-
121
- const sallaLoadingCss = ".s-loading{animation:spin 1s linear infinite;fill:var(--color-primary)}.s-loading-container{display:flex;justify-content:center;align-items:center}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";
122
-
123
- const SallaLoading = class {
124
- constructor(hostRef) {
125
- registerInstance(this, hostRef);
126
- /**
127
- * Sets the diameter of the circle in pixels, Defaults to `32`
128
- */
129
- this.size = 32;
130
- /**
131
- * Sets the stroke of the circle (border) in pixels, Defaults to `4`
132
- */
133
- this.width = 2;
134
- /**
135
- * Spinner content color.
136
- */
137
- this.color = undefined; // TODO: Should be replaced with primary color (variable)
138
- /**
139
- * Spinner background color.
140
- */
141
- this.bgColor = "#e5e7eb";
142
- }
143
- render() {
144
- return (h(Host, { class: "s-loading-container" }, h("svg", { "aria-hidden": "true", style: { width: `${this.size}px`, height: `${this.size}px`, fill: this.color, color: this.bgColor }, class: "s-loading", viewBox: "0 0 100 101", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z", fill: "currentColor" }), h("path", { d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z", fill: "currentFill" }))));
145
- }
146
- };
147
- SallaLoading.style = sallaLoadingCss;
148
-
149
- const sallaLocalizationModalCss = ".s-localization-modal-select{background-image:url(\"data:image/svg+xml;utf8,<svg fill='gray' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>\")}.iti__flag{width:20px}.iti__flag.iti__be{width:18px}.iti__flag.iti__ch{width:15px}.iti__flag.iti__mc{width:19px}.iti__flag.iti__ne{width:18px}.iti__flag.iti__np{width:13px}.iti__flag.iti__va{width:15px}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-size:5652px 15px}}.iti__flag.iti__ac{height:10px;background-position:0px 0px}.iti__flag.iti__ad{height:14px;background-position:-22px 0px}.iti__flag.iti__ae{height:10px;background-position:-44px 0px}.iti__flag.iti__af{height:14px;background-position:-66px 0px}.iti__flag.iti__ag{height:14px;background-position:-88px 0px}.iti__flag.iti__ai{height:10px;background-position:-110px 0px}.iti__flag.iti__al{height:15px;background-position:-132px 0px}.iti__flag.iti__am{height:10px;background-position:-154px 0px}.iti__flag.iti__ao{height:14px;background-position:-176px 0px}.iti__flag.iti__aq{height:14px;background-position:-198px 0px}.iti__flag.iti__ar{height:13px;background-position:-220px 0px}.iti__flag.iti__as{height:10px;background-position:-242px 0px}.iti__flag.iti__at{height:14px;background-position:-264px 0px}.iti__flag.iti__au{height:10px;background-position:-286px 0px}.iti__flag.iti__aw{height:14px;background-position:-308px 0px}.iti__flag.iti__ax{height:13px;background-position:-330px 0px}.iti__flag.iti__az{height:10px;background-position:-352px 0px}.iti__flag.iti__ba{height:10px;background-position:-374px 0px}.iti__flag.iti__bb{height:14px;background-position:-396px 0px}.iti__flag.iti__bd{height:12px;background-position:-418px 0px}.iti__flag.iti__be{height:15px;background-position:-440px 0px}.iti__flag.iti__bf{height:14px;background-position:-460px 0px}.iti__flag.iti__bg{height:12px;background-position:-482px 0px}.iti__flag.iti__bh{height:12px;background-position:-504px 0px}.iti__flag.iti__bi{height:12px;background-position:-526px 0px}.iti__flag.iti__bj{height:14px;background-position:-548px 0px}.iti__flag.iti__bl{height:14px;background-position:-570px 0px}.iti__flag.iti__bm{height:10px;background-position:-592px 0px}.iti__flag.iti__bn{height:10px;background-position:-614px 0px}.iti__flag.iti__bo{height:14px;background-position:-636px 0px}.iti__flag.iti__bq{height:14px;background-position:-658px 0px}.iti__flag.iti__br{height:14px;background-position:-680px 0px}.iti__flag.iti__bs{height:10px;background-position:-702px 0px}.iti__flag.iti__bt{height:14px;background-position:-724px 0px}.iti__flag.iti__bv{height:15px;background-position:-746px 0px}.iti__flag.iti__bw{height:14px;background-position:-768px 0px}.iti__flag.iti__by{height:10px;background-position:-790px 0px}.iti__flag.iti__bz{height:14px;background-position:-812px 0px}.iti__flag.iti__ca{height:10px;background-position:-834px 0px}.iti__flag.iti__cc{height:10px;background-position:-856px 0px}.iti__flag.iti__cd{height:15px;background-position:-878px 0px}.iti__flag.iti__cf{height:14px;background-position:-900px 0px}.iti__flag.iti__cg{height:14px;background-position:-922px 0px}.iti__flag.iti__ch{height:15px;background-position:-944px 0px}.iti__flag.iti__ci{height:14px;background-position:-961px 0px}.iti__flag.iti__ck{height:10px;background-position:-983px 0px}.iti__flag.iti__cl{height:14px;background-position:-1005px 0px}.iti__flag.iti__cm{height:14px;background-position:-1027px 0px}.iti__flag.iti__cn{height:14px;background-position:-1049px 0px}.iti__flag.iti__co{height:14px;background-position:-1071px 0px}.iti__flag.iti__cp{height:14px;background-position:-1093px 0px}.iti__flag.iti__cr{height:12px;background-position:-1115px 0px}.iti__flag.iti__cu{height:10px;background-position:-1137px 0px}.iti__flag.iti__cv{height:12px;background-position:-1159px 0px}.iti__flag.iti__cw{height:14px;background-position:-1181px 0px}.iti__flag.iti__cx{height:10px;background-position:-1203px 0px}.iti__flag.iti__cy{height:14px;background-position:-1225px 0px}.iti__flag.iti__cz{height:14px;background-position:-1247px 0px}.iti__flag.iti__de{height:12px;background-position:-1269px 0px}.iti__flag.iti__dg{height:10px;background-position:-1291px 0px}.iti__flag.iti__dj{height:14px;background-position:-1313px 0px}.iti__flag.iti__dk{height:15px;background-position:-1335px 0px}.iti__flag.iti__dm{height:10px;background-position:-1357px 0px}.iti__flag.iti__do{height:14px;background-position:-1379px 0px}.iti__flag.iti__dz{height:14px;background-position:-1401px 0px}.iti__flag.iti__ea{height:14px;background-position:-1423px 0px}.iti__flag.iti__ec{height:14px;background-position:-1445px 0px}.iti__flag.iti__ee{height:13px;background-position:-1467px 0px}.iti__flag.iti__eg{height:14px;background-position:-1489px 0px}.iti__flag.iti__eh{height:10px;background-position:-1511px 0px}.iti__flag.iti__er{height:10px;background-position:-1533px 0px}.iti__flag.iti__es{height:14px;background-position:-1555px 0px}.iti__flag.iti__et{height:10px;background-position:-1577px 0px}.iti__flag.iti__eu{height:14px;background-position:-1599px 0px}.iti__flag.iti__fi{height:12px;background-position:-1621px 0px}.iti__flag.iti__fj{height:10px;background-position:-1643px 0px}.iti__flag.iti__fk{height:10px;background-position:-1665px 0px}.iti__flag.iti__fm{height:11px;background-position:-1687px 0px}.iti__flag.iti__fo{height:15px;background-position:-1709px 0px}.iti__flag.iti__fr{height:14px;background-position:-1731px 0px}.iti__flag.iti__ga{height:15px;background-position:-1753px 0px}.iti__flag.iti__gb{height:10px;background-position:-1775px 0px}.iti__flag.iti__gd{height:12px;background-position:-1797px 0px}.iti__flag.iti__ge{height:14px;background-position:-1819px 0px}.iti__flag.iti__gf{height:14px;background-position:-1841px 0px}.iti__flag.iti__gg{height:14px;background-position:-1863px 0px}.iti__flag.iti__gh{height:14px;background-position:-1885px 0px}.iti__flag.iti__gi{height:10px;background-position:-1907px 0px}.iti__flag.iti__gl{height:14px;background-position:-1929px 0px}.iti__flag.iti__gm{height:14px;background-position:-1951px 0px}.iti__flag.iti__gn{height:14px;background-position:-1973px 0px}.iti__flag.iti__gp{height:14px;background-position:-1995px 0px}.iti__flag.iti__gq{height:14px;background-position:-2017px 0px}.iti__flag.iti__gr{height:14px;background-position:-2039px 0px}.iti__flag.iti__gs{height:10px;background-position:-2061px 0px}.iti__flag.iti__gt{height:13px;background-position:-2083px 0px}.iti__flag.iti__gu{height:11px;background-position:-2105px 0px}.iti__flag.iti__gw{height:10px;background-position:-2127px 0px}.iti__flag.iti__gy{height:12px;background-position:-2149px 0px}.iti__flag.iti__hk{height:14px;background-position:-2171px 0px}.iti__flag.iti__hm{height:10px;background-position:-2193px 0px}.iti__flag.iti__hn{height:10px;background-position:-2215px 0px}.iti__flag.iti__hr{height:10px;background-position:-2237px 0px}.iti__flag.iti__ht{height:12px;background-position:-2259px 0px}.iti__flag.iti__hu{height:10px;background-position:-2281px 0px}.iti__flag.iti__ic{height:14px;background-position:-2303px 0px}.iti__flag.iti__id{height:14px;background-position:-2325px 0px}.iti__flag.iti__ie{height:10px;background-position:-2347px 0px}.iti__flag.iti__il{height:15px;background-position:-2369px 0px}.iti__flag.iti__im{height:10px;background-position:-2391px 0px}.iti__flag.iti__in{height:14px;background-position:-2413px 0px}.iti__flag.iti__io{height:10px;background-position:-2435px 0px}.iti__flag.iti__iq{height:14px;background-position:-2457px 0px}.iti__flag.iti__ir{height:12px;background-position:-2479px 0px}.iti__flag.iti__is{height:15px;background-position:-2501px 0px}.iti__flag.iti__it{height:14px;background-position:-2523px 0px}.iti__flag.iti__je{height:12px;background-position:-2545px 0px}.iti__flag.iti__jm{height:10px;background-position:-2567px 0px}.iti__flag.iti__jo{height:10px;background-position:-2589px 0px}.iti__flag.iti__jp{height:14px;background-position:-2611px 0px}.iti__flag.iti__ke{height:14px;background-position:-2633px 0px}.iti__flag.iti__kg{height:12px;background-position:-2655px 0px}.iti__flag.iti__kh{height:13px;background-position:-2677px 0px}.iti__flag.iti__ki{height:10px;background-position:-2699px 0px}.iti__flag.iti__km{height:12px;background-position:-2721px 0px}.iti__flag.iti__kn{height:14px;background-position:-2743px 0px}.iti__flag.iti__kp{height:10px;background-position:-2765px 0px}.iti__flag.iti__kr{height:14px;background-position:-2787px 0px}.iti__flag.iti__kw{height:10px;background-position:-2809px 0px}.iti__flag.iti__ky{height:10px;background-position:-2831px 0px}.iti__flag.iti__kz{height:10px;background-position:-2853px 0px}.iti__flag.iti__la{height:14px;background-position:-2875px 0px}.iti__flag.iti__lb{height:14px;background-position:-2897px 0px}.iti__flag.iti__lc{height:10px;background-position:-2919px 0px}.iti__flag.iti__li{height:12px;background-position:-2941px 0px}.iti__flag.iti__lk{height:10px;background-position:-2963px 0px}.iti__flag.iti__lr{height:11px;background-position:-2985px 0px}.iti__flag.iti__ls{height:14px;background-position:-3007px 0px}.iti__flag.iti__lt{height:12px;background-position:-3029px 0px}.iti__flag.iti__lu{height:12px;background-position:-3051px 0px}.iti__flag.iti__lv{height:10px;background-position:-3073px 0px}.iti__flag.iti__ly{height:10px;background-position:-3095px 0px}.iti__flag.iti__ma{height:14px;background-position:-3117px 0px}.iti__flag.iti__mc{height:15px;background-position:-3139px 0px}.iti__flag.iti__md{height:10px;background-position:-3160px 0px}.iti__flag.iti__me{height:10px;background-position:-3182px 0px}.iti__flag.iti__mf{height:14px;background-position:-3204px 0px}.iti__flag.iti__mg{height:14px;background-position:-3226px 0px}.iti__flag.iti__mh{height:11px;background-position:-3248px 0px}.iti__flag.iti__mk{height:10px;background-position:-3270px 0px}.iti__flag.iti__ml{height:14px;background-position:-3292px 0px}.iti__flag.iti__mm{height:14px;background-position:-3314px 0px}.iti__flag.iti__mn{height:10px;background-position:-3336px 0px}.iti__flag.iti__mo{height:14px;background-position:-3358px 0px}.iti__flag.iti__mp{height:10px;background-position:-3380px 0px}.iti__flag.iti__mq{height:14px;background-position:-3402px 0px}.iti__flag.iti__mr{height:14px;background-position:-3424px 0px}.iti__flag.iti__ms{height:10px;background-position:-3446px 0px}.iti__flag.iti__mt{height:14px;background-position:-3468px 0px}.iti__flag.iti__mu{height:14px;background-position:-3490px 0px}.iti__flag.iti__mv{height:14px;background-position:-3512px 0px}.iti__flag.iti__mw{height:14px;background-position:-3534px 0px}.iti__flag.iti__mx{height:12px;background-position:-3556px 0px}.iti__flag.iti__my{height:10px;background-position:-3578px 0px}.iti__flag.iti__mz{height:14px;background-position:-3600px 0px}.iti__flag.iti__na{height:14px;background-position:-3622px 0px}.iti__flag.iti__nc{height:10px;background-position:-3644px 0px}.iti__flag.iti__ne{height:15px;background-position:-3666px 0px}.iti__flag.iti__nf{height:10px;background-position:-3686px 0px}.iti__flag.iti__ng{height:10px;background-position:-3708px 0px}.iti__flag.iti__ni{height:12px;background-position:-3730px 0px}.iti__flag.iti__nl{height:14px;background-position:-3752px 0px}.iti__flag.iti__no{height:15px;background-position:-3774px 0px}.iti__flag.iti__np{height:15px;background-position:-3796px 0px}.iti__flag.iti__nr{height:10px;background-position:-3811px 0px}.iti__flag.iti__nu{height:10px;background-position:-3833px 0px}.iti__flag.iti__nz{height:10px;background-position:-3855px 0px}.iti__flag.iti__om{height:10px;background-position:-3877px 0px}.iti__flag.iti__pa{height:14px;background-position:-3899px 0px}.iti__flag.iti__pe{height:14px;background-position:-3921px 0px}.iti__flag.iti__pf{height:14px;background-position:-3943px 0px}.iti__flag.iti__pg{height:15px;background-position:-3965px 0px}.iti__flag.iti__ph{height:10px;background-position:-3987px 0px}.iti__flag.iti__pk{height:14px;background-position:-4009px 0px}.iti__flag.iti__pl{height:13px;background-position:-4031px 0px}.iti__flag.iti__pm{height:14px;background-position:-4053px 0px}.iti__flag.iti__pn{height:10px;background-position:-4075px 0px}.iti__flag.iti__pr{height:14px;background-position:-4097px 0px}.iti__flag.iti__ps{height:10px;background-position:-4119px 0px}.iti__flag.iti__pt{height:14px;background-position:-4141px 0px}.iti__flag.iti__pw{height:13px;background-position:-4163px 0px}.iti__flag.iti__py{height:11px;background-position:-4185px 0px}.iti__flag.iti__qa{height:8px;background-position:-4207px 0px}.iti__flag.iti__re{height:14px;background-position:-4229px 0px}.iti__flag.iti__ro{height:14px;background-position:-4251px 0px}.iti__flag.iti__rs{height:14px;background-position:-4273px 0px}.iti__flag.iti__ru{height:14px;background-position:-4295px 0px}.iti__flag.iti__rw{height:14px;background-position:-4317px 0px}.iti__flag.iti__sa{height:14px;background-position:-4339px 0px}.iti__flag.iti__sb{height:10px;background-position:-4361px 0px}.iti__flag.iti__sc{height:10px;background-position:-4383px 0px}.iti__flag.iti__sd{height:10px;background-position:-4405px 0px}.iti__flag.iti__se{height:13px;background-position:-4427px 0px}.iti__flag.iti__sg{height:14px;background-position:-4449px 0px}.iti__flag.iti__sh{height:10px;background-position:-4471px 0px}.iti__flag.iti__si{height:10px;background-position:-4493px 0px}.iti__flag.iti__sj{height:15px;background-position:-4515px 0px}.iti__flag.iti__sk{height:14px;background-position:-4537px 0px}.iti__flag.iti__sl{height:14px;background-position:-4559px 0px}.iti__flag.iti__sm{height:15px;background-position:-4581px 0px}.iti__flag.iti__sn{height:14px;background-position:-4603px 0px}.iti__flag.iti__so{height:14px;background-position:-4625px 0px}.iti__flag.iti__sr{height:14px;background-position:-4647px 0px}.iti__flag.iti__ss{height:10px;background-position:-4669px 0px}.iti__flag.iti__st{height:10px;background-position:-4691px 0px}.iti__flag.iti__sv{height:12px;background-position:-4713px 0px}.iti__flag.iti__sx{height:14px;background-position:-4735px 0px}.iti__flag.iti__sy{height:14px;background-position:-4757px 0px}.iti__flag.iti__sz{height:14px;background-position:-4779px 0px}.iti__flag.iti__ta{height:10px;background-position:-4801px 0px}.iti__flag.iti__tc{height:10px;background-position:-4823px 0px}.iti__flag.iti__td{height:14px;background-position:-4845px 0px}.iti__flag.iti__tf{height:14px;background-position:-4867px 0px}.iti__flag.iti__tg{height:13px;background-position:-4889px 0px}.iti__flag.iti__th{height:14px;background-position:-4911px 0px}.iti__flag.iti__tj{height:10px;background-position:-4933px 0px}.iti__flag.iti__tk{height:10px;background-position:-4955px 0px}.iti__flag.iti__tl{height:10px;background-position:-4977px 0px}.iti__flag.iti__tm{height:14px;background-position:-4999px 0px}.iti__flag.iti__tn{height:14px;background-position:-5021px 0px}.iti__flag.iti__to{height:10px;background-position:-5043px 0px}.iti__flag.iti__tr{height:14px;background-position:-5065px 0px}.iti__flag.iti__tt{height:12px;background-position:-5087px 0px}.iti__flag.iti__tv{height:10px;background-position:-5109px 0px}.iti__flag.iti__tw{height:14px;background-position:-5131px 0px}.iti__flag.iti__tz{height:14px;background-position:-5153px 0px}.iti__flag.iti__ua{height:14px;background-position:-5175px 0px}.iti__flag.iti__ug{height:14px;background-position:-5197px 0px}.iti__flag.iti__um{height:11px;background-position:-5219px 0px}.iti__flag.iti__un{height:14px;background-position:-5241px 0px}.iti__flag.iti__us{height:11px;background-position:-5263px 0px}.iti__flag.iti__uy{height:14px;background-position:-5285px 0px}.iti__flag.iti__uz{height:10px;background-position:-5307px 0px}.iti__flag.iti__va{height:15px;background-position:-5329px 0px}.iti__flag.iti__vc{height:14px;background-position:-5346px 0px}.iti__flag.iti__ve{height:14px;background-position:-5368px 0px}.iti__flag.iti__vg{height:10px;background-position:-5390px 0px}.iti__flag.iti__vi{height:14px;background-position:-5412px 0px}.iti__flag.iti__vn{height:14px;background-position:-5434px 0px}.iti__flag.iti__vu{height:12px;background-position:-5456px 0px}.iti__flag.iti__wf{height:14px;background-position:-5478px 0px}.iti__flag.iti__ws{height:10px;background-position:-5500px 0px}.iti__flag.iti__xk{height:15px;background-position:-5522px 0px}.iti__flag.iti__ye{height:14px;background-position:-5544px 0px}.iti__flag.iti__yt{height:14px;background-position:-5566px 0px}.iti__flag.iti__za{height:14px;background-position:-5588px 0px}.iti__flag.iti__zm{height:14px;background-position:-5610px 0px}.iti__flag.iti__zw{height:10px;background-position:-5632px 0px}.iti__flag{height:15px;box-shadow:0px 0px 1px 0px #888;background-image:url(\"https://cdn.salla.network/images/flags.png\");background-repeat:no-repeat;background-color:#f5f7f9;background-position:20px 0}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-image:url(\"https://cdn.salla.network/images/flags@2x.png\")}}.iti__flag.iti__np{background-color:transparent}";
150
-
151
- const SallaLocalizationModal = class {
152
- constructor(hostRef) {
153
- registerInstance(this, hostRef);
154
- var _a, _b;
155
- this.translationLoaded = false;
156
- this.languages = [];
157
- this.currencies = [];
158
- this.isLoading = true;
159
- /**
160
- * Current language (existing or newly selected)
161
- */
162
- this.language = salla.config.get('user.language_code');
163
- /**
164
- * Current currency (existing or newly selected)
165
- */
166
- this.currency = salla.config.get('user.currency_code');
167
- Helper.setHost(this.host);
168
- salla.event.on('localization::open', () => this.open());
169
- salla.lang.onLoaded(() => {
170
- this.translationLoaded = true;
171
- });
172
- /**
173
- * letting developer to insert his own slot like:
174
- * <salla-localization>
175
- * <div slot="language">...{name}....</div>
176
- * <div slot="currency">...{name}....</div>
177
- * </salla-localization>
178
- * Because scoped templates not supported in stencil );
179
- * we made a workaround to pass language & currency attributes, then replace names in rendering
180
- */
181
- this.languageSlot = ((_a = Helper.getElement('[slot="language"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<label class="s-localization-modal-label" for="lang-{code}"><span>{name}</span><div class="s-localization-modal-flag flag iti__flag iti__{country_code}"></div></label>';
182
- this.currencySlot = ((_b = Helper.getElement('[slot="currency"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<label class="s-localization-modal-label" for="currency-{code}"><span>{name}</span><small class="s-localization-modal-currency">{code}</small></label>';
183
- }
184
- /**
185
- * open the component
186
- */
187
- async open() {
188
- return await this.modal.open()
189
- .then(() => this.getLanguages())
190
- .then(() => this.getCurrencies())
191
- .then(() => this.isLoading = false);
192
- }
193
- /**
194
- * Hide the component
195
- */
196
- async close() {
197
- return this.modal.close();
198
- }
199
- async getLanguages() {
200
- this.language = this.language || salla.config.get('user.language_code');
201
- return this.languages.length > 1 ? null : await salla.config.languages().then(data => this.languages = data);
202
- }
203
- async getCurrencies() {
204
- this.currency = this.currency || salla.config.get('user.currency_code');
205
- return this.currencies.length > 1 ? null : await salla.config.currencies().then(data => this.currencies = Object.values(data || {}));
206
- }
207
- onChangeCurrency(event) {
208
- this.currency = event.target.value;
209
- }
210
- onChangeLanguage(event) {
211
- this.language = event.target.value;
212
- }
213
- /**
214
- * Change currency and language to the selected ones.
215
- */
216
- async submit() {
217
- let url;
218
- this.btn.load()
219
- .then(() => {
220
- if (!this.currency) {
221
- salla.log('There is no currency!');
222
- return;
223
- }
224
- if (this.currency === salla.config.get('user.currency_code', 'SAR')) {
225
- return;
226
- }
227
- url = window.location.href;
228
- return salla.currency.api.change(this.currency);
229
- })
230
- .then(() => this.language === salla.config.get('user.language_code', 'ar') || (url = salla.helpers.addParamToUrl('lang', this.language)))
231
- .then(() => this.btn.stop())
232
- .then(() => this.close())
233
- .then(() => url && (window.location.href = url));
234
- }
235
- render() {
236
- return (h("salla-modal", { isLoading: this.isLoading, class: "s-hidden", ref: modal => this.modal = modal, width: "xs" }, h("div", { slot: 'loading' }, h("div", { class: "s-localization-modal-skeleton" }, h("salla-skeleton", { width: '25%', height: '15px' }), h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => h("div", { class: "s-localization-modal-skeleton-item" }, h("div", { class: "s-localization-modal-skeleton-item-flex" }, h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), h("salla-skeleton", { height: '10px', width: '100px' })), h("salla-skeleton", { height: '15px', width: '20px' })))), h("salla-skeleton", { width: '25%', height: '15px' }), h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => h("div", { class: "s-localization-modal-skeleton-item" }, h("div", { class: "s-localization-modal-skeleton-item-flex" }, h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), h("salla-skeleton", { height: '10px', width: '100px' })), h("salla-skeleton", { height: '15px', width: '20px' })))), h("salla-skeleton", { height: '40px', width: '100%' }))), !this.isLoading ?
237
- h("div", { class: "s-localization-modal-inner" }, this.languages.length > 1 ?
238
- h("div", { class: "s-localization-modal-section" }, h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.language')), h("div", { class: "s-localization-modal-section-inner" }, this.languages.length < 6 ?
239
- this.languages.map(lang => h("div", { class: "s-localization-modal-item" }, h("input", { class: "s-localization-modal-input", type: "radio", checked: this.language == lang.iso_code, onChange: () => this.language = lang.iso_code, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }), h("div", { class: "s-localization-modal-label-slot", id: "language-slot", innerHTML: this.languageSlot
240
- .replace(/\{name\}/g, lang.name)
241
- .replace(/\{code\}/g, lang.code)
242
- .replace(/\{country_code\}/g, lang.country_code) }))) :
243
- h("select", { class: "s-localization-modal-select", name: "language", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => h("option", { value: lang.code, selected: this.language == lang.code }, lang.name)))))
244
- : '', this.currencies.length > 1 ?
245
- h("div", { class: "s-localization-modal-section" }, h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.currency')), h("div", { class: "s-localization-modal-section-inner" }, this.currencies.length < 6 ?
246
- this.currencies.map(currency => h("div", { class: "s-localization-modal-item" }, h("input", { class: "s-localization-modal-input", type: "radio", name: "currency", checked: this.currency == currency.code, onChange: () => this.currency = currency.code, id: 'currency-' + currency.code, value: currency.code }), h("div", { class: "s-localization-modal-label-slot", id: "currency-slot", innerHTML: this.currencySlot
247
- .replace(/\{name\}/g, currency.name)
248
- .replace(/\{code\}/g, currency.code)
249
- .replace(/\{country_code\}/g, currency.country_code) }))) :
250
- h("select", { class: "s-localization-modal-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => h("option", { value: currency.code, selected: this.currency == currency.code }, currency.name)))))
251
- : '', h("salla-button", { width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.ok')))
252
- : ''));
253
- }
254
- /**
255
- * to reduce dom levels we will move slot data into the parent dom
256
- */
257
- componentDidRender() {
258
- this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
259
- this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
260
- }
261
- get host() { return getElement(this); }
262
- };
263
- SallaLocalizationModal.style = sallaLocalizationModalCss;
264
-
265
- const UserIcon = `<!-- Generated by IcoMoon.io -->
266
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
267
- <title>user</title>
268
- <path d="M16 16c4.412 0 8-3.588 8-8s-3.588-8-8-8-8 3.588-8 8 3.588 8 8 8zM16 2.667c2.941 0 5.333 2.392 5.333 5.333s-2.392 5.333-5.333 5.333-5.333-2.392-5.333-5.333 2.392-5.333 5.333-5.333zM16 18.667c-7.476 0-13.333 3.66-13.333 8.333v3.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-3.667c0-3.019 4.984-5.667 10.667-5.667s10.667 2.648 10.667 5.667v3.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-3.667c0-4.673-5.857-8.333-13.333-8.333z"></path>
269
- </svg>
270
- `;
271
-
272
- const PhoneIcon = `<!-- Generated by IcoMoon.io -->
273
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
274
- <title>phone</title>
275
- <path d="M30.823 21.713l-3.883-3.883c-1.569-1.568-4.12-1.568-5.689 0l-2.568 2.568c-3.063-1.499-5.583-4.019-7.081-7.083l2.568-2.567c0.759-0.76 1.177-1.771 1.177-2.845s-0.419-2.084-1.179-2.844l-3.881-3.881c-1.52-1.521-4.171-1.521-5.689 0l-1.845 1.847c-2.22 2.219-3.183 5.407-2.573 8.527 1.98 10.144 10.125 18.292 20.269 20.271 0.616 0.121 1.236 0.18 1.849 0.18 2.492 0 4.896-0.972 6.677-2.752l1.847-1.847c1.568-1.571 1.568-4.121 0.001-5.691zM28.936 25.517l-1.845 1.847c-1.592 1.592-3.883 2.283-6.132 1.841-9.089-1.776-16.388-9.075-18.163-18.165-0.439-2.247 0.249-4.539 1.841-6.129l1.847-1.847c0.256-0.257 0.596-0.397 0.959-0.397s0.703 0.14 0.959 0.397l3.883 3.883c0.256 0.256 0.397 0.596 0.397 0.959s-0.141 0.703-0.397 0.96l-3.22 3.217c-0.383 0.384-0.496 0.959-0.287 1.457 1.813 4.339 5.343 7.868 9.683 9.684 0.497 0.207 1.073 0.095 1.457-0.288l3.22-3.22c0.529-0.529 1.389-0.528 1.917 0l3.881 3.883c0.528 0.529 0.528 1.389 0 1.919z"></path>
276
- </svg>
277
- `;
278
-
279
- const KeyboardArrowRightIcon = `<!-- Generated by IcoMoon.io -->
280
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
281
- <title>keyboard_arrow_right</title>
282
- <path d="M11.438 22.479l6.125-6.125-6.125-6.125 1.875-1.875 8 8-8 8z"></path>
283
- </svg>
284
- `;
285
-
286
- const sallaLoginModalCss = "";
287
-
288
- const SallaLoginModal = class {
289
- constructor(hostRef) {
290
- registerInstance(this, hostRef);
291
- /**
292
- * Does the merchant allow to login using email
293
- */
294
- this.isEmailAllowed = true;
295
- /**
296
- * Does the merchant/current location for visitor allow to login using mobile, By default outside KSA is `false`
297
- */
298
- this.isMobileAllowed = true;
299
- /**
300
- * Does the merchant require registration with email & mobile
301
- */
302
- this.isEmailRequired = false;
303
- this.regType = 'phone';
304
- this.translationLoaded = false;
305
- this.typing = (e, submitMethod) => {
306
- const error = e.target.nextElementSibling;
307
- e.target.classList.remove('s-has-error');
308
- (error === null || error === void 0 ? void 0 : error.classList.contains('s-login-modal-error-message')) && (error.innerText = '');
309
- e.key == 'Enter' && submitMethod();
310
- };
311
- this.loginBySMS = async () => {
312
- const { phone, countryCode } = await this.loginTelInput.getValues();
313
- const isPhoneValid = await this.loginTelInput.isValid();
314
- if (!isPhoneValid) {
315
- return;
316
- }
317
- this.login(this.smsBtn, { type: 'mobile', phone: phone, country_code: countryCode });
318
- };
319
- this.loginByEmail = () => {
320
- if (!Helper.isValidEmail(this.loginEmail.value)) {
321
- this.validateField(this.loginEmail, this.emailErrorMsg);
322
- return;
323
- }
324
- this.login(this.emailBtn, { type: 'email', email: this.loginEmail.value });
325
- };
326
- this.newUser = async () => {
327
- var _a;
328
- const { phone: regPhone, countryCode } = this.regType == "email" ? await this.regTelInput.getValues() : await this.loginTelInput.getValues(), emailValue = this.regEmail.value || ((_a = this.loginEmail) === null || _a === void 0 ? void 0 : _a.value);
329
- await this.newUserValidation();
330
- await this.regBtn.load();
331
- await this.regBtn.disable();
332
- let data = {
333
- first_name: this.firstName.value,
334
- last_name: this.lastName.value,
335
- phone: regPhone || this.loginTelInput.phone,
336
- country_code: countryCode,
337
- verified_by: this.regType,
338
- };
339
- emailValue && (data = Object.assign(Object.assign({}, data), { email: emailValue }));
340
- this.verifyTab.getCode()
341
- .then(code => salla.auth.api.register(Object.assign(Object.assign({}, data), { code })))
342
- .then(() => salla.auth.canRedirect && window.location.reload())
343
- .catch((error) => {
344
- salla.logger.error(error);
345
- this.regBtn.stop() && this.regBtn.enable();
346
- });
347
- };
348
- this.title = this.host.title || salla.lang.get('blocks.header.login');
349
- this.host.removeAttribute('title');
350
- this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
351
- this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
352
- this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
353
- salla.lang.onLoaded(() => {
354
- this.translationLoaded = true;
355
- this.title = salla.lang.get('blocks.header.login');
356
- this.updateTranslations();
357
- });
358
- salla.event.on('login::open', (event) => this.open(event));
359
- salla.event.on('twilight::initiated', () => {
360
- this.isEmailAllowed = salla.config.get('store.settings.auth.email_allowed', this.isEmailAllowed);
361
- this.isMobileAllowed = salla.config.get('store.settings.auth.mobile_allowed', this.isMobileAllowed);
362
- this.isEmailRequired = salla.config.get('store.settings.auth.is_email_required', this.isEmailRequired);
363
- });
364
- }
365
- /**
366
- * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
367
- */
368
- onVerified(event) {
369
- var _a, _b;
370
- salla.log('verified', event);
371
- //there is a case when force login is activated & is new user, it will return case inside error key., so cover it.
372
- let verifyCase = ((_a = event.detail) === null || _a === void 0 ? void 0 : _a.data.case) || ((_b = event.detail) === null || _b === void 0 ? void 0 : _b.error.case);
373
- if (!verifyCase) {
374
- salla.log('verified but without case!');
375
- return;
376
- }
377
- if (verifyCase === "new_customer") {
378
- return this.showTab(this.registrationTab);
379
- }
380
- if (!salla.auth.canRedirect()) {
381
- salla.log('Will not auto redirect or reload, due to `salla.auth.canRedirect()`');
382
- return;
383
- }
384
- if (event.detail.data.redirect_url) {
385
- return window.location.href = event.detail.data.redirect_url;
386
- }
387
- window.location.reload();
388
- }
389
- updateTranslations() {
390
- var _a;
391
- this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
392
- this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
393
- this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
394
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
395
- }
396
- /**
397
- * Open login component
398
- */
399
- // @ts-ignore
400
- async open(event = null) {
401
- // todo :: support change the settings from event details
402
- // if(event && event.hasOwnProperty('isEmailAllowed')){
403
- // this.isEmailAllowed = event?.isEmailAllowed;
404
- // }
405
- //
406
- // if(event && event.hasOwnProperty('isMobileAllowed')){
407
- // this.isMobileAllowed = event?.isMobileAllowed;
408
- // }
409
- if (this.isEmailAllowed && this.isMobileAllowed) {
410
- this.showTab(this.homeTab);
411
- }
412
- else if (this.isEmailAllowed) {
413
- this.showTab(this.emailTab);
414
- }
415
- else if (this.isMobileAllowed) {
416
- this.showTab(this.mobileTab);
417
- }
418
- return this.modal.open();
419
- }
420
- showTab(tab, evt) {
421
- var _a;
422
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
423
- let tabs = [this.homeTab, this.mobileTab, this.emailTab, this.verifyTab, this.registrationTab];
424
- tabs.map(el => Helper.toggleElementClassIf(el, 'visible', 's-hidden', () => el == tab));
425
- setTimeout(() => tabs.map(el => Helper.toggleElementClassIf(el, 's-login-modal-active', 's-login-modal-unactive', () => el == tab)), 200);
426
- //we should have only one salla-login, so it's okay to get it from document
427
- //todo:: use better way for resize the modal
428
- setTimeout(() => { var _a; return (_a = this.modal.querySelector('.s-login-modal-wrapper')) === null || _a === void 0 ? void 0 : _a.setAttribute('style', 'height:' + (tab === null || tab === void 0 ? void 0 : tab.scrollHeight) + 'px'); });
429
- if ([this.mobileTab, this.emailTab].includes(tab)) {
430
- this.regType = tab === this.mobileTab ? 'phone' : 'email';
431
- }
432
- let isRegistrationTab = tab == this.registrationTab;
433
- // focus the first input in tab
434
- // tab.querySelector('input')?.focus();
435
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
436
- if (!isRegistrationTab) {
437
- Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
438
- .toggleElementClassIf(this.regEmailBlock, 's-hidden', 's-show', () => this.regType === 'email');
439
- }
440
- return this;
441
- }
442
- login(btn, data) {
443
- btn.load()
444
- .then(() => btn.disable())
445
- .then(() => salla.auth.api.login(data))
446
- .then(() => this.showTab(this.verifyTab))
447
- .then(() => this.verifyTab.open(data))
448
- .finally(() => btn.stop() && btn.enable());
449
- }
450
- async newUserValidation() {
451
- const isLogByPhone = this.regType == "phone", isLogByEmail = this.regType == "email", emailValue = this.regEmail.value || (isLogByEmail && this.loginEmail.value), isEmailValid = Helper.isValidEmail(emailValue), isFirstNameValid = this.firstName.value.length > 0, isLastNameValid = this.lastName.value.length > 0, isPhoneValid = await this.regTelInput.isValid() || isLogByPhone && await this.loginTelInput.isValid(), emailValidation = (emailValue && isEmailValid) || (!emailValue && !this.isEmailRequired);
452
- if (emailValidation && isPhoneValid && isFirstNameValid && isLastNameValid)
453
- return;
454
- !isEmailValid && this.validateField(this.regEmail, this.emailErrorMsg);
455
- !isFirstNameValid && this.validateField(this.firstName, this.firstNameErrorMsg);
456
- !isLastNameValid && this.validateField(this.lastName, this.lastNameErrorMsg);
457
- throw ('Please insert required fields');
458
- }
459
- // eslint-disable-next-line @stencil/own-methods-must-be-private
460
- validateField(field, errorMsg) {
461
- field.classList.add('s-has-error');
462
- field.nextElementSibling['innerText'] = '* ' + errorMsg;
463
- }
464
- render() {
465
- return (h("salla-modal", { class: "s-login-modal", "modal-title": this.title, ref: modal => this.modal = modal, width: "xs" }, h("span", { slot: 'icon', class: "s-login-modal-header-icon", innerHTML: UserIcon }), h("div", { class: "s-login-modal-wrapper" }, this.isEmailAllowed && this.isMobileAllowed ?
466
- h("div", { class: "s-login-modal-tab", ref: tab => this.homeTab = tab }, h("p", { class: "s-login-modal-sub-title" }, salla.lang.get('blocks.header.select_login_way')), h("slot", { name: "before-login-type" }), h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.mobileTab, evt) }, h("span", { class: "s-login-modal-main-btn-icon", innerHTML: PhoneIcon }), h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('blocks.header.sms')), h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.emailTab, evt) }, h("span", { class: "s-login-modal-main-btn-icon", innerHTML: email }), h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('common.elements.email')), h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), h("slot", { name: "after-login-type" }))
467
- : '', this.isMobileAllowed ?
468
- h("div", { class: "s-login-modal-tab", ref: tab => this.mobileTab = tab }, h("slot", { name: "before-login-mobile" }), h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), h("salla-tel-input", { ref: el => this.loginTelInput = el, onKeyDown: e => this.typing(e, this.loginBySMS) }), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginBySMS(), ref: b => this.smsBtn = b }, salla.lang.get('blocks.header.enter')), this.isEmailAllowed ?
469
- h("a", { href: "#", onClick: () => this.showTab(this.emailTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_email')) : '', h("slot", { name: "after-login-mobile" })) : '', this.isEmailAllowed ?
470
- h("div", { class: "s-login-modal-tab", ref: tab => this.emailTab = tab }, h("slot", { name: "before-login-email" }), h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), h("input", { type: "email", ref: el => this.loginEmail = el, onKeyDown: e => this.typing(e, this.loginByEmail), placeholder: "your@email.com", class: "s-login-modal-input s-ltr" }), h("span", { class: "s-login-modal-error-message" }), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginByEmail(), ref: b => this.emailBtn = b }, salla.lang.get('blocks.header.enter')), this.isMobileAllowed ?
471
- h("a", { href: "#", onClick: () => this.showTab(this.mobileTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_sms'))
472
- : '', h("slot", { name: "after-login-email" })) : '', h("salla-verify", { display: "inline", ref: tab => this.verifyTab = tab, autoReload: false }, h("a", { onClick: () => this.showTab(this.regType == 'phone' ? this.mobileTab : this.emailTab), class: "s-verify-back", innerHTML: ArrowRightIcon, slot: "after-footer", href: "#" })), h("div", { ref: tab => this.registrationTab = tab }, h("slot", { name: "before-registration" }), h("div", null, h("label", { class: "s-login-modal-label" }, salla.lang.get('blocks.header.your_name')), h("input", { type: "text", class: "s-login-modal-input", ref: el => this.firstName = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: salla.lang.get('pages.profile.first_name') }), h("span", { class: "s-login-modal-error-message" })), h("div", null, h("label", { class: "s-login-modal-label" }, salla.lang.get('pages.profile.last_name')), h("input", { type: "text", class: "s-login-modal-input", ref: el => this.lastName = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: salla.lang.get('pages.profile.last_name') }), h("span", { class: "s-login-modal-error-message" })), h("div", { ref: el => this.regMobileBlock = el, class: "mb-1.5" }, h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), h("salla-tel-input", { ref: el => this.regTelInput = el, onKeyDown: e => this.typing(e, this.newUser) })), h("div", { ref: el => this.regEmailBlock = el, class: "mb-1.5" }, h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), h("input", { type: "email", ref: el => this.regEmail = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: "your@email.com", class: "s-login-modal-input s-ltr" }), h("span", { class: "s-login-modal-error-message" })), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.newUser(), ref: b => this.regBtn = b }, salla.lang.get('blocks.header.register')), h("slot", { name: "after-registration" })))));
473
- }
474
- get host() { return getElement(this); }
475
- };
476
- SallaLoginModal.style = sallaLoginModalCss;
477
-
478
- const AlertEngineIcon = `<!-- Generated by IcoMoon.io -->
479
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
480
- <title>alert-engine</title>
481
- <path d="M16 18.673c-0.736 0-1.333 0.604-1.333 1.34s0.597 1.333 1.333 1.333 1.333-0.597 1.333-1.333v-0.013c0-0.736-0.597-1.327-1.333-1.327zM2.667 16c0-3.092 1.083-6.105 3.047-8.484 0.469-0.568 0.389-1.408-0.179-1.877-0.568-0.468-1.408-0.388-1.877 0.179-2.359 2.857-3.657 6.473-3.657 10.183s1.299 7.325 3.657 10.183c0.264 0.319 0.645 0.484 1.029 0.484 0.299 0 0.6-0.1 0.848-0.305 0.568-0.469 0.648-1.309 0.179-1.877-1.964-2.379-3.047-5.392-3.047-8.484zM16 10.667c-0.736 0-1.333 0.597-1.333 1.333v4c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-4c0-0.736-0.597-1.333-1.333-1.333zM16 5.333c-5.881 0-10.667 4.785-10.667 10.667s4.785 10.667 10.667 10.667 10.667-4.785 10.667-10.667-4.785-10.667-10.667-10.667zM16 24c-4.412 0-8-3.588-8-8s3.588-8 8-8 8 3.588 8 8-3.588 8-8 8zM28.343 5.817c-0.469-0.567-1.307-0.647-1.877-0.179-0.568 0.469-0.648 1.309-0.179 1.877 1.964 2.379 3.047 5.392 3.047 8.484s-1.083 6.105-3.047 8.484c-0.469 0.568-0.389 1.408 0.179 1.877 0.249 0.205 0.549 0.305 0.848 0.305 0.384 0 0.765-0.165 1.028-0.484 2.36-2.857 3.659-6.473 3.659-10.183s-1.299-7.325-3.657-10.183z"></path>
482
- </svg>
483
- `;
484
-
485
- const sallaModalCss = "";
486
-
487
- const SallaModal = class {
488
- constructor(hostRef) {
489
- registerInstance(this, hostRef);
490
- /**
491
- * Sets the modal to be closable. Defaults to `true`
492
- */
493
- this.isClosable = true; //todo::rename unclude. Suggestion => persistent
494
- /**
495
- * The size of the modal
496
- */
497
- this.width = 'md';
498
- /**
499
- * The position of the modal
500
- */
501
- this.position = 'middle';
502
- /**
503
- * open the modal on rendering
504
- */
505
- this.visible = false;
506
- /**
507
- * open the modal on rendering
508
- */
509
- this.hasSkeleton = false;
510
- /**
511
- * Show loading in the middle
512
- */
513
- this.isLoading = false;
514
- /**
515
- * Show subtitle before the title or not, defaults to `false` (after the title)
516
- */
517
- this.subTitleFirst = false; //todo:: choose better name
518
- /**
519
- * Avoid padding in the modal body or not, defaults to `false`
520
- */
521
- this.noPadding = false; //todo:: choose better name
522
- /**
523
- * Set modal sub title.
524
- */
525
- this.subTitle = '';
526
- /**
527
- * Align modal content to center, defaults to `false`
528
- */
529
- this.centered = false;
530
- /**
531
- * Set the style of the header icon.
532
- */
533
- this.iconStyle = undefined;
534
- Helper.setHost(this.host);
535
- salla.event.on('modal::open', target => target == this.host.id && this.open());
536
- salla.event.on('modal::close', target => target == this.host.id && this.close());
537
- this.modalTitle = this.host.getAttribute('modal-title');
538
- // close modal on Escape button clicked
539
- Helper.onKeyUp(document.body, e => e.keyCode === 27 && this.closeModal());
540
- }
541
- handleVisible(newValue) {
542
- if (!newValue) {
543
- salla.event.dispatch('modalClosed');
544
- this.toggleModal(false);
545
- return;
546
- }
547
- salla.event.dispatch('modalOpened');
548
- this.host.classList.remove('s-hidden');
549
- setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
550
- }
551
- /**
552
- * Open the modal
553
- */
554
- async open() {
555
- this.host.setAttribute('visible', '');
556
- return this.host;
557
- }
558
- /**
559
- * close the modal
560
- */
561
- async close() {
562
- this.host.removeAttribute('visible');
563
- return this.host;
564
- }
565
- /**
566
- * Change the Modal Title
567
- * @param {string} modalTitle
568
- */
569
- async setTitle(modalTitle) {
570
- this.modalTitle = modalTitle;
571
- return this.host;
572
- }
573
- /**
574
- * Start loading
575
- */
576
- async loading() {
577
- this.isLoading = true;
578
- return this.host;
579
- }
580
- /**
581
- * Stop the loading
582
- */
583
- async stopLoading() {
584
- this.isLoading = false;
585
- return this.host;
586
- }
587
- toggleModal(isOpen) {
588
- const body = this.host.querySelector('.s-modal-body');
589
- Helper.toggleElementClassIf(body, 's-modal-entering', 's-modal-leaving', () => isOpen)
590
- .toggleElementClassIf(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
591
- .toggleElementClassIf(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
592
- if (!isOpen) {
593
- setTimeout(() => this.host.classList.add('s-hidden'), 350);
594
- }
595
- }
596
- closeModal() {
597
- if (!this.isClosable) {
598
- return;
599
- }
600
- this.host.removeAttribute('visible');
601
- }
602
- iconBlockClasses() {
603
- return {
604
- 's-modal-icon': true,
605
- 's-modal-bg-error': this.iconStyle == 'error',
606
- 's-modal-bg-success': this.iconStyle == 'success',
607
- 's-modal-bg-normal': !this.iconStyle,
608
- 's-modal-bg-primary': this.iconStyle == 'primary'
609
- };
610
- }
611
- getWidth() {
612
- return this.isLoading ? (this.hasSkeleton ? 'md' : 'xs') : this.width;
613
- }
614
- //todo:: pref for each modal
615
- render() {
616
- this.host.id = this.host.id || 'salla-modal';
617
- if (this.isLoading) {
618
- return (h(Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("div", { class: "s-modal-wrapper" }, h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, h("slot", { name: "loading" }, h("salla-loading", null)), h("div", { class: "s-hidden" }, h("slot", null))))));
619
- }
620
- return (h(Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("div", { class: "s-modal-wrapper" }, h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.centered } }, this.isClosable ?
621
- h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, h("span", { innerHTML: Cancel }))
622
- : '', this.modalTitle || this.subTitle ?
623
- h("div", { class: "s-modal-header-inner" }, h("slot", { name: 'icon' }, !!this.iconStyle ?
624
- h("div", { class: this.iconBlockClasses(), innerHTML: this.iconStyle == 'error' ? AlertEngineIcon : CheckCircle2 })
625
- : ''), h("div", { class: "s-modal-header-content" }, h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.modalTitle }), h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle })))
626
- : ""), h("slot", null), h("slot", { name: "footer" })))));
627
- }
628
- //move the modal as root dom, because we need the model to be outside the forms
629
- componentDidLoad() {
630
- document.body.append(this.host);
631
- }
632
- get host() { return getElement(this); }
633
- static get watchers() { return {
634
- "visible": ["handleVisible"]
635
- }; }
636
- };
637
- SallaModal.style = sallaModalCss;
638
-
639
- const SpecialDiscountIcon = `<!-- Generated by IcoMoon.io -->
640
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
641
- <title>special-discount</title>
642
- <path d="M20.667 19.333c-0.737 0-1.333 0.596-1.333 1.333v0.013c0 0.737 0.596 1.327 1.333 1.327s1.333-0.603 1.333-1.34-0.596-1.333-1.333-1.333zM11.333 12.673c0.737 0 1.333-0.603 1.333-1.34s-0.596-1.333-1.333-1.333-1.333 0.596-1.333 1.333v0.013c0 0.736 0.596 1.327 1.333 1.327zM30.307 16l0.947-4.244c0.107-0.473-0.055-0.969-0.417-1.291l-3.259-2.876-1.732-3.987c-0.193-0.444-0.612-0.749-1.095-0.796l-4.327-0.417-3.748-2.204c-0.416-0.248-0.933-0.248-1.353 0l-3.744 2.204-4.329 0.417c-0.483 0.047-0.901 0.352-1.095 0.796l-1.732 3.987-3.259 2.877c-0.363 0.321-0.525 0.816-0.417 1.289l0.947 4.244-0.947 4.244c-0.107 0.473 0.055 0.969 0.417 1.291l3.259 2.876 1.732 3.987c0.193 0.444 0.612 0.749 1.095 0.796l4.325 0.416 3.749 2.207c0.208 0.123 0.441 0.184 0.676 0.184s0.468-0.061 0.676-0.185l3.747-2.205 4.328-0.416c0.483-0.045 0.903-0.351 1.095-0.796l1.732-3.985 3.259-2.877c0.363-0.321 0.525-0.816 0.417-1.291zM28.48 20.056l-2.892 2.552c-0.145 0.131-0.261 0.291-0.34 0.469l-1.536 3.536-3.84 0.369c-0.195 0.019-0.381 0.080-0.551 0.179l-3.321 1.959-3.324-1.959c-0.168-0.099-0.356-0.16-0.549-0.179l-3.839-0.369-1.536-3.537c-0.077-0.18-0.195-0.339-0.34-0.469l-2.892-2.551 0.84-3.765c0.043-0.192 0.043-0.389 0-0.581l-0.84-3.765 2.892-2.551c0.145-0.131 0.263-0.289 0.34-0.469l1.536-3.539 3.84-0.369c0.195-0.019 0.381-0.080 0.549-0.179l3.323-1.957 3.325 1.957c0.167 0.099 0.355 0.16 0.548 0.179l3.839 0.369 1.536 3.539c0.077 0.18 0.195 0.339 0.34 0.469l2.892 2.551-0.84 3.765c-0.043 0.192-0.043 0.389 0 0.581zM20.391 9.724l-10.667 10.667c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l10.667-10.667c0.521-0.521 0.521-1.364 0-1.885s-1.364-0.521-1.885 0z"></path>
643
- </svg>
644
- `;
645
-
646
- const KeyboardArrowLeftIcon = `<!-- Generated by IcoMoon.io -->
647
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
648
- <title>keyboard_arrow_left</title>
649
- <path d="M20.563 22.104l-1.875 1.875-8-8 8-8 1.875 1.875-6.125 6.125z"></path>
650
- </svg>
651
- `;
652
-
653
- const Tag = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
654
- <title>tag</title>
655
- <path d="M28 0h-9.344c-1.059 0-2.056 0.411-2.809 1.153l-14.673 14.456c-1.56 1.56-1.561 4.097-0.001 5.657l9.56 9.56c0.755 0.755 1.76 1.172 2.828 1.173h0.003c1.068 0 2.072-0.416 2.833-1.179l14.451-14.668c0.743-0.753 1.153-1.751 1.153-2.809v-9.344c0-2.205-1.795-4-4-4zM29.333 13.344c0 0.353-0.137 0.685-0.385 0.937l-14.444 14.661c-0.252 0.252-0.587 0.391-0.941 0.391-0.001 0-0.001 0-0.001 0-0.356-0.001-0.691-0.139-0.943-0.392l-9.561-9.56c-0.52-0.52-0.52-1.365-0.005-1.88l14.667-14.449c0.253-0.248 0.585-0.385 0.937-0.385h9.344c0.736 0 1.333 0.597 1.333 1.333zM24 6.673c-0.737 0-1.333 0.604-1.333 1.341s0.596 1.333 1.333 1.333 1.333-0.596 1.333-1.333v-0.015c0-0.737-0.596-1.327-1.333-1.327z"></path>
656
- </svg>
657
- `;
658
-
659
- const sallaOfferModalCss = "";
660
-
661
- const SallaOfferModal = class {
662
- constructor(hostRef) {
663
- registerInstance(this, hostRef);
664
- var _a, _b;
665
- this.offer = null;
666
- this.translationLoaded = false;
667
- Helper.setHost(this.host);
668
- salla.lang.onLoaded(() => {
669
- this.translationLoaded = true;
670
- });
671
- this.categorySlot = ((_a = Helper.getElement('[slot="category"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || `<span class="s-offer-modal-badge-icon">{tagIcon}</span><span class="s-offer-modal-badge-text">{name}</span>`;
672
- this.productSlot = ((_b = Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.defaultProductSlot();
673
- salla.product.event.onOfferExisted(offer => {
674
- if (salla.storage.get('remember-offer-' + offer.id)) {
675
- salla.log('User selected to don\'t show this offer again.');
676
- return;
677
- }
678
- this.open(offer.product_id);
679
- });
680
- }
681
- /**
682
- * Show the available offers for the product
683
- * @param product_id
684
- */
685
- async open(product_id) {
686
- //TODO:: make sure there is only one offer
687
- return salla.product.offers(product_id)
688
- .then(response => this.showOffer(response.data[0]));
689
- }
690
- /**
691
- * Show offer details
692
- * @param {Offer} offer
693
- */
694
- async showOffer(offer) {
695
- this.offer = offer;
696
- this.offer_name = offer.name;
697
- this.offer_message = offer.message;
698
- this.modal.setTitle(this.offer_name);
699
- return this.modal.open();
700
- }
701
- rememberMe(event) {
702
- salla.storage.set('remember-offer-' + this.offer.id, event.target.checked);
703
- }
704
- //todo:: pass event then use sallaButton from it
705
- addItem() {
706
- // this here, is sallaButton
707
- this['load']();
708
- return salla.cart.api
709
- .quickAdd(this['dataset'].id)
710
- .finally(() => this['stop']());
711
- }
712
- defaultProductSlot() {
713
- return '<a href={url} class="s-offer-modal-product-image-wrap"><img class="s-offer-modal-product-image" src="{image}" /></a>' +
714
- '<div class="s-offer-modal-product-info">' +
715
- ' <a href={url} class="s-offer-modal-product-name">{name}</a>' +
716
- ' <div class="s-offer-modal-product-price">{price}</div>' +
717
- '</div>';
718
- }
719
- render() {
720
- var _a, _b;
721
- return h("salla-modal", { "sub-title-first": true, "sub-title": this.offer_message, ref: modal => this.modal = modal, "is-loading": this.offer === null }, h("span", { slot: 'icon', class: "s-offer-modal-header-icon", innerHTML: SpecialDiscountIcon }), this.offer !== null
722
- ? [h("div", { class: "s-offer-modal-scrolled-slider-wrap" }, h("div", { class: "s-offer-modal-body s-offer-modal-scrolled-slider" }, ((_a = this.offer.get.categories) === null || _a === void 0 ? void 0 : _a.length) > 0
723
- ? this.offer.get.categories.map(category => h("a", { href: category.urls.customer, class: "s-offer-modal-badge s-offer-modal-slider-item", innerHTML: this.categorySlot
724
- .replace(/\{tagIcon\}/g, Tag)
725
- .replace(/\{name\}/g, category.name)
726
- .replace(/\{url\}/g, category.urls.customer) }))
727
- : (_b = this.offer.get.products) === null || _b === void 0 ? void 0 : _b.map(product => h("div", { class: { "s-offer-modal-product": true, "s-offer-modal-slider-item": true, "s-offer-modal-not-available": !product.is_available }, id: 'product_' + product.id, innerHTML: this.productSlot
728
- .replace(/\{name\}/g, product.name)
729
- .replace(/\{url\}/g, product.url)
730
- .replace(/\{image\}/g, product.thumbnail)
731
- .replace(/\{price\}/g, product.has_special_price
732
- ? salla.money(product.price) + '<span class="s-offer-modal-product-old-price">' + salla.money(product.regular_price) + '</span>'
733
- : salla.money(product.price)) }, h("div", { class: "s-offer-modal-btn-wrap" }, h("salla-button", { width: "wide", fill: 'outline', "data-id": product.id, disabled: !product.is_available, "loader-position": "center", onClick: this.addItem }, product.is_available ? salla.lang.get('pages.cart.add_to_cart') : salla.lang.get('pages.products.out_of_stock')))))), h("div", { class: "s-offer-modal-slider-nav" }, h("button", { class: "s-offer-modal-nav-btn s-offer-modal-prev-btn" }, h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowLeftIcon })), h("button", { class: "s-offer-modal-nav-btn s-offer-modal-next-btn" }, h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowRightIcon })))), h("div", { class: "s-offer-modal-footer", slot: "footer" }, this.offer.formatted_date ?
734
- h("p", { class: "s-offer-modal-expiry" }, salla.lang.get('pages.products.offer_expires_in'), " ", this.offer.formatted_date)
735
- : '', h("label", { class: "s-offer-modal-remember-label" }, h("input", { type: "checkbox", onChange: e => this.rememberMe(e), class: "s-offer-modal-remember-input" }), "\u00A0 ", salla.lang.get('common.elements.remember_my_choice'))),
736
- ] : '');
737
- }
738
- componentDidRender() {
739
- // Sooo mini Slider
740
- if (this.offer && window.screen.width > 639) {
741
- let sliderWrap = this.modal.querySelector('.s-offer-modal-scrolled-slider-wrap'), slider = this.modal.querySelector('.s-offer-modal-scrolled-slider'), navButtons = this.modal.querySelectorAll('.s-offer-modal-nav-btn'), nexBtn = this.modal.querySelector('.s-offer-modal-next-btn'), prevBtn = this.modal.querySelector('.s-offer-modal-prev-btn'), items = this.modal.querySelectorAll('.s-offer-modal-slider-item'), sliderNavMargin = 20, // space before displaying the next/prev btns.
742
- current = 0, // current slide
743
- slidesToScroll = 3, itemsLength = items.length;
744
- console.log('items[0]:', items[0]);
745
- let itemSize = items[0].offsetWidth, sliderSize = itemsLength * itemSize, sliderWrapperSize = sliderWrap.offsetWidth, sliderInvisibleSize = sliderSize - sliderWrapperSize, isRTL = document.body.classList.contains('rtl') ? true : false;
746
- if (sliderInvisibleSize > sliderNavMargin)
747
- nexBtn.classList.add('s-offer-modal-btn-is-active');
748
- window.onresize = function () {
749
- sliderWrapperSize = sliderWrap.offsetWidth;
750
- sliderInvisibleSize = sliderSize - sliderWrapperSize;
751
- };
752
- slider.addEventListener('scroll', function () {
753
- let sliderPosition = Math.abs(slider.scrollLeft);
754
- let sliderEndOffset = sliderInvisibleSize - sliderNavMargin;
755
- // show & hide the navigation btns depending on scroll position
756
- if (sliderPosition <= sliderNavMargin) {
757
- nexBtn.classList.add('s-offer-modal-btn-is-active');
758
- prevBtn.classList.remove('s-offer-modal-btn-is-active');
759
- }
760
- else if (sliderPosition < sliderEndOffset) {
761
- // show both btns in the middle
762
- nexBtn.classList.add('s-offer-modal-btn-is-active');
763
- prevBtn.classList.add('s-offer-modal-btn-is-active');
764
- }
765
- else if (sliderPosition >= sliderEndOffset) {
766
- nexBtn.classList.remove('s-offer-modal-btn-is-active');
767
- prevBtn.classList.add('s-offer-modal-btn-is-active');
768
- }
769
- });
770
- // Navigation
771
- navButtons.forEach(btn => {
772
- btn.addEventListener('click', function () {
773
- btn.classList.contains('s-offer-modal-next-btn') ? current++ : current--;
774
- slider.scrollTo({
775
- top: 0,
776
- left: itemSize * slidesToScroll * current * (isRTL ? -1 : 1),
777
- behavior: 'smooth'
778
- });
779
- });
780
- });
781
- }
782
- }
783
- get host() { return getElement(this); }
784
- };
785
- SallaOfferModal.style = sallaOfferModalCss;
786
-
787
- const sallaSearchCss = "";
788
-
789
- const SallaSearch = class {
790
- constructor(hostRef) {
791
- registerInstance(this, hostRef);
792
- var _a;
793
- this.inputValue = '';
794
- this.translationLoaded = false;
795
- this.loading = false;
796
- this.typing = false;
797
- this.debounce = setTimeout(() => '', 1000);
798
- /**
799
- * Set the component display without modal window. Defaults to `false`
800
- */
801
- this.inline = false;
802
- /**
803
- * Adds a border radius to the input. Half of the height.
804
- */
805
- this.oval = false;
806
- /**
807
- * Sets the height of the input
808
- */
809
- this.height = 60;
810
- Helper.setHost(this.host);
811
- this.productSlot = ((_a = Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
812
- salla.event.on('search::open', () => this.open());
813
- salla.lang.onLoaded(() => {
814
- this.translationLoaded = true;
815
- });
816
- salla.event.on('modalClosed', () => this.onModalClose());
817
- }
818
- async open() {
819
- if (!this.inline) {
820
- await this.modal.open().then(() => setTimeout(() => this.searchInput.focus(), 300));
821
- }
822
- }
823
- onModalClose() {
824
- this.searchInput.value = '';
825
- this.results = undefined;
826
- this.afterSearching();
827
- this.container.classList.remove('s-search-no-results');
828
- }
829
- handleKeyDown(ev) {
830
- if (ev.key === 'Enter') {
831
- window.location.href = salla.url.get('/search?q=' + encodeURI(this.search_term));
832
- }
833
- }
834
- getDefaultProductSlot() {
835
- return '<div class="s-search-product-image-container">' +
836
- ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
837
- '</div>' +
838
- '<div class="s-search-product-details">' +
839
- ' <div class="s-search-product-title">{name}</div> <div class="s-search-product-price">{price} <span class="s-search-product-regular-price">{regular_price}</span></div>' +
840
- '</div>';
841
- }
842
- debounceSearch(event) {
843
- this.typing = true;
844
- clearTimeout(this.debounce);
845
- this.debounce = setTimeout(() => {
846
- this.typing = false;
847
- this.search_term = event.target.value;
848
- }, 500);
849
- }
850
- handelSearch(val) {
851
- this.inputValue = val;
852
- if (val.length > 2) {
853
- this.search(val);
854
- }
855
- else {
856
- this.results = undefined;
857
- this.afterSearching();
858
- }
859
- }
860
- search(val) {
861
- Helper.hideElement(this.noResults);
862
- //run loading spinner or stop it
863
- this.loading = true;
864
- salla.product.search(val)
865
- .then(response => this.results = response)
866
- .catch(err => err !== 'Query is same as previous one!' ? this.results = undefined : null)
867
- .finally(() => this.afterSearching(/*isEmpty*/ false));
868
- }
869
- afterSearching(isEmpty = true) {
870
- var _a;
871
- this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
872
- Helper.toggleElementClassIf(this.container, 's-search-container-open', 's-search-no-results', () => { var _a; return (_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length; });
873
- this.loading = false;
874
- salla.product.api.previousQuery = ''; //avoid having error 'Query is same as previous one!' after reopen modal;
875
- this.inputValue.length < 3 ? this.container.classList.remove('s-search-no-results') : '';
876
- }
877
- render() {
878
- var _a;
879
- const searchContent = h("div", { class: { 's-search-container': true, 's-search-inline': this.inline }, ref: container => this.container = container }, h("input", { type: "text", autocomplete: "off", class: "s-search-input", placeholder: salla.lang.get('blocks.header.search_placeholder'), onInput: e => this.debounceSearch(e), onKeyDown: e => this.handleKeyDown(e), ref: input => this.searchInput = input, style: { height: this.height + 'px', borderRadius: this.oval ? this.height / 2 + 'px' : '' } }), h("span", { class: "s-search-icon-wrap" }, h("span", { class: "s-search-icon", innerHTML: this.loading ? '<i class="s-search-spinner-loader"></i>' : Search })), h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
880
- _a.data.map(item => h("a", { href: item.url, class: { "s-search-product": true, 's-search-product-not-available': !item.is_available }, innerHTML: this.productSlot
881
- .replace(/\{name\}/g, item.name)
882
- .replace(/\{price\}/g, salla.money(item.price))
883
- .replace(/\{regular_price\}/g, item.has_special_price ? salla.money(item.regular_price) : '')
884
- .replace(/\{image\}/g, item.thumbnail) })), h("p", { ref: el => this.noResults = el, class: "s-search-no-results-placeholder" }, salla.lang.get('common.elements.no_options'))));
885
- return (this.inline ?
886
- h("div", { class: "s-search-modal" }, searchContent)
887
- :
888
- h("salla-modal", { position: "top", class: "s-search-modal", ref: modal => this.modal = modal }, searchContent));
889
- }
890
- /**
891
- * Run it one time after load
892
- */
893
- componentDidLoad() {
894
- this.afterSearching();
895
- }
896
- get host() { return getElement(this); }
897
- static get watchers() { return {
898
- "search_term": ["handelSearch"]
899
- }; }
900
- };
901
- SallaSearch.style = sallaSearchCss;
902
-
903
- const sallaSkeletonCss = ":host{display:block}";
904
-
905
- const SallaSkeleton = class {
906
- constructor(hostRef) {
907
- registerInstance(this, hostRef);
908
- /**
909
- * Set the shape type of the skeleton is it circle or normal
910
- */
911
- this.type = 'normal';
912
- /**
913
- * Set the skeleton width
914
- */
915
- this.width = '100%';
916
- /**
917
- * Set the skeleton height
918
- */
919
- this.height = '100%';
920
- }
921
- render() {
922
- const classes = {
923
- 's-skeleton-item': true,
924
- 's-skeleton-item-circular': this.type == 'circle',
925
- };
926
- return (h(Host, { class: "s-skeleton-wrapper", style: { width: this.width, height: this.height } }, h("div", { class: classes }, "\u00A0")));
927
- }
928
- };
929
- SallaSkeleton.style = sallaSkeletonCss;
930
-
931
- function createCommonjsModule(fn, basedir, module) {
932
- return module = {
933
- path: basedir,
934
- exports: {},
935
- require: function (path, base) {
936
- return commonjsRequire();
937
- }
938
- }, fn(module, module.exports), module.exports;
939
- }
940
-
941
- function commonjsRequire () {
942
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
943
- }
944
-
945
- var intlTelInput$1 = createCommonjsModule(function (module) {
946
- /*
947
- * International Telephone Input v17.0.18
948
- * https://github.com/jackocnr/intl-tel-input.git
949
- * Licensed under the MIT license
950
- */
951
-
952
- // wrap in UMD
953
- (function(factory) {
954
- if (module.exports) module.exports = factory(); else window.intlTelInput = factory();
955
- })(function(undefined$1) {
956
- return function() {
957
- // Array of country objects for the flag dropdown.
958
- // Here is the criteria for the plugin to support a given country/territory
959
- // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
960
- // - 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
961
- // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
962
- // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
963
- // Each country array has the following information:
964
- // [
965
- // Country name,
966
- // iso2 code,
967
- // International dial code,
968
- // Order (if >1 country with same dial code),
969
- // Area codes
970
- // ]
971
- 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" ] ] ];
972
- // loop over all of the countries above, restructuring the data to be objects with named keys
973
- for (var i = 0; i < allCountries.length; i++) {
974
- var c = allCountries[i];
975
- allCountries[i] = {
976
- name: c[0],
977
- iso2: c[1],
978
- dialCode: c[2],
979
- priority: c[3] || 0,
980
- areaCodes: c[4] || null
981
- };
982
- }
983
- function _classCallCheck(instance, Constructor) {
984
- if (!(instance instanceof Constructor)) {
985
- throw new TypeError("Cannot call a class as a function");
986
- }
987
- }
988
- function _defineProperties(target, props) {
989
- for (var i = 0; i < props.length; i++) {
990
- var descriptor = props[i];
991
- descriptor.enumerable = descriptor.enumerable || false;
992
- descriptor.configurable = true;
993
- if ("value" in descriptor) descriptor.writable = true;
994
- Object.defineProperty(target, descriptor.key, descriptor);
995
- }
996
- }
997
- function _createClass(Constructor, protoProps, staticProps) {
998
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
999
- if (staticProps) _defineProperties(Constructor, staticProps);
1000
- return Constructor;
1001
- }
1002
- var intlTelInputGlobals = {
1003
- getInstance: function getInstance(input) {
1004
- var id = input.getAttribute("data-intl-tel-input-id");
1005
- return window.intlTelInputGlobals.instances[id];
1006
- },
1007
- instances: {},
1008
- // using a global like this allows us to mock it in the tests
1009
- documentReady: function documentReady() {
1010
- return document.readyState === "complete";
1011
- }
1012
- };
1013
- if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
1014
- // these vars persist through all instances of the plugin
1015
- var id = 0;
1016
- var defaults = {
1017
- // whether or not to allow the dropdown
1018
- allowDropdown: true,
1019
- // if there is just a dial code in the input: remove it on blur
1020
- autoHideDialCode: true,
1021
- // add a placeholder in the input with an example number for the selected country
1022
- autoPlaceholder: "polite",
1023
- // modify the parentClass
1024
- customContainer: "",
1025
- // modify the auto placeholder
1026
- customPlaceholder: null,
1027
- // append menu to specified element
1028
- dropdownContainer: null,
1029
- // don't display these countries
1030
- excludeCountries: [],
1031
- // format the input value during initialisation and on setNumber
1032
- formatOnDisplay: true,
1033
- // geoIp lookup function
1034
- geoIpLookup: null,
1035
- // inject a hidden input with this name, and on submit, populate it with the result of getNumber
1036
- hiddenInput: "",
1037
- // initial country
1038
- initialCountry: "",
1039
- // localized country names e.g. { 'de': 'Deutschland' }
1040
- localizedCountries: null,
1041
- // don't insert international dial codes
1042
- nationalMode: true,
1043
- // display only these countries
1044
- onlyCountries: [],
1045
- // number type to use for placeholders
1046
- placeholderNumberType: "MOBILE",
1047
- // the countries at the top of the list. defaults to united states and united kingdom
1048
- preferredCountries: [ "us", "gb" ],
1049
- // display the country dial code next to the selected flag so it's not part of the typed number
1050
- separateDialCode: false,
1051
- // specify the path to the libphonenumber script to enable validation/formatting
1052
- utilsScript: ""
1053
- };
1054
- // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
1055
- var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
1056
- // utility function to iterate over an object. can't use Object.entries or native forEach because
1057
- // of IE11
1058
- var forEachProp = function forEachProp(obj, callback) {
1059
- var keys = Object.keys(obj);
1060
- for (var i = 0; i < keys.length; i++) {
1061
- callback(keys[i], obj[keys[i]]);
1062
- }
1063
- };
1064
- // run a method on each instance of the plugin
1065
- var forEachInstance = function forEachInstance(method) {
1066
- forEachProp(window.intlTelInputGlobals.instances, function(key) {
1067
- window.intlTelInputGlobals.instances[key][method]();
1068
- });
1069
- };
1070
- // this is our plugin class that we will create an instance of
1071
- // eslint-disable-next-line no-unused-vars
1072
- var Iti = /*#__PURE__*/
1073
- function() {
1074
- function Iti(input, options) {
1075
- var _this = this;
1076
- _classCallCheck(this, Iti);
1077
- this.id = id++;
1078
- this.telInput = input;
1079
- this.activeItem = null;
1080
- this.highlightedItem = null;
1081
- // process specified options / defaults
1082
- // alternative to Object.assign, which isn't supported by IE11
1083
- var customOptions = options || {};
1084
- this.options = {};
1085
- forEachProp(defaults, function(key, value) {
1086
- _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
1087
- });
1088
- this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1089
- }
1090
- _createClass(Iti, [ {
1091
- key: "_init",
1092
- value: function _init() {
1093
- var _this2 = this;
1094
- // if in nationalMode, disable options relating to dial codes
1095
- if (this.options.nationalMode) this.options.autoHideDialCode = false;
1096
- // if separateDialCode then doesn't make sense to A) insert dial code into input
1097
- // (autoHideDialCode), and B) display national numbers (because we're displaying the country
1098
- // dial code next to them)
1099
- if (this.options.separateDialCode) {
1100
- this.options.autoHideDialCode = this.options.nationalMode = false;
1101
- }
1102
- // we cannot just test screen size as some smartphones/website meta tags will report desktop
1103
- // resolutions
1104
- // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
1105
- // rest of these declarations
1106
- // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1107
- this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1108
- if (this.isMobile) {
1109
- // trigger the mobile dropdown css
1110
- document.body.classList.add("iti-mobile");
1111
- // on mobile, we want a full screen dropdown, so we must append it to the body
1112
- if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
1113
- }
1114
- // these promises get resolved when their individual requests complete
1115
- // this way the dev can do something like iti.promise.then(...) to know when all requests are
1116
- // complete
1117
- if (typeof Promise !== "undefined") {
1118
- var autoCountryPromise = new Promise(function(resolve, reject) {
1119
- _this2.resolveAutoCountryPromise = resolve;
1120
- _this2.rejectAutoCountryPromise = reject;
1121
- });
1122
- var utilsScriptPromise = new Promise(function(resolve, reject) {
1123
- _this2.resolveUtilsScriptPromise = resolve;
1124
- _this2.rejectUtilsScriptPromise = reject;
1125
- });
1126
- this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
1127
- } else {
1128
- // prevent errors when Promise doesn't exist
1129
- this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {};
1130
- this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {};
1131
- }
1132
- // in various situations there could be no country selected initially, but we need to be able
1133
- // to assume this variable exists
1134
- this.selectedCountryData = {};
1135
- // process all the data: onlyCountries, excludeCountries, preferredCountries etc
1136
- this._processCountryData();
1137
- // generate the markup
1138
- this._generateMarkup();
1139
- // set the initial state of the input value and the selected flag
1140
- this._setInitialState();
1141
- // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
1142
- this._initListeners();
1143
- // utils script, and auto country
1144
- this._initRequests();
1145
- }
1146
- }, {
1147
- key: "_processCountryData",
1148
- value: function _processCountryData() {
1149
- // process onlyCountries or excludeCountries array if present
1150
- this._processAllCountries();
1151
- // process the countryCodes map
1152
- this._processCountryCodes();
1153
- // process the preferredCountries
1154
- this._processPreferredCountries();
1155
- // translate countries according to localizedCountries option
1156
- if (this.options.localizedCountries) this._translateCountriesByLocale();
1157
- // sort countries by name
1158
- if (this.options.onlyCountries.length || this.options.localizedCountries) {
1159
- this.countries.sort(this._countryNameSort);
1160
- }
1161
- }
1162
- }, {
1163
- key: "_addCountryCode",
1164
- value: function _addCountryCode(iso2, countryCode, priority) {
1165
- if (countryCode.length > this.countryCodeMaxLen) {
1166
- this.countryCodeMaxLen = countryCode.length;
1167
- }
1168
- if (!this.countryCodes.hasOwnProperty(countryCode)) {
1169
- this.countryCodes[countryCode] = [];
1170
- }
1171
- // bail if we already have this country for this countryCode
1172
- for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
1173
- if (this.countryCodes[countryCode][i] === iso2) return;
1174
- }
1175
- // check for undefined as 0 is falsy
1176
- var index = priority !== undefined$1 ? priority : this.countryCodes[countryCode].length;
1177
- this.countryCodes[countryCode][index] = iso2;
1178
- }
1179
- }, {
1180
- key: "_processAllCountries",
1181
- value: function _processAllCountries() {
1182
- if (this.options.onlyCountries.length) {
1183
- var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
1184
- return country.toLowerCase();
1185
- });
1186
- this.countries = allCountries.filter(function(country) {
1187
- return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
1188
- });
1189
- } else if (this.options.excludeCountries.length) {
1190
- var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
1191
- return country.toLowerCase();
1192
- });
1193
- this.countries = allCountries.filter(function(country) {
1194
- return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
1195
- });
1196
- } else {
1197
- this.countries = allCountries;
1198
- }
1199
- }
1200
- }, {
1201
- key: "_translateCountriesByLocale",
1202
- value: function _translateCountriesByLocale() {
1203
- for (var i = 0; i < this.countries.length; i++) {
1204
- var iso = this.countries[i].iso2.toLowerCase();
1205
- if (this.options.localizedCountries.hasOwnProperty(iso)) {
1206
- this.countries[i].name = this.options.localizedCountries[iso];
1207
- }
1208
- }
1209
- }
1210
- }, {
1211
- key: "_countryNameSort",
1212
- value: function _countryNameSort(a, b) {
1213
- return a.name.localeCompare(b.name);
1214
- }
1215
- }, {
1216
- key: "_processCountryCodes",
1217
- value: function _processCountryCodes() {
1218
- this.countryCodeMaxLen = 0;
1219
- // here we store just dial codes
1220
- this.dialCodes = {};
1221
- // here we store "country codes" (both dial codes and their area codes)
1222
- this.countryCodes = {};
1223
- // first: add dial codes
1224
- for (var i = 0; i < this.countries.length; i++) {
1225
- var c = this.countries[i];
1226
- if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
1227
- this._addCountryCode(c.iso2, c.dialCode, c.priority);
1228
- }
1229
- // next: add area codes
1230
- // this is a second loop over countries, to make sure we have all of the "root" countries
1231
- // already in the map, so that we can access them, as each time we add an area code substring
1232
- // to the map, we also need to include the "root" country's code, as that also matches
1233
- for (var _i = 0; _i < this.countries.length; _i++) {
1234
- var _c = this.countries[_i];
1235
- // area codes
1236
- if (_c.areaCodes) {
1237
- var rootCountryCode = this.countryCodes[_c.dialCode][0];
1238
- // for each area code
1239
- for (var j = 0; j < _c.areaCodes.length; j++) {
1240
- var areaCode = _c.areaCodes[j];
1241
- // for each digit in the area code to add all partial matches as well
1242
- for (var k = 1; k < areaCode.length; k++) {
1243
- var partialDialCode = _c.dialCode + areaCode.substr(0, k);
1244
- // start with the root country, as that also matches this dial code
1245
- this._addCountryCode(rootCountryCode, partialDialCode);
1246
- this._addCountryCode(_c.iso2, partialDialCode);
1247
- }
1248
- // add the full area code
1249
- this._addCountryCode(_c.iso2, _c.dialCode + areaCode);
1250
- }
1251
- }
1252
- }
1253
- }
1254
- }, {
1255
- key: "_processPreferredCountries",
1256
- value: function _processPreferredCountries() {
1257
- this.preferredCountries = [];
1258
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
1259
- var countryCode = this.options.preferredCountries[i].toLowerCase();
1260
- var countryData = this._getCountryData(countryCode, false, true);
1261
- if (countryData) this.preferredCountries.push(countryData);
1262
- }
1263
- }
1264
- }, {
1265
- key: "_createEl",
1266
- value: function _createEl(name, attrs, container) {
1267
- var el = document.createElement(name);
1268
- if (attrs) forEachProp(attrs, function(key, value) {
1269
- return el.setAttribute(key, value);
1270
- });
1271
- if (container) container.appendChild(el);
1272
- return el;
1273
- }
1274
- }, {
1275
- key: "_generateMarkup",
1276
- value: function _generateMarkup() {
1277
- // if autocomplete does not exist on the element and its form, then
1278
- // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
1279
- // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
1280
- // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
1281
- if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1282
- this.telInput.setAttribute("autocomplete", "off");
1283
- }
1284
- // containers (mostly for positioning)
1285
- var parentClass = "iti";
1286
- if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
1287
- if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
1288
- if (this.options.customContainer) {
1289
- parentClass += " ";
1290
- parentClass += this.options.customContainer;
1291
- }
1292
- var wrapper = this._createEl("div", {
1293
- "class": parentClass
1294
- });
1295
- this.telInput.parentNode.insertBefore(wrapper, this.telInput);
1296
- this.flagsContainer = this._createEl("div", {
1297
- "class": "iti__flag-container"
1298
- }, wrapper);
1299
- wrapper.appendChild(this.telInput);
1300
- // selected flag (displayed to left of input)
1301
- this.selectedFlag = this._createEl("div", {
1302
- "class": "iti__selected-flag",
1303
- role: "combobox",
1304
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
1305
- "aria-owns": "iti-".concat(this.id, "__country-listbox"),
1306
- "aria-expanded": "false"
1307
- }, this.flagsContainer);
1308
- this.selectedFlagInner = this._createEl("div", {
1309
- "class": "iti__flag"
1310
- }, this.selectedFlag);
1311
- if (this.options.separateDialCode) {
1312
- this.selectedDialCode = this._createEl("div", {
1313
- "class": "iti__selected-dial-code"
1314
- }, this.selectedFlag);
1315
- }
1316
- if (this.options.allowDropdown) {
1317
- // make element focusable and tab navigable
1318
- this.selectedFlag.setAttribute("tabindex", "0");
1319
- this.dropdownArrow = this._createEl("div", {
1320
- "class": "iti__arrow"
1321
- }, this.selectedFlag);
1322
- // country dropdown: preferred countries, then divider, then all countries
1323
- this.countryList = this._createEl("ul", {
1324
- "class": "iti__country-list iti__hide",
1325
- id: "iti-".concat(this.id, "__country-listbox"),
1326
- role: "listbox",
1327
- "aria-label": "List of countries"
1328
- });
1329
- if (this.preferredCountries.length) {
1330
- this._appendListItems(this.preferredCountries, "iti__preferred", true);
1331
- this._createEl("li", {
1332
- "class": "iti__divider",
1333
- role: "separator",
1334
- "aria-disabled": "true"
1335
- }, this.countryList);
1336
- }
1337
- this._appendListItems(this.countries, "iti__standard");
1338
- // create dropdownContainer markup
1339
- if (this.options.dropdownContainer) {
1340
- this.dropdown = this._createEl("div", {
1341
- "class": "iti iti--container"
1342
- });
1343
- this.dropdown.appendChild(this.countryList);
1344
- } else {
1345
- this.flagsContainer.appendChild(this.countryList);
1346
- }
1347
- }
1348
- if (this.options.hiddenInput) {
1349
- var hiddenInputName = this.options.hiddenInput;
1350
- var name = this.telInput.getAttribute("name");
1351
- if (name) {
1352
- var i = name.lastIndexOf("[");
1353
- // if input name contains square brackets, then give the hidden input the same name,
1354
- // replacing the contents of the last set of brackets with the given hiddenInput name
1355
- if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
1356
- }
1357
- this.hiddenInput = this._createEl("input", {
1358
- type: "hidden",
1359
- name: hiddenInputName
1360
- });
1361
- wrapper.appendChild(this.hiddenInput);
1362
- }
1363
- }
1364
- }, {
1365
- key: "_appendListItems",
1366
- value: function _appendListItems(countries, className, preferred) {
1367
- // we create so many DOM elements, it is faster to build a temp string
1368
- // and then add everything to the DOM in one go at the end
1369
- var tmp = "";
1370
- // for each country
1371
- for (var i = 0; i < countries.length; i++) {
1372
- var c = countries[i];
1373
- var idSuffix = preferred ? "-preferred" : "";
1374
- // open the list item
1375
- 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'>");
1376
- // add the flag
1377
- tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
1378
- // and the country name and dial code
1379
- tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
1380
- tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
1381
- // close the list item
1382
- tmp += "</li>";
1383
- }
1384
- this.countryList.insertAdjacentHTML("beforeend", tmp);
1385
- }
1386
- }, {
1387
- key: "_setInitialState",
1388
- value: function _setInitialState() {
1389
- // fix firefox bug: when first load page (with input with value set to number with intl dial
1390
- // code) and initialising plugin removes the dial code from the input, then refresh page,
1391
- // and we try to init plugin again but this time on number without dial code so get grey flag
1392
- var attributeValue = this.telInput.getAttribute("value");
1393
- var inputValue = this.telInput.value;
1394
- var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
1395
- var val = useAttribute ? attributeValue : inputValue;
1396
- var dialCode = this._getDialCode(val);
1397
- var isRegionlessNanp = this._isRegionlessNanp(val);
1398
- var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
1399
- // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
1400
- // flag, else fall back to the default country
1401
- if (dialCode && !isRegionlessNanp) {
1402
- this._updateFlagFromNumber(val);
1403
- } else if (initialCountry !== "auto") {
1404
- // see if we should select a flag
1405
- if (initialCountry) {
1406
- this._setFlag(initialCountry.toLowerCase());
1407
- } else {
1408
- if (dialCode && isRegionlessNanp) {
1409
- // has intl dial code, is regionless nanp, and no initialCountry, so default to US
1410
- this._setFlag("us");
1411
- } else {
1412
- // no dial code and no initialCountry, so default to first in list
1413
- this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
1414
- if (!val) {
1415
- this._setFlag(this.defaultCountry);
1416
- }
1417
- }
1418
- }
1419
- // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
1420
- if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
1421
- this.telInput.value = "+".concat(this.selectedCountryData.dialCode);
1422
- }
1423
- }
1424
- // NOTE: if initialCountry is set to auto, that will be handled separately
1425
- // format - note this wont be run after _updateDialCode as that's only called if no val
1426
- if (val) this._updateValFromNumber(val);
1427
- }
1428
- }, {
1429
- key: "_initListeners",
1430
- value: function _initListeners() {
1431
- this._initKeyListeners();
1432
- if (this.options.autoHideDialCode) this._initBlurListeners();
1433
- if (this.options.allowDropdown) this._initDropdownListeners();
1434
- if (this.hiddenInput) this._initHiddenInputListener();
1435
- }
1436
- }, {
1437
- key: "_initHiddenInputListener",
1438
- value: function _initHiddenInputListener() {
1439
- var _this3 = this;
1440
- this._handleHiddenInputSubmit = function() {
1441
- _this3.hiddenInput.value = _this3.getNumber();
1442
- };
1443
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
1444
- }
1445
- }, {
1446
- key: "_getClosestLabel",
1447
- value: function _getClosestLabel() {
1448
- var el = this.telInput;
1449
- while (el && el.tagName !== "LABEL") {
1450
- el = el.parentNode;
1451
- }
1452
- return el;
1453
- }
1454
- }, {
1455
- key: "_initDropdownListeners",
1456
- value: function _initDropdownListeners() {
1457
- var _this4 = this;
1458
- // hack for input nested inside label (which is valid markup): clicking the selected-flag to
1459
- // open the dropdown would then automatically trigger a 2nd click on the input which would
1460
- // close it again
1461
- this._handleLabelClick = function(e) {
1462
- // if the dropdown is closed, then focus the input, else ignore the click
1463
- if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
1464
- };
1465
- var label = this._getClosestLabel();
1466
- if (label) label.addEventListener("click", this._handleLabelClick);
1467
- // toggle country dropdown on click
1468
- this._handleClickSelectedFlag = function() {
1469
- // only intercept this event if we're opening the dropdown
1470
- // else let it bubble up to the top ("click-off-to-close" listener)
1471
- // we cannot just stopPropagation as it may be needed to close another instance
1472
- if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
1473
- _this4._showDropdown();
1474
- }
1475
- };
1476
- this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
1477
- // open dropdown list if currently focused
1478
- this._handleFlagsContainerKeydown = function(e) {
1479
- var isDropdownHidden = _this4.countryList.classList.contains("iti__hide");
1480
- if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) {
1481
- // prevent form from being submitted if "ENTER" was pressed
1482
- e.preventDefault();
1483
- // prevent event from being handled again by document
1484
- e.stopPropagation();
1485
- _this4._showDropdown();
1486
- }
1487
- // allow navigation from dropdown to input on TAB
1488
- if (e.key === "Tab") _this4._closeDropdown();
1489
- };
1490
- this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
1491
- }
1492
- }, {
1493
- key: "_initRequests",
1494
- value: function _initRequests() {
1495
- var _this5 = this;
1496
- // if the user has specified the path to the utils script, fetch it on window.load, else resolve
1497
- if (this.options.utilsScript && !window.intlTelInputUtils) {
1498
- // if the plugin is being initialised after the window.load event has already been fired
1499
- if (window.intlTelInputGlobals.documentReady()) {
1500
- window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
1501
- } else {
1502
- // wait until the load event so we don't block any other requests e.g. the flags image
1503
- window.addEventListener("load", function() {
1504
- window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
1505
- });
1506
- }
1507
- } else this.resolveUtilsScriptPromise();
1508
- if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
1509
- }
1510
- }, {
1511
- key: "_loadAutoCountry",
1512
- value: function _loadAutoCountry() {
1513
- // 3 options:
1514
- // 1) already loaded (we're done)
1515
- // 2) not already started loading (start)
1516
- // 3) already started loading (do nothing - just wait for loading callback to fire)
1517
- if (window.intlTelInputGlobals.autoCountry) {
1518
- this.handleAutoCountry();
1519
- } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
1520
- // don't do this twice!
1521
- window.intlTelInputGlobals.startedLoadingAutoCountry = true;
1522
- if (typeof this.options.geoIpLookup === "function") {
1523
- this.options.geoIpLookup(function(countryCode) {
1524
- window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase();
1525
- // tell all instances the auto country is ready
1526
- // TODO: this should just be the current instances
1527
- // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
1528
- // away (e.g. if they have already done the geo ip lookup somewhere else). Using
1529
- // setTimeout means that the current thread of execution will finish before executing
1530
- // this, which allows the plugin to finish initialising.
1531
- setTimeout(function() {
1532
- return forEachInstance("handleAutoCountry");
1533
- });
1534
- }, function() {
1535
- return forEachInstance("rejectAutoCountryPromise");
1536
- });
1537
- }
1538
- }
1539
- }
1540
- }, {
1541
- key: "_initKeyListeners",
1542
- value: function _initKeyListeners() {
1543
- var _this6 = this;
1544
- // update flag on keyup
1545
- this._handleKeyupEvent = function() {
1546
- if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
1547
- _this6._triggerCountryChange();
1548
- }
1549
- };
1550
- this.telInput.addEventListener("keyup", this._handleKeyupEvent);
1551
- // update flag on cut/paste events (now supported in all major browsers)
1552
- this._handleClipboardEvent = function() {
1553
- // hack because "paste" event is fired before input is updated
1554
- setTimeout(_this6._handleKeyupEvent);
1555
- };
1556
- this.telInput.addEventListener("cut", this._handleClipboardEvent);
1557
- this.telInput.addEventListener("paste", this._handleClipboardEvent);
1558
- }
1559
- }, {
1560
- key: "_cap",
1561
- value: function _cap(number) {
1562
- var max = this.telInput.getAttribute("maxlength");
1563
- return max && number.length > max ? number.substr(0, max) : number;
1564
- }
1565
- }, {
1566
- key: "_initBlurListeners",
1567
- value: function _initBlurListeners() {
1568
- var _this7 = this;
1569
- // on blur or form submit: if just a dial code then remove it
1570
- this._handleSubmitOrBlurEvent = function() {
1571
- _this7._removeEmptyDialCode();
1572
- };
1573
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
1574
- this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
1575
- }
1576
- }, {
1577
- key: "_removeEmptyDialCode",
1578
- value: function _removeEmptyDialCode() {
1579
- if (this.telInput.value.charAt(0) === "+") {
1580
- var numeric = this._getNumeric(this.telInput.value);
1581
- // if just a plus, or if just a dial code
1582
- if (!numeric || this.selectedCountryData.dialCode === numeric) {
1583
- this.telInput.value = "";
1584
- }
1585
- }
1586
- }
1587
- }, {
1588
- key: "_getNumeric",
1589
- value: function _getNumeric(s) {
1590
- return s.replace(/\D/g, "");
1591
- }
1592
- }, {
1593
- key: "_trigger",
1594
- value: function _trigger(name) {
1595
- // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
1596
- var e = document.createEvent("Event");
1597
- e.initEvent(name, true, true);
1598
- // can bubble, and is cancellable
1599
- this.telInput.dispatchEvent(e);
1600
- }
1601
- }, {
1602
- key: "_showDropdown",
1603
- value: function _showDropdown() {
1604
- this.countryList.classList.remove("iti__hide");
1605
- this.selectedFlag.setAttribute("aria-expanded", "true");
1606
- this._setDropdownPosition();
1607
- // update highlighting and scroll to active list item
1608
- if (this.activeItem) {
1609
- this._highlightListItem(this.activeItem, false);
1610
- this._scrollTo(this.activeItem, true);
1611
- }
1612
- // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
1613
- this._bindDropdownListeners();
1614
- // update the arrow
1615
- this.dropdownArrow.classList.add("iti__arrow--up");
1616
- this._trigger("open:countrydropdown");
1617
- }
1618
- }, {
1619
- key: "_toggleClass",
1620
- value: function _toggleClass(el, className, shouldHaveClass) {
1621
- if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
1622
- }
1623
- }, {
1624
- key: "_setDropdownPosition",
1625
- value: function _setDropdownPosition() {
1626
- var _this8 = this;
1627
- if (this.options.dropdownContainer) {
1628
- this.options.dropdownContainer.appendChild(this.dropdown);
1629
- }
1630
- if (!this.isMobile) {
1631
- var pos = this.telInput.getBoundingClientRect();
1632
- // windowTop from https://stackoverflow.com/a/14384091/217866
1633
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1634
- var inputTop = pos.top + windowTop;
1635
- var dropdownHeight = this.countryList.offsetHeight;
1636
- // dropdownFitsBelow = (dropdownBottom < windowBottom)
1637
- var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
1638
- var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
1639
- // by default, the dropdown will be below the input. If we want to position it above the
1640
- // input, we add the dropup class.
1641
- this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove);
1642
- // if dropdownContainer is enabled, calculate postion
1643
- if (this.options.dropdownContainer) {
1644
- // by default the dropdown will be directly over the input because it's not in the flow.
1645
- // If we want to position it below, we need to add some extra top value.
1646
- var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight;
1647
- // calculate placement
1648
- this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
1649
- this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
1650
- // close menu on window scroll
1651
- this._handleWindowScroll = function() {
1652
- return _this8._closeDropdown();
1653
- };
1654
- window.addEventListener("scroll", this._handleWindowScroll);
1655
- }
1656
- }
1657
- }
1658
- }, {
1659
- key: "_getClosestListItem",
1660
- value: function _getClosestListItem(target) {
1661
- var el = target;
1662
- while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
1663
- el = el.parentNode;
1664
- }
1665
- // if we reached the countryList element, then return null
1666
- return el === this.countryList ? null : el;
1667
- }
1668
- }, {
1669
- key: "_bindDropdownListeners",
1670
- value: function _bindDropdownListeners() {
1671
- var _this9 = this;
1672
- // when mouse over a list item, just highlight that one
1673
- // we add the class "highlight", so if they hit "enter" we know which one to select
1674
- this._handleMouseoverCountryList = function(e) {
1675
- // handle event delegation, as we're listening for this event on the countryList
1676
- var listItem = _this9._getClosestListItem(e.target);
1677
- if (listItem) _this9._highlightListItem(listItem, false);
1678
- };
1679
- this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
1680
- // listen for country selection
1681
- this._handleClickCountryList = function(e) {
1682
- var listItem = _this9._getClosestListItem(e.target);
1683
- if (listItem) _this9._selectListItem(listItem);
1684
- };
1685
- this.countryList.addEventListener("click", this._handleClickCountryList);
1686
- // click off to close
1687
- // (except when this initial opening click is bubbling up)
1688
- // we cannot just stopPropagation as it may be needed to close another instance
1689
- var isOpening = true;
1690
- this._handleClickOffToClose = function() {
1691
- if (!isOpening) _this9._closeDropdown();
1692
- isOpening = false;
1693
- };
1694
- document.documentElement.addEventListener("click", this._handleClickOffToClose);
1695
- // listen for up/down scrolling, enter to select, or letters to jump to country name.
1696
- // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
1697
- // just hit down and hold it to scroll down (no keyup event).
1698
- // listen on the document because that's where key events are triggered if no input has focus
1699
- var query = "";
1700
- var queryTimer = null;
1701
- this._handleKeydownOnDropdown = function(e) {
1702
- // prevent down key from scrolling the whole page,
1703
- // and enter key from submitting a form etc
1704
- e.preventDefault();
1705
- // up and down to navigate
1706
- 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)) {
1707
- // jump to countries that start with the query string
1708
- if (queryTimer) clearTimeout(queryTimer);
1709
- query += e.key.toLowerCase();
1710
- _this9._searchForCountry(query);
1711
- // if the timer hits 1 second, reset the query
1712
- queryTimer = setTimeout(function() {
1713
- query = "";
1714
- }, 1e3);
1715
- }
1716
- };
1717
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
1718
- }
1719
- }, {
1720
- key: "_handleUpDownKey",
1721
- value: function _handleUpDownKey(key) {
1722
- var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
1723
- if (next) {
1724
- // skip the divider
1725
- if (next.classList.contains("iti__divider")) {
1726
- next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling;
1727
- }
1728
- this._highlightListItem(next, true);
1729
- }
1730
- }
1731
- }, {
1732
- key: "_handleEnterKey",
1733
- value: function _handleEnterKey() {
1734
- if (this.highlightedItem) this._selectListItem(this.highlightedItem);
1735
- }
1736
- }, {
1737
- key: "_searchForCountry",
1738
- value: function _searchForCountry(query) {
1739
- for (var i = 0; i < this.countries.length; i++) {
1740
- if (this._startsWith(this.countries[i].name, query)) {
1741
- var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2));
1742
- // update highlighting and scroll
1743
- this._highlightListItem(listItem, false);
1744
- this._scrollTo(listItem, true);
1745
- break;
1746
- }
1747
- }
1748
- }
1749
- }, {
1750
- key: "_startsWith",
1751
- value: function _startsWith(a, b) {
1752
- return a.substr(0, b.length).toLowerCase() === b;
1753
- }
1754
- }, {
1755
- key: "_updateValFromNumber",
1756
- value: function _updateValFromNumber(originalNumber) {
1757
- var number = originalNumber;
1758
- if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
1759
- var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+");
1760
- var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
1761
- var format = useNational ? NATIONAL : INTERNATIONAL;
1762
- number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
1763
- }
1764
- number = this._beforeSetNumber(number);
1765
- this.telInput.value = number;
1766
- }
1767
- }, {
1768
- key: "_updateFlagFromNumber",
1769
- value: function _updateFlagFromNumber(originalNumber) {
1770
- // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
1771
- // with a +1 so _getDialCode will be able to extract the area code
1772
- // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
1773
- // from the number), that means we're initialising the plugin with a number that already has a
1774
- // dial code, so fine to ignore this bit
1775
- var number = originalNumber;
1776
- var selectedDialCode = this.selectedCountryData.dialCode;
1777
- var isNanp = selectedDialCode === "1";
1778
- if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
1779
- if (number.charAt(0) !== "1") number = "1".concat(number);
1780
- number = "+".concat(number);
1781
- }
1782
- // update flag if user types area code for another country
1783
- if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
1784
- number = "+".concat(selectedDialCode).concat(number);
1785
- }
1786
- // try and extract valid dial code from input
1787
- var dialCode = this._getDialCode(number, true);
1788
- var numeric = this._getNumeric(number);
1789
- var countryCode = null;
1790
- if (dialCode) {
1791
- var countryCodes = this.countryCodes[this._getNumeric(dialCode)];
1792
- // check if the right country is already selected. this should be false if the number is
1793
- // longer than the matched dial code because in this case we need to make sure that if
1794
- // there are multiple country matches, that the first one is selected (note: we could
1795
- // just check that here, but it requires the same loop that we already have later)
1796
- var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
1797
- var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
1798
- // only update the flag if:
1799
- // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
1800
- // AND
1801
- // B) the right country is not already selected
1802
- if (!isRegionlessNanpNumber && !alreadySelected) {
1803
- // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
1804
- // non-empty index
1805
- for (var j = 0; j < countryCodes.length; j++) {
1806
- if (countryCodes[j]) {
1807
- countryCode = countryCodes[j];
1808
- break;
1809
- }
1810
- }
1811
- }
1812
- } else if (number.charAt(0) === "+" && numeric.length) {
1813
- // invalid dial code, so empty
1814
- // Note: use getNumeric here because the number has not been formatted yet, so could contain
1815
- // bad chars
1816
- countryCode = "";
1817
- } else if (!number || number === "+") {
1818
- // empty, or just a plus, so default
1819
- countryCode = this.defaultCountry;
1820
- }
1821
- if (countryCode !== null) {
1822
- return this._setFlag(countryCode);
1823
- }
1824
- return false;
1825
- }
1826
- }, {
1827
- key: "_isRegionlessNanp",
1828
- value: function _isRegionlessNanp(number) {
1829
- var numeric = this._getNumeric(number);
1830
- if (numeric.charAt(0) === "1") {
1831
- var areaCode = numeric.substr(1, 3);
1832
- return regionlessNanpNumbers.indexOf(areaCode) !== -1;
1833
- }
1834
- return false;
1835
- }
1836
- }, {
1837
- key: "_highlightListItem",
1838
- value: function _highlightListItem(listItem, shouldFocus) {
1839
- var prevItem = this.highlightedItem;
1840
- if (prevItem) prevItem.classList.remove("iti__highlight");
1841
- this.highlightedItem = listItem;
1842
- this.highlightedItem.classList.add("iti__highlight");
1843
- if (shouldFocus) this.highlightedItem.focus();
1844
- }
1845
- }, {
1846
- key: "_getCountryData",
1847
- value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) {
1848
- var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
1849
- for (var i = 0; i < countryList.length; i++) {
1850
- if (countryList[i].iso2 === countryCode) {
1851
- return countryList[i];
1852
- }
1853
- }
1854
- if (allowFail) {
1855
- return null;
1856
- }
1857
- throw new Error("No country data for '".concat(countryCode, "'"));
1858
- }
1859
- }, {
1860
- key: "_setFlag",
1861
- value: function _setFlag(countryCode) {
1862
- var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
1863
- // do this first as it will throw an error and stop if countryCode is invalid
1864
- this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
1865
- // update the defaultCountry - we only need the iso2 from now on, so just store that
1866
- if (this.selectedCountryData.iso2) {
1867
- this.defaultCountry = this.selectedCountryData.iso2;
1868
- }
1869
- this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1870
- // update the selected country's title attribute
1871
- var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
1872
- this.selectedFlag.setAttribute("title", title);
1873
- if (this.options.separateDialCode) {
1874
- var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
1875
- this.selectedDialCode.innerHTML = dialCode;
1876
- // offsetWidth is zero if input is in a hidden container during initialisation
1877
- var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
1878
- // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
1879
- this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
1880
- }
1881
- // and the input's placeholder
1882
- this._updatePlaceholder();
1883
- // update the active list item
1884
- if (this.options.allowDropdown) {
1885
- var prevItem = this.activeItem;
1886
- if (prevItem) {
1887
- prevItem.classList.remove("iti__active");
1888
- prevItem.setAttribute("aria-selected", "false");
1889
- }
1890
- if (countryCode) {
1891
- // check if there is a preferred item first, else fall back to standard
1892
- var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode));
1893
- nextItem.setAttribute("aria-selected", "true");
1894
- nextItem.classList.add("iti__active");
1895
- this.activeItem = nextItem;
1896
- this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id"));
1897
- }
1898
- }
1899
- // return if the flag has changed or not
1900
- return prevCountry.iso2 !== countryCode;
1901
- }
1902
- }, {
1903
- key: "_getHiddenSelectedFlagWidth",
1904
- value: function _getHiddenSelectedFlagWidth() {
1905
- // to get the right styling to apply, all we need is a shallow clone of the container,
1906
- // and then to inject a deep clone of the selectedFlag element
1907
- var containerClone = this.telInput.parentNode.cloneNode();
1908
- containerClone.style.visibility = "hidden";
1909
- document.body.appendChild(containerClone);
1910
- var flagsContainerClone = this.flagsContainer.cloneNode();
1911
- containerClone.appendChild(flagsContainerClone);
1912
- var selectedFlagClone = this.selectedFlag.cloneNode(true);
1913
- flagsContainerClone.appendChild(selectedFlagClone);
1914
- var width = selectedFlagClone.offsetWidth;
1915
- containerClone.parentNode.removeChild(containerClone);
1916
- return width;
1917
- }
1918
- }, {
1919
- key: "_updatePlaceholder",
1920
- value: function _updatePlaceholder() {
1921
- var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite";
1922
- if (window.intlTelInputUtils && shouldSetPlaceholder) {
1923
- var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
1924
- var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
1925
- placeholder = this._beforeSetNumber(placeholder);
1926
- if (typeof this.options.customPlaceholder === "function") {
1927
- placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
1928
- }
1929
- this.telInput.setAttribute("placeholder", placeholder);
1930
- }
1931
- }
1932
- }, {
1933
- key: "_selectListItem",
1934
- value: function _selectListItem(listItem) {
1935
- // update selected flag and active list item
1936
- var flagChanged = this._setFlag(listItem.getAttribute("data-country-code"));
1937
- this._closeDropdown();
1938
- this._updateDialCode(listItem.getAttribute("data-dial-code"), true);
1939
- // focus the input
1940
- this.telInput.focus();
1941
- // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
1942
- // inserting dial code), who try to put the cursor at the beginning the first time
1943
- var len = this.telInput.value.length;
1944
- this.telInput.setSelectionRange(len, len);
1945
- if (flagChanged) {
1946
- this._triggerCountryChange();
1947
- }
1948
- }
1949
- }, {
1950
- key: "_closeDropdown",
1951
- value: function _closeDropdown() {
1952
- this.countryList.classList.add("iti__hide");
1953
- this.selectedFlag.setAttribute("aria-expanded", "false");
1954
- // update the arrow
1955
- this.dropdownArrow.classList.remove("iti__arrow--up");
1956
- // unbind key events
1957
- document.removeEventListener("keydown", this._handleKeydownOnDropdown);
1958
- document.documentElement.removeEventListener("click", this._handleClickOffToClose);
1959
- this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
1960
- this.countryList.removeEventListener("click", this._handleClickCountryList);
1961
- // remove menu from container
1962
- if (this.options.dropdownContainer) {
1963
- if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
1964
- if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
1965
- }
1966
- this._trigger("close:countrydropdown");
1967
- }
1968
- }, {
1969
- key: "_scrollTo",
1970
- value: function _scrollTo(element, middle) {
1971
- var container = this.countryList;
1972
- // windowTop from https://stackoverflow.com/a/14384091/217866
1973
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1974
- var containerHeight = container.offsetHeight;
1975
- var containerTop = container.getBoundingClientRect().top + windowTop;
1976
- var containerBottom = containerTop + containerHeight;
1977
- var elementHeight = element.offsetHeight;
1978
- var elementTop = element.getBoundingClientRect().top + windowTop;
1979
- var elementBottom = elementTop + elementHeight;
1980
- var newScrollTop = elementTop - containerTop + container.scrollTop;
1981
- var middleOffset = containerHeight / 2 - elementHeight / 2;
1982
- if (elementTop < containerTop) {
1983
- // scroll up
1984
- if (middle) newScrollTop -= middleOffset;
1985
- container.scrollTop = newScrollTop;
1986
- } else if (elementBottom > containerBottom) {
1987
- // scroll down
1988
- if (middle) newScrollTop += middleOffset;
1989
- var heightDifference = containerHeight - elementHeight;
1990
- container.scrollTop = newScrollTop - heightDifference;
1991
- }
1992
- }
1993
- }, {
1994
- key: "_updateDialCode",
1995
- value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) {
1996
- var inputVal = this.telInput.value;
1997
- // save having to pass this every time
1998
- var newDialCode = "+".concat(newDialCodeBare);
1999
- var newNumber;
2000
- if (inputVal.charAt(0) === "+") {
2001
- // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
2002
- var prevDialCode = this._getDialCode(inputVal);
2003
- if (prevDialCode) {
2004
- // current number contains a valid dial code, so replace it
2005
- newNumber = inputVal.replace(prevDialCode, newDialCode);
2006
- } else {
2007
- // current number contains an invalid dial code, so ditch it
2008
- // (no way to determine where the invalid dial code ends and the rest of the number begins)
2009
- newNumber = newDialCode;
2010
- }
2011
- } else if (this.options.nationalMode || this.options.separateDialCode) {
2012
- // don't do anything
2013
- return;
2014
- } else {
2015
- // nationalMode is disabled
2016
- if (inputVal) {
2017
- // there is an existing value with no dial code: prefix the new dial code
2018
- newNumber = newDialCode + inputVal;
2019
- } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
2020
- // no existing value and either they've just selected a list item, or autoHideDialCode is
2021
- // disabled: insert new dial code
2022
- newNumber = newDialCode;
2023
- } else {
2024
- return;
2025
- }
2026
- }
2027
- this.telInput.value = newNumber;
2028
- }
2029
- }, {
2030
- key: "_getDialCode",
2031
- value: function _getDialCode(number, includeAreaCode) {
2032
- var dialCode = "";
2033
- // only interested in international numbers (starting with a plus)
2034
- if (number.charAt(0) === "+") {
2035
- var numericChars = "";
2036
- // iterate over chars
2037
- for (var i = 0; i < number.length; i++) {
2038
- var c = number.charAt(i);
2039
- // if char is number (https://stackoverflow.com/a/8935649/217866)
2040
- if (!isNaN(parseInt(c, 10))) {
2041
- numericChars += c;
2042
- // if current numericChars make a valid dial code
2043
- if (includeAreaCode) {
2044
- if (this.countryCodes[numericChars]) {
2045
- // store the actual raw string (useful for matching later)
2046
- dialCode = number.substr(0, i + 1);
2047
- }
2048
- } else {
2049
- if (this.dialCodes[numericChars]) {
2050
- dialCode = number.substr(0, i + 1);
2051
- // if we're just looking for a dial code, we can break as soon as we find one
2052
- break;
2053
- }
2054
- }
2055
- // stop searching as soon as we can - in this case when we hit max len
2056
- if (numericChars.length === this.countryCodeMaxLen) {
2057
- break;
2058
- }
2059
- }
2060
- }
2061
- }
2062
- return dialCode;
2063
- }
2064
- }, {
2065
- key: "_getFullNumber",
2066
- value: function _getFullNumber() {
2067
- var val = this.telInput.value.trim();
2068
- var dialCode = this.selectedCountryData.dialCode;
2069
- var prefix;
2070
- var numericVal = this._getNumeric(val);
2071
- if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
2072
- // when using separateDialCode, it is visible so is effectively part of the typed number
2073
- prefix = "+".concat(dialCode);
2074
- } else {
2075
- prefix = "";
2076
- }
2077
- return prefix + val;
2078
- }
2079
- }, {
2080
- key: "_beforeSetNumber",
2081
- value: function _beforeSetNumber(originalNumber) {
2082
- var number = originalNumber;
2083
- if (this.options.separateDialCode) {
2084
- var dialCode = this._getDialCode(number);
2085
- // if there is a valid dial code
2086
- if (dialCode) {
2087
- // in case _getDialCode returned an area code as well
2088
- dialCode = "+".concat(this.selectedCountryData.dialCode);
2089
- // a lot of numbers will have a space separating the dial code and the main number, and
2090
- // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
2091
- // rid of it
2092
- // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
2093
- var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2094
- number = number.substr(start);
2095
- }
2096
- }
2097
- return this._cap(number);
2098
- }
2099
- }, {
2100
- key: "_triggerCountryChange",
2101
- value: function _triggerCountryChange() {
2102
- this._trigger("countrychange");
2103
- }
2104
- }, {
2105
- key: "handleAutoCountry",
2106
- value: function handleAutoCountry() {
2107
- if (this.options.initialCountry === "auto") {
2108
- // we must set this even if there is an initial val in the input: in case the initial val is
2109
- // invalid and they delete it - they should see their auto country
2110
- this.defaultCountry = window.intlTelInputGlobals.autoCountry;
2111
- // if there's no initial value in the input, then update the flag
2112
- if (!this.telInput.value) {
2113
- this.setCountry(this.defaultCountry);
2114
- }
2115
- this.resolveAutoCountryPromise();
2116
- }
2117
- }
2118
- }, {
2119
- key: "handleUtils",
2120
- value: function handleUtils() {
2121
- // if the request was successful
2122
- if (window.intlTelInputUtils) {
2123
- // if there's an initial value in the input, then format it
2124
- if (this.telInput.value) {
2125
- this._updateValFromNumber(this.telInput.value);
2126
- }
2127
- this._updatePlaceholder();
2128
- }
2129
- this.resolveUtilsScriptPromise();
2130
- }
2131
- }, {
2132
- key: "destroy",
2133
- value: function destroy() {
2134
- var form = this.telInput.form;
2135
- if (this.options.allowDropdown) {
2136
- // make sure the dropdown is closed (and unbind listeners)
2137
- this._closeDropdown();
2138
- this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
2139
- this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
2140
- // label click hack
2141
- var label = this._getClosestLabel();
2142
- if (label) label.removeEventListener("click", this._handleLabelClick);
2143
- }
2144
- // unbind hiddenInput listeners
2145
- if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
2146
- // unbind autoHideDialCode listeners
2147
- if (this.options.autoHideDialCode) {
2148
- if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
2149
- this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
2150
- }
2151
- // unbind key events, and cut/paste events
2152
- this.telInput.removeEventListener("keyup", this._handleKeyupEvent);
2153
- this.telInput.removeEventListener("cut", this._handleClipboardEvent);
2154
- this.telInput.removeEventListener("paste", this._handleClipboardEvent);
2155
- // remove attribute of id instance: data-intl-tel-input-id
2156
- this.telInput.removeAttribute("data-intl-tel-input-id");
2157
- // remove markup (but leave the original input)
2158
- var wrapper = this.telInput.parentNode;
2159
- wrapper.parentNode.insertBefore(this.telInput, wrapper);
2160
- wrapper.parentNode.removeChild(wrapper);
2161
- delete window.intlTelInputGlobals.instances[this.id];
2162
- }
2163
- }, {
2164
- key: "getExtension",
2165
- value: function getExtension() {
2166
- if (window.intlTelInputUtils) {
2167
- return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
2168
- }
2169
- return "";
2170
- }
2171
- }, {
2172
- key: "getNumber",
2173
- value: function getNumber(format) {
2174
- if (window.intlTelInputUtils) {
2175
- var iso2 = this.selectedCountryData.iso2;
2176
- return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
2177
- }
2178
- return "";
2179
- }
2180
- }, {
2181
- key: "getNumberType",
2182
- value: function getNumberType() {
2183
- if (window.intlTelInputUtils) {
2184
- return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
2185
- }
2186
- return -99;
2187
- }
2188
- }, {
2189
- key: "getSelectedCountryData",
2190
- value: function getSelectedCountryData() {
2191
- return this.selectedCountryData;
2192
- }
2193
- }, {
2194
- key: "getValidationError",
2195
- value: function getValidationError() {
2196
- if (window.intlTelInputUtils) {
2197
- var iso2 = this.selectedCountryData.iso2;
2198
- return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
2199
- }
2200
- return -99;
2201
- }
2202
- }, {
2203
- key: "isValidNumber",
2204
- value: function isValidNumber() {
2205
- var val = this._getFullNumber().trim();
2206
- var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
2207
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
2208
- }
2209
- }, {
2210
- key: "setCountry",
2211
- value: function setCountry(originalCountryCode) {
2212
- var countryCode = originalCountryCode.toLowerCase();
2213
- // check if already selected
2214
- if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
2215
- this._setFlag(countryCode);
2216
- this._updateDialCode(this.selectedCountryData.dialCode, false);
2217
- this._triggerCountryChange();
2218
- }
2219
- }
2220
- }, {
2221
- key: "setNumber",
2222
- value: function setNumber(number) {
2223
- // we must update the flag first, which updates this.selectedCountryData, which is used for
2224
- // formatting the number before displaying it
2225
- var flagChanged = this._updateFlagFromNumber(number);
2226
- this._updateValFromNumber(number);
2227
- if (flagChanged) {
2228
- this._triggerCountryChange();
2229
- }
2230
- }
2231
- }, {
2232
- key: "setPlaceholderNumberType",
2233
- value: function setPlaceholderNumberType(type) {
2234
- this.options.placeholderNumberType = type;
2235
- this._updatePlaceholder();
2236
- }
2237
- } ]);
2238
- return Iti;
2239
- }();
2240
- /********************
2241
- * STATIC METHODS
2242
- ********************/
2243
- // get the country data object
2244
- intlTelInputGlobals.getCountryData = function() {
2245
- return allCountries;
2246
- };
2247
- // inject a <script> element to load utils.js
2248
- var injectScript = function injectScript(path, handleSuccess, handleFailure) {
2249
- // inject a new script element into the page
2250
- var script = document.createElement("script");
2251
- script.onload = function() {
2252
- forEachInstance("handleUtils");
2253
- if (handleSuccess) handleSuccess();
2254
- };
2255
- script.onerror = function() {
2256
- forEachInstance("rejectUtilsScriptPromise");
2257
- if (handleFailure) handleFailure();
2258
- };
2259
- script.className = "iti-load-utils";
2260
- script.async = true;
2261
- script.src = path;
2262
- document.body.appendChild(script);
2263
- };
2264
- // load the utils script
2265
- intlTelInputGlobals.loadUtils = function(path) {
2266
- // 2 options:
2267
- // 1) not already started loading (start)
2268
- // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
2269
- // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
2270
- if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
2271
- // only do this once
2272
- window.intlTelInputGlobals.startedLoadingUtilsScript = true;
2273
- // if we have promises, then return a promise
2274
- if (typeof Promise !== "undefined") {
2275
- return new Promise(function(resolve, reject) {
2276
- return injectScript(path, resolve, reject);
2277
- });
2278
- }
2279
- injectScript(path);
2280
- }
2281
- return null;
2282
- };
2283
- // default options
2284
- intlTelInputGlobals.defaults = defaults;
2285
- // version
2286
- intlTelInputGlobals.version = "17.0.18";
2287
- // convenience wrapper
2288
- return function(input, options) {
2289
- var iti = new Iti(input, options);
2290
- iti._init();
2291
- input.setAttribute("data-intl-tel-input-id", iti.id);
2292
- window.intlTelInputGlobals.instances[iti.id] = iti;
2293
- return iti;
2294
- };
2295
- }();
2296
- });
2297
- });
2298
-
2299
- /**
2300
- * Exposing intl-tel-input as a component
2301
- */
2302
- var intlTelInput = intlTelInput$1;
2303
-
2304
- const sallaTelInputCss = ".iti{width:100%;position:relative;display:inline-block}.iti *{box-sizing:border-box;-moz-box-sizing:border-box}.iti__hide{display:none}.iti__v-hide{visibility:hidden}.iti input,.iti input[type=text],.iti input[type=tel]{position:relative;z-index:0;direction:ltr !important;margin-top:0 !important;margin-bottom:0 !important;padding-left:95px !important;padding-right:15px !important;margin-left:0 !important}.iti__flag-container{width:100%;position:absolute;top:0;bottom:0;left:0;padding:1px}.iti__selected-flag{width:80px;z-index:1;position:relative;display:flex;align-items:center;height:100%;float:left;padding:0 15px;box-shadow:none !important;outline:none !important}.ltr .iti__selected-flag{justify-content:flex-end}.iti__selected-flag:before{content:\"\";display:block;width:1px;height:70%;background:#eee;position:absolute;top:15%;right:0}.iti__selected-flag .iti__flag{display:none}.iti__arrow{width:15px;height:15px;line-height:15px;position:absolute;left:10px;top:50%;transform:translateY(-50%)}.iti__arrow:after{content:\"\\e96d\";font-family:sallaicons;font-size:16px;color:#999;opacity:0.65}.iti__arrow--up:after{transform:rotate(180deg)}.iti__country-list{width:100%;max-height:160px;position:absolute;top:100%;left:0;z-index:2;list-style:none;margin:0;padding:0;margin:5px 0 0 0;border-radius:5px;box-shadow:0px 2px 4px 2px rgba(0, 0, 0, 0.05);border:1px solid #f5f7f9;background-color:white;white-space:nowrap;overflow:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch}.iti__country-list::-webkit-scrollbar{width:4px}.dark .iti__country-list{background-color:#52525b;border-color:#52525b}.iti__country-list li{display:flex;align-items:center;justify-content:flex-start;flex-direction:row;padding:8px 10px;transition:background-color 0.3s}.iti__country-list li span{font-size:12px}.iti__country-list li:hover,.iti__country-list li.highlighted{background-color:rgba(0, 0, 0, 0.05)}.iti__country-list--dropup{bottom:100%;top:unset;margin:0 0 5px 0}@media (max-width: 500px){.iti__country-list{white-space:normal}}.iti__flag-box{display:inline-block;width:20px;margin:0 0 0 5px}.iti__divider{padding-bottom:5px;margin-bottom:5px;border-bottom:1px solid #eee}.iti__country{padding:5px 10px;outline:none}.iti__dial-code{font-family:Arial;color:#999;unicode-bidi:plaintext;letter-spacing:1px}.iti__country.iti__highlight{background-color:rgba(0, 0, 0, 0.05)}.iti__flag-box,.iti__country-name,.iti__dial-code{vertical-align:middle}.iti__country-name{flex:auto;margin:0;padding:0 10px;white-space:normal;line-height:1.3}.iti--allow-dropdown .iti__flag-container,.iti--separate-dial-code .iti__flag-container{left:0}.iti--allow-dropdown .iti__flag-container:hover{cursor:pointer}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover{cursor:default}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover .iti__selected-flag,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover .iti__selected-flag{background-color:transparent}.iti--separate-dial-code .iti__selected-dial-code{unicode-bidi:plaintext;direction:ltr;letter-spacing:1px;font-family:\"Arial\", serif;font-size:13px}.iti--container{position:absolute;top:-1000px;z-index:1060;padding:1px}.iti--container:hover{cursor:pointer}.iti-mobile .iti--container{inset:0;margin:20px;width:calc(100% - 40px);position:fixed;z-index:9999}.iti-mobile .iti__country-list{max-height:100%;width:100%;inset:0}.iti-mobile .iti__country{padding:10px 10px;line-height:1.5em}.iti__flag{width:20px}.iti__flag.iti__be{width:18px}.iti__flag.iti__ch{width:15px}.iti__flag.iti__mc{width:19px}.iti__flag.iti__ne{width:18px}.iti__flag.iti__np{width:13px}.iti__flag.iti__va{width:15px}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-size:5652px 15px}}.iti__flag.iti__ac{height:10px;background-position:0px 0px}.iti__flag.iti__ad{height:14px;background-position:-22px 0px}.iti__flag.iti__ae{height:10px;background-position:-44px 0px}.iti__flag.iti__af{height:14px;background-position:-66px 0px}.iti__flag.iti__ag{height:14px;background-position:-88px 0px}.iti__flag.iti__ai{height:10px;background-position:-110px 0px}.iti__flag.iti__al{height:15px;background-position:-132px 0px}.iti__flag.iti__am{height:10px;background-position:-154px 0px}.iti__flag.iti__ao{height:14px;background-position:-176px 0px}.iti__flag.iti__aq{height:14px;background-position:-198px 0px}.iti__flag.iti__ar{height:13px;background-position:-220px 0px}.iti__flag.iti__as{height:10px;background-position:-242px 0px}.iti__flag.iti__at{height:14px;background-position:-264px 0px}.iti__flag.iti__au{height:10px;background-position:-286px 0px}.iti__flag.iti__aw{height:14px;background-position:-308px 0px}.iti__flag.iti__ax{height:13px;background-position:-330px 0px}.iti__flag.iti__az{height:10px;background-position:-352px 0px}.iti__flag.iti__ba{height:10px;background-position:-374px 0px}.iti__flag.iti__bb{height:14px;background-position:-396px 0px}.iti__flag.iti__bd{height:12px;background-position:-418px 0px}.iti__flag.iti__be{height:15px;background-position:-440px 0px}.iti__flag.iti__bf{height:14px;background-position:-460px 0px}.iti__flag.iti__bg{height:12px;background-position:-482px 0px}.iti__flag.iti__bh{height:12px;background-position:-504px 0px}.iti__flag.iti__bi{height:12px;background-position:-526px 0px}.iti__flag.iti__bj{height:14px;background-position:-548px 0px}.iti__flag.iti__bl{height:14px;background-position:-570px 0px}.iti__flag.iti__bm{height:10px;background-position:-592px 0px}.iti__flag.iti__bn{height:10px;background-position:-614px 0px}.iti__flag.iti__bo{height:14px;background-position:-636px 0px}.iti__flag.iti__bq{height:14px;background-position:-658px 0px}.iti__flag.iti__br{height:14px;background-position:-680px 0px}.iti__flag.iti__bs{height:10px;background-position:-702px 0px}.iti__flag.iti__bt{height:14px;background-position:-724px 0px}.iti__flag.iti__bv{height:15px;background-position:-746px 0px}.iti__flag.iti__bw{height:14px;background-position:-768px 0px}.iti__flag.iti__by{height:10px;background-position:-790px 0px}.iti__flag.iti__bz{height:14px;background-position:-812px 0px}.iti__flag.iti__ca{height:10px;background-position:-834px 0px}.iti__flag.iti__cc{height:10px;background-position:-856px 0px}.iti__flag.iti__cd{height:15px;background-position:-878px 0px}.iti__flag.iti__cf{height:14px;background-position:-900px 0px}.iti__flag.iti__cg{height:14px;background-position:-922px 0px}.iti__flag.iti__ch{height:15px;background-position:-944px 0px}.iti__flag.iti__ci{height:14px;background-position:-961px 0px}.iti__flag.iti__ck{height:10px;background-position:-983px 0px}.iti__flag.iti__cl{height:14px;background-position:-1005px 0px}.iti__flag.iti__cm{height:14px;background-position:-1027px 0px}.iti__flag.iti__cn{height:14px;background-position:-1049px 0px}.iti__flag.iti__co{height:14px;background-position:-1071px 0px}.iti__flag.iti__cp{height:14px;background-position:-1093px 0px}.iti__flag.iti__cr{height:12px;background-position:-1115px 0px}.iti__flag.iti__cu{height:10px;background-position:-1137px 0px}.iti__flag.iti__cv{height:12px;background-position:-1159px 0px}.iti__flag.iti__cw{height:14px;background-position:-1181px 0px}.iti__flag.iti__cx{height:10px;background-position:-1203px 0px}.iti__flag.iti__cy{height:14px;background-position:-1225px 0px}.iti__flag.iti__cz{height:14px;background-position:-1247px 0px}.iti__flag.iti__de{height:12px;background-position:-1269px 0px}.iti__flag.iti__dg{height:10px;background-position:-1291px 0px}.iti__flag.iti__dj{height:14px;background-position:-1313px 0px}.iti__flag.iti__dk{height:15px;background-position:-1335px 0px}.iti__flag.iti__dm{height:10px;background-position:-1357px 0px}.iti__flag.iti__do{height:14px;background-position:-1379px 0px}.iti__flag.iti__dz{height:14px;background-position:-1401px 0px}.iti__flag.iti__ea{height:14px;background-position:-1423px 0px}.iti__flag.iti__ec{height:14px;background-position:-1445px 0px}.iti__flag.iti__ee{height:13px;background-position:-1467px 0px}.iti__flag.iti__eg{height:14px;background-position:-1489px 0px}.iti__flag.iti__eh{height:10px;background-position:-1511px 0px}.iti__flag.iti__er{height:10px;background-position:-1533px 0px}.iti__flag.iti__es{height:14px;background-position:-1555px 0px}.iti__flag.iti__et{height:10px;background-position:-1577px 0px}.iti__flag.iti__eu{height:14px;background-position:-1599px 0px}.iti__flag.iti__fi{height:12px;background-position:-1621px 0px}.iti__flag.iti__fj{height:10px;background-position:-1643px 0px}.iti__flag.iti__fk{height:10px;background-position:-1665px 0px}.iti__flag.iti__fm{height:11px;background-position:-1687px 0px}.iti__flag.iti__fo{height:15px;background-position:-1709px 0px}.iti__flag.iti__fr{height:14px;background-position:-1731px 0px}.iti__flag.iti__ga{height:15px;background-position:-1753px 0px}.iti__flag.iti__gb{height:10px;background-position:-1775px 0px}.iti__flag.iti__gd{height:12px;background-position:-1797px 0px}.iti__flag.iti__ge{height:14px;background-position:-1819px 0px}.iti__flag.iti__gf{height:14px;background-position:-1841px 0px}.iti__flag.iti__gg{height:14px;background-position:-1863px 0px}.iti__flag.iti__gh{height:14px;background-position:-1885px 0px}.iti__flag.iti__gi{height:10px;background-position:-1907px 0px}.iti__flag.iti__gl{height:14px;background-position:-1929px 0px}.iti__flag.iti__gm{height:14px;background-position:-1951px 0px}.iti__flag.iti__gn{height:14px;background-position:-1973px 0px}.iti__flag.iti__gp{height:14px;background-position:-1995px 0px}.iti__flag.iti__gq{height:14px;background-position:-2017px 0px}.iti__flag.iti__gr{height:14px;background-position:-2039px 0px}.iti__flag.iti__gs{height:10px;background-position:-2061px 0px}.iti__flag.iti__gt{height:13px;background-position:-2083px 0px}.iti__flag.iti__gu{height:11px;background-position:-2105px 0px}.iti__flag.iti__gw{height:10px;background-position:-2127px 0px}.iti__flag.iti__gy{height:12px;background-position:-2149px 0px}.iti__flag.iti__hk{height:14px;background-position:-2171px 0px}.iti__flag.iti__hm{height:10px;background-position:-2193px 0px}.iti__flag.iti__hn{height:10px;background-position:-2215px 0px}.iti__flag.iti__hr{height:10px;background-position:-2237px 0px}.iti__flag.iti__ht{height:12px;background-position:-2259px 0px}.iti__flag.iti__hu{height:10px;background-position:-2281px 0px}.iti__flag.iti__ic{height:14px;background-position:-2303px 0px}.iti__flag.iti__id{height:14px;background-position:-2325px 0px}.iti__flag.iti__ie{height:10px;background-position:-2347px 0px}.iti__flag.iti__il{height:15px;background-position:-2369px 0px}.iti__flag.iti__im{height:10px;background-position:-2391px 0px}.iti__flag.iti__in{height:14px;background-position:-2413px 0px}.iti__flag.iti__io{height:10px;background-position:-2435px 0px}.iti__flag.iti__iq{height:14px;background-position:-2457px 0px}.iti__flag.iti__ir{height:12px;background-position:-2479px 0px}.iti__flag.iti__is{height:15px;background-position:-2501px 0px}.iti__flag.iti__it{height:14px;background-position:-2523px 0px}.iti__flag.iti__je{height:12px;background-position:-2545px 0px}.iti__flag.iti__jm{height:10px;background-position:-2567px 0px}.iti__flag.iti__jo{height:10px;background-position:-2589px 0px}.iti__flag.iti__jp{height:14px;background-position:-2611px 0px}.iti__flag.iti__ke{height:14px;background-position:-2633px 0px}.iti__flag.iti__kg{height:12px;background-position:-2655px 0px}.iti__flag.iti__kh{height:13px;background-position:-2677px 0px}.iti__flag.iti__ki{height:10px;background-position:-2699px 0px}.iti__flag.iti__km{height:12px;background-position:-2721px 0px}.iti__flag.iti__kn{height:14px;background-position:-2743px 0px}.iti__flag.iti__kp{height:10px;background-position:-2765px 0px}.iti__flag.iti__kr{height:14px;background-position:-2787px 0px}.iti__flag.iti__kw{height:10px;background-position:-2809px 0px}.iti__flag.iti__ky{height:10px;background-position:-2831px 0px}.iti__flag.iti__kz{height:10px;background-position:-2853px 0px}.iti__flag.iti__la{height:14px;background-position:-2875px 0px}.iti__flag.iti__lb{height:14px;background-position:-2897px 0px}.iti__flag.iti__lc{height:10px;background-position:-2919px 0px}.iti__flag.iti__li{height:12px;background-position:-2941px 0px}.iti__flag.iti__lk{height:10px;background-position:-2963px 0px}.iti__flag.iti__lr{height:11px;background-position:-2985px 0px}.iti__flag.iti__ls{height:14px;background-position:-3007px 0px}.iti__flag.iti__lt{height:12px;background-position:-3029px 0px}.iti__flag.iti__lu{height:12px;background-position:-3051px 0px}.iti__flag.iti__lv{height:10px;background-position:-3073px 0px}.iti__flag.iti__ly{height:10px;background-position:-3095px 0px}.iti__flag.iti__ma{height:14px;background-position:-3117px 0px}.iti__flag.iti__mc{height:15px;background-position:-3139px 0px}.iti__flag.iti__md{height:10px;background-position:-3160px 0px}.iti__flag.iti__me{height:10px;background-position:-3182px 0px}.iti__flag.iti__mf{height:14px;background-position:-3204px 0px}.iti__flag.iti__mg{height:14px;background-position:-3226px 0px}.iti__flag.iti__mh{height:11px;background-position:-3248px 0px}.iti__flag.iti__mk{height:10px;background-position:-3270px 0px}.iti__flag.iti__ml{height:14px;background-position:-3292px 0px}.iti__flag.iti__mm{height:14px;background-position:-3314px 0px}.iti__flag.iti__mn{height:10px;background-position:-3336px 0px}.iti__flag.iti__mo{height:14px;background-position:-3358px 0px}.iti__flag.iti__mp{height:10px;background-position:-3380px 0px}.iti__flag.iti__mq{height:14px;background-position:-3402px 0px}.iti__flag.iti__mr{height:14px;background-position:-3424px 0px}.iti__flag.iti__ms{height:10px;background-position:-3446px 0px}.iti__flag.iti__mt{height:14px;background-position:-3468px 0px}.iti__flag.iti__mu{height:14px;background-position:-3490px 0px}.iti__flag.iti__mv{height:14px;background-position:-3512px 0px}.iti__flag.iti__mw{height:14px;background-position:-3534px 0px}.iti__flag.iti__mx{height:12px;background-position:-3556px 0px}.iti__flag.iti__my{height:10px;background-position:-3578px 0px}.iti__flag.iti__mz{height:14px;background-position:-3600px 0px}.iti__flag.iti__na{height:14px;background-position:-3622px 0px}.iti__flag.iti__nc{height:10px;background-position:-3644px 0px}.iti__flag.iti__ne{height:15px;background-position:-3666px 0px}.iti__flag.iti__nf{height:10px;background-position:-3686px 0px}.iti__flag.iti__ng{height:10px;background-position:-3708px 0px}.iti__flag.iti__ni{height:12px;background-position:-3730px 0px}.iti__flag.iti__nl{height:14px;background-position:-3752px 0px}.iti__flag.iti__no{height:15px;background-position:-3774px 0px}.iti__flag.iti__np{height:15px;background-position:-3796px 0px}.iti__flag.iti__nr{height:10px;background-position:-3811px 0px}.iti__flag.iti__nu{height:10px;background-position:-3833px 0px}.iti__flag.iti__nz{height:10px;background-position:-3855px 0px}.iti__flag.iti__om{height:10px;background-position:-3877px 0px}.iti__flag.iti__pa{height:14px;background-position:-3899px 0px}.iti__flag.iti__pe{height:14px;background-position:-3921px 0px}.iti__flag.iti__pf{height:14px;background-position:-3943px 0px}.iti__flag.iti__pg{height:15px;background-position:-3965px 0px}.iti__flag.iti__ph{height:10px;background-position:-3987px 0px}.iti__flag.iti__pk{height:14px;background-position:-4009px 0px}.iti__flag.iti__pl{height:13px;background-position:-4031px 0px}.iti__flag.iti__pm{height:14px;background-position:-4053px 0px}.iti__flag.iti__pn{height:10px;background-position:-4075px 0px}.iti__flag.iti__pr{height:14px;background-position:-4097px 0px}.iti__flag.iti__ps{height:10px;background-position:-4119px 0px}.iti__flag.iti__pt{height:14px;background-position:-4141px 0px}.iti__flag.iti__pw{height:13px;background-position:-4163px 0px}.iti__flag.iti__py{height:11px;background-position:-4185px 0px}.iti__flag.iti__qa{height:8px;background-position:-4207px 0px}.iti__flag.iti__re{height:14px;background-position:-4229px 0px}.iti__flag.iti__ro{height:14px;background-position:-4251px 0px}.iti__flag.iti__rs{height:14px;background-position:-4273px 0px}.iti__flag.iti__ru{height:14px;background-position:-4295px 0px}.iti__flag.iti__rw{height:14px;background-position:-4317px 0px}.iti__flag.iti__sa{height:14px;background-position:-4339px 0px}.iti__flag.iti__sb{height:10px;background-position:-4361px 0px}.iti__flag.iti__sc{height:10px;background-position:-4383px 0px}.iti__flag.iti__sd{height:10px;background-position:-4405px 0px}.iti__flag.iti__se{height:13px;background-position:-4427px 0px}.iti__flag.iti__sg{height:14px;background-position:-4449px 0px}.iti__flag.iti__sh{height:10px;background-position:-4471px 0px}.iti__flag.iti__si{height:10px;background-position:-4493px 0px}.iti__flag.iti__sj{height:15px;background-position:-4515px 0px}.iti__flag.iti__sk{height:14px;background-position:-4537px 0px}.iti__flag.iti__sl{height:14px;background-position:-4559px 0px}.iti__flag.iti__sm{height:15px;background-position:-4581px 0px}.iti__flag.iti__sn{height:14px;background-position:-4603px 0px}.iti__flag.iti__so{height:14px;background-position:-4625px 0px}.iti__flag.iti__sr{height:14px;background-position:-4647px 0px}.iti__flag.iti__ss{height:10px;background-position:-4669px 0px}.iti__flag.iti__st{height:10px;background-position:-4691px 0px}.iti__flag.iti__sv{height:12px;background-position:-4713px 0px}.iti__flag.iti__sx{height:14px;background-position:-4735px 0px}.iti__flag.iti__sy{height:14px;background-position:-4757px 0px}.iti__flag.iti__sz{height:14px;background-position:-4779px 0px}.iti__flag.iti__ta{height:10px;background-position:-4801px 0px}.iti__flag.iti__tc{height:10px;background-position:-4823px 0px}.iti__flag.iti__td{height:14px;background-position:-4845px 0px}.iti__flag.iti__tf{height:14px;background-position:-4867px 0px}.iti__flag.iti__tg{height:13px;background-position:-4889px 0px}.iti__flag.iti__th{height:14px;background-position:-4911px 0px}.iti__flag.iti__tj{height:10px;background-position:-4933px 0px}.iti__flag.iti__tk{height:10px;background-position:-4955px 0px}.iti__flag.iti__tl{height:10px;background-position:-4977px 0px}.iti__flag.iti__tm{height:14px;background-position:-4999px 0px}.iti__flag.iti__tn{height:14px;background-position:-5021px 0px}.iti__flag.iti__to{height:10px;background-position:-5043px 0px}.iti__flag.iti__tr{height:14px;background-position:-5065px 0px}.iti__flag.iti__tt{height:12px;background-position:-5087px 0px}.iti__flag.iti__tv{height:10px;background-position:-5109px 0px}.iti__flag.iti__tw{height:14px;background-position:-5131px 0px}.iti__flag.iti__tz{height:14px;background-position:-5153px 0px}.iti__flag.iti__ua{height:14px;background-position:-5175px 0px}.iti__flag.iti__ug{height:14px;background-position:-5197px 0px}.iti__flag.iti__um{height:11px;background-position:-5219px 0px}.iti__flag.iti__un{height:14px;background-position:-5241px 0px}.iti__flag.iti__us{height:11px;background-position:-5263px 0px}.iti__flag.iti__uy{height:14px;background-position:-5285px 0px}.iti__flag.iti__uz{height:10px;background-position:-5307px 0px}.iti__flag.iti__va{height:15px;background-position:-5329px 0px}.iti__flag.iti__vc{height:14px;background-position:-5346px 0px}.iti__flag.iti__ve{height:14px;background-position:-5368px 0px}.iti__flag.iti__vg{height:10px;background-position:-5390px 0px}.iti__flag.iti__vi{height:14px;background-position:-5412px 0px}.iti__flag.iti__vn{height:14px;background-position:-5434px 0px}.iti__flag.iti__vu{height:12px;background-position:-5456px 0px}.iti__flag.iti__wf{height:14px;background-position:-5478px 0px}.iti__flag.iti__ws{height:10px;background-position:-5500px 0px}.iti__flag.iti__xk{height:15px;background-position:-5522px 0px}.iti__flag.iti__ye{height:14px;background-position:-5544px 0px}.iti__flag.iti__yt{height:14px;background-position:-5566px 0px}.iti__flag.iti__za{height:14px;background-position:-5588px 0px}.iti__flag.iti__zm{height:14px;background-position:-5610px 0px}.iti__flag.iti__zw{height:10px;background-position:-5632px 0px}.iti__flag{height:15px;box-shadow:0px 0px 1px 0px #888;background-image:url(\"https://cdn.salla.network/images/flags.png\");background-repeat:no-repeat;background-color:#f5f7f9;background-position:20px 0}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-image:url(\"https://cdn.salla.network/images/flags@2x.png\")}}.iti__flag.iti__np{background-color:transparent}";
2305
-
2306
- const SallaTelInput = class {
2307
- constructor(hostRef) {
2308
- registerInstance(this, hostRef);
2309
- this.enterClicked = createEvent(this, "enterClicked", 7);
2310
- /**
2311
- * input name
2312
- */
2313
- this.name = 'phone';
2314
- /**
2315
- * Current country_code
2316
- */
2317
- this.countryCode = salla.config.get('user.country_code', 'SA');
2318
- this.countryCodeLabel = salla.lang.get('common.country_code');
2319
- this.mobileLabel = salla.lang.get('common.elements.mobile');
2320
- this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2321
- this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2322
- this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2323
- this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2324
- this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2325
- Helper.setHost(this.host);
2326
- salla.lang.onLoaded(() => {
2327
- this.mobileLabel = salla.lang.get('common.elements.mobile');
2328
- this.countryCodeLabel = salla.lang.get('common.elements.country_code');
2329
- this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2330
- this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2331
- this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2332
- this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2333
- this.mobileRequired = salla.lang.get('common.errors.field_required', { attribute: this.mobileLabel });
2334
- this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2335
- });
2336
- }
2337
- /**
2338
- * Get current values
2339
- * @return {{mobile:number,countryCode:'SA'|string}}
2340
- */
2341
- async getValues() {
2342
- return {
2343
- [this.name]: this.phone = this.phoneInput.value,
2344
- countryCode: this.countryCode = this.countryCodeInput.value
2345
- };
2346
- }
2347
- /**
2348
- * Is current data valid or not
2349
- * @return {boolean}
2350
- */
2351
- async isValid() {
2352
- this.reset();
2353
- if (this.iti.isValidNumber())
2354
- return true;
2355
- if (!this.phoneInput.value.trim()) {
2356
- this.phoneInput.classList.add("s-has-error");
2357
- this.errorMsg.innerText = this.mobileRequired || 'The mobile is required';
2358
- return;
2359
- }
2360
- this.phoneInput.classList.add("s-has-error");
2361
- let errorCode = this.iti.getValidationError();
2362
- this.errorMsg.innerText = this.errorMap[errorCode] || '';
2363
- salla.logger.info('Phone number (' + this.countryCode + ' - ' + this.phone + ') is not valid, error code ' + errorCode);
2364
- return false;
2365
- }
2366
- initTelInput() {
2367
- salla.helpers.inputDigitsOnly(this.phoneInput);
2368
- this.iti = intlTelInput(this.phoneInput, {
2369
- initialCountry: this.countryCode || 'sa',
2370
- preferredCountries: ['sa', 'ae', 'kw', 'bh', 'qa', 'iq', 'om', 'ye', 'eg', 'jo', 'sy', 'ps', 'sd', 'lb', 'dz', 'tn', 'ma', 'ly'],
2371
- formatOnDisplay: false,
2372
- separateDialCode: true,
2373
- autoPlaceholder: 'aggressive',
2374
- utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.min.js',
2375
- });
2376
- this.phoneInput.addEventListener("countrychange", () => {
2377
- let data = this.iti.getSelectedCountryData();
2378
- this.countryCodeInput.value = data.iso2.toUpperCase();
2379
- });
2380
- // on blur: validate
2381
- // this.phoneInput.addEventListener('blur', () => this.isValid());
2382
- // on keyup / change flag: reset
2383
- this.phoneInput.addEventListener('input', e => {
2384
- salla.helpers.inputDigitsOnly(e.target);
2385
- this.reset();
2386
- });
2387
- }
2388
- reset() {
2389
- this.phoneInput.classList.remove("s-has-error");
2390
- this.errorMsg.innerHTML = "";
2391
- }
2392
- ;
2393
- render() {
2394
- return (h(Host, { class: "s-tel-input" }, h("input", { type: "tel", name: this.name, value: this.phone, ref: el => this.phoneInput = el, class: "s-tel-input-control tel-input s-ltr" }), h("span", { class: "s-tel-input-error-msg", ref: el => this.errorMsg = el }), h("input", { type: "hidden", name: "country_code", value: this.countryCode, ref: el => this.countryCodeInput = el, class: "country_code" })));
2395
- }
2396
- componentDidLoad() {
2397
- this.initTelInput();
2398
- }
2399
- get host() { return getElement(this); }
2400
- };
2401
- SallaTelInput.style = sallaTelInputCss;
2402
-
2403
- const AndroidPhoneIcon = `<!-- Generated by IcoMoon.io -->
2404
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2405
- <title>android-phone</title>
2406
- <path d="M22.667 0h-13.333c-2.941 0-5.333 2.392-5.333 5.333v21.333c0 2.941 2.392 5.333 5.333 5.333h13.333c2.941 0 5.333-2.392 5.333-5.333v-21.333c0-2.941-2.392-5.333-5.333-5.333zM25.333 26.667c0 1.471-1.196 2.667-2.667 2.667h-13.333c-1.471 0-2.667-1.196-2.667-2.667v-2.667h18.667zM25.333 21.333h-18.667v-16c0-1.471 1.196-2.667 2.667-2.667h13.333c1.471 0 2.667 1.196 2.667 2.667zM13.333 28h5.333c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333z"></path>
2407
- </svg>
2408
- `;
2409
-
2410
- const sallaVerifyCss = "salla-verify{display:block}";
2411
-
2412
- const SallaVerify = class {
2413
- constructor(hostRef) {
2414
- registerInstance(this, hostRef);
2415
- this.verified = createEvent(this, "verified", 7);
2416
- this.initiated = false;
2417
- this.translationLoaded = false;
2418
- /**
2419
- * Should render component without modal
2420
- */
2421
- this.display = 'modal';
2422
- /**
2423
- * Verifying method
2424
- */
2425
- this.type = 'mobile';
2426
- /**
2427
- * should auto reloading the page after success verification
2428
- */
2429
- this.autoReload = true;
2430
- this.resendAfter = 30;
2431
- /**
2432
- * to use: `salla.api.auth.verify` or `salla.profile.verify`
2433
- */
2434
- this.isProfileVerify = false;
2435
- // Helper.setHost(this.host);
2436
- salla.lang.onLoaded(() => {
2437
- var _a;
2438
- this.translationLoaded = true;
2439
- this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + this.type);
2440
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2441
- });
2442
- if (this.display == 'inline') {
2443
- this.modal = { open: () => '', close: () => '', setTitle: () => '' };
2444
- return;
2445
- }
2446
- salla.event.on('profile::verification', data => {
2447
- var _a;
2448
- this.isProfileVerify = true;
2449
- this.open(data);
2450
- this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + data.type);
2451
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2452
- });
2453
- salla.event.on('modalClosed', () => {
2454
- this.resendAfter = 0;
2455
- this.timer.innerHTML = '30 : 00';
2456
- });
2457
- }
2458
- /**
2459
- * Get current code
2460
- * @return {string}
2461
- */
2462
- async getCode() {
2463
- return this.code.value;
2464
- }
2465
- /**
2466
- * Open verifying modal
2467
- * @param data
2468
- */
2469
- async open(data) {
2470
- var _a;
2471
- this.data = data;
2472
- this.data.type = this.data.type || this.type;
2473
- this.type = this.data.type;
2474
- this.resendTimer();
2475
- this.otpInputs = this.body.querySelectorAll('.s-verify-input');
2476
- if (!this.initiated) {
2477
- Helper.on('input', '.s-verify-input', e => salla.helpers.inputDigitsOnly(e.target));
2478
- Helper.onKeyUp('.s-verify-input', event => {
2479
- var _a, _b, _c, _d;
2480
- let key = event.keyCode || event.charCode;
2481
- if (event.target.value) {
2482
- (_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
2483
- (_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
2484
- }
2485
- else if ([8, 46].includes(key)) {
2486
- (_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
2487
- (_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
2488
- }
2489
- this.toggleOTPSubmit();
2490
- });
2491
- Helper.on('paste', '.s-verify-input', event => {
2492
- let text = salla.helpers.number(event.clipboardData.getData('text')).replace(/[^0-9.]/g, '').replace('..', '.');
2493
- this.otpInputs.forEach((input, i) => input.value = text[i] || '');
2494
- this.toggleOTPSubmit();
2495
- setTimeout(() => this.otpInputs[3].focus(), 100);
2496
- });
2497
- // return this.modal.open();
2498
- this.initiated = true;
2499
- }
2500
- this.reset();
2501
- this.display == 'modal' && ((_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title));
2502
- this.modal.open();
2503
- // focus the first input after opening the modal
2504
- setTimeout(() => this.otpInputs[0].focus(), 100);
2505
- }
2506
- toggleOTPSubmit() {
2507
- let otp = [];
2508
- this.otpInputs.forEach(input => input.value && otp.push(input.value));
2509
- this.code.value = otp.join('');
2510
- if (otp.length === 4) {
2511
- this.btn.disable();
2512
- this.btn.click();
2513
- return;
2514
- }
2515
- this.btn.enable();
2516
- }
2517
- reset() {
2518
- this.otpInputs.forEach((input) => input.value = '');
2519
- this.code.value = '';
2520
- this.otpInputs[0].focus();
2521
- }
2522
- resendTimer() {
2523
- Helper.showElement(this.resendMessage).hideElement(this.resend);
2524
- this.resendAfter = 30;
2525
- let timerId = setInterval(() => {
2526
- if (this.resendAfter <= 0) {
2527
- clearInterval(timerId);
2528
- Helper.hideElement(this.resendMessage).showElement(this.resend);
2529
- }
2530
- else {
2531
- this.timer.innerHTML = `${this.resendAfter >= 10 ? this.resendAfter : '0' + this.resendAfter} : 00`;
2532
- this.resendAfter--;
2533
- }
2534
- }, 1000);
2535
- }
2536
- resendCode() {
2537
- return this.btn.stop()
2538
- .then(() => this.btn.disable())
2539
- .then(() => {
2540
- this.otpInputs.forEach(input => input.value = '');
2541
- this.otpInputs[0].focus();
2542
- })
2543
- .then(() => salla.api.auth.resend(this.data))
2544
- .finally(() => this.resendTimer());
2545
- }
2546
- submit() {
2547
- let data = Object.assign({ code: this.code.value }, this.data);
2548
- return this.btn.load()
2549
- .then(() => this.btn.disable())
2550
- .then(() => this.isProfileVerify ? salla.profile.verify(data) : salla.auth.verify(data, true))
2551
- .then(response => this.verified.emit(response))
2552
- .then(() => this.btn.stop() && this.btn.disable())
2553
- .then(() => this.modal.close())
2554
- .then(() => this.autoReload && window.location.reload())
2555
- .catch((error) => {
2556
- salla.logger.error(error);
2557
- this.btn.stop() && this.btn.enable() && this.reset();
2558
- });
2559
- }
2560
- render() {
2561
- return this.display == 'inline' ? h(Host, null, this.myBody()) :
2562
- h("salla-modal", { width: "xs", class: "s-verify", ref: modal => this.modal = modal, "modal-title": this.title }, h("span", { slot: 'icon', innerHTML: AndroidPhoneIcon }), this.myBody());
2563
- }
2564
- myBody() {
2565
- return (h("div", { class: "s-verify-body", ref: body => this.body = body }, h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }), h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }), h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => h("input", { type: "number", maxlength: "1", class: "s-verify-input", required: true }))), h("div", { slot: "footer", class: "s-verify-footer" }, h("salla-button", { class: "s-verify-submit", "loader-position": 'center', 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'))), h("slot", { name: "after-footer" })));
2566
- }
2567
- get host() { return getElement(this); }
2568
- };
2569
- SallaVerify.style = sallaVerifyCss;
2570
-
2571
- export { SallaButton as salla_button, SallaLoading as salla_loading, SallaLocalizationModal as salla_localization_modal, SallaLoginModal as salla_login_modal, SallaModal as salla_modal, SallaOfferModal as salla_offer_modal, SallaSearch as salla_search, SallaSkeleton as salla_skeleton, SallaTelInput as salla_tel_input, SallaVerify as salla_verify };