@salla.sa/twilight-components 1.0.104 → 1.0.107
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.
- package/README.md +8 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-add-product-button.cjs.entry.js +85 -0
- package/dist/cjs/{salla-add-product-button_6.cjs.entry.js → salla-branches_13.cjs.entry.js} +989 -62
- package/dist/cjs/twilight-components.cjs.js +1 -1
- package/dist/collection/components/salla-login-modal/salla-login-modal.js +15 -4
- package/dist/collection/global/app.js +23 -0
- package/dist/collection/plugins/tailwind-theme/index.js +3 -4
- package/dist/components/salla-login-modal.js +10 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-add-product-button.entry.js +81 -0
- package/dist/esm/{salla-add-product-button_6.entry.js → salla-branches_13.entry.js} +983 -63
- package/dist/esm/twilight-components.js +1 -1
- package/dist/twilight-components/p-6f4f4260.entry.js +4 -0
- package/dist/twilight-components/p-7b5b8647.entry.js +4 -0
- package/dist/twilight-components/twilight-components.esm.js +1 -1
- package/dist/types/components/salla-login-modal/salla-login-modal.d.ts +1 -1
- package/dist/types/components.d.ts +1 -1
- package/dist/types/global/app.d.ts +3 -0
- package/example/assets/tailwind.css +3938 -3
- package/example/assets/translations.js +4981 -0
- package/example/index.html +8 -8
- package/package.json +13 -6
- package/dist/cjs/salla-branches.cjs.entry.js +0 -98
- package/dist/cjs/salla-infinite-scroll.cjs.entry.js +0 -93
- package/dist/cjs/salla-localization-modal.cjs.entry.js +0 -121
- package/dist/cjs/salla-login-modal.cjs.entry.js +0 -196
- package/dist/cjs/salla-offer-modal.cjs.entry.js +0 -145
- package/dist/cjs/salla-rating-modal.cjs.entry.js +0 -177
- package/dist/cjs/salla-rating-stars.cjs.entry.js +0 -76
- package/dist/cjs/salla-verify.cjs.entry.js +0 -168
- package/dist/esm/salla-branches.entry.js +0 -94
- package/dist/esm/salla-infinite-scroll.entry.js +0 -89
- package/dist/esm/salla-localization-modal.entry.js +0 -117
- package/dist/esm/salla-login-modal.entry.js +0 -192
- package/dist/esm/salla-offer-modal.entry.js +0 -141
- package/dist/esm/salla-rating-modal.entry.js +0 -173
- package/dist/esm/salla-rating-stars.entry.js +0 -72
- package/dist/esm/salla-verify.entry.js +0 -164
- package/dist/twilight-components/p-30e63760.entry.js +0 -4
- package/dist/twilight-components/p-799da239.entry.js +0 -4
- package/dist/twilight-components/p-9ff78dd1.entry.js +0 -4
- package/dist/twilight-components/p-c1952856.entry.js +0 -4
- package/dist/twilight-components/p-cf143464.entry.js +0 -4
- package/dist/twilight-components/p-d3778858.entry.js +0 -4
- package/dist/twilight-components/p-ebd2e045.entry.js +0 -4
- package/dist/twilight-components/p-ec0a2892.entry.js +0 -4
- package/dist/twilight-components/p-fab65162.entry.js +0 -4
- package/example/dist/demo.js +0 -153
- package/example/dist/flags.png +0 -0
- package/example/dist/flags@2x.png +0 -0
- package/example/dist/intlTelInput.min.css +0 -1
- package/example/dist/tailwind.css +0 -3856
- package/example/dist/translations.js +0 -1
- package/example/dist/twilight.js +0 -437
|
@@ -8,80 +8,93 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
8
8
|
const index = require('./index-b4140db0.js');
|
|
9
9
|
const Helper = require('./Helper-8ae6a805.js');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const sallaBranchesCss = "";
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const SallaBranches = class {
|
|
14
14
|
constructor(hostRef) {
|
|
15
15
|
index.registerInstance(this, hostRef);
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
this.open = true;
|
|
17
|
+
this.isOpenedBefore = salla.storage.get("branch-choosed-before");
|
|
18
|
+
this.displayAs = 'default'; //todo:: change it to boolean, isPopup default false
|
|
19
|
+
this.browseProductsFrom = 'all'; //todo:: get better name
|
|
20
|
+
this.branches = [
|
|
21
|
+
{ id: 1, name: 'فرع الرياض', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
22
|
+
{ id: 2, name: 'فرع جدة', open: false, available: false, limited: false, tag: 'غير متوفر' },
|
|
23
|
+
{ id: 3, name: 'فرع مكة', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
24
|
+
{ id: 4, name: 'فرع المدينة', open: true, available: true, limited: false, tag: 'متوفر' },
|
|
25
|
+
{ id: 5, name: 'فرع جازان', open: true, available: true, limited: true, tag: 'الكمية محدودة' }
|
|
26
|
+
];
|
|
27
|
+
this.current = 1;
|
|
28
|
+
this.currentBranch = (prop) => {
|
|
29
|
+
return this.branches.filter((el) => el.id == this.current)[0][prop];
|
|
30
|
+
};
|
|
31
|
+
this.statusColor = (branch = null) => {
|
|
32
|
+
return branch ?
|
|
33
|
+
branch.limited ? 's-branches-color-red' : branch.available ? 's-branches-color-green' : 's-branches-color-gray'
|
|
34
|
+
:
|
|
35
|
+
this.currentBranch('limited') ? 's-branches-color-red' : this.currentBranch('available') ? 's-branches-color-green' : 's-branches-color-gray';
|
|
36
|
+
};
|
|
37
|
+
this.isChoiceable = () => {
|
|
38
|
+
return (this.browseProductsFrom !== 'all' && this.position == 'single') || this.position == 'header';
|
|
39
|
+
};
|
|
40
|
+
this.formTitle = () => {
|
|
41
|
+
return this.isChoiceable() ?
|
|
42
|
+
'توفر المنتج في الفروع الآخرى'
|
|
43
|
+
: 'التسوق من فرع آخر';
|
|
44
|
+
};
|
|
45
|
+
salla.event.on('branches::show', btn => btn.dataset.target == this.host.id && this.show());
|
|
46
|
+
salla.lang.onLoaded(() => { var _a; return (_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(salla.lang.get('common.elements.ok')); });
|
|
35
47
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
event.preventDefault();
|
|
42
|
-
/**
|
|
43
|
-
* by default the quick add is just an alias for add item function
|
|
44
|
-
* but its work only when the id is the only value is passed via the object
|
|
45
|
-
* so we will filter the object entities to remove null and zero values in case we don't want the normal add item action
|
|
46
|
-
*/
|
|
47
|
-
const data = Object.entries({
|
|
48
|
-
id: this.productId,
|
|
49
|
-
donating_amount: this.donatingAmount,
|
|
50
|
-
quantity: this.quantity
|
|
51
|
-
}).reduce((a, [k, v]) => (v ? (a[k] = v, a) : a), {});
|
|
52
|
-
return salla.cart.quickAdd(data)
|
|
53
|
-
.then((response) => {
|
|
54
|
-
console.log("🚀 ~ file: salla-add-product-button.tsx ~ line 67 ~ SallaAddProductButton ~ .then ~ response", response);
|
|
55
|
-
return this.success.emit(response);
|
|
56
|
-
})
|
|
57
|
-
.catch((error) => {
|
|
58
|
-
console.log("🚀 ~ file: salla-add-product-button.tsx ~ line 70 ~ SallaAddProductButton ~ addProductToCart ~ error", error);
|
|
59
|
-
return this.failed.emit(error);
|
|
60
|
-
});
|
|
48
|
+
//todo:: add description for all @methods
|
|
49
|
+
async show() {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = this.modal) === null || _a === void 0 ? void 0 : _a.open();
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return this.hostAttributes;
|
|
53
|
+
async hide() {
|
|
54
|
+
var _a;
|
|
55
|
+
return (_a = this.modal) === null || _a === void 0 ? void 0 : _a.close();
|
|
69
56
|
}
|
|
70
|
-
|
|
71
|
-
this.
|
|
57
|
+
handelChange(event) {
|
|
58
|
+
this.selected = event.target.value;
|
|
59
|
+
}
|
|
60
|
+
handleSubmit() {
|
|
61
|
+
this.btn.load().then(() => {
|
|
62
|
+
setTimeout(() => location.reload(), 2000);
|
|
63
|
+
});
|
|
64
|
+
salla.storage.set("branch-choosed-before", true);
|
|
65
|
+
this.show();
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
this.current = this.selected;
|
|
68
|
+
}, 300);
|
|
72
69
|
}
|
|
73
70
|
render() {
|
|
74
|
-
return (index.h(
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
return (index.h("salla-modal", { icon: "sicon-store-alt", "modal-title": "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636", "sub-title": "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646", "sub-title-first": true,
|
|
72
|
+
// is-closable={!this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true'}
|
|
73
|
+
ref: (modal) => this.modal = modal, width: "sm", id: "s-branches-modal", class: "s-hidden" }, index.h("h4", { class: "s-branches-title" }, this.formTitle()), this.branches.length <= 5 ?
|
|
74
|
+
index.h("div", { class: "s-branches-space-v" }, this.branches.map((branch) => index.h("div", { class: "s-branches-input-wrap" }, index.h("input", { id: this.position + '_branch_' + branch.id, disabled: !branch.open && this.isChoiceable(), name: "lang", type: "radio", value: branch.id, onChange: (event) => this.handelChange(event), class: {
|
|
75
|
+
's-branches-input': true,
|
|
76
|
+
'opacity-50': !branch.open,
|
|
77
|
+
's-hidden': !this.isChoiceable()
|
|
78
|
+
}, checked: this.current == branch.id }), index.h("label", { htmlFor: this.position + '_branch_' + branch.id, class: {
|
|
79
|
+
's-branches-label': true,
|
|
80
|
+
's-branches-clickable': this.isChoiceable()
|
|
81
|
+
} }, index.h("span", { class: { 's-branches-is-closed': !branch.open } }, branch.name), this.isChoiceable() ?
|
|
82
|
+
index.h("small", { class: "s-branches-closed-badge" }, branch.open ? '' : 'مُغلق')
|
|
83
|
+
:
|
|
84
|
+
index.h("span", { class: this.statusColor(branch) }, branch.tag)))))
|
|
85
|
+
:
|
|
86
|
+
index.h("select", { class: "s-branches-select", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (index.h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id }, branch.name, " ", branch.open ? '' : '- مُغلق')))), this.isChoiceable() ?
|
|
87
|
+
index.h("slot", { name: "footer" }, index.h("salla-button", { ref: btn => this.btn = btn, onClick: () => this.handleSubmit(), class: "s-branches-submit", width: "wide" }, salla.lang.get('common.elements.ok')))
|
|
88
|
+
: ''));
|
|
77
89
|
}
|
|
78
90
|
componentDidRender() {
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
if (!this.isOpenedBefore && this.displayAs == 'popup') {
|
|
92
|
+
this.show();
|
|
93
|
+
}
|
|
81
94
|
}
|
|
82
95
|
get host() { return index.getElement(this); }
|
|
83
96
|
};
|
|
84
|
-
|
|
97
|
+
SallaBranches.style = sallaBranchesCss;
|
|
85
98
|
|
|
86
99
|
const sallaButtonCss = "";
|
|
87
100
|
|
|
@@ -192,6 +205,391 @@ const SallaButton = class {
|
|
|
192
205
|
};
|
|
193
206
|
SallaButton.style = sallaButtonCss;
|
|
194
207
|
|
|
208
|
+
const sallaInfiniteScrollCss = "";
|
|
209
|
+
|
|
210
|
+
const SallaInfiniteScroll = class {
|
|
211
|
+
constructor(hostRef) {
|
|
212
|
+
index.registerInstance(this, hostRef);
|
|
213
|
+
/**
|
|
214
|
+
* Next Page element
|
|
215
|
+
*/
|
|
216
|
+
this.nextPage = '';
|
|
217
|
+
/**
|
|
218
|
+
* Is there is need to autoload next page when scroll `next-page-autoload|next-page.autoload`
|
|
219
|
+
*/
|
|
220
|
+
this.autoload = false;
|
|
221
|
+
/**
|
|
222
|
+
* Class selector to know the container if it's not the host `<salla-infinite-scroll>`
|
|
223
|
+
*/
|
|
224
|
+
this.container = 'salla-infinite-scroll';
|
|
225
|
+
/**
|
|
226
|
+
* Class selector to know list items
|
|
227
|
+
*/
|
|
228
|
+
this.item = 'salla-infinite-scroll > *';
|
|
229
|
+
Helper.Helper.setHost(this.host);
|
|
230
|
+
this.status = document.createElement('div');
|
|
231
|
+
this.status.className = 's-infinite-scroll-wrapper';
|
|
232
|
+
this.status.innerHTML = `<div class="s-infinite-scroll-status" style="display:none">
|
|
233
|
+
<p class="s-infinite-scroll-last infinite-scroll-last"></p>
|
|
234
|
+
<p class="s-infinite-scroll-error infinite-scroll-error"></p>
|
|
235
|
+
</div>
|
|
236
|
+
<a href="${this.nextPage}" class="s-infinite-scroll-btn s-button-btn btn--has-loading s-button-primary">
|
|
237
|
+
<span class="s-button-text s-infinite-scroll-btn-text">${salla.lang.get('common.elements.load_more')}</span>
|
|
238
|
+
<span class="s-button-loader s-button-loader-center s-infinite-scroll-btn-loader" style="display: none"></span>
|
|
239
|
+
</a>`;
|
|
240
|
+
this.btnLoader = this.status.querySelector('.s-button-loader');
|
|
241
|
+
salla.lang.onLoaded(() => {
|
|
242
|
+
this.status.querySelector('.s-button-text').innerHTML = salla.lang.get('common.elements.load_more');
|
|
243
|
+
this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');
|
|
244
|
+
this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
loading(isLoading = true) {
|
|
248
|
+
let btnText = this.status.querySelector('.s-button-text');
|
|
249
|
+
Helper.Helper.toggleElementClassIf(btnText, 's-button-hide', 's-button-show', () => isLoading);
|
|
250
|
+
this.btnLoader.style.display = isLoading ? 'inherit' : 'none';
|
|
251
|
+
}
|
|
252
|
+
render() {
|
|
253
|
+
return this.nextPage.length > 1 ?
|
|
254
|
+
index.h(index.Host, { class: "s-infinite-scroll-container" }, index.h("slot", null)) : '';
|
|
255
|
+
}
|
|
256
|
+
componentDidLoad() {
|
|
257
|
+
if (this.nextPage.length === 0) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.host.insertAdjacentElement('afterend', this.status);
|
|
261
|
+
let that = this;
|
|
262
|
+
let infScroll = salla.infiniteScroll.initiate(this.container, {
|
|
263
|
+
history: this.autoload ? 'push' : false,
|
|
264
|
+
scrollThreshold: this.autoload ? 400 : false,
|
|
265
|
+
nextPage: this.nextPage,
|
|
266
|
+
checkLastPage: 'salla-infinite-scroll[next-page*=":"],salla-infinite-scroll[next-page*="."]',
|
|
267
|
+
status: '.s-infinite-scroll-status',
|
|
268
|
+
button: this.status.querySelector('.s-button-btn'),
|
|
269
|
+
append: this.item,
|
|
270
|
+
path: function () {
|
|
271
|
+
return that.nextPage.replace(/page\=(\d)/g, 'page=' + (this.loadCount + 2));
|
|
272
|
+
},
|
|
273
|
+
})
|
|
274
|
+
.on('request', () => this.loading())
|
|
275
|
+
.on('load', () => {
|
|
276
|
+
this.loading(false);
|
|
277
|
+
if (infScroll.pageIndex == 2) {
|
|
278
|
+
infScroll.option({ loadOnScroll: false });
|
|
279
|
+
}
|
|
280
|
+
if (infScroll.pageIndex == 3) {
|
|
281
|
+
infScroll.option({ loadOnScroll: true });
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
.on('error', () => this.loading(false));
|
|
285
|
+
}
|
|
286
|
+
get host() { return index.getElement(this); }
|
|
287
|
+
};
|
|
288
|
+
SallaInfiniteScroll.style = sallaInfiniteScrollCss;
|
|
289
|
+
|
|
290
|
+
const sallaLocalizationModalCss = ".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}";
|
|
291
|
+
|
|
292
|
+
const SallaLocalizationModal = class {
|
|
293
|
+
constructor(hostRef) {
|
|
294
|
+
index.registerInstance(this, hostRef);
|
|
295
|
+
var _a, _b;
|
|
296
|
+
this.languages = [];
|
|
297
|
+
this.currencies = [];
|
|
298
|
+
this.isLoading = true;
|
|
299
|
+
this.language = salla.config.get('user.language_code');
|
|
300
|
+
this.currency = salla.config.get('user.currency_code');
|
|
301
|
+
Helper.Helper.setHost(this.host);
|
|
302
|
+
salla.event.on('localization::open', () => this.open());
|
|
303
|
+
salla.lang.onLoaded(() => {
|
|
304
|
+
var _a;
|
|
305
|
+
this.languagesTitle = salla.lang.get('common.titles.language');
|
|
306
|
+
this.currenciesTitle = salla.lang.get('common.titles.currency');
|
|
307
|
+
(_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(salla.lang.get('common.elements.ok'));
|
|
308
|
+
});
|
|
309
|
+
/**
|
|
310
|
+
* letting developer to insert his own slot like:
|
|
311
|
+
* <salla-localization>
|
|
312
|
+
* <div slot="language">...{name}....</div>
|
|
313
|
+
* <div slot="currency">...{name}....</div>
|
|
314
|
+
* </salla-localization>
|
|
315
|
+
* Because scoped templates not supported in stencil );
|
|
316
|
+
* we made a workaround to pass language & currency attributes, then replace names in rendering
|
|
317
|
+
*/
|
|
318
|
+
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>';
|
|
319
|
+
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>';
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* open the component
|
|
323
|
+
*/
|
|
324
|
+
async open() {
|
|
325
|
+
console.log("🚀 ~ file: salla-localization-modal.tsx ~ line 59 ~ SallaLocalizationModal ~ open ~ this.modal", this.modal);
|
|
326
|
+
return await this.modal.open()
|
|
327
|
+
.then(() => this.getLanguages())
|
|
328
|
+
.then(() => this.getCurrencies())
|
|
329
|
+
.then(() => this.isLoading = false);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Hide the component
|
|
333
|
+
*/
|
|
334
|
+
async close() {
|
|
335
|
+
return this.modal.close();
|
|
336
|
+
}
|
|
337
|
+
async getLanguages() {
|
|
338
|
+
this.language = this.language || salla.config.get('user.language_code');
|
|
339
|
+
return this.languages.length > 1 ? null : await salla.config.languages().then(data => this.languages = data);
|
|
340
|
+
}
|
|
341
|
+
async getCurrencies() {
|
|
342
|
+
this.currency = this.currency || salla.config.get('user.currency_code');
|
|
343
|
+
return this.currencies.length > 1 ? null : await salla.config.currencies().then(data => this.currencies = Object.values(data || {}));
|
|
344
|
+
}
|
|
345
|
+
onChangeCurrency(event) {
|
|
346
|
+
this.currency = event.target.value;
|
|
347
|
+
}
|
|
348
|
+
onChangeLanguage(event) {
|
|
349
|
+
this.language = event.target.value;
|
|
350
|
+
}
|
|
351
|
+
async submit() {
|
|
352
|
+
let url;
|
|
353
|
+
this.btn.load()
|
|
354
|
+
.then(() => {
|
|
355
|
+
if (!this.currency) {
|
|
356
|
+
salla.log('There is no currency!');
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (this.currency === salla.config.get('user.currency_code', 'SAR')) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
url = window.location.href;
|
|
363
|
+
return salla.currency.api.change(this.currency);
|
|
364
|
+
})
|
|
365
|
+
.then(() => this.language === salla.config.get('user.language_code', 'ar') || (url = salla.helpers.addParamToUrl('lang', this.language)))
|
|
366
|
+
.then(() => this.btn.stop())
|
|
367
|
+
.then(() => this.close())
|
|
368
|
+
.then(() => url && (window.location.href = url));
|
|
369
|
+
}
|
|
370
|
+
render() {
|
|
371
|
+
return (index.h("salla-modal", { isLoading: this.isLoading, id: "salla-localization", class: "s-hidden", ref: modal => this.modal = modal, width: "xs" }, !this.isLoading ?
|
|
372
|
+
index.h("div", { class: "s-localization-modal-inner" }, this.languages.length > 1 ?
|
|
373
|
+
index.h("div", { class: "s-localization-modal-section" }, index.h("label", { class: "s-localization-modal-title" }, this.languagesTitle), index.h("div", { class: "s-localization-modal-section-inner" }, this.languages.length < 6 ?
|
|
374
|
+
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
|
|
375
|
+
.replace(/\{name\}/g, lang.name)
|
|
376
|
+
.replace(/\{code\}/g, lang.code)
|
|
377
|
+
.replace(/\{country_code\}/g, lang.country_code) }))) :
|
|
378
|
+
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)))))
|
|
379
|
+
: '', this.currencies.length > 1 ?
|
|
380
|
+
index.h("div", { class: "s-localization-modal-section" }, index.h("label", { class: "s-localization-modal-title" }, this.currenciesTitle), index.h("div", { class: "s-localization-modal-section-inner" }, this.currencies.length < 6 ?
|
|
381
|
+
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
|
|
382
|
+
.replace(/\{name\}/g, currency.name)
|
|
383
|
+
.replace(/\{code\}/g, currency.code)
|
|
384
|
+
.replace(/\{country_code\}/g, currency.country_code) }))) :
|
|
385
|
+
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)))))
|
|
386
|
+
: '', index.h("salla-button", { width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.ok')))
|
|
387
|
+
: ''));
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* to reduce dom levels we will move slot data into the parent dom
|
|
391
|
+
*/
|
|
392
|
+
componentDidRender() {
|
|
393
|
+
this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
|
|
394
|
+
this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
|
|
395
|
+
}
|
|
396
|
+
get host() { return index.getElement(this); }
|
|
397
|
+
};
|
|
398
|
+
SallaLocalizationModal.style = sallaLocalizationModalCss;
|
|
399
|
+
|
|
400
|
+
const sallaLoginModalCss = "";
|
|
401
|
+
|
|
402
|
+
const SallaLoginModal = class {
|
|
403
|
+
constructor(hostRef) {
|
|
404
|
+
index.registerInstance(this, hostRef);
|
|
405
|
+
/**
|
|
406
|
+
* Does the merchant allow to login using email
|
|
407
|
+
*/
|
|
408
|
+
this.isEmailAllowed = salla.config.get('store.settings.auth.email_allowed', true);
|
|
409
|
+
/**
|
|
410
|
+
* Does the merchant/current location for visitor allow to login using mobile, By default outside KSA is `false`
|
|
411
|
+
*/
|
|
412
|
+
this.isMobileAllowed = salla.config.get('store.settings.auth.mobile_allowed', true);
|
|
413
|
+
/**
|
|
414
|
+
* Does the merchant require registration with email & mobile
|
|
415
|
+
*/
|
|
416
|
+
this.isEmailRequired = salla.config.get('store.settings.auth.is_email_required', false);
|
|
417
|
+
this.regType = 'phone';
|
|
418
|
+
this.typing = (e, submitMethod) => {
|
|
419
|
+
const error = e.target.nextElementSibling;
|
|
420
|
+
e.target.classList.remove('s-has-error');
|
|
421
|
+
(error === null || error === void 0 ? void 0 : error.classList.contains('s-login-modal-error-message')) && (error.innerText = '');
|
|
422
|
+
e.key == 'Enter' && submitMethod();
|
|
423
|
+
};
|
|
424
|
+
this.loginBySMS = async () => {
|
|
425
|
+
const { phone, countryCode } = await this.loginTelInput.getValues();
|
|
426
|
+
const isPhoneValid = await this.loginTelInput.isValid();
|
|
427
|
+
if (!isPhoneValid)
|
|
428
|
+
return;
|
|
429
|
+
this.login(this.smsBtn, { type: 'mobile', phone: phone, country_code: countryCode });
|
|
430
|
+
};
|
|
431
|
+
this.loginByEmail = () => {
|
|
432
|
+
if (!Helper.Helper.isValidEmail(this.loginEmail.value)) {
|
|
433
|
+
this.validateField(this.loginEmail, this.emailErrorMsg);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
this.login(this.emailBtn, { type: 'email', email: this.loginEmail.value });
|
|
437
|
+
};
|
|
438
|
+
this.newUser = async () => {
|
|
439
|
+
var _a;
|
|
440
|
+
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);
|
|
441
|
+
await this.newUserValidation();
|
|
442
|
+
await this.regBtn.load();
|
|
443
|
+
await this.regBtn.disable();
|
|
444
|
+
let data = {
|
|
445
|
+
first_name: this.firstName.value,
|
|
446
|
+
last_name: this.lastName.value,
|
|
447
|
+
phone: regPhone || this.loginTelInput.phone,
|
|
448
|
+
country_code: countryCode,
|
|
449
|
+
verified_by: this.regType,
|
|
450
|
+
};
|
|
451
|
+
emailValue && (data = Object.assign(Object.assign({}, data), { email: emailValue }));
|
|
452
|
+
this.verifyTab.getCode()
|
|
453
|
+
.then(code => salla.auth.api.register(Object.assign(Object.assign({}, data), { code })))
|
|
454
|
+
.then(() => salla.auth.canRedirect && window.location.reload())
|
|
455
|
+
.catch(() => this.regBtn.stop() && this.regBtn.enable());
|
|
456
|
+
};
|
|
457
|
+
this.title = this.host.title || salla.lang.get('blocks.header.login');
|
|
458
|
+
this.host.removeAttribute('title');
|
|
459
|
+
salla.lang.onLoaded(() => {
|
|
460
|
+
var _a, _b, _c, _d;
|
|
461
|
+
this.title = salla.lang.get('blocks.header.login');
|
|
462
|
+
this.loginTypeTitle = salla.lang.get('blocks.header.select_login_way');
|
|
463
|
+
this.loginText = salla.lang.get('blocks.header.login');
|
|
464
|
+
this.smsLabel = salla.lang.get('blocks.header.sms');
|
|
465
|
+
this.mobileLabel = salla.lang.get('common.elements.mobile');
|
|
466
|
+
this.emailLabel = salla.lang.get('common.elements.email');
|
|
467
|
+
this.bySMSText = salla.lang.get('blocks.header.login_by_sms');
|
|
468
|
+
this.byEmailText = salla.lang.get('blocks.header.login_by_email');
|
|
469
|
+
this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
|
|
470
|
+
this.firstNameLabel = salla.lang.get('blocks.header.your_name');
|
|
471
|
+
this.lastNameLabel = salla.lang.get('pages.profile.last_name');
|
|
472
|
+
this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: this.firstNameLabel });
|
|
473
|
+
this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: this.lastNameLabel });
|
|
474
|
+
(_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
|
|
475
|
+
(_b = this.smsBtn) === null || _b === void 0 ? void 0 : _b.setText(salla.lang.get('blocks.header.enter'));
|
|
476
|
+
(_c = this.emailBtn) === null || _c === void 0 ? void 0 : _c.setText(salla.lang.get('blocks.header.enter'));
|
|
477
|
+
(_d = this.regBtn) === null || _d === void 0 ? void 0 : _d.setText(salla.lang.get('blocks.header.register'));
|
|
478
|
+
});
|
|
479
|
+
salla.auth.event.onVerificationFailed(() => {
|
|
480
|
+
//
|
|
481
|
+
});
|
|
482
|
+
salla.event.on('login::open', (event) => this.open(event));
|
|
483
|
+
salla.event.on('twilight::initiated', () => {
|
|
484
|
+
this.isEmailAllowed = salla.config.get('store.settings.auth.email_allowed', !!this.isEmailAllowed);
|
|
485
|
+
this.isMobileAllowed = salla.config.get('store.settings.auth.mobile_allowed', !!this.isMobileAllowed);
|
|
486
|
+
this.isEmailRequired = salla.config.get('store.settings.auth.is_email_required', !!this.isEmailRequired);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
|
|
491
|
+
*/
|
|
492
|
+
onVerified(event) {
|
|
493
|
+
var _a, _b;
|
|
494
|
+
salla.log('verified', event);
|
|
495
|
+
//there is a case when force login is activated & is new user, it will return case inside error key., so cover it.
|
|
496
|
+
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);
|
|
497
|
+
if (!verifyCase) {
|
|
498
|
+
salla.log('verified but without case!');
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (verifyCase === "new_customer") {
|
|
502
|
+
return this.showTab(this.registrationTab);
|
|
503
|
+
}
|
|
504
|
+
if (!salla.auth.canRedirect()) {
|
|
505
|
+
salla.log('Will not auto redirect or reload, due to `salla.auth.canRedirect()`');
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (event.detail.data.redirect_url) {
|
|
509
|
+
return window.location.href = event.data.redirect_url;
|
|
510
|
+
}
|
|
511
|
+
window.location.reload();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Open login component
|
|
515
|
+
*/
|
|
516
|
+
// @ts-ignore
|
|
517
|
+
async open(event = null) {
|
|
518
|
+
// if(event && event.hasOwnProperty('isEmailAllowed')){
|
|
519
|
+
// this.isEmailAllowed = event?.isEmailAllowed;
|
|
520
|
+
// }
|
|
521
|
+
//
|
|
522
|
+
// if(event && event.hasOwnProperty('isMobileAllowed')){
|
|
523
|
+
// this.isMobileAllowed = event?.isMobileAllowed;
|
|
524
|
+
// }
|
|
525
|
+
if (this.isEmailAllowed && this.isMobileAllowed) {
|
|
526
|
+
this.showTab(this.homeTab);
|
|
527
|
+
}
|
|
528
|
+
else if (this.isEmailAllowed) {
|
|
529
|
+
this.showTab(this.emailTab);
|
|
530
|
+
}
|
|
531
|
+
else if (this.isMobileAllowed) {
|
|
532
|
+
this.showTab(this.mobileTab);
|
|
533
|
+
}
|
|
534
|
+
return this.modal.open();
|
|
535
|
+
}
|
|
536
|
+
showTab(tab, evt) {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
539
|
+
let tabs = [this.homeTab, this.mobileTab, this.emailTab, this.verifyTab, this.registrationTab];
|
|
540
|
+
tabs.map(el => Helper.Helper.toggleElementClassIf(el, 'visible', 's-hidden', () => el == tab));
|
|
541
|
+
setTimeout(() => tabs.map(el => Helper.Helper.toggleElementClassIf(el, 's-login-modal-active', 's-login-modal-unactive', () => el == tab)), 200);
|
|
542
|
+
//we should have only one salla-login, so it's okay to get it from document
|
|
543
|
+
//todo:: use better way for resize the modal
|
|
544
|
+
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'); });
|
|
545
|
+
if ([this.mobileTab, this.emailTab].includes(tab)) {
|
|
546
|
+
this.regType = tab === this.mobileTab ? 'phone' : 'email';
|
|
547
|
+
}
|
|
548
|
+
let isRegistrationTab = tab == this.registrationTab;
|
|
549
|
+
(_a = tab.querySelector('input')) === null || _a === void 0 ? void 0 : _a.focus(); // focus the first input in tab
|
|
550
|
+
(_b = this.modal) === null || _b === void 0 ? void 0 : _b.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
|
|
551
|
+
if (!isRegistrationTab) {
|
|
552
|
+
Helper.Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
|
|
553
|
+
.toggleElementClassIf(this.regEmailBlock, 's-hidden', 's-show', () => this.regType === 'email');
|
|
554
|
+
}
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
login(btn, data) {
|
|
558
|
+
btn.load()
|
|
559
|
+
.then(() => btn.disable())
|
|
560
|
+
.then(() => salla.auth.api.login(data))
|
|
561
|
+
.then(() => this.showTab(this.verifyTab))
|
|
562
|
+
.then(() => this.verifyTab.open(data))
|
|
563
|
+
.finally(() => btn.stop() && btn.enable());
|
|
564
|
+
}
|
|
565
|
+
async newUserValidation() {
|
|
566
|
+
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);
|
|
567
|
+
if (emailValidation && isPhoneValid && isFirstNameValid && isLastNameValid)
|
|
568
|
+
return;
|
|
569
|
+
!isEmailValid && this.validateField(this.regEmail, this.emailErrorMsg);
|
|
570
|
+
!isFirstNameValid && this.validateField(this.firstName, this.firstNameErrorMsg);
|
|
571
|
+
!isLastNameValid && this.validateField(this.lastName, this.lastNameErrorMsg);
|
|
572
|
+
throw ('Please insert required fields');
|
|
573
|
+
}
|
|
574
|
+
// eslint-disable-next-line @stencil/own-methods-must-be-private
|
|
575
|
+
validateField(field, errorMsg) {
|
|
576
|
+
field.classList.add('s-has-error');
|
|
577
|
+
field.nextElementSibling['innerText'] = '* ' + errorMsg;
|
|
578
|
+
}
|
|
579
|
+
render() {
|
|
580
|
+
return (index.h("salla-modal", { id: "salla-login", icon: "sicon-user", "modal-title": this.title, ref: modal => this.modal = modal, width: "xs" }, index.h("div", { class: "s-login-modal-wrapper" }, this.isEmailAllowed && this.isMobileAllowed ?
|
|
581
|
+
index.h("div", { class: "s-login-modal-tab", ref: tab => this.homeTab = tab }, index.h("p", { class: "s-login-modal-sub-title" }, this.loginTypeTitle), 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("i", { class: "s-login-modal-main-btn-icon sicon-phone" }), index.h("span", { class: "s-login-modal-main-btn-text" }, this.smsLabel), index.h("i", { class: "sicon-keyboard_arrow_left arrow" })), index.h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.emailTab, evt) }, index.h("i", { class: "s-login-modal-main-btn-icon sicon-mail" }), index.h("span", { class: "s-login-modal-main-btn-text" }, this.emailLabel), index.h("i", { class: "sicon-keyboard_arrow_left arrow" })), index.h("slot", { name: "after-login-type" }))
|
|
582
|
+
: '', this.isMobileAllowed ?
|
|
583
|
+
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" }, this.mobileLabel), 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 ?
|
|
584
|
+
index.h("a", { href: "#", onClick: () => this.showTab(this.emailTab), class: "s-login-modal-link" }, this.byEmailText) : '', index.h("slot", { name: "after-login-mobile" })) : '', this.isEmailAllowed ?
|
|
585
|
+
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" }, this.emailLabel), 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 ?
|
|
586
|
+
index.h("a", { href: "#", onClick: () => this.showTab(this.mobileTab), class: "s-login-modal-link" }, this.bySMSText)
|
|
587
|
+
: '', 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 sicon-arrow-right", 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" }, this.firstNameLabel), 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" }, this.lastNameLabel), 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" }, this.mobileLabel), 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" }, this.emailLabel), 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" })))));
|
|
588
|
+
}
|
|
589
|
+
get host() { return index.getElement(this); }
|
|
590
|
+
};
|
|
591
|
+
SallaLoginModal.style = sallaLoginModalCss;
|
|
592
|
+
|
|
195
593
|
const sallaModalCss = "";
|
|
196
594
|
|
|
197
595
|
const SallaModal = class {
|
|
@@ -339,6 +737,140 @@ const SallaModal = class {
|
|
|
339
737
|
};
|
|
340
738
|
SallaModal.style = sallaModalCss;
|
|
341
739
|
|
|
740
|
+
const sallaOfferModalCss = "";
|
|
741
|
+
|
|
742
|
+
const SallaOfferModal = class {
|
|
743
|
+
constructor(hostRef) {
|
|
744
|
+
index.registerInstance(this, hostRef);
|
|
745
|
+
var _a, _b;
|
|
746
|
+
this.offer = null;
|
|
747
|
+
this.offer_expires_in = salla.lang.get('pages.products.offer_expires_in');
|
|
748
|
+
this.remember_my_choice = salla.lang.get('commone.remember_my_choice');
|
|
749
|
+
this.add_to_cart = salla.lang.get('pages.cart.add_to_cart');
|
|
750
|
+
this.out_of_stock = salla.lang.get('pages.products.out_of_stock');
|
|
751
|
+
Helper.Helper.setHost(this.host);
|
|
752
|
+
salla.lang.onLoaded(() => {
|
|
753
|
+
this.offer_expires_in = salla.lang.get('pages.products.offer_expires_in');
|
|
754
|
+
this.remember_my_choice = salla.lang.get('common.elements.remember_my_choice');
|
|
755
|
+
this.add_to_cart = salla.lang.get('pages.cart.add_to_cart');
|
|
756
|
+
this.out_of_stock = salla.lang.get('pages.products.out_of_stock');
|
|
757
|
+
});
|
|
758
|
+
this.categorySlot = ((_a = Helper.Helper.getElement('[slot="category"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<i class="s-offer-modal-badge-icon sicon-tag"></i><span class="s-offer-modal-badge-text">{name}</span>';
|
|
759
|
+
this.productSlot = ((_b = Helper.Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.defaultProductSlot();
|
|
760
|
+
salla.product.event.onOfferExisted(offer => {
|
|
761
|
+
if (salla.storage.get('remember-offer-' + offer.id)) {
|
|
762
|
+
salla.log('User selected to don\'t show this offer again.');
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
this.open(offer.product_id);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Show the available offers for the product
|
|
770
|
+
* @param product_id
|
|
771
|
+
*/
|
|
772
|
+
async open(product_id) {
|
|
773
|
+
//TODO:: make sure there is only one offer
|
|
774
|
+
return salla.product.offers(product_id)
|
|
775
|
+
.then(response => this.showOffer(response.data[0]));
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Show offer details
|
|
779
|
+
* @param {Offer} offer
|
|
780
|
+
*/
|
|
781
|
+
async showOffer(offer) {
|
|
782
|
+
this.offer = offer;
|
|
783
|
+
this.offer_name = offer.name;
|
|
784
|
+
this.offer_message = offer.message;
|
|
785
|
+
this.modal.setTitle(this.offer_name);
|
|
786
|
+
return this.modal.open();
|
|
787
|
+
}
|
|
788
|
+
rememberMe(event) {
|
|
789
|
+
console.log("🚀 ~ file: salla-offer-modal.tsx ~ line 75 ~ SallaOfferModal ~ rememberMe ~ rememberMe", event);
|
|
790
|
+
salla.storage.set('remember-offer-' + this.offer.id, event.target.checked);
|
|
791
|
+
}
|
|
792
|
+
//todo:: pass event then use sallaButton from it
|
|
793
|
+
addItem() {
|
|
794
|
+
// this here, is sallaButton
|
|
795
|
+
this['load']();
|
|
796
|
+
return salla.cart.api
|
|
797
|
+
.quickAdd(this['dataset'].id)
|
|
798
|
+
.finally(() => this['stop']());
|
|
799
|
+
}
|
|
800
|
+
defaultProductSlot() {
|
|
801
|
+
return '<a href={url} class="s-offer-modal-product-image-wrap"><img class="s-offer-modal-product-image" src="{image}" /></a>' +
|
|
802
|
+
'<div class="s-offer-modal-product-info">' +
|
|
803
|
+
' <a href={url} class="s-offer-modal-product-name">{name}</a>' +
|
|
804
|
+
' <div class="s-offer-modal-product-price">{price}</div>' +
|
|
805
|
+
'</div>';
|
|
806
|
+
}
|
|
807
|
+
render() {
|
|
808
|
+
var _a, _b;
|
|
809
|
+
return index.h("salla-modal", { id: "salla-offer-modal", "sub-title-first": true, icon: "sicon-special-discount", "sub-title": this.offer_message, ref: modal => this.modal = modal, "is-loading": this.offer === null }, this.offer !== null
|
|
810
|
+
? [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
|
|
811
|
+
? 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
|
|
812
|
+
.replace(/\{name\}/g, category.name)
|
|
813
|
+
.replace(/\{url\}/g, category.urls.customer) }))
|
|
814
|
+
: (_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
|
|
815
|
+
.replace(/\{name\}/g, product.name)
|
|
816
|
+
.replace(/\{url\}/g, product.url)
|
|
817
|
+
.replace(/\{image\}/g, product.thumbnail)
|
|
818
|
+
.replace(/\{price\}/g, product.has_special_price
|
|
819
|
+
? salla.money(product.price) + '<span class="s-offer-modal-product-old-price">' + salla.money(product.regular_price) + '</span>'
|
|
820
|
+
: 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 ? this.add_to_cart : this.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 sicon-keyboard_arrow_left" })), index.h("button", { class: "s-offer-modal-nav-btn s-offer-modal-next-btn" }, index.h("span", { class: "s-offer-modal-nav-btn-icon sicon-keyboard_arrow_right" })))), index.h("div", { class: "s-offer-modal-footer", slot: "footer" }, this.offer.formatted_date ?
|
|
821
|
+
index.h("p", { class: "s-offer-modal-expiry" }, this.offer_expires_in, " ", this.offer.formatted_date)
|
|
822
|
+
: '', 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 ", this.remember_my_choice)),
|
|
823
|
+
] : '');
|
|
824
|
+
}
|
|
825
|
+
componentDidRender() {
|
|
826
|
+
// Sooo mini Slider
|
|
827
|
+
if (this.offer && window.screen.width > 639) {
|
|
828
|
+
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.
|
|
829
|
+
current = 0, // current slide
|
|
830
|
+
slidesToScroll = 3, itemsLength = items.length;
|
|
831
|
+
console.log('items[0]:', items[0]);
|
|
832
|
+
let itemSize = items[0].offsetWidth, sliderSize = itemsLength * itemSize, sliderWrapperSize = sliderWrap.offsetWidth, sliderInvisibleSize = sliderSize - sliderWrapperSize, isRTL = document.body.classList.contains('rtl') ? true : false;
|
|
833
|
+
if (sliderInvisibleSize > sliderNavMargin)
|
|
834
|
+
nexBtn.classList.add('s-offer-modal-btn-is-active');
|
|
835
|
+
window.onresize = function () {
|
|
836
|
+
sliderWrapperSize = sliderWrap.offsetWidth;
|
|
837
|
+
sliderInvisibleSize = sliderSize - sliderWrapperSize;
|
|
838
|
+
};
|
|
839
|
+
slider.addEventListener('scroll', function () {
|
|
840
|
+
let sliderPosition = Math.abs(slider.scrollLeft);
|
|
841
|
+
let sliderEndOffset = sliderInvisibleSize - sliderNavMargin;
|
|
842
|
+
// show & hide the navigation btns depending on scroll position
|
|
843
|
+
if (sliderPosition <= sliderNavMargin) {
|
|
844
|
+
nexBtn.classList.add('s-offer-modal-btn-is-active');
|
|
845
|
+
prevBtn.classList.remove('s-offer-modal-btn-is-active');
|
|
846
|
+
}
|
|
847
|
+
else if (sliderPosition < sliderEndOffset) {
|
|
848
|
+
// show both btns in the middle
|
|
849
|
+
nexBtn.classList.add('s-offer-modal-btn-is-active');
|
|
850
|
+
prevBtn.classList.add('s-offer-modal-btn-is-active');
|
|
851
|
+
}
|
|
852
|
+
else if (sliderPosition >= sliderEndOffset) {
|
|
853
|
+
nexBtn.classList.remove('s-offer-modal-btn-is-active');
|
|
854
|
+
prevBtn.classList.add('s-offer-modal-btn-is-active');
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
// Navigation
|
|
858
|
+
navButtons.forEach(btn => {
|
|
859
|
+
btn.addEventListener('click', function () {
|
|
860
|
+
btn.classList.contains('s-offer-modal-next-btn') ? current++ : current--;
|
|
861
|
+
slider.scrollTo({
|
|
862
|
+
top: 0,
|
|
863
|
+
left: itemSize * slidesToScroll * current * (isRTL ? -1 : 1),
|
|
864
|
+
behavior: 'smooth'
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
get host() { return index.getElement(this); }
|
|
871
|
+
};
|
|
872
|
+
SallaOfferModal.style = sallaOfferModalCss;
|
|
873
|
+
|
|
342
874
|
const sallaProductAvailabilityCss = "";
|
|
343
875
|
|
|
344
876
|
const SallaProductAvailability = class {
|
|
@@ -459,6 +991,237 @@ const SallaProductAvailability = class {
|
|
|
459
991
|
};
|
|
460
992
|
SallaProductAvailability.style = sallaProductAvailabilityCss;
|
|
461
993
|
|
|
994
|
+
const sallaRatingModalCss = "";
|
|
995
|
+
|
|
996
|
+
const SallaRatingModal = class {
|
|
997
|
+
constructor(hostRef) {
|
|
998
|
+
index.registerInstance(this, hostRef);
|
|
999
|
+
this.stepsCount = 0;
|
|
1000
|
+
this.currentIndex = 0;
|
|
1001
|
+
this.submitted = [];
|
|
1002
|
+
/**
|
|
1003
|
+
* The order id, to rate on its products & shipping
|
|
1004
|
+
*/
|
|
1005
|
+
this.orderId = salla.config.get('page.id');
|
|
1006
|
+
this.rate_the_store = salla.lang.get('pages.rating.rate_the_store');
|
|
1007
|
+
this.write_store_rate = salla.lang.get('pages.rating.write_store_rate');
|
|
1008
|
+
this.rate_product_stars = salla.lang.get('pages.rating.rate_product_stars');
|
|
1009
|
+
this.write_product_rate = salla.lang.get('pages.rating.write_product_rate');
|
|
1010
|
+
this.rate_shipping = salla.lang.get('pages.rating.rate_shipping');
|
|
1011
|
+
this.write_shipping_rate = salla.lang.get('pages.rating.write_shipping_rate');
|
|
1012
|
+
this.thanks = salla.lang.get('pages.rating.thanks');
|
|
1013
|
+
this.back = salla.lang.get('common.elements.back');
|
|
1014
|
+
this.next = salla.lang.get('common.elements.next');
|
|
1015
|
+
Helper.Helper.setHost(document);
|
|
1016
|
+
salla.event.on('rating::open', () => this.open());
|
|
1017
|
+
salla.lang.onLoaded(() => {
|
|
1018
|
+
this.rate_the_store = salla.lang.get('pages.rating.rate_the_store');
|
|
1019
|
+
this.write_store_rate = salla.lang.get('pages.rating.write_store_rate');
|
|
1020
|
+
this.rate_product_stars = salla.lang.get('pages.rating.rate_product_stars');
|
|
1021
|
+
this.write_product_rate = salla.lang.get('pages.rating.write_product_rate');
|
|
1022
|
+
this.rate_shipping = salla.lang.get('pages.rating.rate_shipping');
|
|
1023
|
+
this.write_shipping_rate = salla.lang.get('pages.rating.write_shipping_rate');
|
|
1024
|
+
this.thanks = salla.lang.get('pages.rating.thanks');
|
|
1025
|
+
this.back = salla.lang.get('common.elements.back');
|
|
1026
|
+
this.next = salla.lang.get('common.elements.next');
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Show the rating modal
|
|
1031
|
+
*/
|
|
1032
|
+
async open() {
|
|
1033
|
+
return this.modal.open()
|
|
1034
|
+
.then(() => this.order || salla.rating.api.order(this.orderId).then(res => this.order = res.data))
|
|
1035
|
+
.then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
|
|
1036
|
+
.then(() => this.modal.stopLoading())
|
|
1037
|
+
.then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
|
|
1038
|
+
.then(() => setTimeout(() => this.handleWizard(), 100));
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Show the rating modal
|
|
1042
|
+
*/
|
|
1043
|
+
async close() {
|
|
1044
|
+
return this.modal.close();
|
|
1045
|
+
}
|
|
1046
|
+
// handle wizard
|
|
1047
|
+
handleWizard() {
|
|
1048
|
+
this.steps = this.modal.querySelectorAll(".s-rating-modal-step");
|
|
1049
|
+
this.dots = this.modal.querySelectorAll(".s-rating-modal-step-dot");
|
|
1050
|
+
this.showActiveStep();
|
|
1051
|
+
}
|
|
1052
|
+
showActiveStep(current = null) {
|
|
1053
|
+
var _a;
|
|
1054
|
+
this.currentTab = current || this.steps[this.currentIndex];
|
|
1055
|
+
Helper.Helper.toggleClassIf('.s-rating-modal-step-dot', 's-rating-modal-bg-gray', 's-rating-modal-bg-primary', dot => dot != this.dots[this.currentIndex])
|
|
1056
|
+
.toggleClassIf('.s-rating-modal-step', 's-rating-modal-active', 's-rating-modal-hidden', tab => tab == this.currentTab);
|
|
1057
|
+
if (this.currentIndex != 0) {
|
|
1058
|
+
// the animation
|
|
1059
|
+
Helper.Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-unactive', 's-rating-modal-hidden', () => true);
|
|
1060
|
+
setTimeout(() => Helper.Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-active', 's-rating-modal-unactive', () => true), 300);
|
|
1061
|
+
}
|
|
1062
|
+
// Btn text
|
|
1063
|
+
let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
|
|
1064
|
+
this.nextBtn.setText(nextType ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
|
|
1065
|
+
: salla.lang.get('pages.rating.send_ratings'));
|
|
1066
|
+
setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
|
|
1067
|
+
}
|
|
1068
|
+
previousTab() {
|
|
1069
|
+
this.currentIndex > 0 && this.currentIndex--;
|
|
1070
|
+
Helper.Helper.toggleElementClassIf(this.backBtn, 's-rating-modal-unvisiable', 'block', () => this.currentIndex == 0);
|
|
1071
|
+
this.showActiveStep();
|
|
1072
|
+
}
|
|
1073
|
+
submit() {
|
|
1074
|
+
this.submittedBefore() || this.validate();
|
|
1075
|
+
salla.config.canLeave = false;
|
|
1076
|
+
this.nextBtn.load()
|
|
1077
|
+
.then(() => this.submittedBefore() || this.sendFeedback())
|
|
1078
|
+
.then(() => this.currentTab.querySelectorAll('[name],.s-rating-modal-btn-star').forEach(el => el.setAttribute('disabled', '')))
|
|
1079
|
+
.then(() => this.currentIndex < this.stepsCount && this.currentIndex++)
|
|
1080
|
+
.then(() => this.showActiveStep())
|
|
1081
|
+
.then(() => Helper.Helper.toggleClassIf('#prev-btn', 'block', 's-rating-modal-unvisiable', () => true))
|
|
1082
|
+
.finally(() => {
|
|
1083
|
+
this.nextBtn.stop();
|
|
1084
|
+
salla.config.canLeave = true;
|
|
1085
|
+
this.currentIndex == this.stepsCount && this.showThankYou();
|
|
1086
|
+
this.modal.isClosable = false;
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
submittedBefore() {
|
|
1090
|
+
return this.submitted.includes(this.currentIndex);
|
|
1091
|
+
}
|
|
1092
|
+
validate(rating = null, type = null) {
|
|
1093
|
+
if (!rating && this.currentTab.dataset.type == 'products') {
|
|
1094
|
+
return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
|
|
1095
|
+
}
|
|
1096
|
+
rating = rating || this.currentTab;
|
|
1097
|
+
let stars = rating.querySelector('.rating_hidden_input').value;
|
|
1098
|
+
let comment = rating.querySelector('.s-rating-modal-comment');
|
|
1099
|
+
let validationMessage = rating.querySelector('.s-rating-modal-validation-msg');
|
|
1100
|
+
if (stars && comment.value && comment.value.length > 3) {
|
|
1101
|
+
comment.classList.remove('s-has-error');
|
|
1102
|
+
validationMessage.innerHTML = '';
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
type = type || rating['dataset'].type;
|
|
1106
|
+
Helper.Helper.toggleElementClassIf(comment, 'save', 's-has-error', el => el.value.length > 3);
|
|
1107
|
+
throw validationMessage.innerHTML = stars
|
|
1108
|
+
? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
|
|
1109
|
+
: salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
|
|
1110
|
+
}
|
|
1111
|
+
sendFeedback() {
|
|
1112
|
+
let data = {};
|
|
1113
|
+
this.currentTab.querySelectorAll('[name]').forEach((input) => {
|
|
1114
|
+
//decode names like `<input name="jamal[inner]" value="hi">` to be {name:jamal, value: {inner:"hi"}}
|
|
1115
|
+
let inputData = salla.helpers.inputData(input.name, input.value, data);
|
|
1116
|
+
data[inputData.name] = inputData.value;
|
|
1117
|
+
});
|
|
1118
|
+
if (Object.keys(data).length == 0) {
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
data['order_id'] = this.orderId;
|
|
1122
|
+
data['type'] = this.currentTab.dataset.type;
|
|
1123
|
+
this.submitted.push(this.currentIndex);
|
|
1124
|
+
return salla.rating.api[this.currentTab.dataset.type](data);
|
|
1125
|
+
}
|
|
1126
|
+
showThankYou() {
|
|
1127
|
+
let seconds = 10;
|
|
1128
|
+
let timeToClose = setInterval(() => {
|
|
1129
|
+
this.thanksTime.innerHTML = '00:0' + (seconds--);
|
|
1130
|
+
if (seconds > 0) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
clearInterval(timeToClose);
|
|
1134
|
+
this.thanksTime.remove();
|
|
1135
|
+
this.close().then(() => window.location.reload());
|
|
1136
|
+
}, 1000);
|
|
1137
|
+
this.modal.querySelector('.s-rating-modal-footer').classList.add('s-rating-modal-unvisiable');
|
|
1138
|
+
this.showActiveStep(this.thanksTab);
|
|
1139
|
+
}
|
|
1140
|
+
render() {
|
|
1141
|
+
return (index.h(index.Host, { id: "s-rating" }, index.h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
|
|
1142
|
+
? [index.h("div", { class: "s-rating-modal-wrapper", ref: el => this.body = el }, this.order.testimonials_enabled ?
|
|
1143
|
+
index.h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "store" }, index.h("div", { class: "s-rating-modal-rounded-icon" }, index.h("img", { src: salla.config.get('store.logo', 'https://assets.salla.sa/cp/assets/images/logo-new.png'), alt: "store name", class: "s-rating-modal-store-logo" })), index.h("h2", { class: "s-rating-modal-title" }, this.rate_the_store), index.h("div", { class: "s-rating-modal-stars-company" }, index.h("salla-rating-stars", { size: "large" })), index.h("textarea", { id: "storeReview", name: "comment", class: "s-rating-modal-comment", placeholder: this.write_store_rate }), index.h("small", { class: "s-rating-modal-validation-msg" }))
|
|
1144
|
+
: '', this.order.products_enabled
|
|
1145
|
+
? index.h("section", { class: "s-rating-modal-step s-rating-modal-hidden", "data-type": "products" }, this.order.products.map((item, index$1) => index.h("div", { class: "rating-outer-form s-rating-modal-product", "data-stars-error": this.rate_product_stars }, index.h("div", { class: "s-rating-modal-product-img-wrap" }, index.h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-modal-product-img" })), index.h("div", { class: "s-rating-modal-product-details" }, index.h("h3", { class: "s-rating-modal-product-title" }, " ", item.product.name), index.h("div", { class: "s-rating-modal-stars-product" }, index.h("salla-rating-stars", { size: "small", name: `products[${index$1}][rating]` })), index.h("input", { type: "hidden", name: `products[${index$1}][product_id]`, value: item.product.id }), index.h("textarea", { placeholder: this.write_product_rate, name: `products[${index$1}][comment]`, class: "s-rating-modal-comment" }), index.h("small", { class: "s-rating-modal-validation-msg" })))))
|
|
1146
|
+
: '', this.order.shipping_enabled
|
|
1147
|
+
? index.h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "shipping" }, index.h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }), this.order.shipping.company.logo
|
|
1148
|
+
? index.h("div", { class: "s-rating-modal-rounded-icon" }, index.h("img", { src: this.order.shipping.company.logo, class: "s-rating-modal-shipping-logo", alt: this.order.shipping.company.name }))
|
|
1149
|
+
: index.h("span", { class: "s-rating-modal-icon sicon-shipping-fast" }), index.h("div", { class: "s-rating-modal-title" }, " ", this.rate_shipping + ' ' + this.order.shipping.company.name), index.h("div", { class: "s-rating-modal-stars-company" }, index.h("salla-rating-stars", { size: "large" })), index.h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: this.write_shipping_rate }), index.h("small", { class: "s-rating-modal-validation-msg" }))
|
|
1150
|
+
: '', index.h("div", { class: "s-rating-modal-thanks s-rating-modal-hidden", ref: el => this.thanksTab = el }, index.h("span", { class: "s-rating-modal-icon sicon-check-circle2" }), index.h("h3", { class: "s-rating-modal-thanks-title" }, this.thanks), index.h("div", { class: "s-rating-modal-thanks-msg", innerHTML: this.order.thanks_message }), index.h("time", { class: "s-rating-modal-thanks-time", ref: el => this.thanksTime = el }))), index.h("div", { class: "s-rating-modal-footer" }, index.h("button", { ref: el => this.backBtn = el, onClick: () => this.previousTab(), class: "s-rating-modal-btn s-rating-modal-unvisiable" }, this.back), this.stepsCount > 1 ? index.h("ul", { class: "s-rating-modal-dots" }, [0, 1, 2].slice(0, this.stepsCount).map(() => index.h("li", { class: 's-rating-modal-bg-gray s-rating-modal-step-dot' }))) : '', index.h("salla-button", { "loader-position": 'center', ref: el => this.nextBtn = el, onClick: () => this.submit() }, this.next)),]
|
|
1151
|
+
: '')));
|
|
1152
|
+
}
|
|
1153
|
+
componentDidLoad() {
|
|
1154
|
+
salla.event.dispatch('rating::ready', this);
|
|
1155
|
+
}
|
|
1156
|
+
get host() { return index.getElement(this); }
|
|
1157
|
+
};
|
|
1158
|
+
SallaRatingModal.style = sallaRatingModalCss;
|
|
1159
|
+
|
|
1160
|
+
const sallaRatingStarsCss = "";
|
|
1161
|
+
|
|
1162
|
+
const SallaRatingStars = class {
|
|
1163
|
+
constructor(hostRef) {
|
|
1164
|
+
index.registerInstance(this, hostRef);
|
|
1165
|
+
this.name = 'rating';
|
|
1166
|
+
this.size = 'medium';
|
|
1167
|
+
}
|
|
1168
|
+
initiateRating() {
|
|
1169
|
+
this.host.addEventListener('click', () => {
|
|
1170
|
+
if (!this.startsElem)
|
|
1171
|
+
return;
|
|
1172
|
+
// Get the selected star - activeElement is not supported in safari
|
|
1173
|
+
let activeStars = this.startsElem.querySelectorAll('.s-rating-stars-hovered');
|
|
1174
|
+
let selected = activeStars[activeStars.length - 1];
|
|
1175
|
+
if (!selected)
|
|
1176
|
+
return;
|
|
1177
|
+
let selectedIndex = selected.getAttribute('data-star');
|
|
1178
|
+
this.startsElem.querySelector('.rating_hidden_input').value = selectedIndex;
|
|
1179
|
+
// Loop through each star, and add or remove the `.selected` class to toggle highlighting
|
|
1180
|
+
this.startsElem.querySelectorAll('.s-rating-stars-btn-star')
|
|
1181
|
+
.forEach((star, index) => Helper.Helper.toggleElementClassIf(star, 's-rating-stars-selected', 's-rating-stars-unselected', () => index < parseInt(selectedIndex)));
|
|
1182
|
+
// update aria-pressed attr status
|
|
1183
|
+
this.startsElem.querySelectorAll('[aria-pressed]').forEach(star => star.removeAttribute('aria-pressed'));
|
|
1184
|
+
selected.setAttribute('aria-pressed', 'true');
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
highlightSelectedStars() {
|
|
1188
|
+
var _a, _b;
|
|
1189
|
+
let hoveredClass = 's-rating-stars-hovered', stars = (_a = this.startsElem) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.s-rating-stars-btn-star');
|
|
1190
|
+
stars === null || stars === void 0 ? void 0 : stars.forEach((star, index) => {
|
|
1191
|
+
star.addEventListener('mouseover', () => {
|
|
1192
|
+
for (let i = 0; i <= index; i++) {
|
|
1193
|
+
stars[i].classList.add(hoveredClass);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
star.addEventListener('mouseout', () => star.classList.remove(hoveredClass));
|
|
1197
|
+
});
|
|
1198
|
+
(_b = this.startsElem) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseout', () => stars.forEach(star => star.classList.remove(hoveredClass)));
|
|
1199
|
+
}
|
|
1200
|
+
createStars(n) {
|
|
1201
|
+
let stars = [];
|
|
1202
|
+
for (let i = 0; i < 5; i++) {
|
|
1203
|
+
stars.push(index.h("span", { class: {
|
|
1204
|
+
's-rating-stars-btn-star sicon-star2': true,
|
|
1205
|
+
['s-rating-stars-' + this.size]: true,
|
|
1206
|
+
's-rating-stars-selected': i < n
|
|
1207
|
+
} }));
|
|
1208
|
+
}
|
|
1209
|
+
return stars;
|
|
1210
|
+
}
|
|
1211
|
+
render() {
|
|
1212
|
+
return (index.h(index.Host, null, this.value ?
|
|
1213
|
+
index.h("div", { class: "s-rating-stars-wrapper" }, " ", this.createStars(this.value), " ")
|
|
1214
|
+
:
|
|
1215
|
+
index.h("div", { class: "s-rating-stars-element", ref: (el) => this.startsElem = el }, index.h("input", { type: "hidden", class: "rating_hidden_input", name: this.name, value: "" }), [1, 2, 3, 4, 5].map(star => index.h("button", { class: `s-rating-stars-btn-star s-rating-stars-` + this.size, "data-star": star }, index.h("i", { class: "sicon-star2" }))))));
|
|
1216
|
+
}
|
|
1217
|
+
componentDidLoad() {
|
|
1218
|
+
this.initiateRating();
|
|
1219
|
+
this.highlightSelectedStars();
|
|
1220
|
+
}
|
|
1221
|
+
get host() { return index.getElement(this); }
|
|
1222
|
+
};
|
|
1223
|
+
SallaRatingStars.style = sallaRatingStarsCss;
|
|
1224
|
+
|
|
462
1225
|
const sallaSearchCss = "";
|
|
463
1226
|
|
|
464
1227
|
const SallaSearch = class {
|
|
@@ -2031,9 +2794,173 @@ const SallaTelInput = class {
|
|
|
2031
2794
|
};
|
|
2032
2795
|
SallaTelInput.style = sallaTelInputCss;
|
|
2033
2796
|
|
|
2034
|
-
|
|
2797
|
+
const sallaVerifyCss = "salla-verify{display:block}";
|
|
2798
|
+
|
|
2799
|
+
const SallaVerify = class {
|
|
2800
|
+
constructor(hostRef) {
|
|
2801
|
+
index.registerInstance(this, hostRef);
|
|
2802
|
+
this.verified = index.createEvent(this, "verified", 7);
|
|
2803
|
+
this.initiated = false;
|
|
2804
|
+
/**
|
|
2805
|
+
* Should render component without modal
|
|
2806
|
+
*/
|
|
2807
|
+
this.display = 'modal';
|
|
2808
|
+
/**
|
|
2809
|
+
* Verifying method
|
|
2810
|
+
*/
|
|
2811
|
+
this.type = 'mobile';
|
|
2812
|
+
/**
|
|
2813
|
+
* should auto reloading the page after success verification
|
|
2814
|
+
*/
|
|
2815
|
+
this.autoReload = true;
|
|
2816
|
+
this.resendAfter = 30;
|
|
2817
|
+
/**
|
|
2818
|
+
* to use: `salla.api.auth.verify` or `salla.profile.verify`
|
|
2819
|
+
*/
|
|
2820
|
+
this.isProfileVerify = false;
|
|
2821
|
+
// Helper.setHost(this.host);
|
|
2822
|
+
salla.lang.onLoaded(() => {
|
|
2823
|
+
var _a, _b;
|
|
2824
|
+
this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + this.type);
|
|
2825
|
+
(_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
|
|
2826
|
+
(_b = this.btn) === null || _b === void 0 ? void 0 : _b.setText(salla.lang.get('pages.profile.verify'));
|
|
2827
|
+
});
|
|
2828
|
+
if (this.display == 'inline') {
|
|
2829
|
+
this.modal = { open: () => '', close: () => '', setTitle: () => '' };
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
salla.event.on('profile::verification', data => {
|
|
2833
|
+
var _a;
|
|
2834
|
+
this.isProfileVerify = true;
|
|
2835
|
+
this.open(data);
|
|
2836
|
+
this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + data.type);
|
|
2837
|
+
(_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
|
|
2838
|
+
});
|
|
2839
|
+
salla.event.on('modalClosed', () => {
|
|
2840
|
+
this.resendAfter = 0;
|
|
2841
|
+
this.timer.innerHTML = '30 : 00';
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* Get current code
|
|
2846
|
+
* @return {string}
|
|
2847
|
+
*/
|
|
2848
|
+
async getCode() {
|
|
2849
|
+
return this.code.value;
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Open verifying modal
|
|
2853
|
+
* @param data
|
|
2854
|
+
*/
|
|
2855
|
+
async open(data) {
|
|
2856
|
+
var _a;
|
|
2857
|
+
this.data = data;
|
|
2858
|
+
this.data.type = this.data.type || this.type;
|
|
2859
|
+
this.type = this.data.type;
|
|
2860
|
+
this.resendTimer();
|
|
2861
|
+
this.otpInputs = this.body.querySelectorAll('.s-verify-input');
|
|
2862
|
+
if (!this.initiated) {
|
|
2863
|
+
Helper.Helper.on('input', '.s-verify-input', e => salla.helpers.inputDigitsOnly(e.target));
|
|
2864
|
+
Helper.Helper.onKeyUp('.s-verify-input', event => {
|
|
2865
|
+
var _a, _b, _c, _d;
|
|
2866
|
+
let key = event.keyCode || event.charCode;
|
|
2867
|
+
if (event.target.value) {
|
|
2868
|
+
(_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
|
|
2869
|
+
(_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
|
|
2870
|
+
}
|
|
2871
|
+
else if ([8, 46].includes(key)) {
|
|
2872
|
+
(_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
|
|
2873
|
+
(_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
|
|
2874
|
+
}
|
|
2875
|
+
this.toggleOTPSubmit();
|
|
2876
|
+
});
|
|
2877
|
+
Helper.Helper.on('paste', '.s-verify-input', event => {
|
|
2878
|
+
let text = salla.helpers.number(event.clipboardData.getData('text')).replace(/[^0-9.]/g, '').replace('..', '.');
|
|
2879
|
+
this.otpInputs.forEach((input, i) => input.value = text[i] || '');
|
|
2880
|
+
this.toggleOTPSubmit();
|
|
2881
|
+
setTimeout(() => this.otpInputs[3].focus(), 100);
|
|
2882
|
+
});
|
|
2883
|
+
// return this.modal.open();
|
|
2884
|
+
this.initiated = true;
|
|
2885
|
+
}
|
|
2886
|
+
this.reset();
|
|
2887
|
+
this.display == 'modal' && ((_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title));
|
|
2888
|
+
this.modal.open();
|
|
2889
|
+
// focus the first input after opening the modal
|
|
2890
|
+
setTimeout(() => this.otpInputs[0].focus(), 100);
|
|
2891
|
+
}
|
|
2892
|
+
toggleOTPSubmit() {
|
|
2893
|
+
let otp = [];
|
|
2894
|
+
this.otpInputs.forEach(input => input.value && otp.push(input.value));
|
|
2895
|
+
this.code.value = otp.join('');
|
|
2896
|
+
if (otp.length === 4) {
|
|
2897
|
+
this.btn.removeAttribute('disabled');
|
|
2898
|
+
this.btn.click();
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
2901
|
+
this.btn.setAttribute('disabled', '');
|
|
2902
|
+
}
|
|
2903
|
+
reset() {
|
|
2904
|
+
this.otpInputs.forEach((input) => input.value = '');
|
|
2905
|
+
this.code.value = '';
|
|
2906
|
+
this.otpInputs[0].focus();
|
|
2907
|
+
}
|
|
2908
|
+
resendTimer() {
|
|
2909
|
+
Helper.Helper.showElement(this.resendMessage).hideElement(this.resend);
|
|
2910
|
+
this.resendAfter = 30;
|
|
2911
|
+
let timerId = setInterval(() => {
|
|
2912
|
+
if (this.resendAfter <= 0) {
|
|
2913
|
+
clearInterval(timerId);
|
|
2914
|
+
Helper.Helper.hideElement(this.resendMessage).showElement(this.resend);
|
|
2915
|
+
}
|
|
2916
|
+
else {
|
|
2917
|
+
this.timer.innerHTML = `${this.resendAfter >= 10 ? this.resendAfter : '0' + this.resendAfter} : 00`;
|
|
2918
|
+
this.resendAfter--;
|
|
2919
|
+
}
|
|
2920
|
+
}, 1000);
|
|
2921
|
+
}
|
|
2922
|
+
resendCode() {
|
|
2923
|
+
return this.btn.stop()
|
|
2924
|
+
.then(() => this.btn.disable())
|
|
2925
|
+
.then(() => {
|
|
2926
|
+
this.otpInputs.forEach(input => input.value = '');
|
|
2927
|
+
this.otpInputs[0].focus();
|
|
2928
|
+
})
|
|
2929
|
+
.then(() => salla.api.auth.resend(this.data))
|
|
2930
|
+
.finally(() => this.resendTimer());
|
|
2931
|
+
}
|
|
2932
|
+
submit() {
|
|
2933
|
+
let data = Object.assign({ code: this.code.value }, this.data);
|
|
2934
|
+
return this.btn.load()
|
|
2935
|
+
.then(() => this.btn.disable())
|
|
2936
|
+
.then(() => this.isProfileVerify ? salla.profile.verify(data) : salla.auth.verify(data, true))
|
|
2937
|
+
.then(response => this.verified.emit(response))
|
|
2938
|
+
.then(() => this.btn.stop() && this.btn.disable())
|
|
2939
|
+
.then(() => this.modal.close())
|
|
2940
|
+
.then(() => this.autoReload && window.location.reload())
|
|
2941
|
+
.catch(() => this.btn.stop() && this.btn.enable() && this.reset());
|
|
2942
|
+
}
|
|
2943
|
+
render() {
|
|
2944
|
+
return this.display == 'inline' ? index.h(index.Host, null, this.myBody()) :
|
|
2945
|
+
index.h("salla-modal", { icon: "sicon-android-phone", width: "xs", class: "s-verify", ref: modal => this.modal = modal, "modal-title": this.title }, this.myBody());
|
|
2946
|
+
}
|
|
2947
|
+
myBody() {
|
|
2948
|
+
return (index.h("div", { class: "s-verify-body", ref: body => this.body = body }, index.h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }), index.h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }), index.h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => index.h("input", { type: "text", maxlength: "1", class: "s-verify-input", required: true }))), index.h("div", { slot: "footer", class: "s-verify-footer" }, index.h("salla-button", { class: "s-verify-submit", "loader-position": 'center', disabled: true, onClick: () => this.submit(), ref: b => this.btn = b }, salla.lang.get('pages.profile.verify')), index.h("p", { class: "s-verify-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), index.h("b", { class: "s-verify-timer", ref: el => this.timer = el })), index.h("a", { href: "#", class: "s-verify-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit'))), index.h("slot", { name: "after-footer" })));
|
|
2949
|
+
}
|
|
2950
|
+
get host() { return index.getElement(this); }
|
|
2951
|
+
};
|
|
2952
|
+
SallaVerify.style = sallaVerifyCss;
|
|
2953
|
+
|
|
2954
|
+
exports.salla_branches = SallaBranches;
|
|
2035
2955
|
exports.salla_button = SallaButton;
|
|
2956
|
+
exports.salla_infinite_scroll = SallaInfiniteScroll;
|
|
2957
|
+
exports.salla_localization_modal = SallaLocalizationModal;
|
|
2958
|
+
exports.salla_login_modal = SallaLoginModal;
|
|
2036
2959
|
exports.salla_modal = SallaModal;
|
|
2960
|
+
exports.salla_offer_modal = SallaOfferModal;
|
|
2037
2961
|
exports.salla_product_availability = SallaProductAvailability;
|
|
2962
|
+
exports.salla_rating_modal = SallaRatingModal;
|
|
2963
|
+
exports.salla_rating_stars = SallaRatingStars;
|
|
2038
2964
|
exports.salla_search = SallaSearch;
|
|
2039
2965
|
exports.salla_tel_input = SallaTelInput;
|
|
2966
|
+
exports.salla_verify = SallaVerify;
|