From f5fe9bfde5e20fcf0e103ac41b375ec03c5637e3 Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 22:38:46 +0100 Subject: [PATCH] Prevent default event when clicking paging link. --- js/datatable.js | 3 ++- js/datatable.min.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/datatable.js b/js/datatable.js index 4b2ece6..e069f7d 100644 --- a/js/datatable.js +++ b/js/datatable.js @@ -471,7 +471,8 @@ DataTable.prototype = { e.classList.add(dataTable.options.pagingItemClass); } if (e.childNodes.length > 0) { - e.childNodes[0].addEventListener('click', function () { + e.childNodes[0].addEventListener('click', function (event) { + event.preventDefault(); if (this.parentNode.classList.contains('active') || typeof this.dataset.page === 'undefined') { return; diff --git a/js/datatable.min.js b/js/datatable.min.js index 1383f20..cbe9c8b 100644 --- a/js/datatable.min.js +++ b/js/datatable.min.js @@ -1 +1 @@ -"use strict";var DataTable=function(t,e){this.options={},this.table=t,this.currentPage=0,this.currentStart=0,this.filterIndex=[];for(var i in DataTable.defaultOptions)DataTable.defaultOptions.hasOwnProperty(i)&&(e.hasOwnProperty(i)?this.options[i]=e[i]:this.options[i]=DataTable.defaultOptions[i]);e.hasOwnProperty("data")&&(this.options.data=e.data),this.options.nbColumns<0&&(this.options.nbColumns=this.table.tHead.rows[0].cells.length),this.pagingDivs=document.querySelectorAll(this.options.pagingDivSelector);for(var s=0;s
',this.options.data.allInOne)this.getAjaxDataAsync(!0);else for(s=0;s0){this.data=[];var o=this.table.tBodies[0].rows,l=o[0].cells.length;for(s=0;s=0||(p=!1);if(p)for(s=0;s=this.options.data.size?(this.setRefreshTimeout(),this.hideLoadingDivs()):this.loadingDiv.querySelector("div.progress .progress-bar").style.width=parseInt(100*this.data.length/this.options.data.size,10)+"%"},getAjaxDataAsync:function(t,e){void 0===e&&(e=!1),e&&void 0===this.syncData&&(this.syncData={data:[],toAdd:[],toUpdate:{},toDelete:[]});var i,s,a,n=new XMLHttpRequest;n.timeout=this.options.data.timeout,n.onreadystatechange=(i=this,s=t,a=e,function(){if(4==this.readyState)switch(this.status){case 200:if(a)if(this.response.length>0)i.syncData.data=i.syncData.data.concat(this.response),i.getAjaxDataAsync(s+i.options.pageSize*i.options.pagingNumberOfPages,!0);else{var t=i.syncData;delete i.syncData,i.data=t.data,i.addRows(t.toAdd),t.toDelete.forEach(function(t){t instanceof Function?i.deleteAll(t):i.deleteRow(t)});for(var e in t.toUpdate)i.updateRow(e,t.toUpdate[e]);i.sort(!0),i.setRefreshTimeout()}else i.data=i.data.concat(this.response),i.updateLoadingDivs(),i.sort(!0);break;case 404:case 500:console.log("ERROR: "+this.status+" - "+this.statusText),console.log(n);break;default:i.getAjaxDataAsync(s,a)}});var r=this.options.data.url,o=this.options.pageSize*this.options.pagingNumberOfPages,l=new FormData;!0!==t&&("GET"==this.options.data.type.toUpperCase()?r+="?start="+t+"&limit="+o:(l.append("offset",t),l.append("limit",o))),n.open(this.options.data.type,r,!0),n.responseType="json",n.send(l)},getLastPageNumber:function(){return parseInt(Math.ceil(this.filterIndex.length/this.options.pageSize),10)},createPagingLink:function(t,e,i){var s=document.createElement("a");return this.options.pagingLinkClass&&s.classList.add(this.options.pagingLinkClass),this.options.pagingLinkHref&&(s.href=this.options.pagingLinkHref),!1!==this.options.pagingLinkDisabledTabIndex&&i&&(s.tabIndex=this.options.pagingLinkDisabledTabIndex),s.dataset.page=e,s.innerHTML=t,s},updatePaging:function(){var t,e,i=this.options.pagingNumberOfPages,s=this,a=parseInt(this.currentStart/this.options.pageSize,10)+1,n=this.getLastPageNumber(),r=this.filterIndex.length?this.currentStart+1:0,o=this.currentStart+this.options.pageSize>this.filterIndex.length?this.filterIndex.length:this.currentStart+this.options.pageSize;a=n-i/2?(t=n-i+1)<1&&(t=1):t=parseInt(a-i/2+1,10),e=t+i0&&t.childNodes[0].addEventListener("click",function(){if(!this.parentNode.classList.contains("active")&&void 0!==this.dataset.page)switch(this.dataset.page){case"first":s.loadPage(1);break;case"prev":s.loadPage(a-1);break;case"next":s.loadPage(a+1);break;case"last":s.loadPage(n);break;default:s.loadPage(parseInt(parseInt(this.dataset.page),10))}},!1),this.pagingLists[l].appendChild(t)},this)}},updateCounter:function(){for(var t=this.filterIndex.length?parseInt(this.currentStart/this.options.pageSize,10)+1:0,e=parseInt(Math.ceil(this.filterIndex.length/this.options.pageSize),10),i=this.filterIndex.length?this.currentStart+1:0,s=this.currentStart+this.options.pageSize>this.filterIndex.length?this.filterIndex.length:this.currentStart+this.options.pageSize,a=0;an?i?1:-1:a0&&this.table.tHead.appendChild(e)}},filter:function(t){void 0===t&&(t=!1);var e=this.currentStart;this.currentStart=0,this.filterIndex=[];for(var i=0;i=this.filterIndex.length;)this.currentStart-=this.options.pageSize;this.currentStart<0&&(this.currentStart=0)}if(this.options.filterSelectOptions&&this.filterIndex.length>0){for(var s=[],a=0;a0){for(a=0;a0){e.childNodes[0].selected=!0;for(a=1;athis.getLastPageNumber()&&(t=this.getLastPageNumber()),this.currentStart=(t-1)*this.options.pageSize,this.refresh(),this.options.onChange.call(this.table,e+1,t)},getCurrentPage:function(){return this.currentStart/this.options.pageSize+1},refresh:function(){if(this.options.beforeRefresh.call(this.table),this.updatePaging(),this.updateCounter(),this.table.tBodies[0].innerHTML="",this.currentStart>=this.currentDataLength)this.table.tBodies[0].innerHTML='
';else{for(var t=0;t");return i}},DataTable.defaultAjaxOptions={url:null,size:null,refresh:!1,allInOne:!1,timeout:2e3}; +"use strict";var DataTable=function(t,e){for(var i in this.options={},this.table=t,this.currentPage=0,this.currentStart=0,this.filterIndex=[],DataTable.defaultOptions)DataTable.defaultOptions.hasOwnProperty(i)&&(e.hasOwnProperty(i)?this.options[i]=e[i]:this.options[i]=DataTable.defaultOptions[i]);e.hasOwnProperty("data")&&(this.options.data=e.data),this.options.nbColumns<0&&(this.options.nbColumns=this.table.tHead.rows[0].cells.length),this.pagingDivs=document.querySelectorAll(this.options.pagingDivSelector);for(var s=0;s
',this.options.data.allInOne)this.getAjaxDataAsync(!0);else for(s=0;s0){this.data=[];var o=this.table.tBodies[0].rows,l=o[0].cells.length;for(s=0;s=0||(p=!1);if(p)for(s=0;s=this.options.data.size?(this.setRefreshTimeout(),this.hideLoadingDivs()):this.loadingDiv.querySelector("div.progress .progress-bar").style.width=parseInt(100*this.data.length/this.options.data.size,10)+"%"},getAjaxDataAsync:function(t,e){void 0===e&&(e=!1),e&&void 0===this.syncData&&(this.syncData={data:[],toAdd:[],toUpdate:{},toDelete:[]});var i,s,a,n=new XMLHttpRequest;n.timeout=this.options.data.timeout,n.onreadystatechange=(i=this,s=t,a=e,function(){if(4==this.readyState)switch(this.status){case 200:if(a)if(this.response.length>0)i.syncData.data=i.syncData.data.concat(this.response),i.getAjaxDataAsync(s+i.options.pageSize*i.options.pagingNumberOfPages,!0);else{var t=i.syncData;for(var e in delete i.syncData,i.data=t.data,i.addRows(t.toAdd),t.toDelete.forEach(function(t){t instanceof Function?i.deleteAll(t):i.deleteRow(t)}),t.toUpdate)i.updateRow(e,t.toUpdate[e]);i.sort(!0),i.setRefreshTimeout()}else i.data=i.data.concat(this.response),i.updateLoadingDivs(),i.sort(!0);break;case 404:case 500:console.log("ERROR: "+this.status+" - "+this.statusText),console.log(n);break;default:i.getAjaxDataAsync(s,a)}});var r=this.options.data.url,o=this.options.pageSize*this.options.pagingNumberOfPages,l=new FormData;!0!==t&&("GET"==this.options.data.type.toUpperCase()?r+="?start="+t+"&limit="+o:(l.append("offset",t),l.append("limit",o))),n.open(this.options.data.type,r,!0),n.responseType="json",n.send(l)},getLastPageNumber:function(){return parseInt(Math.ceil(this.filterIndex.length/this.options.pageSize),10)},createPagingLink:function(t,e,i){var s=document.createElement("a");return this.options.pagingLinkClass&&s.classList.add(this.options.pagingLinkClass),this.options.pagingLinkHref&&(s.href=this.options.pagingLinkHref),!1!==this.options.pagingLinkDisabledTabIndex&&i&&(s.tabIndex=this.options.pagingLinkDisabledTabIndex),s.dataset.page=e,s.innerHTML=t,s},updatePaging:function(){var t,e,i=this.options.pagingNumberOfPages,s=this,a=parseInt(this.currentStart/this.options.pageSize,10)+1,n=this.getLastPageNumber(),r=this.filterIndex.length?this.currentStart+1:0,o=this.currentStart+this.options.pageSize>this.filterIndex.length?this.filterIndex.length:this.currentStart+this.options.pageSize;a=n-i/2?(t=n-i+1)<1&&(t=1):t=parseInt(a-i/2+1,10),e=t+i0&&t.childNodes[0].addEventListener("click",function(t){if(t.preventDefault(),!this.parentNode.classList.contains("active")&&void 0!==this.dataset.page)switch(this.dataset.page){case"first":s.loadPage(1);break;case"prev":s.loadPage(a-1);break;case"next":s.loadPage(a+1);break;case"last":s.loadPage(n);break;default:s.loadPage(parseInt(parseInt(this.dataset.page),10))}},!1),this.pagingLists[l].appendChild(t)},this)}},updateCounter:function(){for(var t=this.filterIndex.length?parseInt(this.currentStart/this.options.pageSize,10)+1:0,e=parseInt(Math.ceil(this.filterIndex.length/this.options.pageSize),10),i=this.filterIndex.length?this.currentStart+1:0,s=this.currentStart+this.options.pageSize>this.filterIndex.length?this.filterIndex.length:this.currentStart+this.options.pageSize,a=0;an?i?1:-1:a0&&this.table.tHead.appendChild(e)}},filter:function(t){void 0===t&&(t=!1);var e=this.currentStart;this.currentStart=0,this.filterIndex=[];for(var i=0;i=this.filterIndex.length;)this.currentStart-=this.options.pageSize;this.currentStart<0&&(this.currentStart=0)}if(this.options.filterSelectOptions&&this.filterIndex.length>0){for(var s=[],a=0;a0){for(a=0;a0){e.childNodes[0].selected=!0;for(a=1;athis.getLastPageNumber()&&(t=this.getLastPageNumber()),this.currentStart=(t-1)*this.options.pageSize,this.refresh(),this.options.onChange.call(this.table,e+1,t)},getCurrentPage:function(){return this.currentStart/this.options.pageSize+1},refresh:function(){if(this.options.beforeRefresh.call(this.table),this.updatePaging(),this.updateCounter(),this.table.tBodies[0].innerHTML="",this.currentStart>=this.currentDataLength)this.table.tBodies[0].innerHTML='
';else{for(var t=0;t"+e[s]+"");return i}},DataTable.defaultAjaxOptions={url:null,size:null,refresh:!1,allInOne:!1,timeout:2e3};