wickes-css2 2.106.0-IC-1222-back-functionality-poc.1 → 2.106.0-IC-1222-back-functionality-poc.2
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/build/js/page/plp-load-more.js +175 -193
- package/build/js/plp.bundle.min.js +1 -1
- package/package.json +1 -1
- package/src/js/page/plp-load-more.js +175 -193
|
@@ -9,10 +9,11 @@ Wick.PLPLoadMore = {
|
|
|
9
9
|
STEP: 30,
|
|
10
10
|
DEFAULT_START: 30,
|
|
11
11
|
MAX_VISIBLE: 120,
|
|
12
|
-
MAX_VISIBLE_PAGES: 4,
|
|
13
12
|
RESTORE_KEY: 'plpRestoreState',
|
|
13
|
+
RESTORE_DONE_PARAM: 'plpRestoreDone',
|
|
14
|
+
RESTORE_MODE_PARAM: 'plpRestoreMode',
|
|
15
|
+
RESTORE_PRODUCT_PARAM: 'restoreProductCode',
|
|
14
16
|
RESTORE_TTL: 30 * 60 * 1000,
|
|
15
|
-
isRestoring: false,
|
|
16
17
|
|
|
17
18
|
el: {
|
|
18
19
|
$loadMoreBtn: $('.btn-load-more'),
|
|
@@ -32,8 +33,7 @@ Wick.PLPLoadMore = {
|
|
|
32
33
|
modifier: 'basket-loader',
|
|
33
34
|
},
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
currentEndPage: 0,
|
|
36
|
+
currentPage: 0,
|
|
37
37
|
|
|
38
38
|
getPerPage() {
|
|
39
39
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -44,41 +44,84 @@ Wick.PLPLoadMore = {
|
|
|
44
44
|
setPerPage(value) {
|
|
45
45
|
const url = new URL(window.location.href);
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
if (value) {
|
|
48
|
+
url.searchParams.set('perPage', value);
|
|
49
|
+
} else {
|
|
50
|
+
url.searchParams.delete('perPage');
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
history.replaceState(history.state, '', url.toString());
|
|
49
54
|
},
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
getPageParam() {
|
|
57
|
+
const params = new URLSearchParams(window.location.search);
|
|
58
|
+
|
|
59
|
+
return Number(params.get('page')) || 0;
|
|
53
60
|
},
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
setPageParam(value) {
|
|
56
63
|
const url = new URL(window.location.href);
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
if (value || value === 0) {
|
|
66
|
+
url.searchParams.set('page', value);
|
|
67
|
+
} else {
|
|
68
|
+
url.searchParams.delete('page');
|
|
69
|
+
}
|
|
59
70
|
|
|
60
|
-
|
|
71
|
+
history.replaceState(history.state, '', url.toString());
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
getSortValue() {
|
|
75
|
+
return Wick.PLPLoadMore.el.$sortOptions.val() || '';
|
|
61
76
|
},
|
|
62
77
|
|
|
63
78
|
getCardsCountInDOM() {
|
|
64
79
|
return $(Wick.PLPLoadMore.el.productCard).length;
|
|
65
80
|
},
|
|
66
81
|
|
|
67
|
-
|
|
68
|
-
const
|
|
82
|
+
getCurrentUrlBase() {
|
|
83
|
+
const url = new URL(window.location.href);
|
|
69
84
|
|
|
70
|
-
|
|
85
|
+
url.searchParams.delete('perPage');
|
|
86
|
+
url.searchParams.delete('page');
|
|
87
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_DONE_PARAM);
|
|
88
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_MODE_PARAM);
|
|
89
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_PRODUCT_PARAM);
|
|
90
|
+
|
|
91
|
+
return `${url.pathname}${url.search}`;
|
|
71
92
|
},
|
|
72
93
|
|
|
73
94
|
getLastAvailablePage() {
|
|
74
95
|
return Math.max(0, Wick.PLPLoadMore.numberOfPagesPLP - 1);
|
|
75
96
|
},
|
|
76
97
|
|
|
77
|
-
isRestoreStateExpired(
|
|
78
|
-
return (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
isRestoreStateExpired(state) {
|
|
99
|
+
return !state.timestamp || Date.now() - state.timestamp > Wick.PLPLoadMore.RESTORE_TTL;
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
buildRestoreUrl(state) {
|
|
103
|
+
const url = new URL(window.location.href);
|
|
104
|
+
|
|
105
|
+
url.searchParams.delete('perPage');
|
|
106
|
+
url.searchParams.delete('page');
|
|
107
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_DONE_PARAM);
|
|
108
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_MODE_PARAM);
|
|
109
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_PRODUCT_PARAM);
|
|
110
|
+
|
|
111
|
+
if (state.loadedCount <= Wick.PLPLoadMore.MAX_VISIBLE) {
|
|
112
|
+
url.searchParams.set('perPage', state.loadedCount);
|
|
113
|
+
url.searchParams.set(Wick.PLPLoadMore.RESTORE_MODE_PARAM, 'perPage');
|
|
114
|
+
} else {
|
|
115
|
+
const clickedPage = Math.floor((state.clickedIndex - 1) / Wick.PLPLoadMore.STEP);
|
|
116
|
+
|
|
117
|
+
url.searchParams.set('page', clickedPage);
|
|
118
|
+
url.searchParams.set(Wick.PLPLoadMore.RESTORE_MODE_PARAM, 'page');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
url.searchParams.set(Wick.PLPLoadMore.RESTORE_PRODUCT_PARAM, state.productCode);
|
|
122
|
+
url.searchParams.set(Wick.PLPLoadMore.RESTORE_DONE_PARAM, '1');
|
|
123
|
+
|
|
124
|
+
return url.toString();
|
|
82
125
|
},
|
|
83
126
|
|
|
84
127
|
saveRestoreState(e) {
|
|
@@ -98,8 +141,8 @@ Wick.PLPLoadMore = {
|
|
|
98
141
|
const clickedIndex = $cards.index($card) + 1;
|
|
99
142
|
const loadedCount = Wick.PLPLoadMore.getPerPage();
|
|
100
143
|
|
|
101
|
-
const
|
|
102
|
-
|
|
144
|
+
const state = {
|
|
145
|
+
baseUrl: Wick.PLPLoadMore.getCurrentUrlBase(),
|
|
103
146
|
productCode,
|
|
104
147
|
clickedIndex,
|
|
105
148
|
loadedCount,
|
|
@@ -107,35 +150,37 @@ Wick.PLPLoadMore = {
|
|
|
107
150
|
timestamp: Date.now(),
|
|
108
151
|
};
|
|
109
152
|
|
|
110
|
-
|
|
153
|
+
state.restoreUrl = Wick.PLPLoadMore.buildRestoreUrl(state);
|
|
154
|
+
|
|
155
|
+
sessionStorage.setItem(Wick.PLPLoadMore.RESTORE_KEY, JSON.stringify(state));
|
|
111
156
|
},
|
|
112
157
|
|
|
113
158
|
getRestoreState() {
|
|
114
159
|
try {
|
|
115
|
-
const
|
|
160
|
+
const raw = sessionStorage.getItem(Wick.PLPLoadMore.RESTORE_KEY);
|
|
116
161
|
|
|
117
|
-
if (!
|
|
162
|
+
if (!raw) {
|
|
118
163
|
return null;
|
|
119
164
|
}
|
|
120
165
|
|
|
121
|
-
const
|
|
166
|
+
const state = JSON.parse(raw);
|
|
122
167
|
|
|
123
|
-
if (!
|
|
168
|
+
if (!state) {
|
|
124
169
|
return null;
|
|
125
170
|
}
|
|
126
171
|
|
|
127
|
-
if (
|
|
172
|
+
if (Wick.PLPLoadMore.isRestoreStateExpired(state)) {
|
|
173
|
+
Wick.PLPLoadMore.clearRestoreState();
|
|
174
|
+
|
|
128
175
|
return null;
|
|
129
176
|
}
|
|
130
177
|
|
|
131
|
-
if (Wick.PLPLoadMore.
|
|
132
|
-
Wick.PLPLoadMore.clearRestoreState();
|
|
133
|
-
|
|
178
|
+
if (state.baseUrl !== Wick.PLPLoadMore.getCurrentUrlBase()) {
|
|
134
179
|
return null;
|
|
135
180
|
}
|
|
136
181
|
|
|
137
|
-
return
|
|
138
|
-
} catch (
|
|
182
|
+
return state;
|
|
183
|
+
} catch (e) {
|
|
139
184
|
return null;
|
|
140
185
|
}
|
|
141
186
|
},
|
|
@@ -144,71 +189,39 @@ Wick.PLPLoadMore = {
|
|
|
144
189
|
sessionStorage.removeItem(Wick.PLPLoadMore.RESTORE_KEY);
|
|
145
190
|
},
|
|
146
191
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
},
|
|
192
|
+
shouldRedirectToRestoreUrl() {
|
|
193
|
+
const state = Wick.PLPLoadMore.getRestoreState();
|
|
150
194
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const maxVisible = Wick.PLPLoadMore.MAX_VISIBLE;
|
|
154
|
-
const maxVisiblePages = Wick.PLPLoadMore.MAX_VISIBLE_PAGES;
|
|
155
|
-
const loadedCount = restoreState.loadedCount;
|
|
156
|
-
const clickedIndex = restoreState.clickedIndex;
|
|
157
|
-
const loadedPagesCount = Math.ceil(loadedCount / step);
|
|
158
|
-
const loadedLastPage = loadedPagesCount - 1;
|
|
159
|
-
const clickedPage = Math.floor((clickedIndex - 1) / step);
|
|
160
|
-
|
|
161
|
-
if (loadedCount <= maxVisible) {
|
|
162
|
-
return {
|
|
163
|
-
startPage: 0,
|
|
164
|
-
endPage: loadedLastPage,
|
|
165
|
-
showLoadPrevious: false,
|
|
166
|
-
showLoadMore: loadedLastPage < Wick.PLPLoadMore.getLastAvailablePage(),
|
|
167
|
-
};
|
|
195
|
+
if (!state || !state.restoreUrl) {
|
|
196
|
+
return false;
|
|
168
197
|
}
|
|
169
198
|
|
|
170
|
-
|
|
199
|
+
const currentUrl = new URL(window.location.href);
|
|
200
|
+
const restoreUrl = new URL(state.restoreUrl);
|
|
171
201
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
202
|
+
return currentUrl.toString() !== restoreUrl.toString();
|
|
203
|
+
},
|
|
175
204
|
|
|
176
|
-
|
|
205
|
+
redirectToRestoreUrl() {
|
|
206
|
+
const state = Wick.PLPLoadMore.getRestoreState();
|
|
177
207
|
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
startPage = Math.max(0, endPage - maxVisiblePages + 1);
|
|
208
|
+
if (!state || !state.restoreUrl) {
|
|
209
|
+
return;
|
|
181
210
|
}
|
|
182
211
|
|
|
183
|
-
|
|
184
|
-
startPage,
|
|
185
|
-
endPage,
|
|
186
|
-
showLoadPrevious: startPage > 0,
|
|
187
|
-
showLoadMore: endPage < Wick.PLPLoadMore.getLastAvailablePage(),
|
|
188
|
-
};
|
|
212
|
+
window.location.replace(state.restoreUrl);
|
|
189
213
|
},
|
|
190
214
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const eventDetail = { resolve, reject };
|
|
194
|
-
const payload = {
|
|
195
|
-
currentPage: pageNumber,
|
|
196
|
-
sort: Wick.PLPLoadMore.getSortValue(),
|
|
197
|
-
};
|
|
198
|
-
const event = createEvent(Wick.PLPLoadMore.PLP_LOAD_MORE_EVENT, payload, eventDetail);
|
|
215
|
+
showNewCards(newProductsHtml) {
|
|
216
|
+
const $newProductsHtml = $(newProductsHtml);
|
|
199
217
|
|
|
200
|
-
|
|
201
|
-
});
|
|
218
|
+
$(Wick.PLPLoadMore.el.productsList).append($newProductsHtml);
|
|
202
219
|
},
|
|
203
220
|
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
for (let page = startPage; page <= endPage; page++) {
|
|
208
|
-
pages.push(page);
|
|
209
|
-
}
|
|
221
|
+
prependCards(newProductsHtml) {
|
|
222
|
+
const $newProductsHtml = $(newProductsHtml);
|
|
210
223
|
|
|
211
|
-
|
|
224
|
+
$(Wick.PLPLoadMore.el.productsList).prepend($newProductsHtml);
|
|
212
225
|
},
|
|
213
226
|
|
|
214
227
|
afterProductsRendered() {
|
|
@@ -219,26 +232,31 @@ Wick.PLPLoadMore = {
|
|
|
219
232
|
Wick.PLP?.bindEvents?.();
|
|
220
233
|
},
|
|
221
234
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
$(Wick.PLPLoadMore.el.productsList).prepend($newProductsHtml);
|
|
232
|
-
},
|
|
235
|
+
loadPage(pageNumber) {
|
|
236
|
+
return new Promise((resolve, reject) => {
|
|
237
|
+
const eventDetail = { resolve, reject };
|
|
238
|
+
const payload = {
|
|
239
|
+
currentPage: pageNumber,
|
|
240
|
+
sort: Wick.PLPLoadMore.getSortValue(),
|
|
241
|
+
};
|
|
242
|
+
const event = createEvent(Wick.PLPLoadMore.PLP_LOAD_MORE_EVENT, payload, eventDetail);
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
window.dispatchEvent(event);
|
|
245
|
+
});
|
|
236
246
|
},
|
|
237
247
|
|
|
238
248
|
renderLoadPrevious() {
|
|
239
249
|
$(Wick.PLPLoadMore.el.loadPreviousWrap).remove();
|
|
240
250
|
|
|
241
|
-
|
|
251
|
+
const params = new URLSearchParams(window.location.search);
|
|
252
|
+
const restoreMode = params.get(Wick.PLPLoadMore.RESTORE_MODE_PARAM);
|
|
253
|
+
const currentPage = Wick.PLPLoadMore.getPageParam();
|
|
254
|
+
|
|
255
|
+
if (restoreMode !== 'page') {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (currentPage <= 0) {
|
|
242
260
|
return;
|
|
243
261
|
}
|
|
244
262
|
|
|
@@ -253,23 +271,40 @@ Wick.PLPLoadMore = {
|
|
|
253
271
|
$(Wick.PLPLoadMore.el.productsList).before(buttonHtml);
|
|
254
272
|
},
|
|
255
273
|
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
274
|
+
updateLoadPreviousVisibility() {
|
|
275
|
+
const currentPage = Wick.PLPLoadMore.currentPage;
|
|
276
|
+
|
|
277
|
+
if (currentPage <= 0) {
|
|
278
|
+
$(Wick.PLPLoadMore.el.loadPreviousWrap).remove();
|
|
259
279
|
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (!$(Wick.PLPLoadMore.el.loadPreviousWrap).length) {
|
|
284
|
+
Wick.PLPLoadMore.renderLoadPrevious();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
toggleLoadMoreBtn() {
|
|
260
289
|
Wick.PLPLoadMore.el.$loadMoreBtn = $('.btn-load-more');
|
|
261
290
|
|
|
262
291
|
if (!Wick.PLPLoadMore.el.$loadMoreBtn.length) {
|
|
263
292
|
return;
|
|
264
293
|
}
|
|
265
294
|
|
|
295
|
+
const isLastPageVisible =
|
|
296
|
+
Wick.PLPLoadMore.currentPage >= Wick.PLPLoadMore.getLastAvailablePage();
|
|
297
|
+
|
|
266
298
|
Wick.PLPLoadMore.el.$loadMoreBtn.toggleClass(
|
|
267
299
|
Wick.PLPLoadMore.HIDDEN_CLASS_NAME,
|
|
268
300
|
isLastPageVisible
|
|
269
301
|
);
|
|
270
302
|
},
|
|
271
303
|
|
|
272
|
-
|
|
304
|
+
scrollToRestoreProduct() {
|
|
305
|
+
const params = new URLSearchParams(window.location.search);
|
|
306
|
+
const productCode = params.get(Wick.PLPLoadMore.RESTORE_PRODUCT_PARAM);
|
|
307
|
+
|
|
273
308
|
if (!productCode) {
|
|
274
309
|
return;
|
|
275
310
|
}
|
|
@@ -288,53 +323,16 @@ Wick.PLPLoadMore = {
|
|
|
288
323
|
});
|
|
289
324
|
},
|
|
290
325
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
restorePLP() {
|
|
296
|
-
const restoreState = Wick.PLPLoadMore.getRestoreState();
|
|
297
|
-
|
|
298
|
-
if (!restoreState || Wick.PLPLoadMore.isRestoring) {
|
|
299
|
-
return Promise.resolve();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
Wick.PLPLoadMore.isRestoring = true;
|
|
303
|
-
|
|
304
|
-
const config = Wick.PLPLoadMore.getWindowConfig(restoreState);
|
|
305
|
-
const pagesToLoad = Wick.PLPLoadMore.buildPagesArray(config.startPage, config.endPage);
|
|
306
|
-
|
|
307
|
-
showLoader(Wick.PLPLoadMore.el.loader);
|
|
308
|
-
|
|
309
|
-
return Promise.all(pagesToLoad.map((page) => Wick.PLPLoadMore.loadPage(page)))
|
|
310
|
-
.then((responses) => {
|
|
311
|
-
const html = responses.join('');
|
|
312
|
-
|
|
313
|
-
Wick.PLPLoadMore.replaceProductsHtml(html);
|
|
314
|
-
Wick.PLPLoadMore.currentStartPage = config.startPage;
|
|
315
|
-
Wick.PLPLoadMore.currentEndPage = config.endPage;
|
|
326
|
+
cleanupRestoreQueryParams() {
|
|
327
|
+
const url = new URL(window.location.href);
|
|
316
328
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
Wick.PLPLoadMore.afterProductsRendered();
|
|
321
|
-
Wick.PLPLoadMore.scrollToProduct(restoreState.productCode);
|
|
322
|
-
})
|
|
323
|
-
.catch((error) => {
|
|
324
|
-
console.error('[PLP restore failed]', error);
|
|
325
|
-
})
|
|
326
|
-
.finally(() => {
|
|
327
|
-
hideLoader(Wick.PLPLoadMore.el.loader);
|
|
328
|
-
Wick.PLPLoadMore.isRestoring = false;
|
|
329
|
-
});
|
|
329
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_DONE_PARAM);
|
|
330
|
+
url.searchParams.delete(Wick.PLPLoadMore.RESTORE_PRODUCT_PARAM);
|
|
331
|
+
history.replaceState(history.state, '', url.toString());
|
|
330
332
|
},
|
|
331
333
|
|
|
332
334
|
loadMore() {
|
|
333
|
-
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const nextPage = Wick.PLPLoadMore.currentEndPage + 1;
|
|
335
|
+
const nextPage = Wick.PLPLoadMore.currentPage + 1;
|
|
338
336
|
|
|
339
337
|
if (nextPage > Wick.PLPLoadMore.getLastAvailablePage()) {
|
|
340
338
|
return;
|
|
@@ -349,10 +347,13 @@ Wick.PLPLoadMore = {
|
|
|
349
347
|
}
|
|
350
348
|
|
|
351
349
|
Wick.PLPLoadMore.showNewCards(response);
|
|
352
|
-
Wick.PLPLoadMore.
|
|
350
|
+
Wick.PLPLoadMore.currentPage = nextPage;
|
|
351
|
+
|
|
352
|
+
const cardsCount = Wick.PLPLoadMore.getCardsCountInDOM();
|
|
353
|
+
Wick.PLPLoadMore.setPerPage(cardsCount);
|
|
354
|
+
Wick.PLPLoadMore.setPageParam(Wick.PLPLoadMore.currentPage);
|
|
353
355
|
|
|
354
|
-
Wick.PLPLoadMore.
|
|
355
|
-
Wick.PLPLoadMore.renderLoadPrevious();
|
|
356
|
+
Wick.PLPLoadMore.updateLoadPreviousVisibility();
|
|
356
357
|
Wick.PLPLoadMore.toggleLoadMoreBtn();
|
|
357
358
|
Wick.PLPLoadMore.afterProductsRendered();
|
|
358
359
|
})
|
|
@@ -367,11 +368,7 @@ Wick.PLPLoadMore = {
|
|
|
367
368
|
},
|
|
368
369
|
|
|
369
370
|
loadPrevious() {
|
|
370
|
-
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const previousPage = Wick.PLPLoadMore.currentStartPage - 1;
|
|
371
|
+
const previousPage = Wick.PLPLoadMore.currentPage - 1;
|
|
375
372
|
|
|
376
373
|
if (previousPage < 0) {
|
|
377
374
|
return;
|
|
@@ -396,18 +393,19 @@ Wick.PLPLoadMore = {
|
|
|
396
393
|
Wick.PLPLoadMore.STEP;
|
|
397
394
|
|
|
398
395
|
Wick.PLPLoadMore.prependCards(response);
|
|
399
|
-
Wick.PLPLoadMore.
|
|
396
|
+
Wick.PLPLoadMore.currentPage = previousPage;
|
|
397
|
+
|
|
398
|
+
const cardsCount = Wick.PLPLoadMore.getCardsCountInDOM();
|
|
399
|
+
Wick.PLPLoadMore.setPerPage(cardsCount);
|
|
400
|
+
Wick.PLPLoadMore.setPageParam(Wick.PLPLoadMore.currentPage);
|
|
400
401
|
|
|
401
|
-
Wick.PLPLoadMore.
|
|
402
|
-
Wick.PLPLoadMore.renderLoadPrevious();
|
|
402
|
+
Wick.PLPLoadMore.updateLoadPreviousVisibility();
|
|
403
403
|
Wick.PLPLoadMore.toggleLoadMoreBtn();
|
|
404
404
|
Wick.PLPLoadMore.afterProductsRendered();
|
|
405
405
|
|
|
406
|
-
const $
|
|
407
|
-
const $
|
|
408
|
-
const newFirstTop = $
|
|
409
|
-
? $sameOldFirstCard.offset().top
|
|
410
|
-
: oldFirstTop;
|
|
406
|
+
const $allCards = $(Wick.PLPLoadMore.el.productCard);
|
|
407
|
+
const $sameCard = $allCards.eq(insertedCount);
|
|
408
|
+
const newFirstTop = $sameCard.length ? $sameCard.offset().top : oldFirstTop;
|
|
411
409
|
const delta = newFirstTop - oldFirstTop;
|
|
412
410
|
|
|
413
411
|
window.scrollTo({
|
|
@@ -423,28 +421,6 @@ Wick.PLPLoadMore = {
|
|
|
423
421
|
});
|
|
424
422
|
},
|
|
425
423
|
|
|
426
|
-
onPageShow(event) {
|
|
427
|
-
if (!event.persisted) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const restoreState = Wick.PLPLoadMore.getRestoreState();
|
|
432
|
-
|
|
433
|
-
if (!restoreState) {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
const $target = $(
|
|
438
|
-
`${Wick.PLPLoadMore.el.productCard}[data-product-code="${restoreState.productCode}"]`
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
if ($target.length) {
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
Wick.PLPLoadMore.restorePLP();
|
|
446
|
-
},
|
|
447
|
-
|
|
448
424
|
bindEvents() {
|
|
449
425
|
$(document)
|
|
450
426
|
.off('click.plpLoadMore', '.btn-load-more')
|
|
@@ -470,32 +446,38 @@ Wick.PLPLoadMore = {
|
|
|
470
446
|
window.addEventListener('pageshow', Wick.PLPLoadMore.onPageShow);
|
|
471
447
|
},
|
|
472
448
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
449
|
+
onPageShow() {
|
|
450
|
+
if (Wick.PLPLoadMore.shouldRedirectToRestoreUrl()) {
|
|
451
|
+
Wick.PLPLoadMore.redirectToRestoreUrl();
|
|
452
|
+
}
|
|
453
|
+
},
|
|
476
454
|
|
|
477
|
-
|
|
478
|
-
Wick.PLPLoadMore.
|
|
455
|
+
initCurrentPage() {
|
|
456
|
+
Wick.PLPLoadMore.currentPage = Wick.PLPLoadMore.getPageParam();
|
|
479
457
|
},
|
|
480
458
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
Wick.PLPLoadMore.renderLoadPrevious();
|
|
484
|
-
Wick.PLPLoadMore.toggleLoadMoreBtn();
|
|
459
|
+
handleRestoreScroll() {
|
|
460
|
+
const params = new URLSearchParams(window.location.search);
|
|
485
461
|
|
|
462
|
+
if (!params.get(Wick.PLPLoadMore.RESTORE_DONE_PARAM)) {
|
|
486
463
|
return;
|
|
487
464
|
}
|
|
488
465
|
|
|
489
|
-
|
|
466
|
+
requestAnimationFrame(function () {
|
|
467
|
+
requestAnimationFrame(function () {
|
|
468
|
+
Wick.PLPLoadMore.scrollToRestoreProduct();
|
|
469
|
+
Wick.PLPLoadMore.cleanupRestoreQueryParams();
|
|
470
|
+
});
|
|
471
|
+
});
|
|
490
472
|
},
|
|
491
473
|
|
|
492
474
|
init() {
|
|
493
475
|
appendLoader(Wick.PLPLoadMore.loaderPayload);
|
|
494
|
-
Wick.PLPLoadMore.
|
|
476
|
+
Wick.PLPLoadMore.initCurrentPage();
|
|
495
477
|
Wick.PLPLoadMore.bindEvents();
|
|
496
478
|
Wick.PLPLoadMore.renderLoadPrevious();
|
|
497
479
|
Wick.PLPLoadMore.toggleLoadMoreBtn();
|
|
498
|
-
Wick.PLPLoadMore.
|
|
480
|
+
Wick.PLPLoadMore.handleRestoreScroll();
|
|
499
481
|
},
|
|
500
482
|
};
|
|
501
483
|
|