ngx-bootstrap-carousel.umd.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/carousel', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].carousel = {}), global.ng.core, global.utils, global.ng.common));
  5. }(this, function (exports, core, utils, common) { 'use strict';
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation. All rights reserved.
  8. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  9. this file except in compliance with the License. You may obtain a copy of the
  10. License at http://www.apache.org/licenses/LICENSE-2.0
  11. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. MERCHANTABLITY OR NON-INFRINGEMENT.
  15. See the Apache Version 2.0 License for specific language governing permissions
  16. and limitations under the License.
  17. ***************************************************************************** */
  18. function __read(o, n) {
  19. var m = typeof Symbol === "function" && o[Symbol.iterator];
  20. if (!m) return o;
  21. var i = m.call(o), r, ar = [], e;
  22. try {
  23. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  24. }
  25. catch (error) { e = { error: error }; }
  26. finally {
  27. try {
  28. if (r && !r.done && (m = i["return"])) m.call(i);
  29. }
  30. finally { if (e) throw e.error; }
  31. }
  32. return ar;
  33. }
  34. function __spread() {
  35. for (var ar = [], i = 0; i < arguments.length; i++)
  36. ar = ar.concat(__read(arguments[i]));
  37. return ar;
  38. }
  39. /**
  40. * @fileoverview added by tsickle
  41. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  42. */
  43. var CarouselConfig = /** @class */ (function () {
  44. function CarouselConfig() {
  45. /* Default interval of auto changing of slides */
  46. this.interval = 5000;
  47. /* Is loop of auto changing of slides can be paused */
  48. this.noPause = false;
  49. /* Is slides can wrap from the last to the first slide */
  50. this.noWrap = false;
  51. /* Show carousel-indicators */
  52. this.showIndicators = true;
  53. /* Slides can be paused on focus */
  54. this.pauseOnFocus = false;
  55. /* If `true` - carousel indicators indicate slides chunks works ONLY if singleSlideOffset = FALSE */
  56. this.indicatorsByChunk = false;
  57. /* If value more then 1 — carousel works in multilist mode */
  58. this.itemsPerSlide = 1;
  59. /* If `true` — carousel shifts by one element. By default carousel shifts by number
  60. of visible elements (itemsPerSlide field) */
  61. this.singleSlideOffset = false;
  62. }
  63. CarouselConfig.decorators = [
  64. { type: core.Injectable }
  65. ];
  66. return CarouselConfig;
  67. }());
  68. /**
  69. * @fileoverview added by tsickle
  70. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  71. */
  72. /**
  73. * Returns the index of the last element in the array where predicate is true, and -1
  74. * otherwise.
  75. * @template T
  76. * @param {?} array The source array to search in
  77. * @param {?} predicate find calls predicate once for each element of the array, in descending
  78. * order, until it finds one where predicate returns true. If such an element is found,
  79. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  80. * @return {?}
  81. */
  82. function findLastIndex(array, predicate) {
  83. /** @type {?} */
  84. var l = array.length;
  85. while (l--) {
  86. if (predicate(array[l], l, array)) {
  87. return l;
  88. }
  89. }
  90. return -1;
  91. }
  92. /**
  93. * @template T
  94. * @param {?} array
  95. * @param {?} size
  96. * @return {?}
  97. */
  98. function chunkByNumber(array, size) {
  99. /** @type {?} */
  100. var out = [];
  101. /** @type {?} */
  102. var n = Math.ceil((array.length) / size);
  103. /** @type {?} */
  104. var i = 0;
  105. while (i < n) {
  106. /** @type {?} */
  107. var chunk = array.splice(0, (i === n - 1) && size < array.length ? array.length : size);
  108. out.push(chunk);
  109. i++;
  110. }
  111. return out;
  112. }
  113. /**
  114. * @fileoverview added by tsickle
  115. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  116. */
  117. /** @enum {number} */
  118. var Direction = {
  119. UNKNOWN: 0,
  120. NEXT: 1,
  121. PREV: 2,
  122. };
  123. Direction[Direction.UNKNOWN] = 'UNKNOWN';
  124. Direction[Direction.NEXT] = 'NEXT';
  125. Direction[Direction.PREV] = 'PREV';
  126. /**
  127. * Base element to create carousel
  128. */
  129. var CarouselComponent = /** @class */ (function () {
  130. function CarouselComponent(config, ngZone) {
  131. this.ngZone = ngZone;
  132. /* If `true` - carousel indicators indicate slides chunks
  133. works ONLY if singleSlideOffset = FALSE */
  134. this.indicatorsByChunk = false;
  135. /* If value more then 1 — carousel works in multilist mode */
  136. this.itemsPerSlide = 1;
  137. /* If `true` — carousel shifts by one element. By default carousel shifts by number
  138. of visible elements (itemsPerSlide field) */
  139. this.singleSlideOffset = false;
  140. /**
  141. * Will be emitted when active slide has been changed. Part of two-way-bindable [(activeSlide)] property
  142. */
  143. this.activeSlideChange = new core.EventEmitter(false);
  144. /**
  145. * Will be emitted when active slides has been changed in multilist mode
  146. */
  147. this.slideRangeChange = new core.EventEmitter();
  148. /* Index to start display slides from it */
  149. this.startFromIndex = 0;
  150. this._slides = new utils.LinkedList();
  151. this._currentVisibleSlidesIndex = 0;
  152. this.destroyed = false;
  153. this.getActive = (/**
  154. * @param {?} slide
  155. * @return {?}
  156. */
  157. function (slide) { return slide.active; });
  158. this.makeSlidesConsistent = (/**
  159. * @param {?} slides
  160. * @return {?}
  161. */
  162. function (slides) {
  163. slides.forEach((/**
  164. * @param {?} slide
  165. * @param {?} index
  166. * @return {?}
  167. */
  168. function (slide, index) { return slide.item.order = index; }));
  169. });
  170. Object.assign(this, config);
  171. }
  172. Object.defineProperty(CarouselComponent.prototype, "activeSlide", {
  173. get: /**
  174. * @return {?}
  175. */
  176. function () {
  177. return this._currentActiveSlide;
  178. },
  179. /** Index of currently displayed slide(started for 0) */
  180. set: /**
  181. * Index of currently displayed slide(started for 0)
  182. * @param {?} index
  183. * @return {?}
  184. */
  185. function (index) {
  186. if (this.multilist) {
  187. return;
  188. }
  189. if (this._slides.length && index !== this._currentActiveSlide) {
  190. this._select(index);
  191. }
  192. },
  193. enumerable: true,
  194. configurable: true
  195. });
  196. Object.defineProperty(CarouselComponent.prototype, "interval", {
  197. /**
  198. * Delay of item cycling in milliseconds. If false, carousel won't cycle
  199. * automatically.
  200. */
  201. get: /**
  202. * Delay of item cycling in milliseconds. If false, carousel won't cycle
  203. * automatically.
  204. * @return {?}
  205. */
  206. function () {
  207. return this._interval;
  208. },
  209. set: /**
  210. * @param {?} value
  211. * @return {?}
  212. */
  213. function (value) {
  214. this._interval = value;
  215. this.restartTimer();
  216. },
  217. enumerable: true,
  218. configurable: true
  219. });
  220. Object.defineProperty(CarouselComponent.prototype, "slides", {
  221. get: /**
  222. * @return {?}
  223. */
  224. function () {
  225. return this._slides.toArray();
  226. },
  227. enumerable: true,
  228. configurable: true
  229. });
  230. Object.defineProperty(CarouselComponent.prototype, "isBs4", {
  231. get: /**
  232. * @return {?}
  233. */
  234. function () {
  235. return !utils.isBs3();
  236. },
  237. enumerable: true,
  238. configurable: true
  239. });
  240. /**
  241. * @return {?}
  242. */
  243. CarouselComponent.prototype.ngAfterViewInit = /**
  244. * @return {?}
  245. */
  246. function () {
  247. var _this = this;
  248. setTimeout((/**
  249. * @return {?}
  250. */
  251. function () {
  252. if (_this.singleSlideOffset) {
  253. _this.indicatorsByChunk = false;
  254. }
  255. if (_this.multilist) {
  256. _this._chunkedSlides = chunkByNumber(_this.mapSlidesAndIndexes(), _this.itemsPerSlide);
  257. _this.selectInitialSlides();
  258. }
  259. }), 0);
  260. };
  261. /**
  262. * @return {?}
  263. */
  264. CarouselComponent.prototype.ngOnDestroy = /**
  265. * @return {?}
  266. */
  267. function () {
  268. this.destroyed = true;
  269. };
  270. /**
  271. * Adds new slide. If this slide is first in collection - set it as active
  272. * and starts auto changing
  273. * @param slide
  274. */
  275. /**
  276. * Adds new slide. If this slide is first in collection - set it as active
  277. * and starts auto changing
  278. * @param {?} slide
  279. * @return {?}
  280. */
  281. CarouselComponent.prototype.addSlide = /**
  282. * Adds new slide. If this slide is first in collection - set it as active
  283. * and starts auto changing
  284. * @param {?} slide
  285. * @return {?}
  286. */
  287. function (slide) {
  288. this._slides.add(slide);
  289. if (this.multilist && this._slides.length <= this.itemsPerSlide) {
  290. slide.active = true;
  291. }
  292. if (!this.multilist && this._slides.length === 1) {
  293. this._currentActiveSlide = undefined;
  294. this.activeSlide = 0;
  295. this.play();
  296. }
  297. if (this.multilist && this._slides.length > this.itemsPerSlide) {
  298. this.play();
  299. }
  300. };
  301. /**
  302. * Removes specified slide. If this slide is active - will roll to another
  303. * slide
  304. * @param slide
  305. */
  306. /**
  307. * Removes specified slide. If this slide is active - will roll to another
  308. * slide
  309. * @param {?} slide
  310. * @return {?}
  311. */
  312. CarouselComponent.prototype.removeSlide = /**
  313. * Removes specified slide. If this slide is active - will roll to another
  314. * slide
  315. * @param {?} slide
  316. * @return {?}
  317. */
  318. function (slide) {
  319. var _this = this;
  320. /** @type {?} */
  321. var remIndex = this._slides.indexOf(slide);
  322. if (this._currentActiveSlide === remIndex) {
  323. // removing of active slide
  324. /** @type {?} */
  325. var nextSlideIndex_1 = void 0;
  326. if (this._slides.length > 1) {
  327. // if this slide last - will roll to first slide, if noWrap flag is
  328. // FALSE or to previous, if noWrap is TRUE in case, if this slide in
  329. // middle of collection, index of next slide is same to removed
  330. nextSlideIndex_1 = !this.isLast(remIndex)
  331. ? remIndex
  332. : this.noWrap ? remIndex - 1 : 0;
  333. }
  334. this._slides.remove(remIndex);
  335. // prevents exception with changing some value after checking
  336. setTimeout((/**
  337. * @return {?}
  338. */
  339. function () {
  340. _this._select(nextSlideIndex_1);
  341. }), 0);
  342. }
  343. else {
  344. this._slides.remove(remIndex);
  345. /** @type {?} */
  346. var currentSlideIndex_1 = this.getCurrentSlideIndex();
  347. setTimeout((/**
  348. * @return {?}
  349. */
  350. function () {
  351. // after removing, need to actualize index of current active slide
  352. _this._currentActiveSlide = currentSlideIndex_1;
  353. _this.activeSlideChange.emit(_this._currentActiveSlide);
  354. }), 0);
  355. }
  356. };
  357. /**
  358. * @param {?=} force
  359. * @return {?}
  360. */
  361. CarouselComponent.prototype.nextSlideFromInterval = /**
  362. * @param {?=} force
  363. * @return {?}
  364. */
  365. function (force) {
  366. if (force === void 0) { force = false; }
  367. this.move(Direction.NEXT, force);
  368. };
  369. /**
  370. * Rolling to next slide
  371. * @param force: {boolean} if true - will ignore noWrap flag
  372. */
  373. /**
  374. * Rolling to next slide
  375. * @param {?=} force
  376. * @return {?}
  377. */
  378. CarouselComponent.prototype.nextSlide = /**
  379. * Rolling to next slide
  380. * @param {?=} force
  381. * @return {?}
  382. */
  383. function (force) {
  384. if (force === void 0) { force = false; }
  385. if (this.isPlaying) {
  386. this.restartTimer();
  387. }
  388. this.move(Direction.NEXT, force);
  389. };
  390. /**
  391. * Rolling to previous slide
  392. * @param force: {boolean} if true - will ignore noWrap flag
  393. */
  394. /**
  395. * Rolling to previous slide
  396. * @param {?=} force
  397. * @return {?}
  398. */
  399. CarouselComponent.prototype.previousSlide = /**
  400. * Rolling to previous slide
  401. * @param {?=} force
  402. * @return {?}
  403. */
  404. function (force) {
  405. if (force === void 0) { force = false; }
  406. if (this.isPlaying) {
  407. this.restartTimer();
  408. }
  409. this.move(Direction.PREV, force);
  410. };
  411. /**
  412. * @return {?}
  413. */
  414. CarouselComponent.prototype.getFirstVisibleIndex = /**
  415. * @return {?}
  416. */
  417. function () {
  418. return this.slides.findIndex(this.getActive);
  419. };
  420. /**
  421. * @return {?}
  422. */
  423. CarouselComponent.prototype.getLastVisibleIndex = /**
  424. * @return {?}
  425. */
  426. function () {
  427. return findLastIndex(this.slides, this.getActive);
  428. };
  429. /**
  430. * @param {?} direction
  431. * @param {?=} force
  432. * @return {?}
  433. */
  434. CarouselComponent.prototype.move = /**
  435. * @param {?} direction
  436. * @param {?=} force
  437. * @return {?}
  438. */
  439. function (direction, force) {
  440. if (force === void 0) { force = false; }
  441. /** @type {?} */
  442. var firstVisibleIndex = this.getFirstVisibleIndex();
  443. /** @type {?} */
  444. var lastVisibleIndex = this.getLastVisibleIndex();
  445. if (this.noWrap) {
  446. if (direction === Direction.NEXT &&
  447. this.isLast(lastVisibleIndex) ||
  448. direction === Direction.PREV &&
  449. firstVisibleIndex === 0) {
  450. return;
  451. }
  452. }
  453. if (!this.multilist) {
  454. this.activeSlide = this.findNextSlideIndex(direction, force);
  455. }
  456. else {
  457. this.moveMultilist(direction);
  458. }
  459. };
  460. /**
  461. * Swith slides by enter, space and arrows keys
  462. * @internal
  463. */
  464. /**
  465. * Swith slides by enter, space and arrows keys
  466. * \@internal
  467. * @param {?} event
  468. * @return {?}
  469. */
  470. CarouselComponent.prototype.keydownPress = /**
  471. * Swith slides by enter, space and arrows keys
  472. * \@internal
  473. * @param {?} event
  474. * @return {?}
  475. */
  476. function (event) {
  477. // tslint:disable-next-line:deprecation
  478. if (event.keyCode === 13 || event.key === 'Enter' || event.keyCode === 32 || event.key === 'Space') {
  479. this.nextSlide();
  480. event.preventDefault();
  481. return;
  482. }
  483. // tslint:disable-next-line:deprecation
  484. if (event.keyCode === 37 || event.key === 'LeftArrow') {
  485. this.previousSlide();
  486. return;
  487. }
  488. // tslint:disable-next-line:deprecation
  489. if (event.keyCode === 39 || event.key === 'RightArrow') {
  490. this.nextSlide();
  491. return;
  492. }
  493. };
  494. /**
  495. * Play on mouse leave
  496. * @internal
  497. */
  498. /**
  499. * Play on mouse leave
  500. * \@internal
  501. * @return {?}
  502. */
  503. CarouselComponent.prototype.onMouseLeave = /**
  504. * Play on mouse leave
  505. * \@internal
  506. * @return {?}
  507. */
  508. function () {
  509. if (!this.pauseOnFocus) {
  510. this.play();
  511. }
  512. };
  513. /**
  514. * Play on mouse up
  515. * @internal
  516. */
  517. /**
  518. * Play on mouse up
  519. * \@internal
  520. * @return {?}
  521. */
  522. CarouselComponent.prototype.onMouseUp = /**
  523. * Play on mouse up
  524. * \@internal
  525. * @return {?}
  526. */
  527. function () {
  528. if (!this.pauseOnFocus) {
  529. this.play();
  530. }
  531. };
  532. /**
  533. * When slides on focus autoplay is stopped(optional)
  534. * @internal
  535. */
  536. /**
  537. * When slides on focus autoplay is stopped(optional)
  538. * \@internal
  539. * @return {?}
  540. */
  541. CarouselComponent.prototype.pauseFocusIn = /**
  542. * When slides on focus autoplay is stopped(optional)
  543. * \@internal
  544. * @return {?}
  545. */
  546. function () {
  547. if (this.pauseOnFocus) {
  548. this.isPlaying = false;
  549. this.resetTimer();
  550. }
  551. };
  552. /**
  553. * When slides out of focus autoplay is started
  554. * @internal
  555. */
  556. /**
  557. * When slides out of focus autoplay is started
  558. * \@internal
  559. * @return {?}
  560. */
  561. CarouselComponent.prototype.pauseFocusOut = /**
  562. * When slides out of focus autoplay is started
  563. * \@internal
  564. * @return {?}
  565. */
  566. function () {
  567. this.play();
  568. };
  569. /**
  570. * Rolling to specified slide
  571. * @param index: {number} index of slide, which must be shown
  572. */
  573. /**
  574. * Rolling to specified slide
  575. * @param {?} index
  576. * @return {?}
  577. */
  578. CarouselComponent.prototype.selectSlide = /**
  579. * Rolling to specified slide
  580. * @param {?} index
  581. * @return {?}
  582. */
  583. function (index) {
  584. if (this.isPlaying) {
  585. this.restartTimer();
  586. }
  587. if (!this.multilist) {
  588. this.activeSlide = this.indicatorsByChunk ? index * this.itemsPerSlide : index;
  589. }
  590. else {
  591. this.selectSlideRange(this.indicatorsByChunk ? index * this.itemsPerSlide : index);
  592. }
  593. };
  594. /**
  595. * Starts a auto changing of slides
  596. */
  597. /**
  598. * Starts a auto changing of slides
  599. * @return {?}
  600. */
  601. CarouselComponent.prototype.play = /**
  602. * Starts a auto changing of slides
  603. * @return {?}
  604. */
  605. function () {
  606. if (!this.isPlaying) {
  607. this.isPlaying = true;
  608. this.restartTimer();
  609. }
  610. };
  611. /**
  612. * Stops a auto changing of slides
  613. */
  614. /**
  615. * Stops a auto changing of slides
  616. * @return {?}
  617. */
  618. CarouselComponent.prototype.pause = /**
  619. * Stops a auto changing of slides
  620. * @return {?}
  621. */
  622. function () {
  623. if (!this.noPause) {
  624. this.isPlaying = false;
  625. this.resetTimer();
  626. }
  627. };
  628. /**
  629. * Finds and returns index of currently displayed slide
  630. */
  631. /**
  632. * Finds and returns index of currently displayed slide
  633. * @return {?}
  634. */
  635. CarouselComponent.prototype.getCurrentSlideIndex = /**
  636. * Finds and returns index of currently displayed slide
  637. * @return {?}
  638. */
  639. function () {
  640. return this._slides.findIndex(this.getActive);
  641. };
  642. /**
  643. * Defines, whether the specified index is last in collection
  644. * @param index
  645. */
  646. /**
  647. * Defines, whether the specified index is last in collection
  648. * @param {?} index
  649. * @return {?}
  650. */
  651. CarouselComponent.prototype.isLast = /**
  652. * Defines, whether the specified index is last in collection
  653. * @param {?} index
  654. * @return {?}
  655. */
  656. function (index) {
  657. return index + 1 >= this._slides.length;
  658. };
  659. /**
  660. * Defines, whether the specified index is first in collection
  661. * @param index
  662. */
  663. /**
  664. * Defines, whether the specified index is first in collection
  665. * @param {?} index
  666. * @return {?}
  667. */
  668. CarouselComponent.prototype.isFirst = /**
  669. * Defines, whether the specified index is first in collection
  670. * @param {?} index
  671. * @return {?}
  672. */
  673. function (index) {
  674. return index === 0;
  675. };
  676. /**
  677. * @return {?}
  678. */
  679. CarouselComponent.prototype.indicatorsSlides = /**
  680. * @return {?}
  681. */
  682. function () {
  683. var _this = this;
  684. return this.slides.filter((/**
  685. * @param {?} slide
  686. * @param {?} index
  687. * @return {?}
  688. */
  689. function (slide, index) { return !_this.indicatorsByChunk || index % _this.itemsPerSlide === 0; }));
  690. };
  691. /**
  692. * @private
  693. * @return {?}
  694. */
  695. CarouselComponent.prototype.selectInitialSlides = /**
  696. * @private
  697. * @return {?}
  698. */
  699. function () {
  700. /** @type {?} */
  701. var startIndex = this.startFromIndex <= this._slides.length
  702. ? this.startFromIndex
  703. : 0;
  704. this.hideSlides();
  705. if (this.singleSlideOffset) {
  706. this._slidesWithIndexes = this.mapSlidesAndIndexes();
  707. if (this._slides.length - startIndex < this.itemsPerSlide) {
  708. /** @type {?} */
  709. var slidesToAppend = this._slidesWithIndexes.slice(0, startIndex);
  710. this._slidesWithIndexes = __spread(this._slidesWithIndexes, slidesToAppend).slice(slidesToAppend.length)
  711. .slice(0, this.itemsPerSlide);
  712. }
  713. else {
  714. this._slidesWithIndexes = this._slidesWithIndexes.slice(startIndex, startIndex + this.itemsPerSlide);
  715. }
  716. this._slidesWithIndexes.forEach((/**
  717. * @param {?} slide
  718. * @return {?}
  719. */
  720. function (slide) { return slide.item.active = true; }));
  721. this.makeSlidesConsistent(this._slidesWithIndexes);
  722. }
  723. else {
  724. this.selectRangeByNestedIndex(startIndex);
  725. }
  726. this.slideRangeChange.emit(this.getVisibleIndexes());
  727. };
  728. /**
  729. * Defines next slide index, depending of direction
  730. * @param direction: Direction(UNKNOWN|PREV|NEXT)
  731. * @param force: {boolean} if TRUE - will ignore noWrap flag, else will
  732. * return undefined if next slide require wrapping
  733. */
  734. /**
  735. * Defines next slide index, depending of direction
  736. * @private
  737. * @param {?} direction
  738. * @param {?} force
  739. * @return {?}
  740. */
  741. CarouselComponent.prototype.findNextSlideIndex = /**
  742. * Defines next slide index, depending of direction
  743. * @private
  744. * @param {?} direction
  745. * @param {?} force
  746. * @return {?}
  747. */
  748. function (direction, force) {
  749. /** @type {?} */
  750. var nextSlideIndex = 0;
  751. if (!force &&
  752. (this.isLast(this.activeSlide) &&
  753. direction !== Direction.PREV &&
  754. this.noWrap)) {
  755. return undefined;
  756. }
  757. switch (direction) {
  758. case Direction.NEXT:
  759. // if this is last slide, not force, looping is disabled
  760. // and need to going forward - select current slide, as a next
  761. nextSlideIndex = !this.isLast(this._currentActiveSlide)
  762. ? this._currentActiveSlide + 1
  763. : !force && this.noWrap ? this._currentActiveSlide : 0;
  764. break;
  765. case Direction.PREV:
  766. // if this is first slide, not force, looping is disabled
  767. // and need to going backward - select current slide, as a next
  768. nextSlideIndex =
  769. this._currentActiveSlide > 0
  770. ? this._currentActiveSlide - 1
  771. : !force && this.noWrap
  772. ? this._currentActiveSlide
  773. : this._slides.length - 1;
  774. break;
  775. default:
  776. throw new Error('Unknown direction');
  777. }
  778. return nextSlideIndex;
  779. };
  780. /**
  781. * @private
  782. * @return {?}
  783. */
  784. CarouselComponent.prototype.mapSlidesAndIndexes = /**
  785. * @private
  786. * @return {?}
  787. */
  788. function () {
  789. return this.slides
  790. .slice()
  791. .map((/**
  792. * @param {?} slide
  793. * @param {?} index
  794. * @return {?}
  795. */
  796. function (slide, index) {
  797. return {
  798. index: index,
  799. item: slide
  800. };
  801. }));
  802. };
  803. /**
  804. * @private
  805. * @param {?} index
  806. * @return {?}
  807. */
  808. CarouselComponent.prototype.selectSlideRange = /**
  809. * @private
  810. * @param {?} index
  811. * @return {?}
  812. */
  813. function (index) {
  814. if (this.isIndexInRange(index)) {
  815. return;
  816. }
  817. this.hideSlides();
  818. if (!this.singleSlideOffset) {
  819. this.selectRangeByNestedIndex(index);
  820. }
  821. else {
  822. /** @type {?} */
  823. var startIndex = this.isIndexOnTheEdges(index)
  824. ? index
  825. : index - this.itemsPerSlide + 1;
  826. /** @type {?} */
  827. var endIndex = this.isIndexOnTheEdges(index)
  828. ? index + this.itemsPerSlide
  829. : index + 1;
  830. this._slidesWithIndexes = this.mapSlidesAndIndexes().slice(startIndex, endIndex);
  831. this.makeSlidesConsistent(this._slidesWithIndexes);
  832. this._slidesWithIndexes.forEach((/**
  833. * @param {?} slide
  834. * @return {?}
  835. */
  836. function (slide) { return slide.item.active = true; }));
  837. }
  838. this.slideRangeChange.emit(this.getVisibleIndexes());
  839. };
  840. /**
  841. * @private
  842. * @param {?} index
  843. * @return {?}
  844. */
  845. CarouselComponent.prototype.selectRangeByNestedIndex = /**
  846. * @private
  847. * @param {?} index
  848. * @return {?}
  849. */
  850. function (index) {
  851. /** @type {?} */
  852. var selectedRange = this._chunkedSlides
  853. .map((/**
  854. * @param {?} slidesList
  855. * @param {?} i
  856. * @return {?}
  857. */
  858. function (slidesList, i) {
  859. return {
  860. index: i,
  861. list: slidesList
  862. };
  863. }))
  864. .find((/**
  865. * @param {?} slidesList
  866. * @return {?}
  867. */
  868. function (slidesList) {
  869. return slidesList.list.find((/**
  870. * @param {?} slide
  871. * @return {?}
  872. */
  873. function (slide) { return slide.index === index; })) !== undefined;
  874. }));
  875. this._currentVisibleSlidesIndex = selectedRange.index;
  876. this._chunkedSlides[selectedRange.index].forEach((/**
  877. * @param {?} slide
  878. * @return {?}
  879. */
  880. function (slide) {
  881. slide.item.active = true;
  882. }));
  883. };
  884. /**
  885. * @private
  886. * @param {?} index
  887. * @return {?}
  888. */
  889. CarouselComponent.prototype.isIndexOnTheEdges = /**
  890. * @private
  891. * @param {?} index
  892. * @return {?}
  893. */
  894. function (index) {
  895. return (index + 1 - this.itemsPerSlide <= 0 ||
  896. index + this.itemsPerSlide <= this._slides.length);
  897. };
  898. /**
  899. * @private
  900. * @param {?} index
  901. * @return {?}
  902. */
  903. CarouselComponent.prototype.isIndexInRange = /**
  904. * @private
  905. * @param {?} index
  906. * @return {?}
  907. */
  908. function (index) {
  909. if (this.singleSlideOffset) {
  910. /** @type {?} */
  911. var visibleIndexes = this._slidesWithIndexes.map((/**
  912. * @param {?} slide
  913. * @return {?}
  914. */
  915. function (slide) { return slide.index; }));
  916. return visibleIndexes.indexOf(index) >= 0;
  917. }
  918. return (index <= this.getLastVisibleIndex() &&
  919. index >= this.getFirstVisibleIndex());
  920. };
  921. /**
  922. * @private
  923. * @return {?}
  924. */
  925. CarouselComponent.prototype.hideSlides = /**
  926. * @private
  927. * @return {?}
  928. */
  929. function () {
  930. this.slides.forEach((/**
  931. * @param {?} slide
  932. * @return {?}
  933. */
  934. function (slide) { return slide.active = false; }));
  935. };
  936. /**
  937. * @private
  938. * @return {?}
  939. */
  940. CarouselComponent.prototype.isVisibleSlideListLast = /**
  941. * @private
  942. * @return {?}
  943. */
  944. function () {
  945. return this._currentVisibleSlidesIndex === this._chunkedSlides.length - 1;
  946. };
  947. /**
  948. * @private
  949. * @return {?}
  950. */
  951. CarouselComponent.prototype.isVisibleSlideListFirst = /**
  952. * @private
  953. * @return {?}
  954. */
  955. function () {
  956. return this._currentVisibleSlidesIndex === 0;
  957. };
  958. /**
  959. * @private
  960. * @param {?} direction
  961. * @return {?}
  962. */
  963. CarouselComponent.prototype.moveSliderByOneItem = /**
  964. * @private
  965. * @param {?} direction
  966. * @return {?}
  967. */
  968. function (direction) {
  969. /** @type {?} */
  970. var firstVisibleIndex;
  971. /** @type {?} */
  972. var lastVisibleIndex;
  973. /** @type {?} */
  974. var indexToHide;
  975. /** @type {?} */
  976. var indexToShow;
  977. if (this.noWrap) {
  978. firstVisibleIndex = this.getFirstVisibleIndex();
  979. lastVisibleIndex = this.getLastVisibleIndex();
  980. indexToHide = direction === Direction.NEXT
  981. ? firstVisibleIndex
  982. : lastVisibleIndex;
  983. indexToShow = direction !== Direction.NEXT
  984. ? firstVisibleIndex - 1
  985. : !this.isLast(lastVisibleIndex)
  986. ? lastVisibleIndex + 1 : 0;
  987. this._slides.get(indexToHide).active = false;
  988. this._slides.get(indexToShow).active = true;
  989. /** @type {?} */
  990. var slidesToReorder = this.mapSlidesAndIndexes().filter((/**
  991. * @param {?} slide
  992. * @return {?}
  993. */
  994. function (slide) { return slide.item.active; }));
  995. this.makeSlidesConsistent(slidesToReorder);
  996. this.slideRangeChange.emit(this.getVisibleIndexes());
  997. }
  998. else {
  999. /** @type {?} */
  1000. var displayedIndex = void 0;
  1001. firstVisibleIndex = this._slidesWithIndexes[0].index;
  1002. lastVisibleIndex = this._slidesWithIndexes[this._slidesWithIndexes.length - 1].index;
  1003. if (direction === Direction.NEXT) {
  1004. this._slidesWithIndexes.shift();
  1005. displayedIndex = this.isLast(lastVisibleIndex)
  1006. ? 0
  1007. : lastVisibleIndex + 1;
  1008. this._slidesWithIndexes.push({
  1009. index: displayedIndex,
  1010. item: this._slides.get(displayedIndex)
  1011. });
  1012. }
  1013. else {
  1014. this._slidesWithIndexes.pop();
  1015. displayedIndex = this.isFirst(firstVisibleIndex)
  1016. ? this._slides.length - 1
  1017. : firstVisibleIndex - 1;
  1018. this._slidesWithIndexes = __spread([{
  1019. index: displayedIndex,
  1020. item: this._slides.get(displayedIndex)
  1021. }], this._slidesWithIndexes);
  1022. }
  1023. this.hideSlides();
  1024. this._slidesWithIndexes.forEach((/**
  1025. * @param {?} slide
  1026. * @return {?}
  1027. */
  1028. function (slide) { return slide.item.active = true; }));
  1029. this.makeSlidesConsistent(this._slidesWithIndexes);
  1030. this.slideRangeChange.emit(this._slidesWithIndexes.map((/**
  1031. * @param {?} slide
  1032. * @return {?}
  1033. */
  1034. function (slide) { return slide.index; })));
  1035. }
  1036. };
  1037. /**
  1038. * @private
  1039. * @param {?} direction
  1040. * @return {?}
  1041. */
  1042. CarouselComponent.prototype.moveMultilist = /**
  1043. * @private
  1044. * @param {?} direction
  1045. * @return {?}
  1046. */
  1047. function (direction) {
  1048. if (this.singleSlideOffset) {
  1049. this.moveSliderByOneItem(direction);
  1050. }
  1051. else {
  1052. this.hideSlides();
  1053. if (this.noWrap) {
  1054. this._currentVisibleSlidesIndex = direction === Direction.NEXT
  1055. ? this._currentVisibleSlidesIndex + 1
  1056. : this._currentVisibleSlidesIndex - 1;
  1057. }
  1058. else {
  1059. if (direction === Direction.NEXT) {
  1060. this._currentVisibleSlidesIndex = this.isVisibleSlideListLast()
  1061. ? 0
  1062. : this._currentVisibleSlidesIndex + 1;
  1063. }
  1064. else {
  1065. this._currentVisibleSlidesIndex = this.isVisibleSlideListFirst()
  1066. ? this._chunkedSlides.length - 1
  1067. : this._currentVisibleSlidesIndex - 1;
  1068. }
  1069. }
  1070. this._chunkedSlides[this._currentVisibleSlidesIndex].forEach((/**
  1071. * @param {?} slide
  1072. * @return {?}
  1073. */
  1074. function (slide) { return slide.item.active = true; }));
  1075. this.slideRangeChange.emit(this.getVisibleIndexes());
  1076. }
  1077. };
  1078. /**
  1079. * @private
  1080. * @return {?}
  1081. */
  1082. CarouselComponent.prototype.getVisibleIndexes = /**
  1083. * @private
  1084. * @return {?}
  1085. */
  1086. function () {
  1087. if (!this.singleSlideOffset) {
  1088. return this._chunkedSlides[this._currentVisibleSlidesIndex]
  1089. .map((/**
  1090. * @param {?} slide
  1091. * @return {?}
  1092. */
  1093. function (slide) { return slide.index; }));
  1094. }
  1095. else {
  1096. return this._slidesWithIndexes.map((/**
  1097. * @param {?} slide
  1098. * @return {?}
  1099. */
  1100. function (slide) { return slide.index; }));
  1101. }
  1102. };
  1103. /**
  1104. * Sets a slide, which specified through index, as active
  1105. * @param index
  1106. */
  1107. /**
  1108. * Sets a slide, which specified through index, as active
  1109. * @private
  1110. * @param {?} index
  1111. * @return {?}
  1112. */
  1113. CarouselComponent.prototype._select = /**
  1114. * Sets a slide, which specified through index, as active
  1115. * @private
  1116. * @param {?} index
  1117. * @return {?}
  1118. */
  1119. function (index) {
  1120. if (isNaN(index)) {
  1121. this.pause();
  1122. return;
  1123. }
  1124. if (!this.multilist) {
  1125. /** @type {?} */
  1126. var currentSlide = this._slides.get(this._currentActiveSlide);
  1127. if (currentSlide) {
  1128. currentSlide.active = false;
  1129. }
  1130. }
  1131. /** @type {?} */
  1132. var nextSlide = this._slides.get(index);
  1133. if (nextSlide) {
  1134. this._currentActiveSlide = index;
  1135. nextSlide.active = true;
  1136. this.activeSlide = index;
  1137. this.activeSlideChange.emit(index);
  1138. }
  1139. };
  1140. /**
  1141. * Starts loop of auto changing of slides
  1142. */
  1143. /**
  1144. * Starts loop of auto changing of slides
  1145. * @private
  1146. * @return {?}
  1147. */
  1148. CarouselComponent.prototype.restartTimer = /**
  1149. * Starts loop of auto changing of slides
  1150. * @private
  1151. * @return {?}
  1152. */
  1153. function () {
  1154. var _this = this;
  1155. this.resetTimer();
  1156. /** @type {?} */
  1157. var interval = +this.interval;
  1158. if (!isNaN(interval) && interval > 0) {
  1159. this.currentInterval = this.ngZone.runOutsideAngular((/**
  1160. * @return {?}
  1161. */
  1162. function () {
  1163. return setInterval((/**
  1164. * @return {?}
  1165. */
  1166. function () {
  1167. /** @type {?} */
  1168. var nInterval = +_this.interval;
  1169. _this.ngZone.run((/**
  1170. * @return {?}
  1171. */
  1172. function () {
  1173. if (_this.isPlaying &&
  1174. !isNaN(_this.interval) &&
  1175. nInterval > 0 &&
  1176. _this.slides.length) {
  1177. _this.nextSlideFromInterval();
  1178. }
  1179. else {
  1180. _this.pause();
  1181. }
  1182. }));
  1183. }), interval);
  1184. }));
  1185. }
  1186. };
  1187. Object.defineProperty(CarouselComponent.prototype, "multilist", {
  1188. get: /**
  1189. * @return {?}
  1190. */
  1191. function () {
  1192. return this.itemsPerSlide > 1;
  1193. },
  1194. enumerable: true,
  1195. configurable: true
  1196. });
  1197. /**
  1198. * Stops loop of auto changing of slides
  1199. */
  1200. /**
  1201. * Stops loop of auto changing of slides
  1202. * @private
  1203. * @return {?}
  1204. */
  1205. CarouselComponent.prototype.resetTimer = /**
  1206. * Stops loop of auto changing of slides
  1207. * @private
  1208. * @return {?}
  1209. */
  1210. function () {
  1211. if (this.currentInterval) {
  1212. clearInterval(this.currentInterval);
  1213. this.currentInterval = void 0;
  1214. }
  1215. };
  1216. CarouselComponent.decorators = [
  1217. { type: core.Component, args: [{
  1218. selector: 'carousel',
  1219. template: "<div (mouseenter)=\"pause()\" (mouseleave)=\"onMouseLeave()\" (mouseup)=\"onMouseUp()\" class=\"carousel slide\" (keydown)=\"keydownPress($event)\" (focusin)=\"pauseFocusIn()\" (focusout)=\"pauseFocusOut()\" tabindex=\"0\">\n <ol class=\"carousel-indicators\" *ngIf=\"showIndicators && slides.length > 1\">\n <li *ngFor=\"let slidez of indicatorsSlides(); let i = index;\" [class.active]=\"slidez.active === true\" (click)=\"selectSlide(i)\"></li>\n </ol>\n <div class=\"carousel-inner\" [ngStyle]=\"{'display': multilist ? 'flex' : 'block'}\"><ng-content></ng-content></div>\n <a class=\"left carousel-control carousel-control-prev\" [class.disabled]=\"activeSlide === 0 && noWrap\" (click)=\"previousSlide()\" *ngIf=\"slides.length > 1\"\n tabindex=\"0\" role=\"button\">\n <span class=\"icon-prev carousel-control-prev-icon\" aria-hidden=\"true\"></span>\n <span *ngIf=\"isBs4\" class=\"sr-only\">Previous</span>\n </a>\n <a class=\"right carousel-control carousel-control-next\" (click)=\"nextSlide()\" [class.disabled]=\"isLast(activeSlide) && noWrap\" *ngIf=\"slides.length > 1\"\n tabindex=\"0\" role=\"button\">\n <span class=\"icon-next carousel-control-next-icon\" aria-hidden=\"true\"></span>\n <span class=\"sr-only\">Next</span>\n </a>\n</div>\n"
  1220. }] }
  1221. ];
  1222. /** @nocollapse */
  1223. CarouselComponent.ctorParameters = function () { return [
  1224. { type: CarouselConfig },
  1225. { type: core.NgZone }
  1226. ]; };
  1227. CarouselComponent.propDecorators = {
  1228. noWrap: [{ type: core.Input }],
  1229. noPause: [{ type: core.Input }],
  1230. showIndicators: [{ type: core.Input }],
  1231. pauseOnFocus: [{ type: core.Input }],
  1232. indicatorsByChunk: [{ type: core.Input }],
  1233. itemsPerSlide: [{ type: core.Input }],
  1234. singleSlideOffset: [{ type: core.Input }],
  1235. activeSlideChange: [{ type: core.Output }],
  1236. slideRangeChange: [{ type: core.Output }],
  1237. activeSlide: [{ type: core.Input }],
  1238. startFromIndex: [{ type: core.Input }],
  1239. interval: [{ type: core.Input }]
  1240. };
  1241. return CarouselComponent;
  1242. }());
  1243. /**
  1244. * @fileoverview added by tsickle
  1245. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1246. */
  1247. var SlideComponent = /** @class */ (function () {
  1248. function SlideComponent(carousel) {
  1249. this.itemWidth = '100%';
  1250. this.order = 0;
  1251. /**
  1252. * Wraps element by appropriate CSS classes
  1253. */
  1254. this.addClass = true;
  1255. this.carousel = carousel;
  1256. }
  1257. /** Fires changes in container collection after adding a new slide instance */
  1258. /**
  1259. * Fires changes in container collection after adding a new slide instance
  1260. * @return {?}
  1261. */
  1262. SlideComponent.prototype.ngOnInit = /**
  1263. * Fires changes in container collection after adding a new slide instance
  1264. * @return {?}
  1265. */
  1266. function () {
  1267. this.carousel.addSlide(this);
  1268. this.itemWidth = 100 / this.carousel.itemsPerSlide + "%";
  1269. };
  1270. /** Fires changes in container collection after removing of this slide instance */
  1271. /**
  1272. * Fires changes in container collection after removing of this slide instance
  1273. * @return {?}
  1274. */
  1275. SlideComponent.prototype.ngOnDestroy = /**
  1276. * Fires changes in container collection after removing of this slide instance
  1277. * @return {?}
  1278. */
  1279. function () {
  1280. this.carousel.removeSlide(this);
  1281. };
  1282. SlideComponent.decorators = [
  1283. { type: core.Component, args: [{
  1284. selector: 'slide',
  1285. template: "\n <div [class.active]=\"active\" class=\"item\">\n <ng-content></ng-content>\n </div>\n ",
  1286. host: {
  1287. '[attr.aria-hidden]': '!active'
  1288. }
  1289. }] }
  1290. ];
  1291. /** @nocollapse */
  1292. SlideComponent.ctorParameters = function () { return [
  1293. { type: CarouselComponent }
  1294. ]; };
  1295. SlideComponent.propDecorators = {
  1296. active: [{ type: core.HostBinding, args: ['class.active',] }, { type: core.Input }],
  1297. itemWidth: [{ type: core.HostBinding, args: ['style.width',] }],
  1298. order: [{ type: core.HostBinding, args: ['style.order',] }],
  1299. addClass: [{ type: core.HostBinding, args: ['class.item',] }, { type: core.HostBinding, args: ['class.carousel-item',] }]
  1300. };
  1301. return SlideComponent;
  1302. }());
  1303. /**
  1304. * @fileoverview added by tsickle
  1305. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1306. */
  1307. var CarouselModule = /** @class */ (function () {
  1308. function CarouselModule() {
  1309. }
  1310. /**
  1311. * @return {?}
  1312. */
  1313. CarouselModule.forRoot = /**
  1314. * @return {?}
  1315. */
  1316. function () {
  1317. return { ngModule: CarouselModule, providers: [] };
  1318. };
  1319. CarouselModule.decorators = [
  1320. { type: core.NgModule, args: [{
  1321. imports: [common.CommonModule],
  1322. declarations: [SlideComponent, CarouselComponent],
  1323. exports: [SlideComponent, CarouselComponent],
  1324. providers: [CarouselConfig]
  1325. },] }
  1326. ];
  1327. return CarouselModule;
  1328. }());
  1329. exports.CarouselComponent = CarouselComponent;
  1330. exports.CarouselConfig = CarouselConfig;
  1331. exports.CarouselModule = CarouselModule;
  1332. exports.SlideComponent = SlideComponent;
  1333. Object.defineProperty(exports, '__esModule', { value: true });
  1334. }));
  1335. //# sourceMappingURL=ngx-bootstrap-carousel.umd.js.map