From a31c65af9a71e0b8ed873ad1d6606cec4d595ee9 Mon Sep 17 00:00:00 2001 From: fred104 Date: Thu, 16 Aug 2018 18:13:01 +0800 Subject: [PATCH 1/2] Use template to generate pagination info --- pagination/input.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pagination/input.js b/pagination/input.js index ae11a36..ce3e2bc 100644 --- a/pagination/input.js +++ b/pagination/input.js @@ -54,9 +54,9 @@ var lastClassName = 'last'; var paginateClassName = 'paginate'; - var paginateOfClassName = 'paginate_of'; var paginatePageClassName = 'paginate_page'; var paginateInputClassName = 'paginate_input'; + var paginateTotalClassName = 'paginate_total'; $.fn.dataTableExt.oPagination.input = { 'fnInit': function (oSettings, nPaging, fnCallbackDraw) { @@ -65,11 +65,11 @@ var nNext = document.createElement('span'); var nLast = document.createElement('span'); var nInput = document.createElement('input'); - var nPage = document.createElement('span'); - var nOf = document.createElement('span'); + var nTotal = document.createElement('span'); var language = oSettings.oLanguage.oPaginate; var classes = oSettings.oClasses; + var info = language.info || 'Page _INPUT_ of _TOTAL_'; nFirst.innerHTML = language.sFirst; nPrevious.innerHTML = language.sPrevious; @@ -81,9 +81,8 @@ nNext.className = nextClassName + ' ' + classes.sPageButton; nLast.className = lastClassName + ' ' + classes.sPageButton; - nOf.className = paginateOfClassName; - nPage.className = paginatePageClassName; nInput.className = paginateInputClassName; + nTotal.className = paginateTotalClassName; if (oSettings.sTableId !== '') { nPaging.setAttribute('id', oSettings.sTableId + '_' + paginateClassName); @@ -94,13 +93,14 @@ } nInput.type = 'text'; - nPage.innerHTML = 'Page '; + + info = info.replace(/_INPUT_/g, '' + nInput.outerHTML + ''); + info = info.replace(/_TOTAL_/g, '' + nTotal.outerHTML + ''); + info = '' + info + ''; nPaging.appendChild(nFirst); nPaging.appendChild(nPrevious); - nPaging.appendChild(nPage); - nPaging.appendChild(nInput); - nPaging.appendChild(nOf); + nPaging.innerHTML += info; nPaging.appendChild(nNext); nPaging.appendChild(nLast); @@ -136,7 +136,7 @@ } }); - $(nInput).keyup(function (e) { + $(nPaging).find('.' + paginateInputClassName).keyup(function (e) { // 38 = up arrow, 39 = right arrow if (e.which === 38 || e.which === 39) { this.value++; @@ -215,9 +215,9 @@ .addClass(disableClasses[lastClassName]); // Paginate of N pages text - $(an).children('.' + paginateOfClassName).html(' of ' + iPages); + $(an).children('.' + paginateTotalClassName).html(iPages); - // Current page numer input value + // Current page number input value $(an).children('.' + paginateInputClassName).val(iCurrentPage); } }; From c40be6193d3c3f2704d745a764866b2c53c8c1ef Mon Sep 17 00:00:00 2001 From: fred104 Date: Tue, 21 Aug 2018 19:36:34 +0800 Subject: [PATCH 2/2] Fix for buttons not worked --- pagination/input.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pagination/input.js b/pagination/input.js index ce3e2bc..31940cd 100644 --- a/pagination/input.js +++ b/pagination/input.js @@ -66,6 +66,7 @@ var nLast = document.createElement('span'); var nInput = document.createElement('input'); var nTotal = document.createElement('span'); + var nInfo = document.createElement('span'); var language = oSettings.oLanguage.oPaginate; var classes = oSettings.oClasses; @@ -96,11 +97,13 @@ info = info.replace(/_INPUT_/g, '' + nInput.outerHTML + ''); info = info.replace(/_TOTAL_/g, '' + nTotal.outerHTML + ''); - info = '' + info + ''; + nInfo.innerHTML = '' + info + ''; nPaging.appendChild(nFirst); nPaging.appendChild(nPrevious); - nPaging.innerHTML += info; + $(nInfo).children().each(function (i, n) { + nPaging.appendChild(n); + }); nPaging.appendChild(nNext); nPaging.appendChild(nLast); @@ -215,10 +218,10 @@ .addClass(disableClasses[lastClassName]); // Paginate of N pages text - $(an).children('.' + paginateTotalClassName).html(iPages); + $(an).find('.' + paginateTotalClassName).html(iPages); // Current page number input value - $(an).children('.' + paginateInputClassName).val(iCurrentPage); + $(an).find('.' + paginateInputClassName).val(iCurrentPage); } }; })(jQuery);