UNPKG

13.7 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-bootstrap/pagination",["exports","@angular/core","@angular/forms","@angular/common"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self)["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"].pagination={}),t.ng.core,t.ng.forms,t.ng.common)}(this,(function(t,e,i,n){"use strict";var a=function(){this.main={itemsPerPage:10,boundaryLinks:!1,directionLinks:!0,firstText:"First",previousText:"Previous",nextText:"Next",lastText:"Last",pageBtnClass:"",rotate:!0},this.pager={itemsPerPage:15,previousText:"« Previous",nextText:"Next »",pageBtnClass:"",align:!0}};a.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new a},token:a,providedIn:"root"}),a.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}];var s={provide:i.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return o})),multi:!0},o=function(){function t(t,i,n){this.elementRef=t,this.changeDetection=n,this.align=!1,this.boundaryLinks=!1,this.directionLinks=!0,this.firstText="First",this.previousText="« Previous",this.nextText="Next »",this.lastText="Last",this.rotate=!0,this.pageBtnClass="",this.disabled=!1,this.numPages=new e.EventEmitter,this.pageChanged=new e.EventEmitter,this.onChange=Function.prototype,this.onTouched=Function.prototype,this.classMap="",this.inited=!1,this._itemsPerPage=15,this._totalItems=0,this._totalPages=0,this._page=1,this.elementRef=t,this.config||this.configureOptions(Object.assign({},i.main,i.pager))}return Object.defineProperty(t.prototype,"itemsPerPage",{get:function(){return this._itemsPerPage},set:function(t){this._itemsPerPage=t,this.totalPages=this.calculateTotalPages()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalItems",{get:function(){return this._totalItems},set:function(t){this._totalItems=t,this.totalPages=this.calculateTotalPages()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalPages",{get:function(){return this._totalPages},set:function(t){this._totalPages=t,this.numPages.emit(t),this.inited&&this.selectPage(this.page)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this._page},set:function(t){var e=this._page;this._page=t>this.totalPages?this.totalPages:t||1,this.changeDetection.markForCheck(),e!==this._page&&void 0!==e&&this.pageChanged.emit({page:this._page,itemsPerPage:this.itemsPerPage})},enumerable:!1,configurable:!0}),t.prototype.configureOptions=function(t){this.config=Object.assign({},t)},t.prototype.ngOnInit=function(){var t,e,i,n,a,s;"undefined"!=typeof window&&(this.classMap=this.elementRef.nativeElement.getAttribute("class")||""),void 0===this.maxSize&&(this.maxSize=(null===(t=this.config)||void 0===t?void 0:t.maxSize)||0),void 0===this.rotate&&(this.rotate=!!(null===(e=this.config)||void 0===e?void 0:e.rotate)),void 0===this.boundaryLinks&&(this.boundaryLinks=!!(null===(i=this.config)||void 0===i?void 0:i.boundaryLinks)),void 0===this.directionLinks&&(this.directionLinks=!!(null===(n=this.config)||void 0===n?void 0:n.directionLinks)),void 0===this.pageBtnClass&&(this.pageBtnClass=(null===(a=this.config)||void 0===a?void 0:a.pageBtnClass)||""),void 0===this.itemsPerPage&&(this.itemsPerPage=(null===(s=this.config)||void 0===s?void 0:s.itemsPerPage)||0),this.totalPages=this.calculateTotalPages(),this.pages=this.getPages(this.page,this.totalPages),this.inited=!0},t.prototype.writeValue=function(t){this.page=t,this.pages=this.getPages(this.page,this.totalPages)},t.prototype.getText=function(t){return this[t+"Text"]||this.config[t+"Text"]},t.prototype.noPrevious=function(){return 1===this.page},t.prototype.noNext=function(){return this.page===this.totalPages},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.prototype.selectPage=function(t,e){if(e&&e.preventDefault(),!this.disabled){if(e&&e.target)e.target.blur();this.writeValue(t),this.onChange(this.page)}},t.prototype.makePage=function(t,e,i){return{text:e,number:t,active:i}},t.prototype.getPages=function(t,e){var i=[],n=1,a=e,s=void 0!==this.maxSize&&this.maxSize<e;s&&this.maxSize&&(this.rotate?(a=(n=Math.max(t-Math.floor(this.maxSize/2),1))+this.maxSize-1)>e&&(n=(a=e)-this.maxSize+1):(n=(Math.ceil(t/this.maxSize)-1)*this.maxSize+1,a=Math.min(n+this.maxSize-1,e)));for(var o=n;o<=a;o++){var r=this.makePage(o,o.toString(),o===t);i.push(r)}if(s&&!this.rotate){if(n>1){var g=this.makePage(n-1,"...",!1);i.unshift(g)}if(a<e){var l=this.makePage(a+1,"...",!1);i.push(l)}}return i},t.prototype.calculateTotalPages=function(){var t=this.itemsPerPage<1?1:Math.ceil(this.totalItems/this.itemsPerPage);return Math.max(t||0,1)},t}();o.decorators=[{type:e.Component,args:[{selector:"pager",template:'<ul class="pager">\n <li [class.disabled]="noPrevious()" [class.previous]="align"\n [ngClass]="{\'pull-left\': align, \'float-left\': align}"\n class="{{ pageBtnClass }}">\n <a href (click)="selectPage(page - 1, $event)">{{ getText(\'previous\') }}</a>\n </li>\n <li [class.disabled]="noNext()" [class.next]="align"\n [ngClass]="{\'pull-right\': align, \'float-right\': align}"\n class="{{ pageBtnClass }}">\n <a href (click)="selectPage(page + 1, $event)">{{ getText(\'next\') }}</a>\n </li>\n</ul>\n',providers:[s]}]}],o.ctorParameters=function(){return[{type:e.ElementRef},{type:a},{type:e.ChangeDetectorRef}]},o.propDecorators={align:[{type:e.Input}],maxSize:[{type:e.Input}],boundaryLinks:[{type:e.Input}],directionLinks:[{type:e.Input}],firstText:[{type:e.Input}],previousText:[{type:e.Input}],nextText:[{type:e.Input}],lastText:[{type:e.Input}],rotate:[{type:e.Input}],pageBtnClass:[{type:e.Input}],disabled:[{type:e.Input}],numPages:[{type:e.Output}],pageChanged:[{type:e.Output}],itemsPerPage:[{type:e.Input}],totalItems:[{type:e.Input}]};var r={provide:i.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return g})),multi:!0},g=function(){function t(t,i,n){this.elementRef=t,this.changeDetection=n,this.align=!0,this.boundaryLinks=!1,this.directionLinks=!0,this.firstText="First",this.previousText="Previous",this.nextText="Next",this.lastText="Last",this.rotate=!0,this.pageBtnClass="",this.disabled=!1,this.numPages=new e.EventEmitter,this.pageChanged=new e.EventEmitter,this.onChange=Function.prototype,this.onTouched=Function.prototype,this.classMap="",this.inited=!1,this._itemsPerPage=10,this._totalItems=0,this._totalPages=0,this._page=1,this.elementRef=t,this.config||this.configureOptions(i.main)}return Object.defineProperty(t.prototype,"itemsPerPage",{get:function(){return this._itemsPerPage},set:function(t){this._itemsPerPage=t,this.totalPages=this.calculateTotalPages()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalItems",{get:function(){return this._totalItems},set:function(t){this._totalItems=t,this.totalPages=this.calculateTotalPages()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"totalPages",{get:function(){return this._totalPages},set:function(t){this._totalPages=t,this.numPages.emit(t),this.inited&&this.selectPage(this.page)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this._page},set:function(t){var e=this._page;this._page=t>this.totalPages?this.totalPages:t||1,this.changeDetection.markForCheck(),e!==this._page&&void 0!==e&&this.pageChanged.emit({page:this._page,itemsPerPage:this.itemsPerPage})},enumerable:!1,configurable:!0}),t.prototype.configureOptions=function(t){this.config=Object.assign({},t)},t.prototype.ngOnInit=function(){var t,e,i,n,a,s;"undefined"!=typeof window&&(this.classMap=this.elementRef.nativeElement.getAttribute("class")||""),void 0===this.maxSize&&(this.maxSize=(null===(t=this.config)||void 0===t?void 0:t.maxSize)||0),void 0===this.rotate&&(this.rotate=!!(null===(e=this.config)||void 0===e?void 0:e.rotate)),void 0===this.boundaryLinks&&(this.boundaryLinks=!!(null===(i=this.config)||void 0===i?void 0:i.boundaryLinks)),void 0===this.directionLinks&&(this.directionLinks=!!(null===(n=this.config)||void 0===n?void 0:n.directionLinks)),void 0===this.pageBtnClass&&(this.pageBtnClass=(null===(a=this.config)||void 0===a?void 0:a.pageBtnClass)||""),void 0===this.itemsPerPage&&(this.itemsPerPage=(null===(s=this.config)||void 0===s?void 0:s.itemsPerPage)||0),this.totalPages=this.calculateTotalPages(),this.pages=this.getPages(this.page,this.totalPages),this.inited=!0},t.prototype.writeValue=function(t){this.page=t,this.pages=this.getPages(this.page,this.totalPages)},t.prototype.getText=function(t){return this[t+"Text"]||this.config[t+"Text"]},t.prototype.noPrevious=function(){return 1===this.page},t.prototype.noNext=function(){return this.page===this.totalPages},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.prototype.selectPage=function(t,e){if(e&&e.preventDefault(),!this.disabled){if(e&&e.target)e.target.blur();this.writeValue(t),this.onChange(this.page)}},t.prototype.makePage=function(t,e,i){return{text:e,number:t,active:i}},t.prototype.getPages=function(t,e){var i=[],n=1,a=e,s=void 0!==this.maxSize&&this.maxSize<e;s&&this.maxSize&&(this.rotate?(a=(n=Math.max(t-Math.floor(this.maxSize/2),1))+this.maxSize-1)>e&&(n=(a=e)-this.maxSize+1):(n=(Math.ceil(t/this.maxSize)-1)*this.maxSize+1,a=Math.min(n+this.maxSize-1,e)));for(var o=n;o<=a;o++){var r=this.makePage(o,o.toString(),o===t);i.push(r)}if(s&&!this.rotate){if(n>1){var g=this.makePage(n-1,"...",!1);i.unshift(g)}if(a<e){var l=this.makePage(a+1,"...",!1);i.push(l)}}return i},t.prototype.calculateTotalPages=function(){var t=this.itemsPerPage<1?1:Math.ceil(this.totalItems/this.itemsPerPage);return Math.max(t||0,1)},t}();g.decorators=[{type:e.Component,args:[{selector:"pagination",template:'<ul class="pagination" [ngClass]="classMap">\n <li class="pagination-first page-item"\n *ngIf="boundaryLinks"\n [class.disabled]="noPrevious() || disabled">\n <a class="page-link" href (click)="selectPage(1, $event)">\n <ng-container [ngTemplateOutlet]="customFirstTemplate || defaultFirstTemplate"\n [ngTemplateOutletContext]="{disabled: noPrevious() || disabled, currentPage: page}">\n </ng-container>\n </a>\n </li>\n\n <li class="pagination-prev page-item"\n *ngIf="directionLinks"\n [class.disabled]="noPrevious() || disabled">\n <a class="page-link" href (click)="selectPage(page - 1, $event)">\n <ng-container [ngTemplateOutlet]="customPreviousTemplate || defaultPreviousTemplate"\n [ngTemplateOutletContext]="{disabled: noPrevious() || disabled, currentPage: page}">\n </ng-container>\n </a>\n </li>\n\n <li *ngFor="let pg of pages"\n [class.active]="pg.active"\n [class.disabled]="disabled && !pg.active"\n class="pagination-page page-item">\n <a class="page-link" href (click)="selectPage(pg.number, $event)">\n <ng-container [ngTemplateOutlet]="customPageTemplate || defaultPageTemplate"\n [ngTemplateOutletContext]="{disabled: disabled, $implicit: pg, currentPage: page}">\n </ng-container>\n </a>\n </li>\n\n <li class="pagination-next page-item"\n *ngIf="directionLinks"\n [class.disabled]="noNext() || disabled">\n <a class="page-link" href (click)="selectPage(page + 1, $event)">\n <ng-container [ngTemplateOutlet]="customNextTemplate || defaultNextTemplate"\n [ngTemplateOutletContext]="{disabled: noNext() || disabled, currentPage: page}">\n </ng-container>\n </a>\n </li>\n\n <li class="pagination-last page-item"\n *ngIf="boundaryLinks"\n [class.disabled]="noNext() || disabled">\n <a class="page-link" href (click)="selectPage(totalPages, $event)">\n <ng-container [ngTemplateOutlet]="customLastTemplate || defaultLastTemplate"\n [ngTemplateOutletContext]="{disabled: noNext() || disabled, currentPage: page}">\n </ng-container>\n </a>\n </li>\n</ul>\n\n<ng-template #defaultPageTemplate let-page>{{ page.text }}</ng-template>\n\n<ng-template #defaultNextTemplate>{{ getText(\'next\') }}</ng-template>\n\n<ng-template #defaultPreviousTemplate>{{ getText(\'previous\') }}</ng-template>\n\n<ng-template #defaultFirstTemplate>{{ getText(\'first\') }}</ng-template>\n\n<ng-template #defaultLastTemplate>{{ getText(\'last\') }}</ng-template>\n',providers:[r]}]}],g.ctorParameters=function(){return[{type:e.ElementRef},{type:a},{type:e.ChangeDetectorRef}]},g.propDecorators={align:[{type:e.Input}],maxSize:[{type:e.Input}],boundaryLinks:[{type:e.Input}],directionLinks:[{type:e.Input}],firstText:[{type:e.Input}],previousText:[{type:e.Input}],nextText:[{type:e.Input}],lastText:[{type:e.Input}],rotate:[{type:e.Input}],pageBtnClass:[{type:e.Input}],disabled:[{type:e.Input}],customPageTemplate:[{type:e.Input}],customNextTemplate:[{type:e.Input}],customPreviousTemplate:[{type:e.Input}],customFirstTemplate:[{type:e.Input}],customLastTemplate:[{type:e.Input}],numPages:[{type:e.Output}],pageChanged:[{type:e.Output}],itemsPerPage:[{type:e.Input}],totalItems:[{type:e.Input}]};var l=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[]}},t}();l.decorators=[{type:e.NgModule,args:[{imports:[n.CommonModule],declarations:[o,g],exports:[o,g]}]}],t.PagerComponent=o,t.PaginationComponent=g,t.PaginationConfig=a,t.PaginationModule=l,t.ɵa=s,t.ɵb=r,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngx-bootstrap-pagination.umd.min.js.map
\No newline at end of file