| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013 |
- import { Injectable, EventEmitter, Component, NgZone, Input, Output, HostBinding, NgModule } from '@angular/core';
- import { LinkedList, isBs3 } from 'ngx-bootstrap/utils';
- import { CommonModule } from '@angular/common';
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- class CarouselConfig {
- constructor() {
- /* Default interval of auto changing of slides */
- this.interval = 5000;
- /* Is loop of auto changing of slides can be paused */
- this.noPause = false;
- /* Is slides can wrap from the last to the first slide */
- this.noWrap = false;
- /* Show carousel-indicators */
- this.showIndicators = true;
- /* Slides can be paused on focus */
- this.pauseOnFocus = false;
- /* If `true` - carousel indicators indicate slides chunks works ONLY if singleSlideOffset = FALSE */
- this.indicatorsByChunk = false;
- /* If value more then 1 — carousel works in multilist mode */
- this.itemsPerSlide = 1;
- /* If `true` — carousel shifts by one element. By default carousel shifts by number
- of visible elements (itemsPerSlide field) */
- this.singleSlideOffset = false;
- }
- }
- CarouselConfig.decorators = [
- { type: Injectable }
- ];
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * Returns the index of the last element in the array where predicate is true, and -1
- * otherwise.
- * @template T
- * @param {?} array The source array to search in
- * @param {?} predicate find calls predicate once for each element of the array, in descending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
- * @return {?}
- */
- function findLastIndex(array, predicate) {
- /** @type {?} */
- let l = array.length;
- while (l--) {
- if (predicate(array[l], l, array)) {
- return l;
- }
- }
- return -1;
- }
- /**
- * @template T
- * @param {?} array
- * @param {?} size
- * @return {?}
- */
- function chunkByNumber(array, size) {
- /** @type {?} */
- const out = [];
- /** @type {?} */
- const n = Math.ceil((array.length) / size);
- /** @type {?} */
- let i = 0;
- while (i < n) {
- /** @type {?} */
- const chunk = array.splice(0, (i === n - 1) && size < array.length ? array.length : size);
- out.push(chunk);
- i++;
- }
- return out;
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /** @enum {number} */
- const Direction = {
- UNKNOWN: 0,
- NEXT: 1,
- PREV: 2,
- };
- Direction[Direction.UNKNOWN] = 'UNKNOWN';
- Direction[Direction.NEXT] = 'NEXT';
- Direction[Direction.PREV] = 'PREV';
- /**
- * Base element to create carousel
- */
- class CarouselComponent {
- /**
- * @param {?} config
- * @param {?} ngZone
- */
- constructor(config, ngZone) {
- this.ngZone = ngZone;
- /* If `true` - carousel indicators indicate slides chunks
- works ONLY if singleSlideOffset = FALSE */
- this.indicatorsByChunk = false;
- /* If value more then 1 — carousel works in multilist mode */
- this.itemsPerSlide = 1;
- /* If `true` — carousel shifts by one element. By default carousel shifts by number
- of visible elements (itemsPerSlide field) */
- this.singleSlideOffset = false;
- /**
- * Will be emitted when active slide has been changed. Part of two-way-bindable [(activeSlide)] property
- */
- this.activeSlideChange = new EventEmitter(false);
- /**
- * Will be emitted when active slides has been changed in multilist mode
- */
- this.slideRangeChange = new EventEmitter();
- /* Index to start display slides from it */
- this.startFromIndex = 0;
- this._slides = new LinkedList();
- this._currentVisibleSlidesIndex = 0;
- this.destroyed = false;
- this.getActive = (/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.active);
- this.makeSlidesConsistent = (/**
- * @param {?} slides
- * @return {?}
- */
- (slides) => {
- slides.forEach((/**
- * @param {?} slide
- * @param {?} index
- * @return {?}
- */
- (slide, index) => slide.item.order = index));
- });
- Object.assign(this, config);
- }
- /**
- * Index of currently displayed slide(started for 0)
- * @param {?} index
- * @return {?}
- */
- set activeSlide(index) {
- if (this.multilist) {
- return;
- }
- if (this._slides.length && index !== this._currentActiveSlide) {
- this._select(index);
- }
- }
- /**
- * @return {?}
- */
- get activeSlide() {
- return this._currentActiveSlide;
- }
- /**
- * Delay of item cycling in milliseconds. If false, carousel won't cycle
- * automatically.
- * @return {?}
- */
- get interval() {
- return this._interval;
- }
- /**
- * @param {?} value
- * @return {?}
- */
- set interval(value) {
- this._interval = value;
- this.restartTimer();
- }
- /**
- * @return {?}
- */
- get slides() {
- return this._slides.toArray();
- }
- /**
- * @return {?}
- */
- get isBs4() {
- return !isBs3();
- }
- /**
- * @return {?}
- */
- ngAfterViewInit() {
- setTimeout((/**
- * @return {?}
- */
- () => {
- if (this.singleSlideOffset) {
- this.indicatorsByChunk = false;
- }
- if (this.multilist) {
- this._chunkedSlides = chunkByNumber(this.mapSlidesAndIndexes(), this.itemsPerSlide);
- this.selectInitialSlides();
- }
- }), 0);
- }
- /**
- * @return {?}
- */
- ngOnDestroy() {
- this.destroyed = true;
- }
- /**
- * Adds new slide. If this slide is first in collection - set it as active
- * and starts auto changing
- * @param {?} slide
- * @return {?}
- */
- addSlide(slide) {
- this._slides.add(slide);
- if (this.multilist && this._slides.length <= this.itemsPerSlide) {
- slide.active = true;
- }
- if (!this.multilist && this._slides.length === 1) {
- this._currentActiveSlide = undefined;
- this.activeSlide = 0;
- this.play();
- }
- if (this.multilist && this._slides.length > this.itemsPerSlide) {
- this.play();
- }
- }
- /**
- * Removes specified slide. If this slide is active - will roll to another
- * slide
- * @param {?} slide
- * @return {?}
- */
- removeSlide(slide) {
- /** @type {?} */
- const remIndex = this._slides.indexOf(slide);
- if (this._currentActiveSlide === remIndex) {
- // removing of active slide
- /** @type {?} */
- let nextSlideIndex = void 0;
- if (this._slides.length > 1) {
- // if this slide last - will roll to first slide, if noWrap flag is
- // FALSE or to previous, if noWrap is TRUE in case, if this slide in
- // middle of collection, index of next slide is same to removed
- nextSlideIndex = !this.isLast(remIndex)
- ? remIndex
- : this.noWrap ? remIndex - 1 : 0;
- }
- this._slides.remove(remIndex);
- // prevents exception with changing some value after checking
- setTimeout((/**
- * @return {?}
- */
- () => {
- this._select(nextSlideIndex);
- }), 0);
- }
- else {
- this._slides.remove(remIndex);
- /** @type {?} */
- const currentSlideIndex = this.getCurrentSlideIndex();
- setTimeout((/**
- * @return {?}
- */
- () => {
- // after removing, need to actualize index of current active slide
- this._currentActiveSlide = currentSlideIndex;
- this.activeSlideChange.emit(this._currentActiveSlide);
- }), 0);
- }
- }
- /**
- * @param {?=} force
- * @return {?}
- */
- nextSlideFromInterval(force = false) {
- this.move(Direction.NEXT, force);
- }
- /**
- * Rolling to next slide
- * @param {?=} force
- * @return {?}
- */
- nextSlide(force = false) {
- if (this.isPlaying) {
- this.restartTimer();
- }
- this.move(Direction.NEXT, force);
- }
- /**
- * Rolling to previous slide
- * @param {?=} force
- * @return {?}
- */
- previousSlide(force = false) {
- if (this.isPlaying) {
- this.restartTimer();
- }
- this.move(Direction.PREV, force);
- }
- /**
- * @return {?}
- */
- getFirstVisibleIndex() {
- return this.slides.findIndex(this.getActive);
- }
- /**
- * @return {?}
- */
- getLastVisibleIndex() {
- return findLastIndex(this.slides, this.getActive);
- }
- /**
- * @param {?} direction
- * @param {?=} force
- * @return {?}
- */
- move(direction, force = false) {
- /** @type {?} */
- const firstVisibleIndex = this.getFirstVisibleIndex();
- /** @type {?} */
- const lastVisibleIndex = this.getLastVisibleIndex();
- if (this.noWrap) {
- if (direction === Direction.NEXT &&
- this.isLast(lastVisibleIndex) ||
- direction === Direction.PREV &&
- firstVisibleIndex === 0) {
- return;
- }
- }
- if (!this.multilist) {
- this.activeSlide = this.findNextSlideIndex(direction, force);
- }
- else {
- this.moveMultilist(direction);
- }
- }
- /**
- * Swith slides by enter, space and arrows keys
- * \@internal
- * @param {?} event
- * @return {?}
- */
- keydownPress(event) {
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 13 || event.key === 'Enter' || event.keyCode === 32 || event.key === 'Space') {
- this.nextSlide();
- event.preventDefault();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 37 || event.key === 'LeftArrow') {
- this.previousSlide();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 39 || event.key === 'RightArrow') {
- this.nextSlide();
- return;
- }
- }
- /**
- * Play on mouse leave
- * \@internal
- * @return {?}
- */
- onMouseLeave() {
- if (!this.pauseOnFocus) {
- this.play();
- }
- }
- /**
- * Play on mouse up
- * \@internal
- * @return {?}
- */
- onMouseUp() {
- if (!this.pauseOnFocus) {
- this.play();
- }
- }
- /**
- * When slides on focus autoplay is stopped(optional)
- * \@internal
- * @return {?}
- */
- pauseFocusIn() {
- if (this.pauseOnFocus) {
- this.isPlaying = false;
- this.resetTimer();
- }
- }
- /**
- * When slides out of focus autoplay is started
- * \@internal
- * @return {?}
- */
- pauseFocusOut() {
- this.play();
- }
- /**
- * Rolling to specified slide
- * @param {?} index
- * @return {?}
- */
- selectSlide(index) {
- if (this.isPlaying) {
- this.restartTimer();
- }
- if (!this.multilist) {
- this.activeSlide = this.indicatorsByChunk ? index * this.itemsPerSlide : index;
- }
- else {
- this.selectSlideRange(this.indicatorsByChunk ? index * this.itemsPerSlide : index);
- }
- }
- /**
- * Starts a auto changing of slides
- * @return {?}
- */
- play() {
- if (!this.isPlaying) {
- this.isPlaying = true;
- this.restartTimer();
- }
- }
- /**
- * Stops a auto changing of slides
- * @return {?}
- */
- pause() {
- if (!this.noPause) {
- this.isPlaying = false;
- this.resetTimer();
- }
- }
- /**
- * Finds and returns index of currently displayed slide
- * @return {?}
- */
- getCurrentSlideIndex() {
- return this._slides.findIndex(this.getActive);
- }
- /**
- * Defines, whether the specified index is last in collection
- * @param {?} index
- * @return {?}
- */
- isLast(index) {
- return index + 1 >= this._slides.length;
- }
- /**
- * Defines, whether the specified index is first in collection
- * @param {?} index
- * @return {?}
- */
- isFirst(index) {
- return index === 0;
- }
- /**
- * @return {?}
- */
- indicatorsSlides() {
- return this.slides.filter((/**
- * @param {?} slide
- * @param {?} index
- * @return {?}
- */
- (slide, index) => !this.indicatorsByChunk || index % this.itemsPerSlide === 0));
- }
- /**
- * @private
- * @return {?}
- */
- selectInitialSlides() {
- /** @type {?} */
- const startIndex = this.startFromIndex <= this._slides.length
- ? this.startFromIndex
- : 0;
- this.hideSlides();
- if (this.singleSlideOffset) {
- this._slidesWithIndexes = this.mapSlidesAndIndexes();
- if (this._slides.length - startIndex < this.itemsPerSlide) {
- /** @type {?} */
- const slidesToAppend = this._slidesWithIndexes.slice(0, startIndex);
- this._slidesWithIndexes = [
- ...this._slidesWithIndexes,
- ...slidesToAppend
- ]
- .slice(slidesToAppend.length)
- .slice(0, this.itemsPerSlide);
- }
- else {
- this._slidesWithIndexes = this._slidesWithIndexes.slice(startIndex, startIndex + this.itemsPerSlide);
- }
- this._slidesWithIndexes.forEach((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.item.active = true));
- this.makeSlidesConsistent(this._slidesWithIndexes);
- }
- else {
- this.selectRangeByNestedIndex(startIndex);
- }
- this.slideRangeChange.emit(this.getVisibleIndexes());
- }
- /**
- * Defines next slide index, depending of direction
- * @private
- * @param {?} direction
- * @param {?} force
- * @return {?}
- */
- findNextSlideIndex(direction, force) {
- /** @type {?} */
- let nextSlideIndex = 0;
- if (!force &&
- (this.isLast(this.activeSlide) &&
- direction !== Direction.PREV &&
- this.noWrap)) {
- return undefined;
- }
- switch (direction) {
- case Direction.NEXT:
- // if this is last slide, not force, looping is disabled
- // and need to going forward - select current slide, as a next
- nextSlideIndex = !this.isLast(this._currentActiveSlide)
- ? this._currentActiveSlide + 1
- : !force && this.noWrap ? this._currentActiveSlide : 0;
- break;
- case Direction.PREV:
- // if this is first slide, not force, looping is disabled
- // and need to going backward - select current slide, as a next
- nextSlideIndex =
- this._currentActiveSlide > 0
- ? this._currentActiveSlide - 1
- : !force && this.noWrap
- ? this._currentActiveSlide
- : this._slides.length - 1;
- break;
- default:
- throw new Error('Unknown direction');
- }
- return nextSlideIndex;
- }
- /**
- * @private
- * @return {?}
- */
- mapSlidesAndIndexes() {
- return this.slides
- .slice()
- .map((/**
- * @param {?} slide
- * @param {?} index
- * @return {?}
- */
- (slide, index) => {
- return {
- index,
- item: slide
- };
- }));
- }
- /**
- * @private
- * @param {?} index
- * @return {?}
- */
- selectSlideRange(index) {
- if (this.isIndexInRange(index)) {
- return;
- }
- this.hideSlides();
- if (!this.singleSlideOffset) {
- this.selectRangeByNestedIndex(index);
- }
- else {
- /** @type {?} */
- const startIndex = this.isIndexOnTheEdges(index)
- ? index
- : index - this.itemsPerSlide + 1;
- /** @type {?} */
- const endIndex = this.isIndexOnTheEdges(index)
- ? index + this.itemsPerSlide
- : index + 1;
- this._slidesWithIndexes = this.mapSlidesAndIndexes().slice(startIndex, endIndex);
- this.makeSlidesConsistent(this._slidesWithIndexes);
- this._slidesWithIndexes.forEach((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.item.active = true));
- }
- this.slideRangeChange.emit(this.getVisibleIndexes());
- }
- /**
- * @private
- * @param {?} index
- * @return {?}
- */
- selectRangeByNestedIndex(index) {
- /** @type {?} */
- const selectedRange = this._chunkedSlides
- .map((/**
- * @param {?} slidesList
- * @param {?} i
- * @return {?}
- */
- (slidesList, i) => {
- return {
- index: i,
- list: slidesList
- };
- }))
- .find((/**
- * @param {?} slidesList
- * @return {?}
- */
- (slidesList) => {
- return slidesList.list.find((/**
- * @param {?} slide
- * @return {?}
- */
- slide => slide.index === index)) !== undefined;
- }));
- this._currentVisibleSlidesIndex = selectedRange.index;
- this._chunkedSlides[selectedRange.index].forEach((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => {
- slide.item.active = true;
- }));
- }
- /**
- * @private
- * @param {?} index
- * @return {?}
- */
- isIndexOnTheEdges(index) {
- return (index + 1 - this.itemsPerSlide <= 0 ||
- index + this.itemsPerSlide <= this._slides.length);
- }
- /**
- * @private
- * @param {?} index
- * @return {?}
- */
- isIndexInRange(index) {
- if (this.singleSlideOffset) {
- /** @type {?} */
- const visibleIndexes = this._slidesWithIndexes.map((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.index));
- return visibleIndexes.indexOf(index) >= 0;
- }
- return (index <= this.getLastVisibleIndex() &&
- index >= this.getFirstVisibleIndex());
- }
- /**
- * @private
- * @return {?}
- */
- hideSlides() {
- this.slides.forEach((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.active = false));
- }
- /**
- * @private
- * @return {?}
- */
- isVisibleSlideListLast() {
- return this._currentVisibleSlidesIndex === this._chunkedSlides.length - 1;
- }
- /**
- * @private
- * @return {?}
- */
- isVisibleSlideListFirst() {
- return this._currentVisibleSlidesIndex === 0;
- }
- /**
- * @private
- * @param {?} direction
- * @return {?}
- */
- moveSliderByOneItem(direction) {
- /** @type {?} */
- let firstVisibleIndex;
- /** @type {?} */
- let lastVisibleIndex;
- /** @type {?} */
- let indexToHide;
- /** @type {?} */
- let indexToShow;
- if (this.noWrap) {
- firstVisibleIndex = this.getFirstVisibleIndex();
- lastVisibleIndex = this.getLastVisibleIndex();
- indexToHide = direction === Direction.NEXT
- ? firstVisibleIndex
- : lastVisibleIndex;
- indexToShow = direction !== Direction.NEXT
- ? firstVisibleIndex - 1
- : !this.isLast(lastVisibleIndex)
- ? lastVisibleIndex + 1 : 0;
- this._slides.get(indexToHide).active = false;
- this._slides.get(indexToShow).active = true;
- /** @type {?} */
- const slidesToReorder = this.mapSlidesAndIndexes().filter((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.item.active));
- this.makeSlidesConsistent(slidesToReorder);
- this.slideRangeChange.emit(this.getVisibleIndexes());
- }
- else {
- /** @type {?} */
- let displayedIndex;
- firstVisibleIndex = this._slidesWithIndexes[0].index;
- lastVisibleIndex = this._slidesWithIndexes[this._slidesWithIndexes.length - 1].index;
- if (direction === Direction.NEXT) {
- this._slidesWithIndexes.shift();
- displayedIndex = this.isLast(lastVisibleIndex)
- ? 0
- : lastVisibleIndex + 1;
- this._slidesWithIndexes.push({
- index: displayedIndex,
- item: this._slides.get(displayedIndex)
- });
- }
- else {
- this._slidesWithIndexes.pop();
- displayedIndex = this.isFirst(firstVisibleIndex)
- ? this._slides.length - 1
- : firstVisibleIndex - 1;
- this._slidesWithIndexes = [{
- index: displayedIndex,
- item: this._slides.get(displayedIndex)
- }, ...this._slidesWithIndexes];
- }
- this.hideSlides();
- this._slidesWithIndexes.forEach((/**
- * @param {?} slide
- * @return {?}
- */
- slide => slide.item.active = true));
- this.makeSlidesConsistent(this._slidesWithIndexes);
- this.slideRangeChange.emit(this._slidesWithIndexes.map((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.index)));
- }
- }
- /**
- * @private
- * @param {?} direction
- * @return {?}
- */
- moveMultilist(direction) {
- if (this.singleSlideOffset) {
- this.moveSliderByOneItem(direction);
- }
- else {
- this.hideSlides();
- if (this.noWrap) {
- this._currentVisibleSlidesIndex = direction === Direction.NEXT
- ? this._currentVisibleSlidesIndex + 1
- : this._currentVisibleSlidesIndex - 1;
- }
- else {
- if (direction === Direction.NEXT) {
- this._currentVisibleSlidesIndex = this.isVisibleSlideListLast()
- ? 0
- : this._currentVisibleSlidesIndex + 1;
- }
- else {
- this._currentVisibleSlidesIndex = this.isVisibleSlideListFirst()
- ? this._chunkedSlides.length - 1
- : this._currentVisibleSlidesIndex - 1;
- }
- }
- this._chunkedSlides[this._currentVisibleSlidesIndex].forEach((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.item.active = true));
- this.slideRangeChange.emit(this.getVisibleIndexes());
- }
- }
- /**
- * @private
- * @return {?}
- */
- getVisibleIndexes() {
- if (!this.singleSlideOffset) {
- return this._chunkedSlides[this._currentVisibleSlidesIndex]
- .map((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.index));
- }
- else {
- return this._slidesWithIndexes.map((/**
- * @param {?} slide
- * @return {?}
- */
- (slide) => slide.index));
- }
- }
- /**
- * Sets a slide, which specified through index, as active
- * @private
- * @param {?} index
- * @return {?}
- */
- _select(index) {
- if (isNaN(index)) {
- this.pause();
- return;
- }
- if (!this.multilist) {
- /** @type {?} */
- const currentSlide = this._slides.get(this._currentActiveSlide);
- if (currentSlide) {
- currentSlide.active = false;
- }
- }
- /** @type {?} */
- const nextSlide = this._slides.get(index);
- if (nextSlide) {
- this._currentActiveSlide = index;
- nextSlide.active = true;
- this.activeSlide = index;
- this.activeSlideChange.emit(index);
- }
- }
- /**
- * Starts loop of auto changing of slides
- * @private
- * @return {?}
- */
- restartTimer() {
- this.resetTimer();
- /** @type {?} */
- const interval = +this.interval;
- if (!isNaN(interval) && interval > 0) {
- this.currentInterval = this.ngZone.runOutsideAngular((/**
- * @return {?}
- */
- () => {
- return setInterval((/**
- * @return {?}
- */
- () => {
- /** @type {?} */
- const nInterval = +this.interval;
- this.ngZone.run((/**
- * @return {?}
- */
- () => {
- if (this.isPlaying &&
- !isNaN(this.interval) &&
- nInterval > 0 &&
- this.slides.length) {
- this.nextSlideFromInterval();
- }
- else {
- this.pause();
- }
- }));
- }), interval);
- }));
- }
- }
- /**
- * @return {?}
- */
- get multilist() {
- return this.itemsPerSlide > 1;
- }
- /**
- * Stops loop of auto changing of slides
- * @private
- * @return {?}
- */
- resetTimer() {
- if (this.currentInterval) {
- clearInterval(this.currentInterval);
- this.currentInterval = void 0;
- }
- }
- }
- CarouselComponent.decorators = [
- { type: Component, args: [{
- selector: 'carousel',
- 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"
- }] }
- ];
- /** @nocollapse */
- CarouselComponent.ctorParameters = () => [
- { type: CarouselConfig },
- { type: NgZone }
- ];
- CarouselComponent.propDecorators = {
- noWrap: [{ type: Input }],
- noPause: [{ type: Input }],
- showIndicators: [{ type: Input }],
- pauseOnFocus: [{ type: Input }],
- indicatorsByChunk: [{ type: Input }],
- itemsPerSlide: [{ type: Input }],
- singleSlideOffset: [{ type: Input }],
- activeSlideChange: [{ type: Output }],
- slideRangeChange: [{ type: Output }],
- activeSlide: [{ type: Input }],
- startFromIndex: [{ type: Input }],
- interval: [{ type: Input }]
- };
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- class SlideComponent {
- /**
- * @param {?} carousel
- */
- constructor(carousel) {
- this.itemWidth = '100%';
- this.order = 0;
- /**
- * Wraps element by appropriate CSS classes
- */
- this.addClass = true;
- this.carousel = carousel;
- }
- /**
- * Fires changes in container collection after adding a new slide instance
- * @return {?}
- */
- ngOnInit() {
- this.carousel.addSlide(this);
- this.itemWidth = `${100 / this.carousel.itemsPerSlide}%`;
- }
- /**
- * Fires changes in container collection after removing of this slide instance
- * @return {?}
- */
- ngOnDestroy() {
- this.carousel.removeSlide(this);
- }
- }
- SlideComponent.decorators = [
- { type: Component, args: [{
- selector: 'slide',
- template: `
- <div [class.active]="active" class="item">
- <ng-content></ng-content>
- </div>
- `,
- host: {
- '[attr.aria-hidden]': '!active'
- }
- }] }
- ];
- /** @nocollapse */
- SlideComponent.ctorParameters = () => [
- { type: CarouselComponent }
- ];
- SlideComponent.propDecorators = {
- active: [{ type: HostBinding, args: ['class.active',] }, { type: Input }],
- itemWidth: [{ type: HostBinding, args: ['style.width',] }],
- order: [{ type: HostBinding, args: ['style.order',] }],
- addClass: [{ type: HostBinding, args: ['class.item',] }, { type: HostBinding, args: ['class.carousel-item',] }]
- };
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- class CarouselModule {
- /**
- * @return {?}
- */
- static forRoot() {
- return { ngModule: CarouselModule, providers: [] };
- }
- }
- CarouselModule.decorators = [
- { type: NgModule, args: [{
- imports: [CommonModule],
- declarations: [SlideComponent, CarouselComponent],
- exports: [SlideComponent, CarouselComponent],
- providers: [CarouselConfig]
- },] }
- ];
- export { CarouselComponent, CarouselConfig, CarouselModule, SlideComponent };
- //# sourceMappingURL=ngx-bootstrap-carousel.js.map
|