From 2933bafee20448d9e6de0fc92ec619814f55a475 Mon Sep 17 00:00:00 2001 From: pkExec Date: Thu, 10 Jul 2025 11:39:35 +0300 Subject: [PATCH 1/3] implement pageLink parameter --- src/pagination.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pagination.js b/src/pagination.js index f5e900d..ef047fb 100644 --- a/src/pagination.js +++ b/src/pagination.js @@ -141,7 +141,18 @@ getPageLinkTag: function(index) { var pageLink = attributes.pageLink; - return pageLink ? `${index}` : `${index}`; + let pageIndex = index; + let total = attributes.totalNumber; + let currentPage = attributes.pageNumber; + switch (index){ + case attributes.prevText: + pageIndex = (currentPage>1)?currentPage-1:1; + break; + case attributes.nextText: + pageIndex= (currentPage${index}` : `${index}`; }, // Generate HTML for page numbers From d0076e6d10978fe6b7a1bca2daef70f57b7dc4ef Mon Sep 17 00:00:00 2001 From: pkExec Date: Thu, 10 Jul 2025 11:39:54 +0300 Subject: [PATCH 2/3] pageLink parameter documentation --- docs/en.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/en.md b/docs/en.md index a0a958b..46e12c8 100644 --- a/docs/en.md +++ b/docs/en.md @@ -130,6 +130,27 @@ Number of data items per page. If you want to show all pages, just set it to `null`. +### pageLink string (default ``) +`pageLink` customizes the anchor href attribute in the pagination page buttons, for SEO purposes mostly. + +By default, they use `{{INDEX}}`. + +By setting a string in `pageLink`, it becomes `{{INDEX}}`. + +If you use the special string `{{index}}` inside your `pageLink`, the link will be customized with the current index. + +Example: + +pageLink: `/mysite/products/?page={{index}}` + +will render: + +`1` + +`2` + +etc. + ### callback function(data, pagination) Used to customize item's innerHTML, will be invoked on each paging. From 4f3a1b8821956db741975dd27ed7ee72f3517aca Mon Sep 17 00:00:00 2001 From: pkExec Date: Thu, 10 Jul 2025 11:40:01 +0300 Subject: [PATCH 3/3] pageLink example --- examples/pagination.html | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/examples/pagination.html b/examples/pagination.html index 02be9b9..46e13b8 100644 --- a/examples/pagination.html +++ b/examples/pagination.html @@ -41,6 +41,8 @@
+
+
@@ -168,6 +170,52 @@ } }) })('demo3'); + + (function(name) { + var container = $('#pagination-' + name); + if (!container.length) return; + var sources = function () { + var result = []; + + for (var i = 1; i < 196; i++) { + result.push(i); + } + + return result; + }(); + + var options = { + dataSource: sources, + pageLink: '/mysite/products/?page={{index}}', //to show the page button href attribute + pageNumber: 5, //to show how the next/prev links are calculated + callback: function (response, pagination) { + window.console && console.log(response, pagination); + + var dataHtml = '
    '; + + $.each(response, function (index, item) { + dataHtml += '
  • ' + item + '
  • '; + }); + + dataHtml += '
'; + + container.prev().html(dataHtml); + } + }; + + //$.pagination(container, options); + + container.addHook('beforeInit', function () { + window.console && console.log('beforeInit...'); + }); + container.pagination(options); + + container.addHook('beforePageOnClick', function () { + window.console && console.log('beforePageOnClick...'); + //return false + }); + })('demo4'); + })