filesbox/web/dist/design/designstatic/front/js/paging.js

2 lines
7.2 KiB
JavaScript
Raw Permalink Normal View History

2024-07-26 06:10:54 +00:00
(function(c,u){"use strict";typeof module=="object"&&typeof module.exports=="object"?module.exports=c.document?u(c,!0):function(o){if(!o.document)throw new Error("Page requires a window with a document");return u(o)}:u(c)})(typeof window!="undefined"?window:this,function(c,u){function o(t){t=t||{},this.el=t.el,this.nums=t.nums,this.counts=t.counts||10,this.parent=document.querySelector(this.el),this.parent.classList.add("page-elem-field-root"),this.parentNode=document.createElement("div"),this.parent.appendChild(this.parentNode),this.defaultPage=Number(t.defaultPage)||1,this.jumpToOrder=!!t.jumpToOrder,this.showNowAndAll=!!t.showNowAndAll,this.showHeadFoot=!!t.showHeadFoot,this.head=t.head||"\u9996\u9875",this.foot=t.foot||"\u5C3E\u9875",this.prev="&lt;",this.next="&gt;",this.headfoot=[],this.div=t.div||"div",this.domList=[],this.showDomList=[];var e=this;function s(){t.clickEvent&&typeof t.clickEvent=="function"&&t.clickEvent(e.currect,e)}this.clickEvent=s,this.init()}return o.prototype={init:function(){this.setPages(),this.createDom(),this.showDom(),this.watcherCurrect(),this.watcherPages(),this.watcherNums(),this.watcherCounts(),this.addDom(),this.reanderHeadFoot(),this.jumpToOrderPage(),this.showNowAndAllPage()},setPages:function(){this.last=this.nums%this.counts,this.pages=parseInt(this.nums/this.counts),this.last!=0&&this.pages++},showNowAndAllPage:function(){if(this.showNowAndAll){var t=document.createElement("div"),e=document.createElement("div"),s=document.createElement("div"),i=document.createElement("div");t.classList.add("pagesbox"),e.classList.add("allPages"),s.classList.add("currectPage"),i.classList.add("line"),s.innerText=this.currect,e.innerText=this.pages,i.innerText="/",t.appendChild(s),t.appendChild(i),t.appendChild(e),this.parent.appendChild(t),this.showNowAndAllPageDom={pagesbox:t,allPages:e,currectPage:s,line:i}}},jumpToOrderPage:function(){if(this.jumpToOrder){var t=document.createElement("div"),e=document.createElement("div"),s=document.createElement("input");t.classList.add("toPage"),e.classList.add("inputBox"),s.classList.add("inputborder"),s.type="text",s.value=this.currect,this.addEventForInput(s),e.appendChild(s),t.appendChild(e),this.parent.appendChild(t),this.jumpToOrderPageDom={toPage:t,input:s,inputBox:e}}},addEventForInput:function(t,e){var s=this;t.addEventListener("change",function(i){var r=i.target.value;r>s.pages?r=s.pages:r<1&&(r=1),s.currect=r,this.value=r})},updateCurrectAndOrderBox:function(t){this.jumpToOrder&&(this.jumpToOrderPageDom.input.value=t),this.showNowAndAll&&(this.showNowAndAllPageDom.currectPage.innerText=t)},reanderHeadFoot:function(){if(!!this.showHeadFoot){this.headfoot=[];var t=this.div,e=document.createElement(t),s=document.createElement(t);e.innerHTML=this.head,e.classList.add("item"),e.classList.add("head"),s.innerHTML=this.foot,s.classList.add("item"),s.classList.add("foot"),this.headfoot.push(e),this.headfoot.push(s),this.parentNode.insertBefore(e,this.parentNode.firstChild),this.parentNode.appendChild(s),this.addEventHeadFoot(),this.headFootDisable()}},headFootDisable:function(){this.currect===1&&this.headfoot[0].classList.add("item-disable"),this.currect===this.pages&&this.headfoot[1].classList.add("item-disable")},addEventHeadFoot:function(){var t=this;this.headfoot[0].addEventListener("click",function(){t.currect!=1&&(t.currect=1)}),this.headfoot[1].addEventListener("click",function(){t.currect!=t.pages&&(t.currect=t.pages)})},createDom:function(){var t=this.div,e=this.domList=[],s=document.createElement(t),i=document.createElement(t);s.innerHTML=this.prev,s.classList.add("item"),i.innerHTML=this.next,i.classList.add("item"),e[0]=s;for(var r=this.pages,a=0;a<r;a++){var d=document.createElement(t);d.classList.add("item"),d.innerHTML=a+1,e[a+1]=d}return e.push(i),e},showDom:function(){var t=this.domList,e=t.length,s=this.showDomList=[],i=this.defaultPage;if(e<=12)for(var r=0;r<e;r++)s[r]=t[r];else{var a=i-6<0?0:i-6,d=this.pages-i;d<5&&(a=this.pages-10),s[0]=t[0];for(var r=1;r<11;r++)s[r]=t[r+a];s[r]=t[e-1]}return s},addDom:function(){this.parentNode.inne