@salla.sa/twilight-components 1.6.2 → 1.6.4

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