@salla.sa/twilight-components 1.6.1 → 1.6.3

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 (62) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/salla-add-product-button.cjs.entry.js +104 -0
  3. package/dist/cjs/salla-button_24.cjs.entry.js +10087 -0
  4. package/dist/cjs/twilight-components.cjs.js +1 -1
  5. package/dist/collection/components/salla-login-modal/salla-login-modal.js +3 -4
  6. package/dist/components/salla-login-modal.js +3 -4
  7. package/dist/esm/loader.js +1 -1
  8. package/dist/esm/salla-add-product-button.entry.js +100 -0
  9. package/dist/esm/salla-button_24.entry.js +10060 -0
  10. package/dist/esm/twilight-components.js +1 -1
  11. package/dist/twilight-components/p-30b2c5b0.entry.js +4 -0
  12. package/dist/twilight-components/p-76cb2574.entry.js +4 -0
  13. package/dist/twilight-components/twilight-components.esm.js +1 -1
  14. package/package.json +9 -3
  15. package/dist/cjs/Helper-8ae6a805.js +0 -28
  16. package/dist/cjs/arrow-right-3d137e4c.js +0 -13
  17. package/dist/cjs/cancel-ae668d91.js +0 -13
  18. package/dist/cjs/check-circle2-1aac98d1.js +0 -13
  19. package/dist/cjs/mail-2db058ee.js +0 -13
  20. package/dist/cjs/salla-add-product-button_13.cjs.entry.js +0 -2870
  21. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +0 -93
  22. package/dist/cjs/salla-list-tile_2.cjs.entry.js +0 -80
  23. package/dist/cjs/salla-loyalty.cjs.entry.js +0 -229
  24. package/dist/cjs/salla-product-size-guide.cjs.entry.js +0 -52
  25. package/dist/cjs/salla-quantity-input.cjs.entry.js +0 -101
  26. package/dist/cjs/salla-rating-modal.cjs.entry.js +0 -169
  27. package/dist/cjs/salla-social-share.cjs.entry.js +0 -1447
  28. package/dist/cjs/salla-swiper.cjs.entry.js +0 -5023
  29. package/dist/cjs/salla-tab-content_3.cjs.entry.js +0 -159
  30. package/dist/cjs/star2-8288e6e1.js +0 -13
  31. package/dist/esm/Helper-e1d414a5.js +0 -26
  32. package/dist/esm/arrow-right-1c3e04f2.js +0 -11
  33. package/dist/esm/cancel-41a92070.js +0 -11
  34. package/dist/esm/check-circle2-f6e5f685.js +0 -11
  35. package/dist/esm/mail-9d5204c6.js +0 -11
  36. package/dist/esm/salla-add-product-button_13.entry.js +0 -2854
  37. package/dist/esm/salla-infinite-scroll.entry.js +0 -89
  38. package/dist/esm/salla-list-tile_2.entry.js +0 -75
  39. package/dist/esm/salla-loyalty.entry.js +0 -225
  40. package/dist/esm/salla-product-size-guide.entry.js +0 -48
  41. package/dist/esm/salla-quantity-input.entry.js +0 -97
  42. package/dist/esm/salla-rating-modal.entry.js +0 -165
  43. package/dist/esm/salla-social-share.entry.js +0 -1443
  44. package/dist/esm/salla-swiper.entry.js +0 -5019
  45. package/dist/esm/salla-tab-content_3.entry.js +0 -153
  46. package/dist/esm/star2-b134fc74.js +0 -11
  47. package/dist/twilight-components/p-14f0ff17.entry.js +0 -4
  48. package/dist/twilight-components/p-2749c9d3.entry.js +0 -4
  49. package/dist/twilight-components/p-335abbbb.entry.js +0 -4
  50. package/dist/twilight-components/p-4cafb11b.entry.js +0 -4
  51. package/dist/twilight-components/p-5e63e308.entry.js +0 -4
  52. package/dist/twilight-components/p-648e74e5.entry.js +0 -4
  53. package/dist/twilight-components/p-897b2018.js +0 -4
  54. package/dist/twilight-components/p-93708e1e.js +0 -4
  55. package/dist/twilight-components/p-9d236cf4.entry.js +0 -4
  56. package/dist/twilight-components/p-9d2ca9c8.js +0 -4
  57. package/dist/twilight-components/p-af7d5660.js +0 -4
  58. package/dist/twilight-components/p-bdbd2386.entry.js +0 -4
  59. package/dist/twilight-components/p-cac3db69.entry.js +0 -4
  60. package/dist/twilight-components/p-d914a212.js +0 -4
  61. package/dist/twilight-components/p-dace8e6d.js +0 -4
  62. package/dist/twilight-components/p-f9253fda.entry.js +0 -4
