ngx-bootstrap-pagination.js 27 KB

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