ngx-bootstrap-pagination.umd.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/pagination', ['exports', '@angular/core', '@angular/forms', '@angular/common'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].pagination = {}), global.ng.core, global.ng.forms, global.ng.common));
  5. }(this, function (exports, core, forms, common) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. /**
  11. * Provides default values for Pagination and pager components
  12. */
  13. var PaginationConfig = /** @class */ (function () {
  14. function PaginationConfig() {
  15. this.main = {
  16. maxSize: void 0,
  17. itemsPerPage: 10,
  18. boundaryLinks: false,
  19. directionLinks: true,
  20. firstText: 'First',
  21. previousText: 'Previous',
  22. nextText: 'Next',
  23. lastText: 'Last',
  24. pageBtnClass: '',
  25. rotate: true
  26. };
  27. this.pager = {
  28. itemsPerPage: 15,
  29. previousText: '« Previous',
  30. nextText: 'Next »',
  31. pageBtnClass: '',
  32. align: true
  33. };
  34. }
  35. PaginationConfig.decorators = [
  36. { type: core.Injectable }
  37. ];
  38. return PaginationConfig;
  39. }());
  40. /**
  41. * @fileoverview added by tsickle
  42. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  43. */
  44. /** @type {?} */
  45. var PAGER_CONTROL_VALUE_ACCESSOR = {
  46. provide: forms.NG_VALUE_ACCESSOR,
  47. /* tslint:disable-next-line: no-use-before-declare */
  48. useExisting: core.forwardRef((/**
  49. * @return {?}
  50. */
  51. function () { return PagerComponent; })),
  52. multi: true
  53. };
  54. var PagerComponent = /** @class */ (function () {
  55. function PagerComponent(elementRef, paginationConfig, changeDetection) {
  56. this.elementRef = elementRef;
  57. this.changeDetection = changeDetection;
  58. /**
  59. * fired when total pages count changes, $event:number equals to total pages count
  60. */
  61. this.numPages = new core.EventEmitter();
  62. /**
  63. * fired when page was changed, $event:{page, itemsPerPage} equals to
  64. * object with current page index and number of items per page
  65. */
  66. this.pageChanged = new core.EventEmitter();
  67. this.onChange = Function.prototype;
  68. this.onTouched = Function.prototype;
  69. this.inited = false;
  70. this._page = 1;
  71. this.elementRef = elementRef;
  72. if (!this.config) {
  73. this.configureOptions(Object.assign({}, paginationConfig.main, paginationConfig.pager));
  74. }
  75. }
  76. Object.defineProperty(PagerComponent.prototype, "itemsPerPage", {
  77. /** maximum number of items per page. If value less than 1 will display all items on one page */
  78. get: /**
  79. * maximum number of items per page. If value less than 1 will display all items on one page
  80. * @return {?}
  81. */
  82. function () {
  83. return this._itemsPerPage;
  84. },
  85. set: /**
  86. * @param {?} v
  87. * @return {?}
  88. */
  89. function (v) {
  90. this._itemsPerPage = v;
  91. this.totalPages = this.calculateTotalPages();
  92. },
  93. enumerable: true,
  94. configurable: true
  95. });
  96. Object.defineProperty(PagerComponent.prototype, "totalItems", {
  97. /** total number of items in all pages */
  98. get: /**
  99. * total number of items in all pages
  100. * @return {?}
  101. */
  102. function () {
  103. return this._totalItems;
  104. },
  105. set: /**
  106. * @param {?} v
  107. * @return {?}
  108. */
  109. function (v) {
  110. this._totalItems = v;
  111. this.totalPages = this.calculateTotalPages();
  112. },
  113. enumerable: true,
  114. configurable: true
  115. });
  116. Object.defineProperty(PagerComponent.prototype, "totalPages", {
  117. get: /**
  118. * @return {?}
  119. */
  120. function () {
  121. return this._totalPages;
  122. },
  123. set: /**
  124. * @param {?} v
  125. * @return {?}
  126. */
  127. function (v) {
  128. this._totalPages = v;
  129. this.numPages.emit(v);
  130. if (this.inited) {
  131. this.selectPage(this.page);
  132. }
  133. },
  134. enumerable: true,
  135. configurable: true
  136. });
  137. Object.defineProperty(PagerComponent.prototype, "page", {
  138. get: /**
  139. * @return {?}
  140. */
  141. function () {
  142. return this._page;
  143. },
  144. set: /**
  145. * @param {?} value
  146. * @return {?}
  147. */
  148. function (value) {
  149. /** @type {?} */
  150. var _previous = this._page;
  151. this._page = value > this.totalPages ? this.totalPages : value || 1;
  152. this.changeDetection.markForCheck();
  153. if (_previous === this._page || typeof _previous === 'undefined') {
  154. return;
  155. }
  156. this.pageChanged.emit({
  157. page: this._page,
  158. itemsPerPage: this.itemsPerPage
  159. });
  160. },
  161. enumerable: true,
  162. configurable: true
  163. });
  164. /**
  165. * @param {?} config
  166. * @return {?}
  167. */
  168. PagerComponent.prototype.configureOptions = /**
  169. * @param {?} config
  170. * @return {?}
  171. */
  172. function (config) {
  173. this.config = Object.assign({}, config);
  174. };
  175. /**
  176. * @return {?}
  177. */
  178. PagerComponent.prototype.ngOnInit = /**
  179. * @return {?}
  180. */
  181. function () {
  182. if (typeof window !== 'undefined') {
  183. this.classMap = this.elementRef.nativeElement.getAttribute('class') || '';
  184. }
  185. // watch for maxSize
  186. this.maxSize =
  187. typeof this.maxSize !== 'undefined' ? this.maxSize : this.config.maxSize;
  188. this.rotate =
  189. typeof this.rotate !== 'undefined' ? this.rotate : this.config.rotate;
  190. this.boundaryLinks =
  191. typeof this.boundaryLinks !== 'undefined'
  192. ? this.boundaryLinks
  193. : this.config.boundaryLinks;
  194. this.directionLinks =
  195. typeof this.directionLinks !== 'undefined'
  196. ? this.directionLinks
  197. : this.config.directionLinks;
  198. this.pageBtnClass =
  199. typeof this.pageBtnClass !== 'undefined'
  200. ? this.pageBtnClass
  201. : this.config.pageBtnClass;
  202. // base class
  203. this.itemsPerPage =
  204. typeof this.itemsPerPage !== 'undefined'
  205. ? this.itemsPerPage
  206. : this.config.itemsPerPage;
  207. this.totalPages = this.calculateTotalPages();
  208. // this class
  209. this.pages = this.getPages(this.page, this.totalPages);
  210. this.inited = true;
  211. };
  212. /**
  213. * @param {?} value
  214. * @return {?}
  215. */
  216. PagerComponent.prototype.writeValue = /**
  217. * @param {?} value
  218. * @return {?}
  219. */
  220. function (value) {
  221. this.page = value;
  222. this.pages = this.getPages(this.page, this.totalPages);
  223. };
  224. /**
  225. * @param {?} key
  226. * @return {?}
  227. */
  228. PagerComponent.prototype.getText = /**
  229. * @param {?} key
  230. * @return {?}
  231. */
  232. function (key) {
  233. // tslint:disable-next-line:no-any
  234. return ((/** @type {?} */ (this)))[key + "Text"] || ((/** @type {?} */ (this))).config[key + "Text"];
  235. };
  236. /**
  237. * @return {?}
  238. */
  239. PagerComponent.prototype.noPrevious = /**
  240. * @return {?}
  241. */
  242. function () {
  243. return this.page === 1;
  244. };
  245. /**
  246. * @return {?}
  247. */
  248. PagerComponent.prototype.noNext = /**
  249. * @return {?}
  250. */
  251. function () {
  252. return this.page === this.totalPages;
  253. };
  254. /**
  255. * @param {?} fn
  256. * @return {?}
  257. */
  258. PagerComponent.prototype.registerOnChange = /**
  259. * @param {?} fn
  260. * @return {?}
  261. */
  262. function (fn) {
  263. this.onChange = fn;
  264. };
  265. /**
  266. * @param {?} fn
  267. * @return {?}
  268. */
  269. PagerComponent.prototype.registerOnTouched = /**
  270. * @param {?} fn
  271. * @return {?}
  272. */
  273. function (fn) {
  274. this.onTouched = fn;
  275. };
  276. /**
  277. * @param {?} page
  278. * @param {?=} event
  279. * @return {?}
  280. */
  281. PagerComponent.prototype.selectPage = /**
  282. * @param {?} page
  283. * @param {?=} event
  284. * @return {?}
  285. */
  286. function (page, event) {
  287. if (event) {
  288. event.preventDefault();
  289. }
  290. if (!this.disabled) {
  291. if (event && event.target) {
  292. // tslint:disable-next-line:no-any
  293. /** @type {?} */
  294. var target = event.target;
  295. target.blur();
  296. }
  297. this.writeValue(page);
  298. this.onChange(this.page);
  299. }
  300. };
  301. // Create page object used in template
  302. // Create page object used in template
  303. /**
  304. * @protected
  305. * @param {?} num
  306. * @param {?} text
  307. * @param {?} active
  308. * @return {?}
  309. */
  310. PagerComponent.prototype.makePage =
  311. // Create page object used in template
  312. /**
  313. * @protected
  314. * @param {?} num
  315. * @param {?} text
  316. * @param {?} active
  317. * @return {?}
  318. */
  319. function (num, text, active) {
  320. return { text: text, number: num, active: active };
  321. };
  322. /**
  323. * @protected
  324. * @param {?} currentPage
  325. * @param {?} totalPages
  326. * @return {?}
  327. */
  328. PagerComponent.prototype.getPages = /**
  329. * @protected
  330. * @param {?} currentPage
  331. * @param {?} totalPages
  332. * @return {?}
  333. */
  334. function (currentPage, totalPages) {
  335. /** @type {?} */
  336. var pages = [];
  337. // Default page limits
  338. /** @type {?} */
  339. var startPage = 1;
  340. /** @type {?} */
  341. var endPage = totalPages;
  342. /** @type {?} */
  343. var isMaxSized = typeof this.maxSize !== 'undefined' && this.maxSize < totalPages;
  344. // recompute if maxSize
  345. if (isMaxSized) {
  346. if (this.rotate) {
  347. // Current page is displayed in the middle of the visible ones
  348. startPage = Math.max(currentPage - Math.floor(this.maxSize / 2), 1);
  349. endPage = startPage + this.maxSize - 1;
  350. // Adjust if limit is exceeded
  351. if (endPage > totalPages) {
  352. endPage = totalPages;
  353. startPage = endPage - this.maxSize + 1;
  354. }
  355. }
  356. else {
  357. // Visible pages are paginated with maxSize
  358. startPage =
  359. (Math.ceil(currentPage / this.maxSize) - 1) * this.maxSize + 1;
  360. // Adjust last page if limit is exceeded
  361. endPage = Math.min(startPage + this.maxSize - 1, totalPages);
  362. }
  363. }
  364. // Add page number links
  365. for (var num = startPage; num <= endPage; num++) {
  366. /** @type {?} */
  367. var page = this.makePage(num, num.toString(), num === currentPage);
  368. pages.push(page);
  369. }
  370. // Add links to move between page sets
  371. if (isMaxSized && !this.rotate) {
  372. if (startPage > 1) {
  373. /** @type {?} */
  374. var previousPageSet = this.makePage(startPage - 1, '...', false);
  375. pages.unshift(previousPageSet);
  376. }
  377. if (endPage < totalPages) {
  378. /** @type {?} */
  379. var nextPageSet = this.makePage(endPage + 1, '...', false);
  380. pages.push(nextPageSet);
  381. }
  382. }
  383. return pages;
  384. };
  385. // base class
  386. // base class
  387. /**
  388. * @protected
  389. * @return {?}
  390. */
  391. PagerComponent.prototype.calculateTotalPages =
  392. // base class
  393. /**
  394. * @protected
  395. * @return {?}
  396. */
  397. function () {
  398. /** @type {?} */
  399. var totalPages = this.itemsPerPage < 1
  400. ? 1
  401. : Math.ceil(this.totalItems / this.itemsPerPage);
  402. return Math.max(totalPages || 0, 1);
  403. };
  404. PagerComponent.decorators = [
  405. { type: core.Component, args: [{
  406. selector: 'pager',
  407. template: "<ul class=\"pager\">\n <li [class.disabled]=\"noPrevious()\" [class.previous]=\"align\"\n [ngClass]=\"{'pull-right': align, 'float-right': 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",
  408. providers: [PAGER_CONTROL_VALUE_ACCESSOR]
  409. }] }
  410. ];
  411. /** @nocollapse */
  412. PagerComponent.ctorParameters = function () { return [
  413. { type: core.ElementRef },
  414. { type: PaginationConfig },
  415. { type: core.ChangeDetectorRef }
  416. ]; };
  417. PagerComponent.propDecorators = {
  418. align: [{ type: core.Input }],
  419. maxSize: [{ type: core.Input }],
  420. boundaryLinks: [{ type: core.Input }],
  421. directionLinks: [{ type: core.Input }],
  422. firstText: [{ type: core.Input }],
  423. previousText: [{ type: core.Input }],
  424. nextText: [{ type: core.Input }],
  425. lastText: [{ type: core.Input }],
  426. rotate: [{ type: core.Input }],
  427. pageBtnClass: [{ type: core.Input }],
  428. disabled: [{ type: core.Input }],
  429. numPages: [{ type: core.Output }],
  430. pageChanged: [{ type: core.Output }],
  431. itemsPerPage: [{ type: core.Input }],
  432. totalItems: [{ type: core.Input }]
  433. };
  434. return PagerComponent;
  435. }());
  436. /**
  437. * @fileoverview added by tsickle
  438. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  439. */
  440. /** @type {?} */
  441. var PAGINATION_CONTROL_VALUE_ACCESSOR = {
  442. provide: forms.NG_VALUE_ACCESSOR,
  443. /* tslint:disable-next-line: no-use-before-declare */
  444. useExisting: core.forwardRef((/**
  445. * @return {?}
  446. */
  447. function () { return PaginationComponent; })),
  448. multi: true
  449. };
  450. var PaginationComponent = /** @class */ (function () {
  451. function PaginationComponent(elementRef, paginationConfig, changeDetection) {
  452. this.elementRef = elementRef;
  453. this.changeDetection = changeDetection;
  454. /**
  455. * fired when total pages count changes, $event:number equals to total pages count
  456. */
  457. this.numPages = new core.EventEmitter();
  458. /**
  459. * fired when page was changed, $event:{page, itemsPerPage} equals to object
  460. * with current page index and number of items per page
  461. */
  462. this.pageChanged = new core.EventEmitter();
  463. this.onChange = Function.prototype;
  464. this.onTouched = Function.prototype;
  465. this.inited = false;
  466. this._page = 1;
  467. this.elementRef = elementRef;
  468. if (!this.config) {
  469. this.configureOptions(paginationConfig.main);
  470. }
  471. }
  472. Object.defineProperty(PaginationComponent.prototype, "itemsPerPage", {
  473. /** maximum number of items per page. If value less than 1 will display all items on one page */
  474. get: /**
  475. * maximum number of items per page. If value less than 1 will display all items on one page
  476. * @return {?}
  477. */
  478. function () {
  479. return this._itemsPerPage;
  480. },
  481. set: /**
  482. * @param {?} v
  483. * @return {?}
  484. */
  485. function (v) {
  486. this._itemsPerPage = v;
  487. this.totalPages = this.calculateTotalPages();
  488. },
  489. enumerable: true,
  490. configurable: true
  491. });
  492. Object.defineProperty(PaginationComponent.prototype, "totalItems", {
  493. /** total number of items in all pages */
  494. get: /**
  495. * total number of items in all pages
  496. * @return {?}
  497. */
  498. function () {
  499. return this._totalItems;
  500. },
  501. set: /**
  502. * @param {?} v
  503. * @return {?}
  504. */
  505. function (v) {
  506. this._totalItems = v;
  507. this.totalPages = this.calculateTotalPages();
  508. },
  509. enumerable: true,
  510. configurable: true
  511. });
  512. Object.defineProperty(PaginationComponent.prototype, "totalPages", {
  513. get: /**
  514. * @return {?}
  515. */
  516. function () {
  517. return this._totalPages;
  518. },
  519. set: /**
  520. * @param {?} v
  521. * @return {?}
  522. */
  523. function (v) {
  524. this._totalPages = v;
  525. this.numPages.emit(v);
  526. if (this.inited) {
  527. this.selectPage(this.page);
  528. }
  529. },
  530. enumerable: true,
  531. configurable: true
  532. });
  533. Object.defineProperty(PaginationComponent.prototype, "page", {
  534. get: /**
  535. * @return {?}
  536. */
  537. function () {
  538. return this._page;
  539. },
  540. set: /**
  541. * @param {?} value
  542. * @return {?}
  543. */
  544. function (value) {
  545. /** @type {?} */
  546. var _previous = this._page;
  547. this._page = value > this.totalPages ? this.totalPages : value || 1;
  548. this.changeDetection.markForCheck();
  549. if (_previous === this._page || typeof _previous === 'undefined') {
  550. return;
  551. }
  552. this.pageChanged.emit({
  553. page: this._page,
  554. itemsPerPage: this.itemsPerPage
  555. });
  556. },
  557. enumerable: true,
  558. configurable: true
  559. });
  560. /**
  561. * @param {?} config
  562. * @return {?}
  563. */
  564. PaginationComponent.prototype.configureOptions = /**
  565. * @param {?} config
  566. * @return {?}
  567. */
  568. function (config) {
  569. this.config = Object.assign({}, config);
  570. };
  571. /**
  572. * @return {?}
  573. */
  574. PaginationComponent.prototype.ngOnInit = /**
  575. * @return {?}
  576. */
  577. function () {
  578. if (typeof window !== 'undefined') {
  579. this.classMap = this.elementRef.nativeElement.getAttribute('class') || '';
  580. }
  581. // watch for maxSize
  582. this.maxSize =
  583. typeof this.maxSize !== 'undefined' ? this.maxSize : this.config.maxSize;
  584. this.rotate =
  585. typeof this.rotate !== 'undefined' ? this.rotate : this.config.rotate;
  586. this.boundaryLinks =
  587. typeof this.boundaryLinks !== 'undefined'
  588. ? this.boundaryLinks
  589. : this.config.boundaryLinks;
  590. this.directionLinks =
  591. typeof this.directionLinks !== 'undefined'
  592. ? this.directionLinks
  593. : this.config.directionLinks;
  594. this.pageBtnClass =
  595. typeof this.pageBtnClass !== 'undefined'
  596. ? this.pageBtnClass
  597. : this.config.pageBtnClass;
  598. // base class
  599. this.itemsPerPage =
  600. typeof this.itemsPerPage !== 'undefined'
  601. ? this.itemsPerPage
  602. : this.config.itemsPerPage;
  603. this.totalPages = this.calculateTotalPages();
  604. // this class
  605. this.pages = this.getPages(this.page, this.totalPages);
  606. this.inited = true;
  607. };
  608. /**
  609. * @param {?} value
  610. * @return {?}
  611. */
  612. PaginationComponent.prototype.writeValue = /**
  613. * @param {?} value
  614. * @return {?}
  615. */
  616. function (value) {
  617. this.page = value;
  618. this.pages = this.getPages(this.page, this.totalPages);
  619. };
  620. /**
  621. * @param {?} key
  622. * @return {?}
  623. */
  624. PaginationComponent.prototype.getText = /**
  625. * @param {?} key
  626. * @return {?}
  627. */
  628. function (key) {
  629. // tslint:disable-next-line:no-any
  630. return ((/** @type {?} */ (this)))[key + "Text"] || ((/** @type {?} */ (this))).config[key + "Text"];
  631. };
  632. /**
  633. * @return {?}
  634. */
  635. PaginationComponent.prototype.noPrevious = /**
  636. * @return {?}
  637. */
  638. function () {
  639. return this.page === 1;
  640. };
  641. /**
  642. * @return {?}
  643. */
  644. PaginationComponent.prototype.noNext = /**
  645. * @return {?}
  646. */
  647. function () {
  648. return this.page === this.totalPages;
  649. };
  650. /**
  651. * @param {?} fn
  652. * @return {?}
  653. */
  654. PaginationComponent.prototype.registerOnChange = /**
  655. * @param {?} fn
  656. * @return {?}
  657. */
  658. function (fn) {
  659. this.onChange = fn;
  660. };
  661. /**
  662. * @param {?} fn
  663. * @return {?}
  664. */
  665. PaginationComponent.prototype.registerOnTouched = /**
  666. * @param {?} fn
  667. * @return {?}
  668. */
  669. function (fn) {
  670. this.onTouched = fn;
  671. };
  672. /**
  673. * @param {?} page
  674. * @param {?=} event
  675. * @return {?}
  676. */
  677. PaginationComponent.prototype.selectPage = /**
  678. * @param {?} page
  679. * @param {?=} event
  680. * @return {?}
  681. */
  682. function (page, event) {
  683. if (event) {
  684. event.preventDefault();
  685. }
  686. if (!this.disabled) {
  687. if (event && event.target) {
  688. // tslint:disable-next-line:no-any
  689. /** @type {?} */
  690. var target = event.target;
  691. target.blur();
  692. }
  693. this.writeValue(page);
  694. this.onChange(this.page);
  695. }
  696. };
  697. // Create page object used in template
  698. // Create page object used in template
  699. /**
  700. * @protected
  701. * @param {?} num
  702. * @param {?} text
  703. * @param {?} active
  704. * @return {?}
  705. */
  706. PaginationComponent.prototype.makePage =
  707. // Create page object used in template
  708. /**
  709. * @protected
  710. * @param {?} num
  711. * @param {?} text
  712. * @param {?} active
  713. * @return {?}
  714. */
  715. function (num, text, active) {
  716. return { text: text, number: num, active: active };
  717. };
  718. /**
  719. * @protected
  720. * @param {?} currentPage
  721. * @param {?} totalPages
  722. * @return {?}
  723. */
  724. PaginationComponent.prototype.getPages = /**
  725. * @protected
  726. * @param {?} currentPage
  727. * @param {?} totalPages
  728. * @return {?}
  729. */
  730. function (currentPage, totalPages) {
  731. /** @type {?} */
  732. var pages = [];
  733. // Default page limits
  734. /** @type {?} */
  735. var startPage = 1;
  736. /** @type {?} */
  737. var endPage = totalPages;
  738. /** @type {?} */
  739. var isMaxSized = typeof this.maxSize !== 'undefined' && this.maxSize < totalPages;
  740. // recompute if maxSize
  741. if (isMaxSized) {
  742. if (this.rotate) {
  743. // Current page is displayed in the middle of the visible ones
  744. startPage = Math.max(currentPage - Math.floor(this.maxSize / 2), 1);
  745. endPage = startPage + this.maxSize - 1;
  746. // Adjust if limit is exceeded
  747. if (endPage > totalPages) {
  748. endPage = totalPages;
  749. startPage = endPage - this.maxSize + 1;
  750. }
  751. }
  752. else {
  753. // Visible pages are paginated with maxSize
  754. startPage =
  755. (Math.ceil(currentPage / this.maxSize) - 1) * this.maxSize + 1;
  756. // Adjust last page if limit is exceeded
  757. endPage = Math.min(startPage + this.maxSize - 1, totalPages);
  758. }
  759. }
  760. // Add page number links
  761. for (var num = startPage; num <= endPage; num++) {
  762. /** @type {?} */
  763. var page = this.makePage(num, num.toString(), num === currentPage);
  764. pages.push(page);
  765. }
  766. // Add links to move between page sets
  767. if (isMaxSized && !this.rotate) {
  768. if (startPage > 1) {
  769. /** @type {?} */
  770. var previousPageSet = this.makePage(startPage - 1, '...', false);
  771. pages.unshift(previousPageSet);
  772. }
  773. if (endPage < totalPages) {
  774. /** @type {?} */
  775. var nextPageSet = this.makePage(endPage + 1, '...', false);
  776. pages.push(nextPageSet);
  777. }
  778. }
  779. return pages;
  780. };
  781. // base class
  782. // base class
  783. /**
  784. * @protected
  785. * @return {?}
  786. */
  787. PaginationComponent.prototype.calculateTotalPages =
  788. // base class
  789. /**
  790. * @protected
  791. * @return {?}
  792. */
  793. function () {
  794. /** @type {?} */
  795. var totalPages = this.itemsPerPage < 1
  796. ? 1
  797. : Math.ceil(this.totalItems / this.itemsPerPage);
  798. return Math.max(totalPages || 0, 1);
  799. };
  800. PaginationComponent.decorators = [
  801. { type: core.Component, args: [{
  802. selector: 'pagination',
  803. 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 [innerHTML]=\"getText('first')\"></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 [innerHTML]=\"getText('previous')\"></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 [innerHTML]=\"pg.text\"></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 [innerHTML]=\"getText('next')\"></a></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 [innerHTML]=\"getText('last')\"></a></li>\n</ul>\n",
  804. providers: [PAGINATION_CONTROL_VALUE_ACCESSOR]
  805. }] }
  806. ];
  807. /** @nocollapse */
  808. PaginationComponent.ctorParameters = function () { return [
  809. { type: core.ElementRef },
  810. { type: PaginationConfig },
  811. { type: core.ChangeDetectorRef }
  812. ]; };
  813. PaginationComponent.propDecorators = {
  814. align: [{ type: core.Input }],
  815. maxSize: [{ type: core.Input }],
  816. boundaryLinks: [{ type: core.Input }],
  817. directionLinks: [{ type: core.Input }],
  818. firstText: [{ type: core.Input }],
  819. previousText: [{ type: core.Input }],
  820. nextText: [{ type: core.Input }],
  821. lastText: [{ type: core.Input }],
  822. rotate: [{ type: core.Input }],
  823. pageBtnClass: [{ type: core.Input }],
  824. disabled: [{ type: core.Input }],
  825. numPages: [{ type: core.Output }],
  826. pageChanged: [{ type: core.Output }],
  827. itemsPerPage: [{ type: core.Input }],
  828. totalItems: [{ type: core.Input }]
  829. };
  830. return PaginationComponent;
  831. }());
  832. /**
  833. * @fileoverview added by tsickle
  834. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  835. */
  836. var PaginationModule = /** @class */ (function () {
  837. function PaginationModule() {
  838. }
  839. /**
  840. * @return {?}
  841. */
  842. PaginationModule.forRoot = /**
  843. * @return {?}
  844. */
  845. function () {
  846. return { ngModule: PaginationModule, providers: [PaginationConfig] };
  847. };
  848. PaginationModule.decorators = [
  849. { type: core.NgModule, args: [{
  850. imports: [common.CommonModule],
  851. declarations: [PagerComponent, PaginationComponent],
  852. exports: [PagerComponent, PaginationComponent]
  853. },] }
  854. ];
  855. return PaginationModule;
  856. }());
  857. exports.PagerComponent = PagerComponent;
  858. exports.PaginationComponent = PaginationComponent;
  859. exports.PaginationConfig = PaginationConfig;
  860. exports.PaginationModule = PaginationModule;
  861. exports.ɵa = PAGER_CONTROL_VALUE_ACCESSOR;
  862. exports.ɵb = PAGINATION_CONTROL_VALUE_ACCESSOR;
  863. Object.defineProperty(exports, '__esModule', { value: true });
  864. }));
  865. //# sourceMappingURL=ngx-bootstrap-pagination.umd.js.map