@@ -1,2870 +0,0 @@
1
- /*!
2
- * Crafted with ❤ by Salla
3
- */
4
- 'use strict';
5
-
6
- Object.defineProperty(exports, '__esModule', { value: true });
7
-
8
- const index = require('./index-0d0167d5.js');
9
- const Helper = require('./Helper-8ae6a805.js');
10
- const mail = require('./mail-2db058ee.js');
11
- const arrowRight = require('./arrow-right-3d137e4c.js');
12
- const cancel = require('./cancel-ae668d91.js');
13
- const checkCircle2 = require('./check-circle2-1aac98d1.js');
14
- const star2 = require('./star2-8288e6e1.js');
15
- const search = require('./search-b487cc49.js');
16
-
17
- const sallaAddProductButtonCss = ":host{display:block}salla-add-product-button[width=wide]{width:100%}";
18
-
19
- const SallaAddProductButton = class {
20
- constructor(hostRef) {
21
- index.registerInstance(this, hostRef);
22
- this.success = index.createEvent(this, "success", 7);
23
- this.failed = index.createEvent(this, "failed", 7);
24
- this.hostAttributes = {};
25
- this.hasLabel = false;
26
- /**
27
- * Channels.
28
- */
29
- this.channels = null;
30
- /**
31
- * Product Quantity
32
- */
33
- this.quantity = 0;
34
- /**
35
- * Donating amount.
36
- */
37
- this.donatingAmount = 0;
38
- /**
39
- * Product Status.Defaults to `sale`
40
- */
41
- this.productStatus = 'sale';
42
- /**
43
- * Product type. Defaults to `product`
44
- */
45
- this.productType = 'product';
46
- }
47
- getLabel() {
48
- if (this.productStatus === 'sale') {
49
- return salla.lang.get('pages.cart.add_to_cart');
50
- }
51
- if (this.productType !== 'donating') {
52
- return salla.lang.get('pages.products.out_of_stock');
53
- }
54
- // donating
55
- return salla.lang.get('pages.products.donation_exceed');
56
- }
57
- addProductToCart(event) {
58
- // we want to ignore the click action when the type of button is submit a form
59
- if (this.hostAttributes['type'] === 'submit') {
60
- return false;
61
- }
62
- event.preventDefault();
63
- /**
64
- * by default the quick add is just an alias for add item function
65
- * but its work only when the id is the only value is passed via the object
66
- * so we will filter the object entities to remove null and zero values in case we don't want the normal add item action
67
- */
68
- const data = Object.entries({
69
- id: this.productId,
70
- donating_amount: this.donatingAmount,
71
- quantity: this.quantity
72
- }).reduce((a, [k, v]) => (v ? (a[k] = v, a) : a), {});
73
- return salla.cart.quickAdd(data)
74
- .then((response) => {
75
- return this.success.emit(response);
76
- })
77
- .catch((error) => {
78
- return this.failed.emit(error);
79
- });
80
- }
81
- getBtnAttributes() {
82
- for (let i = 0; i < this.host.attributes.length; i++) {
83
- if (!['id', 'class'].includes(this.host.attributes[i].name)) {
84
- this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
85
- }
86
- }
87
- return this.hostAttributes;
88
- }
89
- componentWillLoad() {
90
- this.hasLabel = !!this.host.innerHTML.replace('<!---->', '').trim();
91
- }
92
- render() {
93
- return (index.h(index.Host, null, this.productStatus === 'out-and-notify' && this.channels ?
94
- index.h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), index.h("slot", null)) :
95
- index.h("salla-button", Object.assign({ ref: el => this.btn = el, onClick: event => this.addProductToCart(event), type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', color: this.productStatus === 'sale' ? 'primary' : 'light', "loader-position": "center" }, this.getBtnAttributes(), { disabled: this.productStatus !== 'sale' }), index.h("slot", null))));
96
- }
97
- componentDidRender() {
98
- //if label not passed, get label
99
- if (this.hasLabel) {
100
- return;
101
- }
102
- this.btn.setText(this.getLabel() || 'اضافة للسلة');
103
- salla.lang.onLoaded(() => {
104
- this.btn.setText(this.getLabel() || 'اضافة للسلة');
105
- });
106
- }
107
- get host() { return index.getElement(this); }
108
- };
109
- SallaAddProductButton.style = sallaAddProductButtonCss;
110
-
111
- const sallaButtonCss = "";
112
-
113
- const SallaButton = class {
114
- constructor(hostRef) {
115
- index.registerInstance(this, hostRef);
116
- this.hostAttributes = {};
117
- /**
118
- * Button Type
119
- */
120
- this.shape = 'btn';
121
- /**
122
- * Button Color
123
- */
124
- this.color = 'primary';
125
- /**
126
- * Button Fill
127
- */
128
- this.fill = 'solid';
129
- /**
130
- * Button Size
131
- */
132
- this.size = 'medium';
133
- /**
134
- * Button Width
135
- */
136
- this.width = 'normal';
137
- /**
138
- * Is the button currently loading
139
- */
140
- this.loading = false;
141
- /**
142
- * Is the button currently disabled
143
- */
144
- this.disabled = false;
145
- /**
146
- * If there is need to change loader position, pass the position
147
- */
148
- this.loaderPosition = 'after';
149
- }
150
- /**
151
- * Run loading animation
152
- */
153
- async load() {
154
- if (this.loaderPosition == 'center')
155
- this.text.classList.add('s-button-hide');
156
- this.host.setAttribute('loading', '');
157
- return this.host;
158
- }
159
- /**
160
- * Stop loading animation
161
- */
162
- async stop() {
163
- this.host.removeAttribute('loading');
164
- this.host.querySelector('button').removeAttribute('loading');
165
- if (this.loaderPosition == 'center')
166
- this.text.classList.remove('s-button-hide');
167
- return this.host;
168
- }
169
- /**
170
- * Changing the body of the button
171
- * @param html
172
- */
173
- async setText(html) {
174
- this.text.innerHTML = html;
175
- return this.host;
176
- }
177
- /**
178
- * Add `disabled` attribute
179
- */
180
- async disable() {
181
- this.host.setAttribute('disabled', '');
182
- return this.host;
183
- }
184
- /**
185
- * Remove `disabled` attribute
186
- */
187
- async enable() {
188
- this.host.removeAttribute('disabled');
189
- return this.host;
190
- }
191
- getBtnAttributes() {
192
- for (let i = 0; i < this.host.attributes.length; i++) {
193
- if (!['color', 'fill', 'size', 'width', 'id'].includes(this.host.attributes[i].name)) {
194
- this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
195
- }
196
- }
197
- this.hostAttributes.type = this.hostAttributes.type || 'button';
198
- this.hostAttributes.class +=
199
- ' s-button-element s-button-' + this.shape
200
- + ' s-button-' + (this.fill == "none" ? 'fill-none' : this.fill)
201
- + (this.size != "medium" ? ' s-button-' + this.size : '')
202
- + (this.width != "normal" ? ' s-button-' + this.width : '')
203
- + (this.shape == "link" ? ' s-button-' + this.color + '-link' : '')
204
- + (this.shape != "link" && this.fill != 'outline' ? ' s-button-' + this.color : '')
205
- + (this.fill == 'outline' ? ' s-button-' + this.color + '-outline' : '')
206
- + (this.disabled ? ' s-button-disabled ' : '')
207
- + (this.shape == 'icon' ? ' s-button-loader-center' : ' s-button-loader-' + this.loaderPosition);
208
- return this.hostAttributes;
209
- }
210
- button() {
211
- return (index.h("button", Object.assign({}, this.getBtnAttributes(), { disabled: this.disabled }), index.h("span", { class: "s-button-text", ref: el => this.text = el }, index.h("slot", null)), this.loading ? index.h("span", { class: "s-button-loader" }) : ''));
212
- }
213
- render() {
214
- return (index.h(index.Host, { class: "s-button-wrap" }, this.href ? index.h("a", { href: this.href }, this.button()) : this.button()));
215
- }
216
- get host() { return index.getElement(this); }
217
- };
218
- SallaButton.style = sallaButtonCss;
219
-
220
- 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)}}";
221
-
222
- const SallaLoading = class {
223
- constructor(hostRef) {
224
- index.registerInstance(this, hostRef);
225
- /**
226
- * Sets the diameter of the circle in pixels, Defaults to `32`
227
- */
228
- this.size = 32;
229
- /**
230
- * Sets the stroke of the circle (border) in pixels, Defaults to `4`
231
- */
232
- this.width = 2;
233
- /**
234
- * Spinner content color.
235
- */
236
- this.color = undefined; // TODO: Should be replaced with primary color (variable)
237
- /**
238
- * Spinner background color.
239
- */
240
- this.bgColor = "#e5e7eb";
241
- }
242
- render() {
243
- return (index.h(index.Host, { class: "s-loading-container" }, index.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" }, index.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" }), index.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" }))));
244
- }
245
- };
246
- SallaLoading.style = sallaLoadingCss;
247
-
248
- 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}";
249
-
250
- const SallaLocalizationModal = class {
251
- constructor(hostRef) {
252
- index.registerInstance(this, hostRef);
253
- var _a, _b;
254
- this.translationLoaded = false;
255
- this.languages = [];
256
- this.currencies = [];
257
- this.isLoading = true;
258
- /**
259
- * Current language (existing or newly selected)
260
- */
261
- this.language = salla.config.get('user.language_code');
262
- /**
263
- * Current currency (existing or newly selected)
264
- */
265
- this.currency = salla.config.get('user.currency_code');
266
- Helper.Helper.setHost(this.host);
267
- salla.event.on('localization::open', () => this.open());
268
- salla.lang.onLoaded(() => {
269
- this.translationLoaded = true;
270
- });
271
- /**
272
- * letting developer to insert his own slot like:
273
- * <salla-localization>
274
- * <div slot="language">...{name}....</div>
275
- * <div slot="currency">...{name}....</div>
276
- * </salla-localization>
277
- * Because scoped templates not supported in stencil );
278
- * we made a workaround to pass language & currency attributes, then replace names in rendering
279
- */
280
- this.languageSlot = ((_a = Helper.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>';
281
- this.currencySlot = ((_b = Helper.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>';
282
- }
283
- /**
284
- * open the component
285
- */
286
- async open() {
287
- return await this.modal.open()
288
- .then(() => this.getLanguages())
289
- .then(() => this.getCurrencies())
290
- .then(() => this.isLoading = false);
291
- }
292
- /**
293
- * Hide the component
294
- */
295
- async close() {
296
- return this.modal.close();
297
- }
298
- async getLanguages() {
299
- this.language = this.language || salla.config.get('user.language_code');
300
- return this.languages.length > 1 ? null : await salla.config.languages().then(data => this.languages = data);
301
- }
302
- async getCurrencies() {
303
- this.currency = this.currency || salla.config.get('user.currency_code');
304
- return this.currencies.length > 1 ? null : await salla.config.currencies().then(data => this.currencies = Object.values(data || {}));
305
- }
306
- onChangeCurrency(event) {
307
- this.currency = event.target.value;
308
- }
309
- onChangeLanguage(event) {
310
- this.language = event.target.value;
311
- }
312
- /**
313
- * Change currency and language to the selected ones.
314
- */
315
- async submit() {
316
- let url;
317
- this.btn.load()
318
- .then(() => {
319
- if (!this.currency) {
320
- salla.log('There is no currency!');
321
- return;
322
- }
323
- if (this.currency === salla.config.get('user.currency_code', 'SAR')) {
324
- return;
325
- }
326
- url = window.location.href;
327
- return salla.currency.api.change(this.currency);
328
- })
329
- .then(() => this.language === salla.config.get('user.language_code', 'ar') || (url = salla.helpers.addParamToUrl('lang', this.language)))
330
- .then(() => this.btn.stop())
331
- .then(() => this.close())
332
- .then(() => url && (window.location.href = url));
333
- }
334
- render() {
335
- return (index.h("salla-modal", { isLoading: this.isLoading, class: "s-hidden", ref: modal => this.modal = modal, width: "xs" }, index.h("div", { slot: 'loading' }, index.h("div", { class: "s-localization-modal-skeleton" }, index.h("salla-skeleton", { width: '25%', height: '15px' }), index.h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => index.h("div", { class: "s-localization-modal-skeleton-item" }, index.h("div", { class: "s-localization-modal-skeleton-item-flex" }, index.h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), index.h("salla-skeleton", { height: '10px', width: '100px' })), index.h("salla-skeleton", { height: '15px', width: '20px' })))), index.h("salla-skeleton", { width: '25%', height: '15px' }), index.h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => index.h("div", { class: "s-localization-modal-skeleton-item" }, index.h("div", { class: "s-localization-modal-skeleton-item-flex" }, index.h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), index.h("salla-skeleton", { height: '10px', width: '100px' })), index.h("salla-skeleton", { height: '15px', width: '20px' })))), index.h("salla-skeleton", { height: '40px', width: '100%' }))), !this.isLoading ?
336
- index.h("div", { class: "s-localization-modal-inner" }, this.languages.length > 1 ?
337
- index.h("div", { class: "s-localization-modal-section" }, index.h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.language')), index.h("div", { class: "s-localization-modal-section-inner" }, this.languages.length < 6 ?
338
- this.languages.map(lang => index.h("div", { class: "s-localization-modal-item" }, index.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 }), index.h("div", { class: "s-localization-modal-label-slot", id: "language-slot", innerHTML: this.languageSlot
339
- .replace(/\{name\}/g, lang.name)
340
- .replace(/\{code\}/g, lang.code)
341
- .replace(/\{country_code\}/g, lang.country_code) }))) :
342
- index.h("select", { class: "s-localization-modal-select", name: "language", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => index.h("option", { value: lang.code, selected: this.language == lang.code }, lang.name)))))
343
- : '', this.currencies.length > 1 ?
344
- index.h("div", { class: "s-localization-modal-section" }, index.h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.currency')), index.h("div", { class: "s-localization-modal-section-inner" }, this.currencies.length < 6 ?
345
- this.currencies.map(currency => index.h("div", { class: "s-localization-modal-item" }, index.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 }), index.h("div", { class: "s-localization-modal-label-slot", id: "currency-slot", innerHTML: this.currencySlot
346
- .replace(/\{name\}/g, currency.name)
347
- .replace(/\{code\}/g, currency.code)
348
- .replace(/\{country_code\}/g, currency.country_code) }))) :
349
- index.h("select", { class: "s-localization-modal-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => index.h("option", { value: currency.code, selected: this.currency == currency.code }, currency.name)))))
350
- : '', index.h("salla-button", { width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.ok')))
351
- : ''));
352
- }
353
- /**
354
- * to reduce dom levels we will move slot data into the parent dom
355
- */
356
- componentDidRender() {
357
- this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
358
- this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
359
- }
360
- get host() { return index.getElement(this); }
361
- };
362
- SallaLocalizationModal.style = sallaLocalizationModalCss;
363
-
364
- const UserIcon = `<!-- Generated by IcoMoon.io -->
365
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
366
- <title>user</title>
367
- <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>
368
- </svg>
369
- `;
370
-
371
- const PhoneIcon = `<!-- Generated by IcoMoon.io -->
372
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
373
- <title>phone</title>
374
- <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>
375
- </svg>
376
- `;
377
-
378
- const KeyboardArrowRightIcon = `<!-- Generated by IcoMoon.io -->
379
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
380
- <title>keyboard_arrow_right</title>
381
- <path d="M11.438 22.479l6.125-6.125-6.125-6.125 1.875-1.875 8 8-8 8z"></path>
382
- </svg>
383
- `;
384
-
385
- const sallaLoginModalCss = "";
386
-
387
- const SallaLoginModal = class {
388
- constructor(hostRef) {
389
- index.registerInstance(this, hostRef);
390
- /**
391
- * Does the merchant allow to login using email
392
- */
393
- this.isEmailAllowed = true;
394
- /**
395
- * Does the merchant/current location for visitor allow to login using mobile, By default outside KSA is `false`
396
- */
397
- this.isMobileAllowed = true;
398
- /**
399
- * Does the merchant require registration with email & mobile
400
- */
401
- this.isEmailRequired = false;
402
- this.regType = 'phone';
403
- this.translationLoaded = false;
404
- this.typing = (e, submitMethod) => {
405
- const error = e.target.nextElementSibling;
406
- e.target.classList.remove('s-has-error');
407
- (error === null || error === void 0 ? void 0 : error.classList.contains('s-login-modal-error-message')) && (error.innerText = '');
408
- e.key == 'Enter' && submitMethod();
409
- };
410
- this.loginBySMS = async () => {
411
- const { phone, countryCode } = await this.loginTelInput.getValues();
412
- const isPhoneValid = await this.loginTelInput.isValid();
413
- if (!isPhoneValid) {
414
- return;
415
- }
416
- this.login(this.smsBtn, { type: 'mobile', phone: phone, country_code: countryCode });
417
- };
418
- this.loginByEmail = () => {
419
- if (!Helper.Helper.isValidEmail(this.loginEmail.value)) {
420
- this.validateField(this.loginEmail, this.emailErrorMsg);
421
- return;
422
- }
423
- this.login(this.emailBtn, { type: 'email', email: this.loginEmail.value });
424
- };
425
- this.newUser = async () => {
426
- var _a;
427
- 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);
428
- await this.newUserValidation();
429
- await this.regBtn.load();
430
- await this.regBtn.disable();
431
- let data = {
432
- first_name: this.firstName.value,
433
- last_name: this.lastName.value,
434
- phone: regPhone || this.loginTelInput.phone,
435
- country_code: countryCode,
436
- verified_by: this.regType,
437
- };
438
- emailValue && (data = Object.assign(Object.assign({}, data), { email: emailValue }));
439
- this.verifyTab.getCode()
440
- .then(code => salla.auth.api.register(Object.assign(Object.assign({}, data), { code })))
441
- .then(() => salla.auth.canRedirect && window.location.reload())
442
- .catch((error) => {
443
- salla.logger.error(error);
444
- this.regBtn.stop() && this.regBtn.enable();
445
- });
446
- };
447
- this.title = this.host.title || salla.lang.get('blocks.header.login');
448
- this.host.removeAttribute('title');
449
- this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
450
- this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
451
- this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
452
- salla.lang.onLoaded(() => {
453
- this.translationLoaded = true;
454
- this.title = salla.lang.get('blocks.header.login');
455
- this.updateTranslations();
456
- });
457
- salla.event.on('login::open', (event) => this.open(event));
458
- salla.event.on('twilight::initiated', () => {
459
- this.isEmailAllowed = salla.config.get('store.settings.auth.email_allowed', this.isEmailAllowed);
460
- this.isMobileAllowed = salla.config.get('store.settings.auth.mobile_allowed', this.isMobileAllowed);
461
- this.isEmailRequired = salla.config.get('store.settings.auth.is_email_required', this.isEmailRequired);
462
- });
463
- }
464
- /**
465
- * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
466
- */
467
- onVerified(event) {
468
- var _a, _b;
469
- salla.log('verified', event);
470
- //there is a case when force login is activated & is new user, it will return case inside error key., so cover it.
471
- 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);
472
- if (!verifyCase) {
473
- salla.log('verified but without case!');
474
- return;
475
- }
476
- if (verifyCase === "new_customer") {
477
- return this.showTab(this.registrationTab);
478
- }
479
- if (!salla.auth.canRedirect()) {
480
- salla.log('Will not auto redirect or reload, due to `salla.auth.canRedirect()`');
481
- return;
482
- }
483
- if (event.detail.data.redirect_url) {
484
- return window.location.href = event.detail.data.redirect_url;
485
- }
486
- window.location.reload();
487
- }
488
- updateTranslations() {
489
- var _a;
490
- this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
491
- this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
492
- this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
493
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
494
- }
495
- /**
496
- * Open login component
497
- */
498
- // @ts-ignore
499
- async open(event = null) {
500
- // todo :: support change the settings from event details
501
- // if(event && event.hasOwnProperty('isEmailAllowed')){
502
- // this.isEmailAllowed = event?.isEmailAllowed;
503
- // }
504
- //
505
- // if(event && event.hasOwnProperty('isMobileAllowed')){
506
- // this.isMobileAllowed = event?.isMobileAllowed;
507
- // }
508
- if (this.isEmailAllowed && this.isMobileAllowed) {
509
- this.showTab(this.homeTab);
510
- }
511
- else if (this.isEmailAllowed) {
512
- this.showTab(this.emailTab);
513
- }
514
- else if (this.isMobileAllowed) {
515
- this.showTab(this.mobileTab);
516
- }
517
- return this.modal.open();
518
- }
519
- showTab(tab, evt) {
520
- var _a;
521
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
522
- let tabs = [this.homeTab, this.mobileTab, this.emailTab, this.verifyTab, this.registrationTab];
523
- tabs.map(el => Helper.Helper.toggleElementClassIf(el, 'visible', 's-hidden', () => el == tab));
524
- setTimeout(() => tabs.map(el => Helper.Helper.toggleElementClassIf(el, 's-login-modal-active', 's-login-modal-unactive', () => el == tab)), 200);
525
- //we should have only one salla-login, so it's okay to get it from document
526
- //todo:: use better way for resize the modal
527
- 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'); });
528
- if ([this.mobileTab, this.emailTab].includes(tab)) {
529
- this.regType = tab === this.mobileTab ? 'phone' : 'email';
530
- }
531
- let isRegistrationTab = tab == this.registrationTab;
532
- // focus the first input in tab
533
- // tab.querySelector('input')?.focus();
534
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
535
- if (!isRegistrationTab) {
536
- Helper.Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
537
- .toggleElementClassIf(this.regEmailBlock, 's-hidden', 's-show', () => this.regType === 'email');
538
- }
539
- return this;
540
- }
541
- login(btn, data) {
542
- btn.load()
543
- .then(() => btn.disable())
544
- .then(() => salla.auth.api.login(data))
545
- .then(() => this.showTab(this.verifyTab))
546
- .then(() => this.verifyTab.open(data))
547
- .finally(() => btn.stop() && btn.enable());
548
- }
549
- async newUserValidation() {
550
- const isLogByPhone = this.regType == "phone", isLogByEmail = this.regType == "email", emailValue = this.regEmail.value || (isLogByEmail && this.loginEmail.value), isEmailValid = Helper.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);
551
- if (emailValidation && isPhoneValid && isFirstNameValid && isLastNameValid)
552
- return;
553
- !isEmailValid && this.validateField(this.regEmail, this.emailErrorMsg);
554
- !isFirstNameValid && this.validateField(this.firstName, this.firstNameErrorMsg);
555
- !isLastNameValid && this.validateField(this.lastName, this.lastNameErrorMsg);
556
- throw ('Please insert required fields');
557
- }
558
- // eslint-disable-next-line @stencil/own-methods-must-be-private
559
- validateField(field, errorMsg) {
560
- field.classList.add('s-has-error');
561
- field.nextElementSibling['innerText'] = '* ' + errorMsg;
562
- }
563
- render() {
564
- return (index.h("salla-modal", { class: "s-login-modal", "modal-title": this.title, ref: modal => this.modal = modal, width: "xs" }, index.h("span", { slot: 'icon', class: "s-login-modal-header-icon", innerHTML: UserIcon }), index.h("div", { class: "s-login-modal-wrapper" }, this.isEmailAllowed && this.isMobileAllowed ?
565
- index.h("div", { class: "s-login-modal-tab", ref: tab => this.homeTab = tab }, index.h("p", { class: "s-login-modal-sub-title" }, salla.lang.get('blocks.header.select_login_way')), index.h("slot", { name: "before-login-type" }), index.h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.mobileTab, evt) }, index.h("span", { class: "s-login-modal-main-btn-icon", innerHTML: PhoneIcon }), index.h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('blocks.header.sms')), index.h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), index.h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.emailTab, evt) }, index.h("span", { class: "s-login-modal-main-btn-icon", innerHTML: mail.email }), index.h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('common.elements.email')), index.h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), index.h("slot", { name: "after-login-type" }))
566
- : '', this.isMobileAllowed ?
567
- index.h("div", { class: "s-login-modal-tab", ref: tab => this.mobileTab = tab }, index.h("slot", { name: "before-login-mobile" }), index.h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), index.h("salla-tel-input", { ref: el => this.loginTelInput = el, onKeyDown: e => this.typing(e, this.loginBySMS) }), index.h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginBySMS(), ref: b => this.smsBtn = b }, salla.lang.get('blocks.header.enter')), this.isEmailAllowed ?
568
- index.h("a", { href: "#", onClick: () => this.showTab(this.emailTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_email')) : '', index.h("slot", { name: "after-login-mobile" })) : '', this.isEmailAllowed ?
569
- index.h("div", { class: "s-login-modal-tab", ref: tab => this.emailTab = tab }, index.h("slot", { name: "before-login-email" }), index.h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), index.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" }), index.h("span", { class: "s-login-modal-error-message" }), index.h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginByEmail(), ref: b => this.emailBtn = b }, salla.lang.get('blocks.header.enter')), this.isMobileAllowed ?
570
- index.h("a", { href: "#", onClick: () => this.showTab(this.mobileTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_sms'))
571
- : '', index.h("slot", { name: "after-login-email" })) : '', index.h("salla-verify", { display: "inline", ref: tab => this.verifyTab = tab, autoReload: false }, index.h("a", { onClick: () => this.showTab(this.regType == 'phone' ? this.mobileTab : this.emailTab), class: "s-verify-back", innerHTML: arrowRight.ArrowRightIcon, slot: "after-footer", href: "#" })), index.h("div", { ref: tab => this.registrationTab = tab }, index.h("slot", { name: "before-registration" }), index.h("div", null, index.h("label", { class: "s-login-modal-label" }, salla.lang.get('blocks.header.your_name')), index.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') }), index.h("span", { class: "s-login-modal-error-message" })), index.h("div", null, index.h("label", { class: "s-login-modal-label" }, salla.lang.get('pages.profile.last_name')), index.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') }), index.h("span", { class: "s-login-modal-error-message" })), index.h("div", { ref: el => this.regMobileBlock = el, class: "mb-1.5" }, index.h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), index.h("salla-tel-input", { ref: el => this.regTelInput = el, onKeyDown: e => this.typing(e, this.newUser) })), index.h("div", { ref: el => this.regEmailBlock = el, class: "mb-1.5" }, index.h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), index.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" }), index.h("span", { class: "s-login-modal-error-message" })), index.h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.newUser(), ref: b => this.regBtn = b }, salla.lang.get('blocks.header.register')), index.h("slot", { name: "after-registration" })))));
572
- }
573
- get host() { return index.getElement(this); }
574
- };
575
- SallaLoginModal.style = sallaLoginModalCss;
576
-
577
- const AlertEngineIcon = `<!-- Generated by IcoMoon.io -->
578
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
579
- <title>alert-engine</title>
580
- <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>
581
- </svg>
582
- `;
583
-
584
- const sallaModalCss = "";
585
-
586
- const SallaModal = class {
587
- constructor(hostRef) {
588
- index.registerInstance(this, hostRef);
589
- /**
590
- * Sets the modal to be closable. Defaults to `true`
591
- */
592
- this.isClosable = true; //todo::rename unclude. Suggestion => persistent
593
- /**
594
- * The size of the modal
595
- */
596
- this.width = 'md';
597
- /**
598
- * The position of the modal
599
- */
600
- this.position = 'middle';
601
- /**
602
- * open the modal on rendering
603
- */
604
- this.visible = false;
605
- /**
606
- * open the modal on rendering
607
- */
608
- this.hasSkeleton = false;
609
- /**
610
- * Show loading in the middle
611
- */
612
- this.isLoading = false;
613
- /**
614
- * Show subtitle before the title or not, defaults to `false` (after the title)
615
- */
616
- this.subTitleFirst = false; //todo:: choose better name
617
- /**
618
- * Avoid padding in the modal body or not, defaults to `false`
619
- */
620
- this.noPadding = false; //todo:: choose better name
621
- /**
622
- * Set modal sub title.
623
- */
624
- this.subTitle = '';
625
- /**
626
- * Align modal content to center, defaults to `false`
627
- */
628
- this.centered = false;
629
- /**
630
- * Set the style of the header icon.
631
- */
632
- this.iconStyle = undefined;
633
- Helper.Helper.setHost(this.host);
634
- salla.event.on('modal::open', target => target == this.host.id && this.open());
635
- salla.event.on('modal::close', target => target == this.host.id && this.close());
636
- this.modalTitle = this.host.getAttribute('modal-title');
637
- // close modal on Escape button clicked
638
- Helper.Helper.onKeyUp(document.body, e => e.keyCode === 27 && this.closeModal());
639
- }
640
- handleVisible(newValue) {
641
- if (!newValue) {
642
- salla.event.dispatch('modalClosed');
643
- this.toggleModal(false);
644
- return;
645
- }
646
- salla.event.dispatch('modalOpened');
647
- this.host.classList.remove('s-hidden');
648
- setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
649
- }
650
- /**
651
- * Open the modal
652
- */
653
- async open() {
654
- this.host.setAttribute('visible', '');
655
- return this.host;
656
- }
657
- /**
658
- * close the modal
659
- */
660
- async close() {
661
- this.host.removeAttribute('visible');
662
- return this.host;
663
- }
664
- /**
665
- * Change the Modal Title
666
- * @param {string} modalTitle
667
- */
668
- async setTitle(modalTitle) {
669
- this.modalTitle = modalTitle;
670
- return this.host;
671
- }
672
- /**
673
- * Start loading
674
- */
675
- async loading() {
676
- this.isLoading = true;
677
- return this.host;
678
- }
679
- /**
680
- * Stop the loading
681
- */
682
- async stopLoading() {
683
- this.isLoading = false;
684
- return this.host;
685
- }
686
- toggleModal(isOpen) {
687
- const body = this.host.querySelector('.s-modal-body');
688
- Helper.Helper.toggleElementClassIf(body, 's-modal-entering', 's-modal-leaving', () => isOpen)
689
- .toggleElementClassIf(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
690
- .toggleElementClassIf(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
691
- if (!isOpen) {
692
- setTimeout(() => this.host.classList.add('s-hidden'), 350);
693
- }
694
- }
695
- closeModal() {
696
- if (!this.isClosable) {
697
- return;
698
- }
699
- this.host.removeAttribute('visible');
700
- }
701
- iconBlockClasses() {
702
- return {
703
- 's-modal-icon': true,
704
- 's-modal-bg-error': this.iconStyle == 'error',
705
- 's-modal-bg-success': this.iconStyle == 'success',
706
- 's-modal-bg-normal': !this.iconStyle,
707
- 's-modal-bg-primary': this.iconStyle == 'primary'
708
- };
709
- }
710
- getWidth() {
711
- return this.isLoading ? (this.hasSkeleton ? 'md' : 'xs') : this.width;
712
- }
713
- //todo:: pref for each modal
714
- render() {
715
- this.host.id = this.host.id || 'salla-modal';
716
- if (this.isLoading) {
717
- return (index.h(index.Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, index.h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), index.h("div", { class: "s-modal-wrapper" }, index.h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), index.h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, index.h("slot", { name: "loading" }, index.h("salla-loading", null)), index.h("div", { class: "s-hidden" }, index.h("slot", null))))));
718
- }
719
- return (index.h(index.Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, index.h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), index.h("div", { class: "s-modal-wrapper" }, index.h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), index.h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, index.h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.centered } }, this.isClosable ?
720
- index.h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, index.h("span", { innerHTML: cancel.Cancel }))
721
- : '', this.modalTitle || this.subTitle ?
722
- index.h("div", { class: "s-modal-header-inner" }, index.h("slot", { name: 'icon' }, !!this.iconStyle ?
723
- index.h("div", { class: this.iconBlockClasses(), innerHTML: this.iconStyle == 'error' ? AlertEngineIcon : checkCircle2.CheckCircle2 })
724
- : ''), index.h("div", { class: "s-modal-header-content" }, index.h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.modalTitle }), index.h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle })))
725
- : ""), index.h("slot", null), index.h("slot", { name: "footer" })))));
726
- }
727
- //move the modal as root dom, because we need the model to be outside the forms
728
- componentDidLoad() {
729
- document.body.append(this.host);
730
- }
731
- get host() { return index.getElement(this); }
732
- static get watchers() { return {
733
- "visible": ["handleVisible"]
734
- }; }
735
- };
736
- SallaModal.style = sallaModalCss;
737
-
738
- const SpecialDiscountIcon = `<!-- Generated by IcoMoon.io -->
739
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
740
- <title>special-discount</title>
741
- <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>
742
- </svg>
743
- `;
744
-
745
- const KeyboardArrowLeftIcon = `<!-- Generated by IcoMoon.io -->
746
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
747
- <title>keyboard_arrow_left</title>
748
- <path d="M20.563 22.104l-1.875 1.875-8-8 8-8 1.875 1.875-6.125 6.125z"></path>
749
- </svg>
750
- `;
751
-
752
- const Tag = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
753
- <title>tag</title>
754
- <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>
755
- </svg>
756
- `;
757
-
758
- const sallaOfferModalCss = "";
759
-
760
- const SallaOfferModal = class {
761
- constructor(hostRef) {
762
- index.registerInstance(this, hostRef);
763
- var _a, _b;
764
- this.offer = null;
765
- this.translationLoaded = false;
766
- Helper.Helper.setHost(this.host);
767
- salla.lang.onLoaded(() => {
768
- this.translationLoaded = true;
769
- });
770
- this.categorySlot = ((_a = Helper.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>`;
771
- this.productSlot = ((_b = Helper.Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.defaultProductSlot();
772
- salla.product.event.onOfferExisted(offer => {
773
- if (salla.storage.get('remember-offer-' + offer.id)) {
774
- salla.log('User selected to don\'t show this offer again.');
775
- return;
776
- }
777
- this.open(offer.product_id);
778
- });
779
- }
780
- /**
781
- * Show the available offers for the product
782
- * @param product_id
783
- */
784
- async open(product_id) {
785
- //TODO:: make sure there is only one offer
786
- return salla.product.offers(product_id)
787
- .then(response => this.showOffer(response.data[0]));
788
- }
789
- /**
790
- * Show offer details
791
- * @param {Offer} offer
792
- */
793
- async showOffer(offer) {
794
- this.offer = offer;
795
- this.offer_name = offer.name;
796
- this.offer_message = offer.message;
797
- this.modal.setTitle(this.offer_name);
798
- return this.modal.open();
799
- }
800
- rememberMe(event) {
801
- salla.storage.set('remember-offer-' + this.offer.id, event.target.checked);
802
- }
803
- //todo:: pass event then use sallaButton from it
804
- addItem() {
805
- // this here, is sallaButton
806
- this['load']();
807
- return salla.cart.api
808
- .quickAdd(this['dataset'].id)
809
- .finally(() => this['stop']());
810
- }
811
- defaultProductSlot() {
812
- return '<a href={url} class="s-offer-modal-product-image-wrap"><img class="s-offer-modal-product-image" src="{image}" /></a>' +
813
- '<div class="s-offer-modal-product-info">' +
814
- ' <a href={url} class="s-offer-modal-product-name">{name}</a>' +
815
- ' <div class="s-offer-modal-product-price">{price}</div>' +
816
- '</div>';
817
- }
818
- render() {
819
- var _a, _b;
820
- return index.h("salla-modal", { "sub-title-first": true, "sub-title": this.offer_message, ref: modal => this.modal = modal, "is-loading": this.offer === null }, index.h("span", { slot: 'icon', class: "s-offer-modal-header-icon", innerHTML: SpecialDiscountIcon }), this.offer !== null
821
- ? [index.h("div", { class: "s-offer-modal-scrolled-slider-wrap" }, index.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
822
- ? this.offer.get.categories.map(category => index.h("a", { href: category.urls.customer, class: "s-offer-modal-badge s-offer-modal-slider-item", innerHTML: this.categorySlot
823
- .replace(/\{tagIcon\}/g, Tag)
824
- .replace(/\{name\}/g, category.name)
825
- .replace(/\{url\}/g, category.urls.customer) }))
826
- : (_b = this.offer.get.products) === null || _b === void 0 ? void 0 : _b.map(product => index.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
827
- .replace(/\{name\}/g, product.name)
828
- .replace(/\{url\}/g, product.url)
829
- .replace(/\{image\}/g, product.thumbnail)
830
- .replace(/\{price\}/g, product.has_special_price
831
- ? salla.money(product.price) + '<span class="s-offer-modal-product-old-price">' + salla.money(product.regular_price) + '</span>'
832
- : salla.money(product.price)) }, index.h("div", { class: "s-offer-modal-btn-wrap" }, index.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')))))), index.h("div", { class: "s-offer-modal-slider-nav" }, index.h("button", { class: "s-offer-modal-nav-btn s-offer-modal-prev-btn" }, index.h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowLeftIcon })), index.h("button", { class: "s-offer-modal-nav-btn s-offer-modal-next-btn" }, index.h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowRightIcon })))), index.h("div", { class: "s-offer-modal-footer", slot: "footer" }, this.offer.formatted_date ?
833
- index.h("p", { class: "s-offer-modal-expiry" }, salla.lang.get('pages.products.offer_expires_in'), " ", this.offer.formatted_date)
834
- : '', index.h("label", { class: "s-offer-modal-remember-label" }, index.h("input", { type: "checkbox", onChange: e => this.rememberMe(e), class: "s-offer-modal-remember-input" }), "\u00A0 ", salla.lang.get('common.elements.remember_my_choice'))),
835
- ] : '');
836
- }
837
- componentDidRender() {
838
- // Sooo mini Slider
839
- if (this.offer && window.screen.width > 639) {
840
- 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.
841
- current = 0, // current slide
842
- slidesToScroll = 3, itemsLength = items.length;
843
- console.log('items[0]:', items[0]);
844
- let itemSize = items[0].offsetWidth, sliderSize = itemsLength * itemSize, sliderWrapperSize = sliderWrap.offsetWidth, sliderInvisibleSize = sliderSize - sliderWrapperSize, isRTL = document.body.classList.contains('rtl') ? true : false;
845
- if (sliderInvisibleSize > sliderNavMargin)
846
- nexBtn.classList.add('s-offer-modal-btn-is-active');
847
- window.onresize = function () {
848
- sliderWrapperSize = sliderWrap.offsetWidth;
849
- sliderInvisibleSize = sliderSize - sliderWrapperSize;
850
- };
851
- slider.addEventListener('scroll', function () {
852
- let sliderPosition = Math.abs(slider.scrollLeft);
853
- let sliderEndOffset = sliderInvisibleSize - sliderNavMargin;
854
- // show & hide the navigation btns depending on scroll position
855
- if (sliderPosition <= sliderNavMargin) {
856
- nexBtn.classList.add('s-offer-modal-btn-is-active');
857
- prevBtn.classList.remove('s-offer-modal-btn-is-active');
858
- }
859
- else if (sliderPosition < sliderEndOffset) {
860
- // show both btns in the middle
861
- nexBtn.classList.add('s-offer-modal-btn-is-active');
862
- prevBtn.classList.add('s-offer-modal-btn-is-active');
863
- }
864
- else if (sliderPosition >= sliderEndOffset) {
865
- nexBtn.classList.remove('s-offer-modal-btn-is-active');
866
- prevBtn.classList.add('s-offer-modal-btn-is-active');
867
- }
868
- });
869
- // Navigation
870
- navButtons.forEach(btn => {
871
- btn.addEventListener('click', function () {
872
- btn.classList.contains('s-offer-modal-next-btn') ? current++ : current--;
873
- slider.scrollTo({
874
- top: 0,
875
- left: itemSize * slidesToScroll * current * (isRTL ? -1 : 1),
876
- behavior: 'smooth'
877
- });
878
- });
879
- });
880
- }
881
- }
882
- get host() { return index.getElement(this); }
883
- };
884
- SallaOfferModal.style = sallaOfferModalCss;
885
-
886
- const BellRingIcon = `<!-- Generated by IcoMoon.io -->
887
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
888
- <title>bell-ring</title>
889
- <path d="M2.667 13.333v-4c0-2.592 0.748-5.107 2.161-7.271 0.404-0.616 0.231-1.443-0.387-1.845-0.616-0.401-1.443-0.228-1.845 0.388-1.699 2.599-2.596 5.617-2.596 8.728v4c0 0.736 0.596 1.333 1.333 1.333s1.333-0.596 1.333-1.333zM25.333 15.647v-6.313c0-5.147-4.188-9.333-9.333-9.333s-9.333 4.187-9.333 9.333v6.312l-5.157 9.027c-0.236 0.413-0.235 0.92 0.004 1.331 0.239 0.412 0.679 0.664 1.153 0.664h8c0 2.941 2.392 5.333 5.333 5.333s5.333-2.392 5.333-5.333h8c0.475 0 0.915-0.252 1.153-0.664 0.239-0.411 0.24-0.917 0.004-1.331zM16 29.333c-1.471 0-2.667-1.196-2.667-2.667h5.333c0 1.472-1.196 2.667-2.667 2.667zM4.965 24l4.193-7.339c0.113-0.2 0.175-0.429 0.175-0.661v-6.667c0-3.676 2.991-6.667 6.667-6.667s6.667 2.991 6.667 6.667v6.667c0 0.232 0.061 0.46 0.176 0.661l4.192 7.339zM29.403 0.603c-0.403-0.616-1.232-0.789-1.845-0.387-0.617 0.403-0.791 1.229-0.387 1.845 1.415 2.165 2.163 4.68 2.163 7.272v4c0 0.736 0.596 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-4c0-3.112-0.899-6.132-2.597-8.731z"></path>
890
- </svg>
891
- `;
892
-
893
- const sallaProductAvailabilityCss = "";
894
-
895
- const SallaProductAvailability = class {
896
- constructor(hostRef) {
897
- index.registerInstance(this, hostRef);
898
- this.isUser = Helper.Helper.isUser();
899
- this.translationLoaded = false;
900
- /**
901
- * product id that can visitor subscribe to its availability notification
902
- */
903
- this.productId = salla.config.get('page.id');
904
- /**
905
- * is current user already subscribed
906
- */
907
- this.isSubscribed = false;
908
- // @Method()
909
- this.submit = async () => {
910
- if (this.isUser) {
911
- return salla.api.product.availabilitySubscribe(this.productId)
912
- .then(() => this.isSubscribed = true);
913
- }
914
- let data = { id: this.productId };
915
- if (this.channels_.includes('sms')) {
916
- let { phone, countryCode } = await this.mobileInput.getValues();
917
- data['country_code'] = countryCode;
918
- data['phone'] = phone;
919
- }
920
- if (this.channels_.includes('email')) {
921
- this.email.value !== '' && (data['email'] = this.email.value);
922
- }
923
- await this.validateform();
924
- return this.btn.load()
925
- .then(() => this.btn.disable())
926
- .then(() => salla.api.product.availabilitySubscribe(data))
927
- .then(() => {
928
- this.isSubscribed = true;
929
- salla.storage.set(`product-${this.productId}-subscribed`, true);
930
- }) //no need to wait until finishing alert animation
931
- .then(() => this.btn.stop())
932
- .then(() => this.modal.close())
933
- .catch(() => this.btn.stop() && this.btn.enable());
934
- };
935
- // helpers
936
- this.typing = (e, submitMethod) => {
937
- const error = e.target.nextElementSibling;
938
- e.target.classList.remove('s-has-error');
939
- (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
940
- e.key == 'Enter' && submitMethod();
941
- };
942
- salla.lang.onLoaded(() => {
943
- var _a;
944
- this.translationLoaded = true;
945
- this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
946
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title_);
947
- });
948
- if (this.isUser)
949
- return;
950
- this.channelsWatcher(this.channels);
951
- this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
952
- this.host.removeAttribute('title');
953
- this.isVisitorSubscribed = salla.storage.get(`product-${this.productId}-subscribed`);
954
- }
955
- channelsWatcher(newValue) {
956
- this.channels_ = !!newValue ? newValue.split(',') : [];
957
- }
958
- async validateform() {
959
- try {
960
- if (this.channels_.includes('email')) {
961
- const isEmailValid = Helper.Helper.isValidEmail(this.email.value);
962
- if (isEmailValid)
963
- return;
964
- !isEmailValid && this.validateField(this.email, salla.lang.get('common.elements.email_is_valid'));
965
- }
966
- if (this.channels_.includes('sms')) {
967
- const isPhoneValid = await this.mobileInput.isValid();
968
- if (isPhoneValid)
969
- return;
970
- }
971
- }
972
- catch (error) {
973
- throw ('Please insert required fields');
974
- }
975
- }
976
- validateField(field, errorMsg) {
977
- field.classList.add('s-has-error');
978
- field.nextElementSibling['innerText'] = '* ' + errorMsg;
979
- }
980
- render() {
981
- return (index.h(index.Host, { class: "s-product-availability-wrap" }, this.isSubscribed || this.isVisitorSubscribed
982
- ? index.h("div", { class: "s-product-availability-subscribed" }, index.h("span", { innerHTML: BellRingIcon, class: "s-product-availability-subs-icon" }), " ", salla.lang.get('pages.products.notify_availability_success'))
983
- :
984
- index.h("salla-button", { width: "wide", onClick: () => this.isUser ? this.submit() : this.modal.open() }, salla.lang.get('pages.products.notify_availability')), this.isUser || this.isSubscribed || this.isVisitorSubscribed ? '' : this.renderModal()));
985
- }
986
- renderModal() {
987
- return (index.h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: salla.lang.get('pages.products.notify_availability_subtitle'), width: "sm" }, index.h("span", { slot: 'icon', innerHTML: BellRingIcon }), index.h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
988
- index.h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
989
- index.h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
990
- index.h("span", { class: "s-product-availability-error-msg" })
991
- ] : '', this.channels_.includes('sms') ? [
992
- index.h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
993
- index.h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
994
- ] : ''), index.h("div", { slot: "footer", class: "s-product-availability-footer" }, index.h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')), index.h("salla-button", { class: "submit-btn", "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
995
- }
996
- get host() { return index.getElement(this); }
997
- static get watchers() { return {
998
- "channels": ["channelsWatcher"]
999
- }; }
1000
- };
1001
- SallaProductAvailability.style = sallaProductAvailabilityCss;
1002
-
1003
- const sallaRatingStarsCss = "";
1004
-
1005
- const SallaRatingStars = class {
1006
- constructor(hostRef) {
1007
- index.registerInstance(this, hostRef);
1008
- /**
1009
- * Sets input name.
1010
- */
1011
- this.name = 'rating';
1012
- /**
1013
- * Sets the height and width of the component. Defaults to medium.
1014
- */
1015
- this.size = 'medium';
1016
- }
1017
- initiateRating() {
1018
- this.host.addEventListener('click', () => {
1019
- if (!this.startsElem)
1020
- return;
1021
- // Get the selected star - activeElement is not supported in safari
1022
- let activeStars = this.startsElem.querySelectorAll('.s-rating-stars-hovered');
1023
- let selected = activeStars[activeStars.length - 1];
1024
- if (!selected)
1025
- return;
1026
- let selectedIndex = selected.getAttribute('data-star');
1027
- this.startsElem.querySelector('.rating_hidden_input').value = selectedIndex;
1028
- // Loop through each star, and add or remove the `.selected` class to toggle highlighting
1029
- this.startsElem.querySelectorAll('.s-rating-stars-btn-star')
1030
- .forEach((star, index) => Helper.Helper.toggleElementClassIf(star, 's-rating-stars-selected', 's-rating-stars-unselected', () => index < parseInt(selectedIndex)));
1031
- // update aria-pressed attr status
1032
- this.startsElem.querySelectorAll('[aria-pressed]').forEach(star => star.removeAttribute('aria-pressed'));
1033
- selected.setAttribute('aria-pressed', 'true');
1034
- });
1035
- }
1036
- highlightSelectedStars() {
1037
- var _a, _b;
1038
- let hoveredClass = 's-rating-stars-hovered', stars = (_a = this.startsElem) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.s-rating-stars-btn-star');
1039
- stars === null || stars === void 0 ? void 0 : stars.forEach((star, index) => {
1040
- star.addEventListener('mouseover', () => {
1041
- for (let i = 0; i <= index; i++) {
1042
- stars[i].classList.add(hoveredClass);
1043
- }
1044
- });
1045
- star.addEventListener('mouseout', () => star.classList.remove(hoveredClass));
1046
- });
1047
- (_b = this.startsElem) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseout', () => stars.forEach(star => star.classList.remove(hoveredClass)));
1048
- }
1049
- createStars(n) {
1050
- let stars = [];
1051
- for (let i = 0; i < 5; i++) {
1052
- stars.push(index.h("span", { class: {
1053
- 's-rating-stars-btn-star': true,
1054
- ['s-rating-stars-' + this.size]: true,
1055
- 's-rating-stars-selected': i < n
1056
- }, innerHTML: star2.Star2 }));
1057
- }
1058
- return stars;
1059
- }
1060
- render() {
1061
- return (index.h(index.Host, null, this.value ?
1062
- index.h("div", { class: "s-rating-stars-wrapper" }, " ", this.createStars(this.value), " ")
1063
- :
1064
- index.h("div", { class: "s-rating-stars-element", ref: (el) => this.startsElem = el }, index.h("input", { type: "hidden", class: "rating_hidden_input", name: this.name, value: "" }), [1, 2, 3, 4, 5].map(star => index.h("button", { class: `s-rating-stars-btn-star s-rating-stars-` + this.size, "data-star": star }, index.h("span", { innerHTML: star2.Star2 }))))));
1065
- }
1066
- componentDidLoad() {
1067
- this.initiateRating();
1068
- this.highlightSelectedStars();
1069
- }
1070
- get host() { return index.getElement(this); }
1071
- };
1072
- SallaRatingStars.style = sallaRatingStarsCss;
1073
-
1074
- const sallaSearchCss = "";
1075
-
1076
- const SallaSearch = class {
1077
- constructor(hostRef) {
1078
- index.registerInstance(this, hostRef);
1079
- var _a;
1080
- this.inputValue = '';
1081
- this.translationLoaded = false;
1082
- this.loading = false;
1083
- this.typing = false;
1084
- this.debounce = setTimeout(() => '', 1000);
1085
- /**
1086
- * Set the component display without modal window. Defaults to `false`
1087
- */
1088
- this.inline = false;
1089
- /**
1090
- * Adds a border radius to the input. Half of the height.
1091
- */
1092
- this.oval = false;
1093
- /**
1094
- * Sets the height of the input
1095
- */
1096
- this.height = 60;
1097
- Helper.Helper.setHost(this.host);
1098
- this.productSlot = ((_a = Helper.Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
1099
- salla.event.on('search::open', () => this.open());
1100
- salla.lang.onLoaded(() => {
1101
- this.translationLoaded = true;
1102
- });
1103
- salla.event.on('modalClosed', () => this.onModalClose());
1104
- }
1105
- async open() {
1106
- if (!this.inline) {
1107
- await this.modal.open().then(() => setTimeout(() => this.searchInput.focus(), 300));
1108
- }
1109
- }
1110
- onModalClose() {
1111
- this.searchInput.value = '';
1112
- this.results = undefined;
1113
- this.afterSearching();
1114
- this.container.classList.remove('s-search-no-results');
1115
- }
1116
- handleKeyDown(ev) {
1117
- if (ev.key === 'Enter') {
1118
- window.location.href = salla.url.get('/search?q=' + encodeURI(this.search_term));
1119
- }
1120
- }
1121
- getDefaultProductSlot() {
1122
- return '<div class="s-search-product-image-container">' +
1123
- ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
1124
- '</div>' +
1125
- '<div class="s-search-product-details">' +
1126
- ' <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>' +
1127
- '</div>';
1128
- }
1129
- debounceSearch(event) {
1130
- this.typing = true;
1131
- clearTimeout(this.debounce);
1132
- this.debounce = setTimeout(() => {
1133
- this.typing = false;
1134
- this.search_term = event.target.value;
1135
- }, 500);
1136
- }
1137
- handelSearch(val) {
1138
- this.inputValue = val;
1139
- if (val.length > 2) {
1140
- this.search(val);
1141
- }
1142
- else {
1143
- this.results = undefined;
1144
- this.afterSearching();
1145
- }
1146
- }
1147
- search(val) {
1148
- Helper.Helper.hideElement(this.noResults);
1149
- //run loading spinner or stop it
1150
- this.loading = true;
1151
- salla.product.search(val)
1152
- .then(response => this.results = response)
1153
- .catch(err => err !== 'Query is same as previous one!' ? this.results = undefined : null)
1154
- .finally(() => this.afterSearching(/*isEmpty*/ false));
1155
- }
1156
- afterSearching(isEmpty = true) {
1157
- var _a;
1158
- this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
1159
- Helper.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; });
1160
- this.loading = false;
1161
- salla.product.api.previousQuery = ''; //avoid having error 'Query is same as previous one!' after reopen modal;
1162
- this.inputValue.length < 3 ? this.container.classList.remove('s-search-no-results') : '';
1163
- }
1164
- render() {
1165
- var _a;
1166
- const searchContent = index.h("div", { class: { 's-search-container': true, 's-search-inline': this.inline }, ref: container => this.container = container }, index.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' : '' } }), index.h("span", { class: "s-search-icon-wrap" }, index.h("span", { class: "s-search-icon", innerHTML: this.loading ? '<i class="s-search-spinner-loader"></i>' : search.Search })), index.h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
1167
- _a.data.map(item => index.h("a", { href: item.url, class: { "s-search-product": true, 's-search-product-not-available': !item.is_available }, innerHTML: this.productSlot
1168
- .replace(/\{name\}/g, item.name)
1169
- .replace(/\{price\}/g, salla.money(item.price))
1170
- .replace(/\{regular_price\}/g, item.has_special_price ? salla.money(item.regular_price) : '')
1171
- .replace(/\{image\}/g, item.thumbnail) })), index.h("p", { ref: el => this.noResults = el, class: "s-search-no-results-placeholder" }, salla.lang.get('common.elements.no_options'))));
1172
- return (this.inline ?
1173
- index.h("div", { class: "s-search-modal" }, searchContent)
1174
- :
1175
- index.h("salla-modal", { position: "top", class: "s-search-modal", ref: modal => this.modal = modal }, searchContent));
1176
- }
1177
- /**
1178
- * Run it one time after load
1179
- */
1180
- componentDidLoad() {
1181
- this.afterSearching();
1182
- }
1183
- get host() { return index.getElement(this); }
1184
- static get watchers() { return {
1185
- "search_term": ["handelSearch"]
1186
- }; }
1187
- };
1188
- SallaSearch.style = sallaSearchCss;
1189
-
1190
- const sallaSkeletonCss = ":host{display:block}";
1191
-
1192
- const SallaSkeleton = class {
1193
- constructor(hostRef) {
1194
- index.registerInstance(this, hostRef);
1195
- /**
1196
- * Set the shape type of the skeleton is it circle or normal
1197
- */
1198
- this.type = 'normal';
1199
- /**
1200
- * Set the skeleton width
1201
- */
1202
- this.width = '100%';
1203
- /**
1204
- * Set the skeleton height
1205
- */
1206
- this.height = '100%';
1207
- }
1208
- render() {
1209
- const classes = {
1210
- 's-skeleton-item': true,
1211
- 's-skeleton-item-circular': this.type == 'circle',
1212
- };
1213
- return (index.h(index.Host, { class: "s-skeleton-wrapper", style: { width: this.width, height: this.height } }, index.h("div", { class: classes }, "\u00A0")));
1214
- }
1215
- };
1216
- SallaSkeleton.style = sallaSkeletonCss;
1217
-
1218
- function createCommonjsModule(fn, basedir, module) {
1219
- return module = {
1220
- path: basedir,
1221
- exports: {},
1222
- require: function (path, base) {
1223
- return commonjsRequire();
1224
- }
1225
- }, fn(module, module.exports), module.exports;
1226
- }
1227
-
1228
- function commonjsRequire () {
1229
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
1230
- }
1231
-
1232
- var intlTelInput$1 = createCommonjsModule(function (module) {
1233
- /*
1234
- * International Telephone Input v17.0.18
1235
- * https://github.com/jackocnr/intl-tel-input.git
1236
- * Licensed under the MIT license
1237
- */
1238
-
1239
- // wrap in UMD
1240
- (function(factory) {
1241
- if (module.exports) module.exports = factory(); else window.intlTelInput = factory();
1242
- })(function(undefined$1) {
1243
- return function() {
1244
- // Array of country objects for the flag dropdown.
1245
- // Here is the criteria for the plugin to support a given country/territory
1246
- // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1247
- // - 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
1248
- // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
1249
- // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
1250
- // Each country array has the following information:
1251
- // [
1252
- // Country name,
1253
- // iso2 code,
1254
- // International dial code,
1255
- // Order (if >1 country with same dial code),
1256
- // Area codes
1257
- // ]
1258
- 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" ] ] ];
1259
- // loop over all of the countries above, restructuring the data to be objects with named keys
1260
- for (var i = 0; i < allCountries.length; i++) {
1261
- var c = allCountries[i];
1262
- allCountries[i] = {
1263
- name: c[0],
1264
- iso2: c[1],
1265
- dialCode: c[2],
1266
- priority: c[3] || 0,
1267
- areaCodes: c[4] || null
1268
- };
1269
- }
1270
- function _classCallCheck(instance, Constructor) {
1271
- if (!(instance instanceof Constructor)) {
1272
- throw new TypeError("Cannot call a class as a function");
1273
- }
1274
- }
1275
- function _defineProperties(target, props) {
1276
- for (var i = 0; i < props.length; i++) {
1277
- var descriptor = props[i];
1278
- descriptor.enumerable = descriptor.enumerable || false;
1279
- descriptor.configurable = true;
1280
- if ("value" in descriptor) descriptor.writable = true;
1281
- Object.defineProperty(target, descriptor.key, descriptor);
1282
- }
1283
- }
1284
- function _createClass(Constructor, protoProps, staticProps) {
1285
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1286
- if (staticProps) _defineProperties(Constructor, staticProps);
1287
- return Constructor;
1288
- }
1289
- var intlTelInputGlobals = {
1290
- getInstance: function getInstance(input) {
1291
- var id = input.getAttribute("data-intl-tel-input-id");
1292
- return window.intlTelInputGlobals.instances[id];
1293
- },
1294
- instances: {},
1295
- // using a global like this allows us to mock it in the tests
1296
- documentReady: function documentReady() {
1297
- return document.readyState === "complete";
1298
- }
1299
- };
1300
- if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
1301
- // these vars persist through all instances of the plugin
1302
- var id = 0;
1303
- var defaults = {
1304
- // whether or not to allow the dropdown
1305
- allowDropdown: true,
1306
- // if there is just a dial code in the input: remove it on blur
1307
- autoHideDialCode: true,
1308
- // add a placeholder in the input with an example number for the selected country
1309
- autoPlaceholder: "polite",
1310
- // modify the parentClass
1311
- customContainer: "",
1312
- // modify the auto placeholder
1313
- customPlaceholder: null,
1314
- // append menu to specified element
1315
- dropdownContainer: null,
1316
- // don't display these countries
1317
- excludeCountries: [],
1318
- // format the input value during initialisation and on setNumber
1319
- formatOnDisplay: true,
1320
- // geoIp lookup function
1321
- geoIpLookup: null,
1322
- // inject a hidden input with this name, and on submit, populate it with the result of getNumber
1323
- hiddenInput: "",
1324
- // initial country
1325
- initialCountry: "",
1326
- // localized country names e.g. { 'de': 'Deutschland' }
1327
- localizedCountries: null,
1328
- // don't insert international dial codes
1329
- nationalMode: true,
1330
- // display only these countries
1331
- onlyCountries: [],
1332
- // number type to use for placeholders
1333
- placeholderNumberType: "MOBILE",
1334
- // the countries at the top of the list. defaults to united states and united kingdom
1335
- preferredCountries: [ "us", "gb" ],
1336
- // display the country dial code next to the selected flag so it's not part of the typed number
1337
- separateDialCode: false,
1338
- // specify the path to the libphonenumber script to enable validation/formatting
1339
- utilsScript: ""
1340
- };
1341
- // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
1342
- var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
1343
- // utility function to iterate over an object. can't use Object.entries or native forEach because
1344
- // of IE11
1345
- var forEachProp = function forEachProp(obj, callback) {
1346
- var keys = Object.keys(obj);
1347
- for (var i = 0; i < keys.length; i++) {
1348
- callback(keys[i], obj[keys[i]]);
1349
- }
1350
- };
1351
- // run a method on each instance of the plugin
1352
- var forEachInstance = function forEachInstance(method) {
1353
- forEachProp(window.intlTelInputGlobals.instances, function(key) {
1354
- window.intlTelInputGlobals.instances[key][method]();
1355
- });
1356
- };
1357
- // this is our plugin class that we will create an instance of
1358
- // eslint-disable-next-line no-unused-vars
1359
- var Iti = /*#__PURE__*/
1360
- function() {
1361
- function Iti(input, options) {
1362
- var _this = this;
1363
- _classCallCheck(this, Iti);
1364
- this.id = id++;
1365
- this.telInput = input;
1366
- this.activeItem = null;
1367
- this.highlightedItem = null;
1368
- // process specified options / defaults
1369
- // alternative to Object.assign, which isn't supported by IE11
1370
- var customOptions = options || {};
1371
- this.options = {};
1372
- forEachProp(defaults, function(key, value) {
1373
- _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
1374
- });
1375
- this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1376
- }
1377
- _createClass(Iti, [ {
1378
- key: "_init",
1379
- value: function _init() {
1380
- var _this2 = this;
1381
- // if in nationalMode, disable options relating to dial codes
1382
- if (this.options.nationalMode) this.options.autoHideDialCode = false;
1383
- // if separateDialCode then doesn't make sense to A) insert dial code into input
1384
- // (autoHideDialCode), and B) display national numbers (because we're displaying the country
1385
- // dial code next to them)
1386
- if (this.options.separateDialCode) {
1387
- this.options.autoHideDialCode = this.options.nationalMode = false;
1388
- }
1389
- // we cannot just test screen size as some smartphones/website meta tags will report desktop
1390
- // resolutions
1391
- // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
1392
- // rest of these declarations
1393
- // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1394
- this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1395
- if (this.isMobile) {
1396
- // trigger the mobile dropdown css
1397
- document.body.classList.add("iti-mobile");
1398
- // on mobile, we want a full screen dropdown, so we must append it to the body
1399
- if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
1400
- }
1401
- // these promises get resolved when their individual requests complete
1402
- // this way the dev can do something like iti.promise.then(...) to know when all requests are
1403
- // complete
1404
- if (typeof Promise !== "undefined") {
1405
- var autoCountryPromise = new Promise(function(resolve, reject) {
1406
- _this2.resolveAutoCountryPromise = resolve;
1407
- _this2.rejectAutoCountryPromise = reject;
1408
- });
1409
- var utilsScriptPromise = new Promise(function(resolve, reject) {
1410
- _this2.resolveUtilsScriptPromise = resolve;
1411
- _this2.rejectUtilsScriptPromise = reject;
1412
- });
1413
- this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
1414
- } else {
1415
- // prevent errors when Promise doesn't exist
1416
- this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {};
1417
- this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {};
1418
- }
1419
- // in various situations there could be no country selected initially, but we need to be able
1420
- // to assume this variable exists
1421
- this.selectedCountryData = {};
1422
- // process all the data: onlyCountries, excludeCountries, preferredCountries etc
1423
- this._processCountryData();
1424
- // generate the markup
1425
- this._generateMarkup();
1426
- // set the initial state of the input value and the selected flag
1427
- this._setInitialState();
1428
- // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
1429
- this._initListeners();
1430
- // utils script, and auto country
1431
- this._initRequests();
1432
- }
1433
- }, {
1434
- key: "_processCountryData",
1435
- value: function _processCountryData() {
1436
- // process onlyCountries or excludeCountries array if present
1437
- this._processAllCountries();
1438
- // process the countryCodes map
1439
- this._processCountryCodes();
1440
- // process the preferredCountries
1441
- this._processPreferredCountries();
1442
- // translate countries according to localizedCountries option
1443
- if (this.options.localizedCountries) this._translateCountriesByLocale();
1444
- // sort countries by name
1445
- if (this.options.onlyCountries.length || this.options.localizedCountries) {
1446
- this.countries.sort(this._countryNameSort);
1447
- }
1448
- }
1449
- }, {
1450
- key: "_addCountryCode",
1451
- value: function _addCountryCode(iso2, countryCode, priority) {
1452
- if (countryCode.length > this.countryCodeMaxLen) {
1453
- this.countryCodeMaxLen = countryCode.length;
1454
- }
1455
- if (!this.countryCodes.hasOwnProperty(countryCode)) {
1456
- this.countryCodes[countryCode] = [];
1457
- }
1458
- // bail if we already have this country for this countryCode
1459
- for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
1460
- if (this.countryCodes[countryCode][i] === iso2) return;
1461
- }
1462
- // check for undefined as 0 is falsy
1463
- var index = priority !== undefined$1 ? priority : this.countryCodes[countryCode].length;
1464
- this.countryCodes[countryCode][index] = iso2;
1465
- }
1466
- }, {
1467
- key: "_processAllCountries",
1468
- value: function _processAllCountries() {
1469
- if (this.options.onlyCountries.length) {
1470
- var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
1471
- return country.toLowerCase();
1472
- });
1473
- this.countries = allCountries.filter(function(country) {
1474
- return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
1475
- });
1476
- } else if (this.options.excludeCountries.length) {
1477
- var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
1478
- return country.toLowerCase();
1479
- });
1480
- this.countries = allCountries.filter(function(country) {
1481
- return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
1482
- });
1483
- } else {
1484
- this.countries = allCountries;
1485
- }
1486
- }
1487
- }, {
1488
- key: "_translateCountriesByLocale",
1489
- value: function _translateCountriesByLocale() {
1490
- for (var i = 0; i < this.countries.length; i++) {
1491
- var iso = this.countries[i].iso2.toLowerCase();
1492
- if (this.options.localizedCountries.hasOwnProperty(iso)) {
1493
- this.countries[i].name = this.options.localizedCountries[iso];
1494
- }
1495
- }
1496
- }
1497
- }, {
1498
- key: "_countryNameSort",
1499
- value: function _countryNameSort(a, b) {
1500
- return a.name.localeCompare(b.name);
1501
- }
1502
- }, {
1503
- key: "_processCountryCodes",
1504
- value: function _processCountryCodes() {
1505
- this.countryCodeMaxLen = 0;
1506
- // here we store just dial codes
1507
- this.dialCodes = {};
1508
- // here we store "country codes" (both dial codes and their area codes)
1509
- this.countryCodes = {};
1510
- // first: add dial codes
1511
- for (var i = 0; i < this.countries.length; i++) {
1512
- var c = this.countries[i];
1513
- if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
1514
- this._addCountryCode(c.iso2, c.dialCode, c.priority);
1515
- }
1516
- // next: add area codes
1517
- // this is a second loop over countries, to make sure we have all of the "root" countries
1518
- // already in the map, so that we can access them, as each time we add an area code substring
1519
- // to the map, we also need to include the "root" country's code, as that also matches
1520
- for (var _i = 0; _i < this.countries.length; _i++) {
1521
- var _c = this.countries[_i];
1522
- // area codes
1523
- if (_c.areaCodes) {
1524
- var rootCountryCode = this.countryCodes[_c.dialCode][0];
1525
- // for each area code
1526
- for (var j = 0; j < _c.areaCodes.length; j++) {
1527
- var areaCode = _c.areaCodes[j];
1528
- // for each digit in the area code to add all partial matches as well
1529
- for (var k = 1; k < areaCode.length; k++) {
1530
- var partialDialCode = _c.dialCode + areaCode.substr(0, k);
1531
- // start with the root country, as that also matches this dial code
1532
- this._addCountryCode(rootCountryCode, partialDialCode);
1533
- this._addCountryCode(_c.iso2, partialDialCode);
1534
- }
1535
- // add the full area code
1536
- this._addCountryCode(_c.iso2, _c.dialCode + areaCode);
1537
- }
1538
- }
1539
- }
1540
- }
1541
- }, {
1542
- key: "_processPreferredCountries",
1543
- value: function _processPreferredCountries() {
1544
- this.preferredCountries = [];
1545
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
1546
- var countryCode = this.options.preferredCountries[i].toLowerCase();
1547
- var countryData = this._getCountryData(countryCode, false, true);
1548
- if (countryData) this.preferredCountries.push(countryData);
1549
- }
1550
- }
1551
- }, {
1552
- key: "_createEl",
1553
- value: function _createEl(name, attrs, container) {
1554
- var el = document.createElement(name);
1555
- if (attrs) forEachProp(attrs, function(key, value) {
1556
- return el.setAttribute(key, value);
1557
- });
1558
- if (container) container.appendChild(el);
1559
- return el;
1560
- }
1561
- }, {
1562
- key: "_generateMarkup",
1563
- value: function _generateMarkup() {
1564
- // if autocomplete does not exist on the element and its form, then
1565
- // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
1566
- // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
1567
- // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
1568
- if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1569
- this.telInput.setAttribute("autocomplete", "off");
1570
- }
1571
- // containers (mostly for positioning)
1572
- var parentClass = "iti";
1573
- if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
1574
- if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
1575
- if (this.options.customContainer) {
1576
- parentClass += " ";
1577
- parentClass += this.options.customContainer;
1578
- }
1579
- var wrapper = this._createEl("div", {
1580
- "class": parentClass
1581
- });
1582
- this.telInput.parentNode.insertBefore(wrapper, this.telInput);
1583
- this.flagsContainer = this._createEl("div", {
1584
- "class": "iti__flag-container"
1585
- }, wrapper);
1586
- wrapper.appendChild(this.telInput);
1587
- // selected flag (displayed to left of input)
1588
- this.selectedFlag = this._createEl("div", {
1589
- "class": "iti__selected-flag",
1590
- role: "combobox",
1591
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
1592
- "aria-owns": "iti-".concat(this.id, "__country-listbox"),
1593
- "aria-expanded": "false"
1594
- }, this.flagsContainer);
1595
- this.selectedFlagInner = this._createEl("div", {
1596
- "class": "iti__flag"
1597
- }, this.selectedFlag);
1598
- if (this.options.separateDialCode) {
1599
- this.selectedDialCode = this._createEl("div", {
1600
- "class": "iti__selected-dial-code"
1601
- }, this.selectedFlag);
1602
- }
1603
- if (this.options.allowDropdown) {
1604
- // make element focusable and tab navigable
1605
- this.selectedFlag.setAttribute("tabindex", "0");
1606
- this.dropdownArrow = this._createEl("div", {
1607
- "class": "iti__arrow"
1608
- }, this.selectedFlag);
1609
- // country dropdown: preferred countries, then divider, then all countries
1610
- this.countryList = this._createEl("ul", {
1611
- "class": "iti__country-list iti__hide",
1612
- id: "iti-".concat(this.id, "__country-listbox"),
1613
- role: "listbox",
1614
- "aria-label": "List of countries"
1615
- });
1616
- if (this.preferredCountries.length) {
1617
- this._appendListItems(this.preferredCountries, "iti__preferred", true);
1618
- this._createEl("li", {
1619
- "class": "iti__divider",
1620
- role: "separator",
1621
- "aria-disabled": "true"
1622
- }, this.countryList);
1623
- }
1624
- this._appendListItems(this.countries, "iti__standard");
1625
- // create dropdownContainer markup
1626
- if (this.options.dropdownContainer) {
1627
- this.dropdown = this._createEl("div", {
1628
- "class": "iti iti--container"
1629
- });
1630
- this.dropdown.appendChild(this.countryList);
1631
- } else {
1632
- this.flagsContainer.appendChild(this.countryList);
1633
- }
1634
- }
1635
- if (this.options.hiddenInput) {
1636
- var hiddenInputName = this.options.hiddenInput;
1637
- var name = this.telInput.getAttribute("name");
1638
- if (name) {
1639
- var i = name.lastIndexOf("[");
1640
- // if input name contains square brackets, then give the hidden input the same name,
1641
- // replacing the contents of the last set of brackets with the given hiddenInput name
1642
- if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
1643
- }
1644
- this.hiddenInput = this._createEl("input", {
1645
- type: "hidden",
1646
- name: hiddenInputName
1647
- });
1648
- wrapper.appendChild(this.hiddenInput);
1649
- }
1650
- }
1651
- }, {
1652
- key: "_appendListItems",
1653
- value: function _appendListItems(countries, className, preferred) {
1654
- // we create so many DOM elements, it is faster to build a temp string
1655
- // and then add everything to the DOM in one go at the end
1656
- var tmp = "";
1657
- // for each country
1658
- for (var i = 0; i < countries.length; i++) {
1659
- var c = countries[i];
1660
- var idSuffix = preferred ? "-preferred" : "";
1661
- // open the list item
1662
- 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'>");
1663
- // add the flag
1664
- tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
1665
- // and the country name and dial code
1666
- tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
1667
- tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
1668
- // close the list item
1669
- tmp += "</li>";
1670
- }
1671
- this.countryList.insertAdjacentHTML("beforeend", tmp);
1672
- }
1673
- }, {
1674
- key: "_setInitialState",
1675
- value: function _setInitialState() {
1676
- // fix firefox bug: when first load page (with input with value set to number with intl dial
1677
- // code) and initialising plugin removes the dial code from the input, then refresh page,
1678
- // and we try to init plugin again but this time on number without dial code so get grey flag
1679
- var attributeValue = this.telInput.getAttribute("value");
1680
- var inputValue = this.telInput.value;
1681
- var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
1682
- var val = useAttribute ? attributeValue : inputValue;
1683
- var dialCode = this._getDialCode(val);
1684
- var isRegionlessNanp = this._isRegionlessNanp(val);
1685
- var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
1686
- // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
1687
- // flag, else fall back to the default country
1688
- if (dialCode && !isRegionlessNanp) {
1689
- this._updateFlagFromNumber(val);
1690
- } else if (initialCountry !== "auto") {
1691
- // see if we should select a flag
1692
- if (initialCountry) {
1693
- this._setFlag(initialCountry.toLowerCase());
1694
- } else {
1695
- if (dialCode && isRegionlessNanp) {
1696
- // has intl dial code, is regionless nanp, and no initialCountry, so default to US
1697
- this._setFlag("us");
1698
- } else {
1699
- // no dial code and no initialCountry, so default to first in list
1700
- this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
1701
- if (!val) {
1702
- this._setFlag(this.defaultCountry);
1703
- }
1704
- }
1705
- }
1706
- // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
1707
- if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
1708
- this.telInput.value = "+".concat(this.selectedCountryData.dialCode);
1709
- }
1710
- }
1711
- // NOTE: if initialCountry is set to auto, that will be handled separately
1712
- // format - note this wont be run after _updateDialCode as that's only called if no val
1713
- if (val) this._updateValFromNumber(val);
1714
- }
1715
- }, {
1716
- key: "_initListeners",
1717
- value: function _initListeners() {
1718
- this._initKeyListeners();
1719
- if (this.options.autoHideDialCode) this._initBlurListeners();
1720
- if (this.options.allowDropdown) this._initDropdownListeners();
1721
- if (this.hiddenInput) this._initHiddenInputListener();
1722
- }
1723
- }, {
1724
- key: "_initHiddenInputListener",
1725
- value: function _initHiddenInputListener() {
1726
- var _this3 = this;
1727
- this._handleHiddenInputSubmit = function() {
1728
- _this3.hiddenInput.value = _this3.getNumber();
1729
- };
1730
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
1731
- }
1732
- }, {
1733
- key: "_getClosestLabel",
1734
- value: function _getClosestLabel() {
1735
- var el = this.telInput;
1736
- while (el && el.tagName !== "LABEL") {
1737
- el = el.parentNode;
1738
- }
1739
- return el;
1740
- }
1741
- }, {
1742
- key: "_initDropdownListeners",
1743
- value: function _initDropdownListeners() {
1744
- var _this4 = this;
1745
- // hack for input nested inside label (which is valid markup): clicking the selected-flag to
1746
- // open the dropdown would then automatically trigger a 2nd click on the input which would
1747
- // close it again
1748
- this._handleLabelClick = function(e) {
1749
- // if the dropdown is closed, then focus the input, else ignore the click
1750
- if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
1751
- };
1752
- var label = this._getClosestLabel();
1753
- if (label) label.addEventListener("click", this._handleLabelClick);
1754
- // toggle country dropdown on click
1755
- this._handleClickSelectedFlag = function() {
1756
- // only intercept this event if we're opening the dropdown
1757
- // else let it bubble up to the top ("click-off-to-close" listener)
1758
- // we cannot just stopPropagation as it may be needed to close another instance
1759
- if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
1760
- _this4._showDropdown();
1761
- }
1762
- };
1763
- this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
1764
- // open dropdown list if currently focused
1765
- this._handleFlagsContainerKeydown = function(e) {
1766
- var isDropdownHidden = _this4.countryList.classList.contains("iti__hide");
1767
- if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) {
1768
- // prevent form from being submitted if "ENTER" was pressed
1769
- e.preventDefault();
1770
- // prevent event from being handled again by document
1771
- e.stopPropagation();
1772
- _this4._showDropdown();
1773
- }
1774
- // allow navigation from dropdown to input on TAB
1775
- if (e.key === "Tab") _this4._closeDropdown();
1776
- };
1777
- this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
1778
- }
1779
- }, {
1780
- key: "_initRequests",
1781
- value: function _initRequests() {
1782
- var _this5 = this;
1783
- // if the user has specified the path to the utils script, fetch it on window.load, else resolve
1784
- if (this.options.utilsScript && !window.intlTelInputUtils) {
1785
- // if the plugin is being initialised after the window.load event has already been fired
1786
- if (window.intlTelInputGlobals.documentReady()) {
1787
- window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
1788
- } else {
1789
- // wait until the load event so we don't block any other requests e.g. the flags image
1790
- window.addEventListener("load", function() {
1791
- window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
1792
- });
1793
- }
1794
- } else this.resolveUtilsScriptPromise();
1795
- if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
1796
- }
1797
- }, {
1798
- key: "_loadAutoCountry",
1799
- value: function _loadAutoCountry() {
1800
- // 3 options:
1801
- // 1) already loaded (we're done)
1802
- // 2) not already started loading (start)
1803
- // 3) already started loading (do nothing - just wait for loading callback to fire)
1804
- if (window.intlTelInputGlobals.autoCountry) {
1805
- this.handleAutoCountry();
1806
- } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
1807
- // don't do this twice!
1808
- window.intlTelInputGlobals.startedLoadingAutoCountry = true;
1809
- if (typeof this.options.geoIpLookup === "function") {
1810
- this.options.geoIpLookup(function(countryCode) {
1811
- window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase();
1812
- // tell all instances the auto country is ready
1813
- // TODO: this should just be the current instances
1814
- // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
1815
- // away (e.g. if they have already done the geo ip lookup somewhere else). Using
1816
- // setTimeout means that the current thread of execution will finish before executing
1817
- // this, which allows the plugin to finish initialising.
1818
- setTimeout(function() {
1819
- return forEachInstance("handleAutoCountry");
1820
- });
1821
- }, function() {
1822
- return forEachInstance("rejectAutoCountryPromise");
1823
- });
1824
- }
1825
- }
1826
- }
1827
- }, {
1828
- key: "_initKeyListeners",
1829
- value: function _initKeyListeners() {
1830
- var _this6 = this;
1831
- // update flag on keyup
1832
- this._handleKeyupEvent = function() {
1833
- if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
1834
- _this6._triggerCountryChange();
1835
- }
1836
- };
1837
- this.telInput.addEventListener("keyup", this._handleKeyupEvent);
1838
- // update flag on cut/paste events (now supported in all major browsers)
1839
- this._handleClipboardEvent = function() {
1840
- // hack because "paste" event is fired before input is updated
1841
- setTimeout(_this6._handleKeyupEvent);
1842
- };
1843
- this.telInput.addEventListener("cut", this._handleClipboardEvent);
1844
- this.telInput.addEventListener("paste", this._handleClipboardEvent);
1845
- }
1846
- }, {
1847
- key: "_cap",
1848
- value: function _cap(number) {
1849
- var max = this.telInput.getAttribute("maxlength");
1850
- return max && number.length > max ? number.substr(0, max) : number;
1851
- }
1852
- }, {
1853
- key: "_initBlurListeners",
1854
- value: function _initBlurListeners() {
1855
- var _this7 = this;
1856
- // on blur or form submit: if just a dial code then remove it
1857
- this._handleSubmitOrBlurEvent = function() {
1858
- _this7._removeEmptyDialCode();
1859
- };
1860
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
1861
- this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
1862
- }
1863
- }, {
1864
- key: "_removeEmptyDialCode",
1865
- value: function _removeEmptyDialCode() {
1866
- if (this.telInput.value.charAt(0) === "+") {
1867
- var numeric = this._getNumeric(this.telInput.value);
1868
- // if just a plus, or if just a dial code
1869
- if (!numeric || this.selectedCountryData.dialCode === numeric) {
1870
- this.telInput.value = "";
1871
- }
1872
- }
1873
- }
1874
- }, {
1875
- key: "_getNumeric",
1876
- value: function _getNumeric(s) {
1877
- return s.replace(/\D/g, "");
1878
- }
1879
- }, {
1880
- key: "_trigger",
1881
- value: function _trigger(name) {
1882
- // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
1883
- var e = document.createEvent("Event");
1884
- e.initEvent(name, true, true);
1885
- // can bubble, and is cancellable
1886
- this.telInput.dispatchEvent(e);
1887
- }
1888
- }, {
1889
- key: "_showDropdown",
1890
- value: function _showDropdown() {
1891
- this.countryList.classList.remove("iti__hide");
1892
- this.selectedFlag.setAttribute("aria-expanded", "true");
1893
- this._setDropdownPosition();
1894
- // update highlighting and scroll to active list item
1895
- if (this.activeItem) {
1896
- this._highlightListItem(this.activeItem, false);
1897
- this._scrollTo(this.activeItem, true);
1898
- }
1899
- // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
1900
- this._bindDropdownListeners();
1901
- // update the arrow
1902
- this.dropdownArrow.classList.add("iti__arrow--up");
1903
- this._trigger("open:countrydropdown");
1904
- }
1905
- }, {
1906
- key: "_toggleClass",
1907
- value: function _toggleClass(el, className, shouldHaveClass) {
1908
- if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
1909
- }
1910
- }, {
1911
- key: "_setDropdownPosition",
1912
- value: function _setDropdownPosition() {
1913
- var _this8 = this;
1914
- if (this.options.dropdownContainer) {
1915
- this.options.dropdownContainer.appendChild(this.dropdown);
1916
- }
1917
- if (!this.isMobile) {
1918
- var pos = this.telInput.getBoundingClientRect();
1919
- // windowTop from https://stackoverflow.com/a/14384091/217866
1920
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1921
- var inputTop = pos.top + windowTop;
1922
- var dropdownHeight = this.countryList.offsetHeight;
1923
- // dropdownFitsBelow = (dropdownBottom < windowBottom)
1924
- var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
1925
- var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
1926
- // by default, the dropdown will be below the input. If we want to position it above the
1927
- // input, we add the dropup class.
1928
- this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove);
1929
- // if dropdownContainer is enabled, calculate postion
1930
- if (this.options.dropdownContainer) {
1931
- // by default the dropdown will be directly over the input because it's not in the flow.
1932
- // If we want to position it below, we need to add some extra top value.
1933
- var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight;
1934
- // calculate placement
1935
- this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
1936
- this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
1937
- // close menu on window scroll
1938
- this._handleWindowScroll = function() {
1939
- return _this8._closeDropdown();
1940
- };
1941
- window.addEventListener("scroll", this._handleWindowScroll);
1942
- }
1943
- }
1944
- }
1945
- }, {
1946
- key: "_getClosestListItem",
1947
- value: function _getClosestListItem(target) {
1948
- var el = target;
1949
- while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
1950
- el = el.parentNode;
1951
- }
1952
- // if we reached the countryList element, then return null
1953
- return el === this.countryList ? null : el;
1954
- }
1955
- }, {
1956
- key: "_bindDropdownListeners",
1957
- value: function _bindDropdownListeners() {
1958
- var _this9 = this;
1959
- // when mouse over a list item, just highlight that one
1960
- // we add the class "highlight", so if they hit "enter" we know which one to select
1961
- this._handleMouseoverCountryList = function(e) {
1962
- // handle event delegation, as we're listening for this event on the countryList
1963
- var listItem = _this9._getClosestListItem(e.target);
1964
- if (listItem) _this9._highlightListItem(listItem, false);
1965
- };
1966
- this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
1967
- // listen for country selection
1968
- this._handleClickCountryList = function(e) {
1969
- var listItem = _this9._getClosestListItem(e.target);
1970
- if (listItem) _this9._selectListItem(listItem);
1971
- };
1972
- this.countryList.addEventListener("click", this._handleClickCountryList);
1973
- // click off to close
1974
- // (except when this initial opening click is bubbling up)
1975
- // we cannot just stopPropagation as it may be needed to close another instance
1976
- var isOpening = true;
1977
- this._handleClickOffToClose = function() {
1978
- if (!isOpening) _this9._closeDropdown();
1979
- isOpening = false;
1980
- };
1981
- document.documentElement.addEventListener("click", this._handleClickOffToClose);
1982
- // listen for up/down scrolling, enter to select, or letters to jump to country name.
1983
- // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
1984
- // just hit down and hold it to scroll down (no keyup event).
1985
- // listen on the document because that's where key events are triggered if no input has focus
1986
- var query = "";
1987
- var queryTimer = null;
1988
- this._handleKeydownOnDropdown = function(e) {
1989
- // prevent down key from scrolling the whole page,
1990
- // and enter key from submitting a form etc
1991
- e.preventDefault();
1992
- // up and down to navigate
1993
- 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)) {
1994
- // jump to countries that start with the query string
1995
- if (queryTimer) clearTimeout(queryTimer);
1996
- query += e.key.toLowerCase();
1997
- _this9._searchForCountry(query);
1998
- // if the timer hits 1 second, reset the query
1999
- queryTimer = setTimeout(function() {
2000
- query = "";
2001
- }, 1e3);
2002
- }
2003
- };
2004
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
2005
- }
2006
- }, {
2007
- key: "_handleUpDownKey",
2008
- value: function _handleUpDownKey(key) {
2009
- var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
2010
- if (next) {
2011
- // skip the divider
2012
- if (next.classList.contains("iti__divider")) {
2013
- next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling;
2014
- }
2015
- this._highlightListItem(next, true);
2016
- }
2017
- }
2018
- }, {
2019
- key: "_handleEnterKey",
2020
- value: function _handleEnterKey() {
2021
- if (this.highlightedItem) this._selectListItem(this.highlightedItem);
2022
- }
2023
- }, {
2024
- key: "_searchForCountry",
2025
- value: function _searchForCountry(query) {
2026
- for (var i = 0; i < this.countries.length; i++) {
2027
- if (this._startsWith(this.countries[i].name, query)) {
2028
- var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2));
2029
- // update highlighting and scroll
2030
- this._highlightListItem(listItem, false);
2031
- this._scrollTo(listItem, true);
2032
- break;
2033
- }
2034
- }
2035
- }
2036
- }, {
2037
- key: "_startsWith",
2038
- value: function _startsWith(a, b) {
2039
- return a.substr(0, b.length).toLowerCase() === b;
2040
- }
2041
- }, {
2042
- key: "_updateValFromNumber",
2043
- value: function _updateValFromNumber(originalNumber) {
2044
- var number = originalNumber;
2045
- if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
2046
- var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+");
2047
- var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
2048
- var format = useNational ? NATIONAL : INTERNATIONAL;
2049
- number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
2050
- }
2051
- number = this._beforeSetNumber(number);
2052
- this.telInput.value = number;
2053
- }
2054
- }, {
2055
- key: "_updateFlagFromNumber",
2056
- value: function _updateFlagFromNumber(originalNumber) {
2057
- // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
2058
- // with a +1 so _getDialCode will be able to extract the area code
2059
- // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
2060
- // from the number), that means we're initialising the plugin with a number that already has a
2061
- // dial code, so fine to ignore this bit
2062
- var number = originalNumber;
2063
- var selectedDialCode = this.selectedCountryData.dialCode;
2064
- var isNanp = selectedDialCode === "1";
2065
- if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
2066
- if (number.charAt(0) !== "1") number = "1".concat(number);
2067
- number = "+".concat(number);
2068
- }
2069
- // update flag if user types area code for another country
2070
- if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
2071
- number = "+".concat(selectedDialCode).concat(number);
2072
- }
2073
- // try and extract valid dial code from input
2074
- var dialCode = this._getDialCode(number, true);
2075
- var numeric = this._getNumeric(number);
2076
- var countryCode = null;
2077
- if (dialCode) {
2078
- var countryCodes = this.countryCodes[this._getNumeric(dialCode)];
2079
- // check if the right country is already selected. this should be false if the number is
2080
- // longer than the matched dial code because in this case we need to make sure that if
2081
- // there are multiple country matches, that the first one is selected (note: we could
2082
- // just check that here, but it requires the same loop that we already have later)
2083
- var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2084
- var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
2085
- // only update the flag if:
2086
- // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
2087
- // AND
2088
- // B) the right country is not already selected
2089
- if (!isRegionlessNanpNumber && !alreadySelected) {
2090
- // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
2091
- // non-empty index
2092
- for (var j = 0; j < countryCodes.length; j++) {
2093
- if (countryCodes[j]) {
2094
- countryCode = countryCodes[j];
2095
- break;
2096
- }
2097
- }
2098
- }
2099
- } else if (number.charAt(0) === "+" && numeric.length) {
2100
- // invalid dial code, so empty
2101
- // Note: use getNumeric here because the number has not been formatted yet, so could contain
2102
- // bad chars
2103
- countryCode = "";
2104
- } else if (!number || number === "+") {
2105
- // empty, or just a plus, so default
2106
- countryCode = this.defaultCountry;
2107
- }
2108
- if (countryCode !== null) {
2109
- return this._setFlag(countryCode);
2110
- }
2111
- return false;
2112
- }
2113
- }, {
2114
- key: "_isRegionlessNanp",
2115
- value: function _isRegionlessNanp(number) {
2116
- var numeric = this._getNumeric(number);
2117
- if (numeric.charAt(0) === "1") {
2118
- var areaCode = numeric.substr(1, 3);
2119
- return regionlessNanpNumbers.indexOf(areaCode) !== -1;
2120
- }
2121
- return false;
2122
- }
2123
- }, {
2124
- key: "_highlightListItem",
2125
- value: function _highlightListItem(listItem, shouldFocus) {
2126
- var prevItem = this.highlightedItem;
2127
- if (prevItem) prevItem.classList.remove("iti__highlight");
2128
- this.highlightedItem = listItem;
2129
- this.highlightedItem.classList.add("iti__highlight");
2130
- if (shouldFocus) this.highlightedItem.focus();
2131
- }
2132
- }, {
2133
- key: "_getCountryData",
2134
- value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) {
2135
- var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
2136
- for (var i = 0; i < countryList.length; i++) {
2137
- if (countryList[i].iso2 === countryCode) {
2138
- return countryList[i];
2139
- }
2140
- }
2141
- if (allowFail) {
2142
- return null;
2143
- }
2144
- throw new Error("No country data for '".concat(countryCode, "'"));
2145
- }
2146
- }, {
2147
- key: "_setFlag",
2148
- value: function _setFlag(countryCode) {
2149
- var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
2150
- // do this first as it will throw an error and stop if countryCode is invalid
2151
- this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
2152
- // update the defaultCountry - we only need the iso2 from now on, so just store that
2153
- if (this.selectedCountryData.iso2) {
2154
- this.defaultCountry = this.selectedCountryData.iso2;
2155
- }
2156
- this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
2157
- // update the selected country's title attribute
2158
- var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
2159
- this.selectedFlag.setAttribute("title", title);
2160
- if (this.options.separateDialCode) {
2161
- var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
2162
- this.selectedDialCode.innerHTML = dialCode;
2163
- // offsetWidth is zero if input is in a hidden container during initialisation
2164
- var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
2165
- // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
2166
- this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
2167
- }
2168
- // and the input's placeholder
2169
- this._updatePlaceholder();
2170
- // update the active list item
2171
- if (this.options.allowDropdown) {
2172
- var prevItem = this.activeItem;
2173
- if (prevItem) {
2174
- prevItem.classList.remove("iti__active");
2175
- prevItem.setAttribute("aria-selected", "false");
2176
- }
2177
- if (countryCode) {
2178
- // check if there is a preferred item first, else fall back to standard
2179
- var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode));
2180
- nextItem.setAttribute("aria-selected", "true");
2181
- nextItem.classList.add("iti__active");
2182
- this.activeItem = nextItem;
2183
- this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id"));
2184
- }
2185
- }
2186
- // return if the flag has changed or not
2187
- return prevCountry.iso2 !== countryCode;
2188
- }
2189
- }, {
2190
- key: "_getHiddenSelectedFlagWidth",
2191
- value: function _getHiddenSelectedFlagWidth() {
2192
- // to get the right styling to apply, all we need is a shallow clone of the container,
2193
- // and then to inject a deep clone of the selectedFlag element
2194
- var containerClone = this.telInput.parentNode.cloneNode();
2195
- containerClone.style.visibility = "hidden";
2196
- document.body.appendChild(containerClone);
2197
- var flagsContainerClone = this.flagsContainer.cloneNode();
2198
- containerClone.appendChild(flagsContainerClone);
2199
- var selectedFlagClone = this.selectedFlag.cloneNode(true);
2200
- flagsContainerClone.appendChild(selectedFlagClone);
2201
- var width = selectedFlagClone.offsetWidth;
2202
- containerClone.parentNode.removeChild(containerClone);
2203
- return width;
2204
- }
2205
- }, {
2206
- key: "_updatePlaceholder",
2207
- value: function _updatePlaceholder() {
2208
- var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite";
2209
- if (window.intlTelInputUtils && shouldSetPlaceholder) {
2210
- var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
2211
- var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
2212
- placeholder = this._beforeSetNumber(placeholder);
2213
- if (typeof this.options.customPlaceholder === "function") {
2214
- placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
2215
- }
2216
- this.telInput.setAttribute("placeholder", placeholder);
2217
- }
2218
- }
2219
- }, {
2220
- key: "_selectListItem",
2221
- value: function _selectListItem(listItem) {
2222
- // update selected flag and active list item
2223
- var flagChanged = this._setFlag(listItem.getAttribute("data-country-code"));
2224
- this._closeDropdown();
2225
- this._updateDialCode(listItem.getAttribute("data-dial-code"), true);
2226
- // focus the input
2227
- this.telInput.focus();
2228
- // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
2229
- // inserting dial code), who try to put the cursor at the beginning the first time
2230
- var len = this.telInput.value.length;
2231
- this.telInput.setSelectionRange(len, len);
2232
- if (flagChanged) {
2233
- this._triggerCountryChange();
2234
- }
2235
- }
2236
- }, {
2237
- key: "_closeDropdown",
2238
- value: function _closeDropdown() {
2239
- this.countryList.classList.add("iti__hide");
2240
- this.selectedFlag.setAttribute("aria-expanded", "false");
2241
- // update the arrow
2242
- this.dropdownArrow.classList.remove("iti__arrow--up");
2243
- // unbind key events
2244
- document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2245
- document.documentElement.removeEventListener("click", this._handleClickOffToClose);
2246
- this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
2247
- this.countryList.removeEventListener("click", this._handleClickCountryList);
2248
- // remove menu from container
2249
- if (this.options.dropdownContainer) {
2250
- if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
2251
- if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
2252
- }
2253
- this._trigger("close:countrydropdown");
2254
- }
2255
- }, {
2256
- key: "_scrollTo",
2257
- value: function _scrollTo(element, middle) {
2258
- var container = this.countryList;
2259
- // windowTop from https://stackoverflow.com/a/14384091/217866
2260
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
2261
- var containerHeight = container.offsetHeight;
2262
- var containerTop = container.getBoundingClientRect().top + windowTop;
2263
- var containerBottom = containerTop + containerHeight;
2264
- var elementHeight = element.offsetHeight;
2265
- var elementTop = element.getBoundingClientRect().top + windowTop;
2266
- var elementBottom = elementTop + elementHeight;
2267
- var newScrollTop = elementTop - containerTop + container.scrollTop;
2268
- var middleOffset = containerHeight / 2 - elementHeight / 2;
2269
- if (elementTop < containerTop) {
2270
- // scroll up
2271
- if (middle) newScrollTop -= middleOffset;
2272
- container.scrollTop = newScrollTop;
2273
- } else if (elementBottom > containerBottom) {
2274
- // scroll down
2275
- if (middle) newScrollTop += middleOffset;
2276
- var heightDifference = containerHeight - elementHeight;
2277
- container.scrollTop = newScrollTop - heightDifference;
2278
- }
2279
- }
2280
- }, {
2281
- key: "_updateDialCode",
2282
- value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) {
2283
- var inputVal = this.telInput.value;
2284
- // save having to pass this every time
2285
- var newDialCode = "+".concat(newDialCodeBare);
2286
- var newNumber;
2287
- if (inputVal.charAt(0) === "+") {
2288
- // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
2289
- var prevDialCode = this._getDialCode(inputVal);
2290
- if (prevDialCode) {
2291
- // current number contains a valid dial code, so replace it
2292
- newNumber = inputVal.replace(prevDialCode, newDialCode);
2293
- } else {
2294
- // current number contains an invalid dial code, so ditch it
2295
- // (no way to determine where the invalid dial code ends and the rest of the number begins)
2296
- newNumber = newDialCode;
2297
- }
2298
- } else if (this.options.nationalMode || this.options.separateDialCode) {
2299
- // don't do anything
2300
- return;
2301
- } else {
2302
- // nationalMode is disabled
2303
- if (inputVal) {
2304
- // there is an existing value with no dial code: prefix the new dial code
2305
- newNumber = newDialCode + inputVal;
2306
- } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
2307
- // no existing value and either they've just selected a list item, or autoHideDialCode is
2308
- // disabled: insert new dial code
2309
- newNumber = newDialCode;
2310
- } else {
2311
- return;
2312
- }
2313
- }
2314
- this.telInput.value = newNumber;
2315
- }
2316
- }, {
2317
- key: "_getDialCode",
2318
- value: function _getDialCode(number, includeAreaCode) {
2319
- var dialCode = "";
2320
- // only interested in international numbers (starting with a plus)
2321
- if (number.charAt(0) === "+") {
2322
- var numericChars = "";
2323
- // iterate over chars
2324
- for (var i = 0; i < number.length; i++) {
2325
- var c = number.charAt(i);
2326
- // if char is number (https://stackoverflow.com/a/8935649/217866)
2327
- if (!isNaN(parseInt(c, 10))) {
2328
- numericChars += c;
2329
- // if current numericChars make a valid dial code
2330
- if (includeAreaCode) {
2331
- if (this.countryCodes[numericChars]) {
2332
- // store the actual raw string (useful for matching later)
2333
- dialCode = number.substr(0, i + 1);
2334
- }
2335
- } else {
2336
- if (this.dialCodes[numericChars]) {
2337
- dialCode = number.substr(0, i + 1);
2338
- // if we're just looking for a dial code, we can break as soon as we find one
2339
- break;
2340
- }
2341
- }
2342
- // stop searching as soon as we can - in this case when we hit max len
2343
- if (numericChars.length === this.countryCodeMaxLen) {
2344
- break;
2345
- }
2346
- }
2347
- }
2348
- }
2349
- return dialCode;
2350
- }
2351
- }, {
2352
- key: "_getFullNumber",
2353
- value: function _getFullNumber() {
2354
- var val = this.telInput.value.trim();
2355
- var dialCode = this.selectedCountryData.dialCode;
2356
- var prefix;
2357
- var numericVal = this._getNumeric(val);
2358
- if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
2359
- // when using separateDialCode, it is visible so is effectively part of the typed number
2360
- prefix = "+".concat(dialCode);
2361
- } else {
2362
- prefix = "";
2363
- }
2364
- return prefix + val;
2365
- }
2366
- }, {
2367
- key: "_beforeSetNumber",
2368
- value: function _beforeSetNumber(originalNumber) {
2369
- var number = originalNumber;
2370
- if (this.options.separateDialCode) {
2371
- var dialCode = this._getDialCode(number);
2372
- // if there is a valid dial code
2373
- if (dialCode) {
2374
- // in case _getDialCode returned an area code as well
2375
- dialCode = "+".concat(this.selectedCountryData.dialCode);
2376
- // a lot of numbers will have a space separating the dial code and the main number, and
2377
- // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
2378
- // rid of it
2379
- // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
2380
- var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2381
- number = number.substr(start);
2382
- }
2383
- }
2384
- return this._cap(number);
2385
- }
2386
- }, {
2387
- key: "_triggerCountryChange",
2388
- value: function _triggerCountryChange() {
2389
- this._trigger("countrychange");
2390
- }
2391
- }, {
2392
- key: "handleAutoCountry",
2393
- value: function handleAutoCountry() {
2394
- if (this.options.initialCountry === "auto") {
2395
- // we must set this even if there is an initial val in the input: in case the initial val is
2396
- // invalid and they delete it - they should see their auto country
2397
- this.defaultCountry = window.intlTelInputGlobals.autoCountry;
2398
- // if there's no initial value in the input, then update the flag
2399
- if (!this.telInput.value) {
2400
- this.setCountry(this.defaultCountry);
2401
- }
2402
- this.resolveAutoCountryPromise();
2403
- }
2404
- }
2405
- }, {
2406
- key: "handleUtils",
2407
- value: function handleUtils() {
2408
- // if the request was successful
2409
- if (window.intlTelInputUtils) {
2410
- // if there's an initial value in the input, then format it
2411
- if (this.telInput.value) {
2412
- this._updateValFromNumber(this.telInput.value);
2413
- }
2414
- this._updatePlaceholder();
2415
- }
2416
- this.resolveUtilsScriptPromise();
2417
- }
2418
- }, {
2419
- key: "destroy",
2420
- value: function destroy() {
2421
- var form = this.telInput.form;
2422
- if (this.options.allowDropdown) {
2423
- // make sure the dropdown is closed (and unbind listeners)
2424
- this._closeDropdown();
2425
- this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
2426
- this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
2427
- // label click hack
2428
- var label = this._getClosestLabel();
2429
- if (label) label.removeEventListener("click", this._handleLabelClick);
2430
- }
2431
- // unbind hiddenInput listeners
2432
- if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
2433
- // unbind autoHideDialCode listeners
2434
- if (this.options.autoHideDialCode) {
2435
- if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
2436
- this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
2437
- }
2438
- // unbind key events, and cut/paste events
2439
- this.telInput.removeEventListener("keyup", this._handleKeyupEvent);
2440
- this.telInput.removeEventListener("cut", this._handleClipboardEvent);
2441
- this.telInput.removeEventListener("paste", this._handleClipboardEvent);
2442
- // remove attribute of id instance: data-intl-tel-input-id
2443
- this.telInput.removeAttribute("data-intl-tel-input-id");
2444
- // remove markup (but leave the original input)
2445
- var wrapper = this.telInput.parentNode;
2446
- wrapper.parentNode.insertBefore(this.telInput, wrapper);
2447
- wrapper.parentNode.removeChild(wrapper);
2448
- delete window.intlTelInputGlobals.instances[this.id];
2449
- }
2450
- }, {
2451
- key: "getExtension",
2452
- value: function getExtension() {
2453
- if (window.intlTelInputUtils) {
2454
- return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
2455
- }
2456
- return "";
2457
- }
2458
- }, {
2459
- key: "getNumber",
2460
- value: function getNumber(format) {
2461
- if (window.intlTelInputUtils) {
2462
- var iso2 = this.selectedCountryData.iso2;
2463
- return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
2464
- }
2465
- return "";
2466
- }
2467
- }, {
2468
- key: "getNumberType",
2469
- value: function getNumberType() {
2470
- if (window.intlTelInputUtils) {
2471
- return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
2472
- }
2473
- return -99;
2474
- }
2475
- }, {
2476
- key: "getSelectedCountryData",
2477
- value: function getSelectedCountryData() {
2478
- return this.selectedCountryData;
2479
- }
2480
- }, {
2481
- key: "getValidationError",
2482
- value: function getValidationError() {
2483
- if (window.intlTelInputUtils) {
2484
- var iso2 = this.selectedCountryData.iso2;
2485
- return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
2486
- }
2487
- return -99;
2488
- }
2489
- }, {
2490
- key: "isValidNumber",
2491
- value: function isValidNumber() {
2492
- var val = this._getFullNumber().trim();
2493
- var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
2494
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
2495
- }
2496
- }, {
2497
- key: "setCountry",
2498
- value: function setCountry(originalCountryCode) {
2499
- var countryCode = originalCountryCode.toLowerCase();
2500
- // check if already selected
2501
- if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
2502
- this._setFlag(countryCode);
2503
- this._updateDialCode(this.selectedCountryData.dialCode, false);
2504
- this._triggerCountryChange();
2505
- }
2506
- }
2507
- }, {
2508
- key: "setNumber",
2509
- value: function setNumber(number) {
2510
- // we must update the flag first, which updates this.selectedCountryData, which is used for
2511
- // formatting the number before displaying it
2512
- var flagChanged = this._updateFlagFromNumber(number);
2513
- this._updateValFromNumber(number);
2514
- if (flagChanged) {
2515
- this._triggerCountryChange();
2516
- }
2517
- }
2518
- }, {
2519
- key: "setPlaceholderNumberType",
2520
- value: function setPlaceholderNumberType(type) {
2521
- this.options.placeholderNumberType = type;
2522
- this._updatePlaceholder();
2523
- }
2524
- } ]);
2525
- return Iti;
2526
- }();
2527
- /********************
2528
- * STATIC METHODS
2529
- ********************/
2530
- // get the country data object
2531
- intlTelInputGlobals.getCountryData = function() {
2532
- return allCountries;
2533
- };
2534
- // inject a <script> element to load utils.js
2535
- var injectScript = function injectScript(path, handleSuccess, handleFailure) {
2536
- // inject a new script element into the page
2537
- var script = document.createElement("script");
2538
- script.onload = function() {
2539
- forEachInstance("handleUtils");
2540
- if (handleSuccess) handleSuccess();
2541
- };
2542
- script.onerror = function() {
2543
- forEachInstance("rejectUtilsScriptPromise");
2544
- if (handleFailure) handleFailure();
2545
- };
2546
- script.className = "iti-load-utils";
2547
- script.async = true;
2548
- script.src = path;
2549
- document.body.appendChild(script);
2550
- };
2551
- // load the utils script
2552
- intlTelInputGlobals.loadUtils = function(path) {
2553
- // 2 options:
2554
- // 1) not already started loading (start)
2555
- // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
2556
- // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
2557
- if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
2558
- // only do this once
2559
- window.intlTelInputGlobals.startedLoadingUtilsScript = true;
2560
- // if we have promises, then return a promise
2561
- if (typeof Promise !== "undefined") {
2562
- return new Promise(function(resolve, reject) {
2563
- return injectScript(path, resolve, reject);
2564
- });
2565
- }
2566
- injectScript(path);
2567
- }
2568
- return null;
2569
- };
2570
- // default options
2571
- intlTelInputGlobals.defaults = defaults;
2572
- // version
2573
- intlTelInputGlobals.version = "17.0.18";
2574
- // convenience wrapper
2575
- return function(input, options) {
2576
- var iti = new Iti(input, options);
2577
- iti._init();
2578
- input.setAttribute("data-intl-tel-input-id", iti.id);
2579
- window.intlTelInputGlobals.instances[iti.id] = iti;
2580
- return iti;
2581
- };
2582
- }();
2583
- });
2584
- });
2585
-
2586
- /**
2587
- * Exposing intl-tel-input as a component
2588
- */
2589
- var intlTelInput = intlTelInput$1;
2590
-
2591
- 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}";
2592
-
2593
- const SallaTelInput = class {
2594
- constructor(hostRef) {
2595
- index.registerInstance(this, hostRef);
2596
- this.enterClicked = index.createEvent(this, "enterClicked", 7);
2597
- /**
2598
- * input name
2599
- */
2600
- this.name = 'phone';
2601
- /**
2602
- * Current country_code
2603
- */
2604
- this.countryCode = salla.config.get('user.country_code', 'SA');
2605
- this.countryCodeLabel = salla.lang.get('common.country_code');
2606
- this.mobileLabel = salla.lang.get('common.elements.mobile');
2607
- this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2608
- this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2609
- this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2610
- this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2611
- this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2612
- Helper.Helper.setHost(this.host);
2613
- salla.lang.onLoaded(() => {
2614
- this.mobileLabel = salla.lang.get('common.elements.mobile');
2615
- this.countryCodeLabel = salla.lang.get('common.elements.country_code');
2616
- this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2617
- this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2618
- this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2619
- this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2620
- this.mobileRequired = salla.lang.get('common.errors.field_required', { attribute: this.mobileLabel });
2621
- this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2622
- });
2623
- }
2624
- /**
2625
- * Get current values
2626
- * @return {{mobile:number,countryCode:'SA'|string}}
2627
- */
2628
- async getValues() {
2629
- return {
2630
- [this.name]: this.phone = this.phoneInput.value,
2631
- countryCode: this.countryCode = this.countryCodeInput.value
2632
- };
2633
- }
2634
- /**
2635
- * Is current data valid or not
2636
- * @return {boolean}
2637
- */
2638
- async isValid() {
2639
- this.reset();
2640
- if (this.iti.isValidNumber())
2641
- return true;
2642
- if (!this.phoneInput.value.trim()) {
2643
- this.phoneInput.classList.add("s-has-error");
2644
- this.errorMsg.innerText = this.mobileRequired || 'The mobile is required';
2645
- return;
2646
- }
2647
- this.phoneInput.classList.add("s-has-error");
2648
- let errorCode = this.iti.getValidationError();
2649
- this.errorMsg.innerText = this.errorMap[errorCode] || '';
2650
- salla.logger.info('Phone number (' + this.countryCode + ' - ' + this.phone + ') is not valid, error code ' + errorCode);
2651
- return false;
2652
- }
2653
- initTelInput() {
2654
- salla.helpers.inputDigitsOnly(this.phoneInput);
2655
- this.iti = intlTelInput(this.phoneInput, {
2656
- initialCountry: this.countryCode || 'sa',
2657
- preferredCountries: ['sa', 'ae', 'kw', 'bh', 'qa', 'iq', 'om', 'ye', 'eg', 'jo', 'sy', 'ps', 'sd', 'lb', 'dz', 'tn', 'ma', 'ly'],
2658
- formatOnDisplay: false,
2659
- separateDialCode: true,
2660
- autoPlaceholder: 'aggressive',
2661
- utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.min.js',
2662
- });
2663
- this.phoneInput.addEventListener("countrychange", () => {
2664
- let data = this.iti.getSelectedCountryData();
2665
- this.countryCodeInput.value = data.iso2.toUpperCase();
2666
- });
2667
- // on blur: validate
2668
- // this.phoneInput.addEventListener('blur', () => this.isValid());
2669
- // on keyup / change flag: reset
2670
- this.phoneInput.addEventListener('input', e => {
2671
- salla.helpers.inputDigitsOnly(e.target);
2672
- this.reset();
2673
- });
2674
- }
2675
- reset() {
2676
- this.phoneInput.classList.remove("s-has-error");
2677
- this.errorMsg.innerHTML = "";
2678
- }
2679
- ;
2680
- render() {
2681
- return (index.h(index.Host, { class: "s-tel-input" }, index.h("input", { type: "tel", name: this.name, value: this.phone, ref: el => this.phoneInput = el, class: "s-tel-input-control tel-input s-ltr" }), index.h("span", { class: "s-tel-input-error-msg", ref: el => this.errorMsg = el }), index.h("input", { type: "hidden", name: "country_code", value: this.countryCode, ref: el => this.countryCodeInput = el, class: "country_code" })));
2682
- }
2683
- componentDidLoad() {
2684
- this.initTelInput();
2685
- }
2686
- get host() { return index.getElement(this); }
2687
- };
2688
- SallaTelInput.style = sallaTelInputCss;
2689
-
2690
- const AndroidPhoneIcon = `<!-- Generated by IcoMoon.io -->
2691
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2692
- <title>android-phone</title>
2693
- <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>
2694
- </svg>
2695
- `;
2696
-
2697
- const sallaVerifyCss = "salla-verify{display:block}";
2698
-
2699
- const SallaVerify = class {
2700
- constructor(hostRef) {
2701
- index.registerInstance(this, hostRef);
2702
- this.verified = index.createEvent(this, "verified", 7);
2703
- this.initiated = false;
2704
- this.translationLoaded = false;
2705
- /**
2706
- * Should render component without modal
2707
- */
2708
- this.display = 'modal';
2709
- /**
2710
- * Verifying method
2711
- */
2712
- this.type = 'mobile';
2713
- /**
2714
- * should auto reloading the page after success verification
2715
- */
2716
- this.autoReload = true;
2717
- this.resendAfter = 30;
2718
- /**
2719
- * to use: `salla.api.auth.verify` or `salla.profile.verify`
2720
- */
2721
- this.isProfileVerify = false;
2722
- // Helper.setHost(this.host);
2723
- salla.lang.onLoaded(() => {
2724
- var _a;
2725
- this.translationLoaded = true;
2726
- this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + this.type);
2727
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2728
- });
2729
- if (this.display == 'inline') {
2730
- this.modal = { open: () => '', close: () => '', setTitle: () => '' };
2731
- return;
2732
- }
2733
- salla.event.on('profile::verification', data => {
2734
- var _a;
2735
- this.isProfileVerify = true;
2736
- this.open(data);
2737
- this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + data.type);
2738
- (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2739
- });
2740
- salla.event.on('modalClosed', () => {
2741
- this.resendAfter = 0;
2742
- this.timer.innerHTML = '30 : 00';
2743
- });
2744
- }
2745
- /**
2746
- * Get current code
2747
- * @return {string}
2748
- */
2749
- async getCode() {
2750
- return this.code.value;
2751
- }
2752
- /**
2753
- * Open verifying modal
2754
- * @param data
2755
- */
2756
- async open(data) {
2757
- var _a;
2758
- this.data = data;
2759
- this.data.type = this.data.type || this.type;
2760
- this.type = this.data.type;
2761
- this.resendTimer();
2762
- this.otpInputs = this.body.querySelectorAll('.s-verify-input');
2763
- if (!this.initiated) {
2764
- Helper.Helper.on('input', '.s-verify-input', e => salla.helpers.inputDigitsOnly(e.target));
2765
- Helper.Helper.onKeyUp('.s-verify-input', event => {
2766
- var _a, _b, _c, _d;
2767
- let key = event.keyCode || event.charCode;
2768
- if (event.target.value) {
2769
- (_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
2770
- (_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
2771
- }
2772
- else if ([8, 46].includes(key)) {
2773
- (_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
2774
- (_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
2775
- }
2776
- this.toggleOTPSubmit();
2777
- });
2778
- Helper.Helper.on('paste', '.s-verify-input', event => {
2779
- let text = salla.helpers.number(event.clipboardData.getData('text')).replace(/[^0-9.]/g, '').replace('..', '.');
2780
- this.otpInputs.forEach((input, i) => input.value = text[i] || '');
2781
- this.toggleOTPSubmit();
2782
- setTimeout(() => this.otpInputs[3].focus(), 100);
2783
- });
2784
- // return this.modal.open();
2785
- this.initiated = true;
2786
- }
2787
- this.reset();
2788
- this.display == 'modal' && ((_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title));
2789
- this.modal.open();
2790
- // focus the first input after opening the modal
2791
- setTimeout(() => this.otpInputs[0].focus(), 100);
2792
- }
2793
- toggleOTPSubmit() {
2794
- let otp = [];
2795
- this.otpInputs.forEach(input => input.value && otp.push(input.value));
2796
- this.code.value = otp.join('');
2797
- if (otp.length === 4) {
2798
- this.btn.disable();
2799
- this.btn.click();
2800
- return;
2801
- }
2802
- this.btn.enable();
2803
- }
2804
- reset() {
2805
- this.otpInputs.forEach((input) => input.value = '');
2806
- this.code.value = '';
2807
- this.otpInputs[0].focus();
2808
- }
2809
- resendTimer() {
2810
- Helper.Helper.showElement(this.resendMessage).hideElement(this.resend);
2811
- this.resendAfter = 30;
2812
- let timerId = setInterval(() => {
2813
- if (this.resendAfter <= 0) {
2814
- clearInterval(timerId);
2815
- Helper.Helper.hideElement(this.resendMessage).showElement(this.resend);
2816
- }
2817
- else {
2818
- this.timer.innerHTML = `${this.resendAfter >= 10 ? this.resendAfter : '0' + this.resendAfter} : 00`;
2819
- this.resendAfter--;
2820
- }
2821
- }, 1000);
2822
- }
2823
- resendCode() {
2824
- return this.btn.stop()
2825
- .then(() => this.btn.disable())
2826
- .then(() => {
2827
- this.otpInputs.forEach(input => input.value = '');
2828
- this.otpInputs[0].focus();
2829
- })
2830
- .then(() => salla.api.auth.resend(this.data))
2831
- .finally(() => this.resendTimer());
2832
- }
2833
- submit() {
2834
- let data = Object.assign({ code: this.code.value }, this.data);
2835
- return this.btn.load()
2836
- .then(() => this.btn.disable())
2837
- .then(() => this.isProfileVerify ? salla.profile.verify(data) : salla.auth.verify(data, true))
2838
- .then(response => this.verified.emit(response))
2839
- .then(() => this.btn.stop() && this.btn.disable())
2840
- .then(() => this.modal.close())
2841
- .then(() => this.autoReload && window.location.reload())
2842
- .catch((error) => {
2843
- salla.logger.error(error);
2844
- this.btn.stop() && this.btn.enable() && this.reset();
2845
- });
2846
- }
2847
- render() {
2848
- return this.display == 'inline' ? index.h(index.Host, null, this.myBody()) :
2849
- index.h("salla-modal", { width: "xs", class: "s-verify", ref: modal => this.modal = modal, "modal-title": this.title }, index.h("span", { slot: 'icon', innerHTML: AndroidPhoneIcon }), this.myBody());
2850
- }
2851
- myBody() {
2852
- return (index.h("div", { class: "s-verify-body", ref: body => this.body = body }, index.h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }), index.h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }), index.h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => index.h("input", { type: "text", maxlength: "1", class: "s-verify-input", required: true }))), index.h("div", { slot: "footer", class: "s-verify-footer" }, index.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')), index.h("p", { class: "s-verify-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), index.h("b", { class: "s-verify-timer", ref: el => this.timer = el }), " "), index.h("a", { href: "#", class: "s-verify-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit'))), index.h("slot", { name: "after-footer" })));
2853
- }
2854
- get host() { return index.getElement(this); }
2855
- };
2856
- SallaVerify.style = sallaVerifyCss;
2857
-
2858
- exports.salla_add_product_button = SallaAddProductButton;
2859
- exports.salla_button = SallaButton;
2860
- exports.salla_loading = SallaLoading;
2861
- exports.salla_localization_modal = SallaLocalizationModal;
2862
- exports.salla_login_modal = SallaLoginModal;
2863
- exports.salla_modal = SallaModal;
2864
- exports.salla_offer_modal = SallaOfferModal;
2865
- exports.salla_product_availability = SallaProductAvailability;
2866
- exports.salla_rating_stars = SallaRatingStars;
2867
- exports.salla_search = SallaSearch;
2868
- exports.salla_skeleton = SallaSkeleton;
2869
- exports.salla_tel_input = SallaTelInput;
2870
- exports.salla_verify = SallaVerify;