UNPKG

angular-io-pager

Version:
2 lines 5.51 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define("angular-io-pager",["exports","@angular/core","@angular/forms","@angular/platform-browser"],e):e(t["angular-io-pager"]={},t.ng.core,t.ng.forms,t.ng.platformBrowser)}(this,function(t,e,a,i){"use strict";function s(t,e){var a="function"==typeof Symbol&&t[Symbol.iterator];if(!a)return t;var i,s,r=a.call(t),n=[];try{for(;(void 0===e||0<e--)&&!(i=r.next()).done;)n.push(i.value)}catch(o){s={error:o}}finally{try{i&&!i.done&&(a=r["return"])&&a.call(r)}finally{if(s)throw s.error}}return n}function r(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(s(arguments[e]));return t}var n=function(){function t(){this.pageGap=10,this.id=1,this.noOfPages=10,this.pageClick=new e.EventEmitter,this.from=1,this.to=0,this.pageLength=20,this.currentPage=1,this.pages=[],this.pageNum=[],this.showLeftNav=!1,this.showRightNav=!1,this.totalPageLength=0,this.leftNavString="<<",this.rightNavString=">>",this.lastPageMax=0,this.lastPageMin=0,this._total=0}return Object.defineProperty(t.prototype,"totalRecords",{get:function(){return this._total},set:function(t){0<(this._total=t)&&this.pagePreparation()},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){for(var t=1;t<=this.pageLength;t++)this.pages.push(t*this.pageGap);this.to=this.pages[0]},t.prototype.pagePreparation=function(){var t=this;this.reCalculatePageNumbers(),setTimeout(function(){t.setSelectedPage()},0)},t.prototype.reCalculatePageNumbers=function(){var t=(this.totalRecords/this.pageGap).toString().split("."),e=parseInt(t[0],10),a=0;2===t.length&&(a=1),this.totalPageLength=e+a,this.pageNum.length=0,this.populatePages(1)},t.prototype.populatePages=function(t){var e=1;this.pageNum.length=0;for(var a=t;a<=this.totalPageLength&&e<=this.noOfPages;a++)this.pageNum.push(a),e++;this.currentPage=this.lastPageMin=Math.min.apply(Math,r(this.pageNum)),this.lastPageMax=Math.max.apply(Math,r(this.pageNum)),this.setPrevNextNav()},t.prototype.pageLengthChange=function(){this.reCalculatePageNumbers(),this.setSelectedPage()},t.prototype.pageChange=function(t){t.target.classList.contains("cmdLeft")?(this.populatePages(this.lastPageMin-this.noOfPages),this.setSelectedPage()):t.target.classList.contains("cmdRight")?(this.populatePages(++this.lastPageMax),this.setSelectedPage()):this.setSelectedPage(t.target)},t.prototype.setSelectedPage=function(e){var a=this;void 0===e&&(e=null),null!=e&&(this.currentPage=parseInt(e.innerText,10)),this.to=Math.min(this.currentPage*this.pageGap,this.totalRecords),this.from=this.currentPage*this.pageGap-this.pageGap+1,setTimeout(function(){for(var t=e=null==e?document.getElementById("pager"+a.id).querySelector(".pageElements"):e;(t=t.parentElement)&&!t.classList.contains("pageNumbers"););Array.from(t.children).forEach(function(t){return t.classList.remove("selected")}),e.classList.add("selected")},0),this.emitPageClick()},t.prototype.setPrevNextNav=function(){this.showLeftNav=this.showRightNav=!1,this.currentPage>this.noOfPages&&(this.showLeftNav=!0);var t=2===(this.currentPage/this.noOfPages).toString().split(".").length;parseInt((this.currentPage/this.noOfPages).toString(),10)*this.noOfPages+(t?this.noOfPages:0)<this.totalPageLength&&(this.showRightNav=!0)},t.prototype.emitPageClick=function(){this.pageClick.emit({from:this.from,to:this.to})},t.decorators=[{type:e.Component,args:[{selector:"sr-angular-io-pager",template:'<div class="pager" [ngClass]="{\'hidden\': totalRecords <= 0}" [id]="\'pager\' + id">\n <div class="left">\n Show\n <select [(ngModel)]="pageGap" (change)="pageLengthChange()"\n id="pageGap">\n <option *ngFor="let pg of pages" [value]="pg">{{pg}}</option>\n </select>\n Showing {{from}}-{{to}} of {{totalRecords}}\n </div>\n <div class="right">\n <ul class="pageNumbers" id="pageList">\n <li *ngIf="showLeftNav" (click)="pageChange($event)"\n class="cmdLeft"> {{leftNavString}} </li>\n <li *ngFor="let pn of pageNum" (click)="pageChange($event)"\n class="pageElements">{{pn}}</li>\n <li *ngIf="showRightNav" (click)="pageChange($event)"\n class="cmdRight"> {{rightNavString}} </li>\n </ul>\n </div>\n</div>',styles:[".pager{font:bold 13px Arial;color:#377bba}.pageNumbers{list-style:none;border:1px solid #dfdfdf;display:inline-block;padding-left:0;margin:0}.pageNumbers li{float:left;padding:8px 10px;background:#fff;border-left:1px solid #dfdfdf;border-collapse:collapse;color:#377bba;cursor:pointer;min-width:15px;text-align:center}.pageNumbers li.selected{background:#377bba;color:#fff}.pageNumbers li:first-of-type{border-left:0}.pageNumbers li:hover{background:#3a4046;color:#fff}div.left{padding:9px 0}select{color:#377bba;font-weight:700;font-size:.9em;padding:2px;border:1px solid #377bba}.left{float:left}.right{float:right}.hidden{display:none}"]}]}],t.ctorParameters=function(){return[]},t.propDecorators={pageGap:[{type:e.Input}],id:[{type:e.Input}],noOfPages:[{type:e.Input}],totalRecords:[{type:e.Input}],pageClick:[{type:e.Output}]},t}(),o=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[a.FormsModule,i.BrowserModule],declarations:[n],exports:[n]}]}],t}();t.AngularIoPagerModule=o,t.ɵa=n,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=angular-io-pager.umd.min.js.map