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. 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 = ''; + + 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'); + }) 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