PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.87
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.87
51.1.87 51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 All 41 releases
king-addons / includes / widgets / Woo_Products_Pagination / script.js

script.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.87, at includes/widgets/Woo_Products_Pagination/script.js

64 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (() => {
2 'use strict';
3
4 const matchesTarget = (el, detail) => {
5 const ownArg = el.dataset.pageArg || '';
6 if (ownArg) {
7 return ownArg === (detail.pageArg || '');
8 }
9 const own = el.dataset.queryId || '';
10 if (!detail.queryId) {
11 return true;
12 }
13 return !own || own === detail.queryId;
14 };
15
16 const hrefFor = (pageArg, page) => {
17 const url = new URL(window.location.href);
18 if (!pageArg) {
19 return url.pathname + url.search;
20 }
21 if (page <= 1) {
22 url.searchParams.delete(pageArg);
23 } else {
24 url.searchParams.set(pageArg, String(page));
25 }
26 return url.pathname + url.search;
27 };
28
29 const buildLinks = (page, maxPages, pageArg) => {
30 const parts = [];
31 if (page > 1) {
32 parts.push('<a class="prev page-numbers" href="' + hrefFor(pageArg, page - 1) + '">&laquo;</a>');
33 }
34 for (let i = 1; i <= maxPages; i += 1) {
35 if (i === page) {
36 parts.push('<span aria-current="page" class="page-numbers current">' + i + '</span>');
37 } else {
38 parts.push('<a class="page-numbers" href="' + hrefFor(pageArg, i) + '">' + i + '</a>');
39 }
40 }
41 if (page < maxPages) {
42 parts.push('<a class="next page-numbers" href="' + hrefFor(pageArg, page + 1) + '">&raquo;</a>');
43 }
44 return parts.join('');
45 };
46
47 const applyPage = (detail) => {
48 const page = Math.max(1, parseInt(detail.page, 10) || 1);
49 const maxPages = Math.max(1, parseInt(detail.maxPages, 10) || 1);
50
51 document.querySelectorAll('.ka-woo-pagination').forEach((el) => {
52 if (!matchesTarget(el, detail)) {
53 return;
54 }
55 const pageArg = el.dataset.pageArg || detail.pageArg || '';
56 el.innerHTML = buildLinks(page, maxPages, pageArg);
57 });
58 };
59
60 document.addEventListener('kingaddons:grid:page', (event) => {
61 applyPage(event.detail || {});
62 });
63 })();
64