@schukai/monster 4.38.5 → 4.38.6
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.
@@ -13,9 +13,9 @@
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
import {
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
assembleMethodSymbol,
|
17
|
+
CustomElement,
|
18
|
+
registerCustomElement,
|
19
19
|
} from "../../dom/customelement.mjs";
|
20
20
|
import { findElementWithSelectorUpwards, getWindow } from "../../dom/util.mjs";
|
21
21
|
import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
|
@@ -82,288 +82,288 @@ const debounceSizeSymbol = Symbol("debounceSize");
|
|
82
82
|
* @summary The Pagination component is used to show the current page and the total number of pages.
|
83
83
|
*/
|
84
84
|
class Pagination extends CustomElement {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
85
|
+
/**
|
86
|
+
*/
|
87
|
+
constructor() {
|
88
|
+
super();
|
89
|
+
this[datasourceLinkedElementSymbol] = null;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* This method is called by the `instanceof` operator.
|
94
|
+
* @return {symbol}
|
95
|
+
*/
|
96
|
+
static get [instanceSymbol]() {
|
97
|
+
return Symbol.for("@schukai/monster/components/pagination");
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
102
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
103
|
+
*
|
104
|
+
* The individual configuration values can be found in the table.
|
105
|
+
*
|
106
|
+
* @property {Object} templates Template definitions
|
107
|
+
* @property {string} templates.main Main template
|
108
|
+
* @property {Object} datasource Datasource configuration
|
109
|
+
* @property {string} datasource.selector Datasource selector
|
110
|
+
* @property {Object} labels Label definitions
|
111
|
+
* @property {string} labels.page Page label
|
112
|
+
* @property {string} labels.description Description label
|
113
|
+
* @property {string} labels.previous Previous label
|
114
|
+
* @property {string} labels.next Next label
|
115
|
+
* @property {string} labels.of Of label
|
116
|
+
* @property {string} href Href
|
117
|
+
* @property {number} currentPage Current page
|
118
|
+
* @property {number} pages Pages
|
119
|
+
* @property {number} objectsPerPage Objects per page
|
120
|
+
* @property {Object} mapping Mapping
|
121
|
+
* @property {string} mapping.pages Pages mapping
|
122
|
+
* @property {string} mapping.objectsPerPage Objects per page mapping
|
123
|
+
* @property {string} mapping.currentPage Current page mapping
|
124
|
+
*/
|
125
|
+
get defaults() {
|
126
|
+
return Object.assign(
|
127
|
+
{},
|
128
|
+
super.defaults,
|
129
|
+
{
|
130
|
+
templates: {
|
131
|
+
main: getTemplate(),
|
132
|
+
},
|
133
|
+
|
134
|
+
datasource: {
|
135
|
+
selector: null,
|
136
|
+
},
|
137
|
+
|
138
|
+
labels: getTranslations(),
|
139
|
+
|
140
|
+
href: "page-${page}",
|
141
|
+
|
142
|
+
pages: null,
|
143
|
+
objectsPerPage: 20,
|
144
|
+
currentPage: null,
|
145
|
+
|
146
|
+
mapping: {
|
147
|
+
pages: "sys.pagination.pages",
|
148
|
+
objectsPerPage: "sys.pagination.objectsPerPage",
|
149
|
+
currentPage: "sys.pagination.currentPage",
|
150
|
+
},
|
151
|
+
|
152
|
+
/* @private */
|
153
|
+
pagination: {
|
154
|
+
items: [],
|
155
|
+
},
|
156
|
+
},
|
157
|
+
initOptionsFromArguments.call(this),
|
158
|
+
);
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
*
|
163
|
+
* @return {string}
|
164
|
+
*/
|
165
|
+
static getTag() {
|
166
|
+
return "monster-pagination";
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* @return {void}
|
171
|
+
*/
|
172
|
+
disconnectedCallback() {
|
173
|
+
super.disconnectedCallback();
|
174
|
+
if (this?.[resizeObserverSymbol] instanceof ResizeObserver) {
|
175
|
+
this[resizeObserverSymbol].disconnect();
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* @return {void}
|
181
|
+
*/
|
182
|
+
connectedCallback() {
|
183
|
+
super.connectedCallback();
|
184
|
+
|
185
|
+
const parentNode = this.parentNode;
|
186
|
+
if (!parentNode) {
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
|
190
|
+
try {
|
191
|
+
handleDataSourceChanges.call(this);
|
192
|
+
} catch (e) {
|
193
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e?.message || `${e}`);
|
194
|
+
}
|
195
|
+
|
196
|
+
requestAnimationFrame(() => {
|
197
|
+
const parentParentNode = parentNode?.parentNode || parentNode;
|
198
|
+
|
199
|
+
const parentWidth = parentParentNode.offsetWidth;
|
200
|
+
const ownWidth = this.offsetWidth;
|
201
|
+
|
202
|
+
this[sizeDataSymbol] = {
|
203
|
+
last: {
|
204
|
+
parentWidth: 0,
|
205
|
+
},
|
206
|
+
showNumbers: ownWidth < parentWidth,
|
207
|
+
};
|
208
|
+
|
209
|
+
this[resizeObserverSymbol] = new ResizeObserver(() => {
|
210
|
+
if (this[debounceSizeSymbol] instanceof DeadMansSwitch) {
|
211
|
+
try {
|
212
|
+
this[debounceSizeSymbol].touch();
|
213
|
+
return;
|
214
|
+
} catch (e) {
|
215
|
+
delete this[debounceSizeSymbol];
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
this[debounceSizeSymbol] = new DeadMansSwitch(250, () => {
|
220
|
+
queueMicrotask(() => {
|
221
|
+
const parentWidth = parentParentNode.offsetWidth;
|
222
|
+
const ownWidth = this.clientWidth;
|
223
|
+
|
224
|
+
if (this[sizeDataSymbol]?.last?.parentWidth === parentWidth) {
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
|
228
|
+
this[sizeDataSymbol].last = {
|
229
|
+
parentWidth: parentWidth,
|
230
|
+
};
|
231
|
+
|
232
|
+
this[sizeDataSymbol].showNumbers = ownWidth <= parentWidth;
|
233
|
+
handleDataSourceChanges.call(this);
|
234
|
+
});
|
235
|
+
});
|
236
|
+
});
|
237
|
+
|
238
|
+
this[resizeObserverSymbol].observe(this?.parentNode?.parentNode);
|
239
|
+
});
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* @return {void}
|
244
|
+
*/
|
245
|
+
[assembleMethodSymbol]() {
|
246
|
+
super[assembleMethodSymbol]();
|
247
|
+
|
248
|
+
initControlReferences.call(this);
|
249
|
+
initEventHandler.call(this);
|
250
|
+
|
251
|
+
const selector = this.getOption("datasource.selector", "");
|
252
|
+
|
253
|
+
if (isString(selector)) {
|
254
|
+
const element = findElementWithSelectorUpwards(this, selector);
|
255
|
+
if (element === null) {
|
256
|
+
throw new Error("the selector must match exactly one element");
|
257
|
+
}
|
258
|
+
|
259
|
+
if (!(element instanceof Datasource)) {
|
260
|
+
throw new TypeError("the element must be a datasource");
|
261
|
+
}
|
262
|
+
|
263
|
+
this[datasourceLinkedElementSymbol] = element;
|
264
|
+
element.datasource.attachObserver(
|
265
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
266
|
+
);
|
267
|
+
|
268
|
+
element.attachObserver(new Observer(handleDataSourceChanges.bind(this)));
|
269
|
+
|
270
|
+
handleDataSourceChanges.call(this);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* @private
|
276
|
+
* @return {CSSStyleSheet}
|
277
|
+
*/
|
278
|
+
static getControlCSSStyleSheet() {
|
279
|
+
return PaginationStyleSheet;
|
280
|
+
}
|
281
|
+
|
282
|
+
/**
|
283
|
+
* @return {CSSStyleSheet[]}
|
284
|
+
*/
|
285
|
+
static getCSSStyleSheet() {
|
286
|
+
return [this.getControlCSSStyleSheet(), DisplayStyleSheet, ThemeStyleSheet];
|
287
|
+
}
|
288
288
|
}
|
289
289
|
|
290
290
|
function getTranslations() {
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
291
|
+
const locale = getLocaleOfDocument();
|
292
|
+
switch (locale.language) {
|
293
|
+
case "de":
|
294
|
+
return {
|
295
|
+
page: "${page}",
|
296
|
+
description: "Seite ${page}",
|
297
|
+
previous: "Vorherige",
|
298
|
+
next: "Nächste",
|
299
|
+
of: "von",
|
300
|
+
};
|
301
|
+
case "fr":
|
302
|
+
return {
|
303
|
+
page: "${page}",
|
304
|
+
description: "Page ${page}",
|
305
|
+
previous: "Précédent",
|
306
|
+
next: "Suivant",
|
307
|
+
of: "de",
|
308
|
+
};
|
309
|
+
case "sp":
|
310
|
+
return {
|
311
|
+
page: "${page}",
|
312
|
+
description: "Página ${page}",
|
313
|
+
previous: "Anterior",
|
314
|
+
next: "Siguiente",
|
315
|
+
of: "de",
|
316
|
+
};
|
317
|
+
case "it":
|
318
|
+
return {
|
319
|
+
page: "${page}",
|
320
|
+
description: "Pagina ${page}",
|
321
|
+
previous: "Precedente",
|
322
|
+
next: "Successivo",
|
323
|
+
of: "di",
|
324
|
+
};
|
325
|
+
case "pl":
|
326
|
+
return {
|
327
|
+
page: "${page}",
|
328
|
+
description: "Strona ${page}",
|
329
|
+
previous: "Poprzednia",
|
330
|
+
next: "Następna",
|
331
|
+
of: "z",
|
332
|
+
};
|
333
|
+
case "no":
|
334
|
+
return {
|
335
|
+
page: "${page}",
|
336
|
+
description: "Side ${page}",
|
337
|
+
previous: "Forrige",
|
338
|
+
next: "Neste",
|
339
|
+
of: "av",
|
340
|
+
};
|
341
|
+
case "dk":
|
342
|
+
return {
|
343
|
+
page: "${page}",
|
344
|
+
description: "Side ${page}",
|
345
|
+
previous: "Forrige",
|
346
|
+
next: "Næste",
|
347
|
+
of: "af",
|
348
|
+
};
|
349
|
+
case "sw":
|
350
|
+
return {
|
351
|
+
page: "${page}",
|
352
|
+
description: "Sida ${page}",
|
353
|
+
previous: "Föregående",
|
354
|
+
next: "Nästa",
|
355
|
+
of: "av",
|
356
|
+
};
|
357
|
+
default:
|
358
|
+
case "en":
|
359
|
+
return {
|
360
|
+
page: "${page}",
|
361
|
+
description: "Page ${page}",
|
362
|
+
previous: "Previous",
|
363
|
+
next: "Next",
|
364
|
+
of: "of",
|
365
|
+
};
|
366
|
+
}
|
367
367
|
}
|
368
368
|
|
369
369
|
/**
|
@@ -372,89 +372,89 @@ function getTranslations() {
|
|
372
372
|
* @throws {Error} no shadow-root is defined
|
373
373
|
*/
|
374
374
|
function initControlReferences() {
|
375
|
-
|
376
|
-
|
377
|
-
|
375
|
+
if (!this.shadowRoot) {
|
376
|
+
throw new Error("no shadow-root is defined");
|
377
|
+
}
|
378
378
|
|
379
|
-
|
380
|
-
|
381
|
-
|
379
|
+
this[paginationElementSymbol] = this.shadowRoot.querySelector(
|
380
|
+
"[data-monster-role=pagination]",
|
381
|
+
);
|
382
382
|
}
|
383
383
|
|
384
384
|
/**
|
385
385
|
* @private
|
386
386
|
*/
|
387
387
|
function initEventHandler() {
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
388
|
+
const self = this;
|
389
|
+
|
390
|
+
self[paginationElementSymbol].addEventListener("click", function (event) {
|
391
|
+
let element = null;
|
392
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
393
|
+
if (!datasource) {
|
394
|
+
return;
|
395
|
+
}
|
396
|
+
|
397
|
+
element = findTargetElementFromEvent(
|
398
|
+
event,
|
399
|
+
ATTRIBUTE_ROLE,
|
400
|
+
"pagination-item",
|
401
|
+
);
|
402
|
+
|
403
|
+
if (!element) {
|
404
|
+
element = findTargetElementFromEvent(
|
405
|
+
event,
|
406
|
+
ATTRIBUTE_ROLE,
|
407
|
+
"pagination-next",
|
408
|
+
);
|
409
|
+
if (!element) {
|
410
|
+
element = findTargetElementFromEvent(
|
411
|
+
event,
|
412
|
+
ATTRIBUTE_ROLE,
|
413
|
+
"pagination-prev",
|
414
|
+
);
|
415
|
+
if (!element) {
|
416
|
+
return;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
}
|
420
|
+
|
421
|
+
if (!(element instanceof HTMLElement)) {
|
422
|
+
return;
|
423
|
+
}
|
424
|
+
|
425
|
+
let page = null;
|
426
|
+
|
427
|
+
if (!element.hasAttribute("data-page-no")) {
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
|
431
|
+
page = element.getAttribute("data-page-no");
|
432
|
+
|
433
|
+
if (
|
434
|
+
!page ||
|
435
|
+
page === "" ||
|
436
|
+
page === "…" ||
|
437
|
+
page === null ||
|
438
|
+
page === undefined ||
|
439
|
+
page === "undefined" ||
|
440
|
+
page === "null"
|
441
|
+
) {
|
442
|
+
return;
|
443
|
+
}
|
444
|
+
|
445
|
+
if (typeof datasource.setParameters !== "function") {
|
446
|
+
return;
|
447
|
+
}
|
448
|
+
|
449
|
+
event.preventDefault();
|
450
|
+
datasource.setParameters({ page });
|
451
|
+
|
452
|
+
if (typeof datasource.reload !== "function") {
|
453
|
+
return;
|
454
|
+
}
|
455
|
+
|
456
|
+
datasource.reload();
|
457
|
+
});
|
458
458
|
}
|
459
459
|
|
460
460
|
/**
|
@@ -470,55 +470,53 @@ function initEventHandler() {
|
|
470
470
|
* @throws {Error} the datasource could not be initialized
|
471
471
|
*/
|
472
472
|
function initOptionsFromArguments() {
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
473
|
+
const options = {};
|
474
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
475
|
+
if (selector) {
|
476
|
+
options.datasource = { selector: selector };
|
477
|
+
}
|
478
478
|
|
479
|
-
|
479
|
+
return options;
|
480
480
|
}
|
481
481
|
|
482
482
|
/**
|
483
483
|
* @private
|
484
484
|
*/
|
485
485
|
function handleDataSourceChanges() {
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
this.setOption("pagination", pagination);
|
521
|
-
});
|
486
|
+
let pagination;
|
487
|
+
|
488
|
+
if (!this[datasourceLinkedElementSymbol]) {
|
489
|
+
return;
|
490
|
+
}
|
491
|
+
|
492
|
+
const mapping = this.getOption("mapping");
|
493
|
+
const pf = new Pathfinder(this[datasourceLinkedElementSymbol].data);
|
494
|
+
|
495
|
+
for (const key in mapping) {
|
496
|
+
const path = mapping[key];
|
497
|
+
|
498
|
+
if (pf.exists(path)) {
|
499
|
+
const value = pf.getVia(path);
|
500
|
+
this.setOption(key, value);
|
501
|
+
}
|
502
|
+
|
503
|
+
const o = this[datasourceLinkedElementSymbol].getOption(path);
|
504
|
+
if (o !== undefined && o !== null) {
|
505
|
+
this.setOption(key, o);
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
pagination = buildPagination.call(
|
510
|
+
this,
|
511
|
+
this.getOption("currentPage"),
|
512
|
+
this.getOption("pages"),
|
513
|
+
);
|
514
|
+
console.log(pagination);
|
515
|
+
if (this?.[sizeDataSymbol]?.showNumbers !== true) {
|
516
|
+
pagination.items = [];
|
517
|
+
}
|
518
|
+
|
519
|
+
this.setOption("pagination", pagination);
|
522
520
|
}
|
523
521
|
|
524
522
|
/**
|
@@ -528,97 +526,97 @@ function handleDataSourceChanges() {
|
|
528
526
|
* @return {object}
|
529
527
|
*/
|
530
528
|
function buildPagination(current, max) {
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
529
|
+
current = parseInt(current, 10);
|
530
|
+
max = parseInt(max, 10);
|
531
|
+
|
532
|
+
let prev = current === 1 ? null : current - 1;
|
533
|
+
let next = current === max ? null : current + 1;
|
534
|
+
const itemList = [1];
|
535
|
+
|
536
|
+
if (current > 4) itemList.push(-1);
|
537
|
+
|
538
|
+
const r = 2;
|
539
|
+
const r1 = current - r;
|
540
|
+
const r2 = current + r;
|
541
|
+
|
542
|
+
for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++) itemList.push(i);
|
543
|
+
|
544
|
+
if (r2 + 1 < max) itemList.push(-1);
|
545
|
+
if (r2 < max) itemList.push(max);
|
546
|
+
|
547
|
+
let prevClass = "";
|
548
|
+
|
549
|
+
if (prev === null) {
|
550
|
+
prevClass = " disabled";
|
551
|
+
}
|
552
|
+
|
553
|
+
let nextClass = "";
|
554
|
+
if (next === null) {
|
555
|
+
nextClass = " disabled";
|
556
|
+
}
|
557
|
+
|
558
|
+
const items = itemList.map((item) => {
|
559
|
+
let p = `${item}`;
|
560
|
+
|
561
|
+
if (item === -1) {
|
562
|
+
item = null;
|
563
|
+
p = "…";
|
564
|
+
}
|
565
|
+
|
566
|
+
const c = `${current}`;
|
567
|
+
|
568
|
+
const obj = {
|
569
|
+
pageNo: item, // as integer
|
570
|
+
page: p, // as string
|
571
|
+
current: p === c,
|
572
|
+
class: (p === c ? "current" : "").trim(),
|
573
|
+
};
|
574
|
+
|
575
|
+
if (item === null) {
|
576
|
+
obj.class += " disabled".trim();
|
577
|
+
}
|
578
|
+
|
579
|
+
const formatter = new Formatter(obj);
|
580
|
+
|
581
|
+
obj.description = formatter.format(this.getOption("labels.description"));
|
582
|
+
obj.label = formatter.format(this.getOption("labels.page"));
|
583
|
+
obj.href =
|
584
|
+
item === null
|
585
|
+
? "#"
|
586
|
+
: p === c
|
587
|
+
? "#"
|
588
|
+
: p === "1"
|
589
|
+
? "#"
|
590
|
+
: `#${formatter.format(this.getOption("href"))}`;
|
591
|
+
return obj;
|
592
|
+
});
|
593
|
+
|
594
|
+
const nextNo = next;
|
595
|
+
next = `${next}`;
|
596
|
+
|
597
|
+
const nextHref =
|
598
|
+
next === "null"
|
599
|
+
? "#"
|
600
|
+
: `#${new Formatter({ page: next }).format(this.getOption("href"))}`;
|
601
|
+
const prevNo = prev;
|
602
|
+
prev = `${prev}`;
|
603
|
+
const prevHref =
|
604
|
+
prev === "null"
|
605
|
+
? "#"
|
606
|
+
: `#${new Formatter({ page: prev }).format(this.getOption("href"))}`;
|
607
|
+
|
608
|
+
return {
|
609
|
+
current,
|
610
|
+
nextNo,
|
611
|
+
next,
|
612
|
+
nextClass,
|
613
|
+
nextHref,
|
614
|
+
prevNo,
|
615
|
+
prev,
|
616
|
+
prevClass,
|
617
|
+
prevHref,
|
618
|
+
items,
|
619
|
+
};
|
622
620
|
}
|
623
621
|
|
624
622
|
/**
|
@@ -626,8 +624,8 @@ function buildPagination(current, max) {
|
|
626
624
|
* @return {string}
|
627
625
|
*/
|
628
626
|
function getTemplate() {
|
629
|
-
|
630
|
-
|
627
|
+
// language=HTML
|
628
|
+
return `
|
631
629
|
<template id="items">
|
632
630
|
<li><a data-monster-attributes="class path:items.class,
|
633
631
|
href path:items.href,
|