UNPKG

ngx-bootstrap-fix-datepicker

Version:
1,369 lines (1,343 loc) 60.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common')) : typeof define === 'function' && define.amd ? define('ngx-bootstrap/carousel', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common'], factory) : (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].carousel = {}), global.ng.core, global.utils, global.ng.common)); }(this, (function (exports, core, utils, common) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var CarouselConfig = /** @class */ (function () { function CarouselConfig() { /* 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: core.Injectable } ]; return CarouselConfig; }()); if (false) { /** @type {?} */ CarouselConfig.prototype.interval; /** @type {?} */ CarouselConfig.prototype.noPause; /** @type {?} */ CarouselConfig.prototype.noWrap; /** @type {?} */ CarouselConfig.prototype.showIndicators; /** @type {?} */ CarouselConfig.prototype.pauseOnFocus; /** @type {?} */ CarouselConfig.prototype.indicatorsByChunk; /** @type {?} */ CarouselConfig.prototype.itemsPerSlide; /** @type {?} */ CarouselConfig.prototype.singleSlideOffset; } /** * @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 {?} */ var 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 {?} */ var out = []; /** @type {?} */ var n = Math.ceil((array.length) / size); /** @type {?} */ var i = 0; while (i < n) { /** @type {?} */ var 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} */ var Direction = { UNKNOWN: 0, NEXT: 1, PREV: 2, }; Direction[Direction.UNKNOWN] = 'UNKNOWN'; Direction[Direction.NEXT] = 'NEXT'; Direction[Direction.PREV] = 'PREV'; /** * Base element to create carousel */ var CarouselComponent = /** @class */ (function () { function CarouselComponent(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; /** * Turn on/off animation. Animation doesn't work for multilist carousel */ this.isAnimated = false; /** * Will be emitted when active slide has been changed. Part of two-way-bindable [(activeSlide)] property */ this.activeSlideChange = new core.EventEmitter(false); /** * Will be emitted when active slides has been changed in multilist mode */ this.slideRangeChange = new core.EventEmitter(); /* Index to start display slides from it */ this.startFromIndex = 0; this._slides = new utils.LinkedList(); this._currentVisibleSlidesIndex = 0; this.destroyed = false; this.getActive = (/** * @param {?} slide * @return {?} */ function (slide) { return slide.active; }); this.makeSlidesConsistent = (/** * @param {?} slides * @return {?} */ function (slides) { slides.forEach((/** * @param {?} slide * @param {?} index * @return {?} */ function (slide, index) { return slide.item.order = index; })); }); Object.assign(this, config); } Object.defineProperty(CarouselComponent.prototype, "activeSlide", { get: /** * @return {?} */ function () { return this._currentActiveSlide; }, /** Index of currently displayed slide(started for 0) */ set: /** * Index of currently displayed slide(started for 0) * @param {?} index * @return {?} */ function (index) { if (this.multilist) { return; } if (this._slides.length && index !== this._currentActiveSlide) { this._select(index); } }, enumerable: true, configurable: true }); Object.defineProperty(CarouselComponent.prototype, "interval", { /** * Delay of item cycling in milliseconds. If false, carousel won't cycle * automatically. */ get: /** * Delay of item cycling in milliseconds. If false, carousel won't cycle * automatically. * @return {?} */ function () { return this._interval; }, set: /** * @param {?} value * @return {?} */ function (value) { this._interval = value; this.restartTimer(); }, enumerable: true, configurable: true }); Object.defineProperty(CarouselComponent.prototype, "slides", { get: /** * @return {?} */ function () { return this._slides.toArray(); }, enumerable: true, configurable: true }); Object.defineProperty(CarouselComponent.prototype, "isBs4", { get: /** * @return {?} */ function () { return !utils.isBs3(); }, enumerable: true, configurable: true }); /** * @return {?} */ CarouselComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; setTimeout((/** * @return {?} */ function () { if (_this.singleSlideOffset) { _this.indicatorsByChunk = false; } if (_this.multilist) { _this._chunkedSlides = chunkByNumber(_this.mapSlidesAndIndexes(), _this.itemsPerSlide); _this.selectInitialSlides(); } }), 0); }; /** * @return {?} */ CarouselComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroyed = true; }; /** * Adds new slide. If this slide is first in collection - set it as active * and starts auto changing * @param slide */ /** * Adds new slide. If this slide is first in collection - set it as active * and starts auto changing * @param {?} slide * @return {?} */ CarouselComponent.prototype.addSlide = /** * Adds new slide. If this slide is first in collection - set it as active * and starts auto changing * @param {?} slide * @return {?} */ function (slide) { this._slides.add(slide); if (this.multilist && this._slides.length <= this.itemsPerSlide) { slide.active = true; } if (!this.multilist && this.isAnimated) { slide.isAnimated = 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 */ /** * Removes specified slide. If this slide is active - will roll to another * slide * @param {?} slide * @return {?} */ CarouselComponent.prototype.removeSlide = /** * Removes specified slide. If this slide is active - will roll to another * slide * @param {?} slide * @return {?} */ function (slide) { var _this = this; /** @type {?} */ var remIndex = this._slides.indexOf(slide); if (this._currentActiveSlide === remIndex) { // removing of active slide /** @type {?} */ var nextSlideIndex_1 = 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_1 = !this.isLast(remIndex) ? remIndex : this.noWrap ? remIndex - 1 : 0; } this._slides.remove(remIndex); // prevents exception with changing some value after checking setTimeout((/** * @return {?} */ function () { _this._select(nextSlideIndex_1); }), 0); } else { this._slides.remove(remIndex); /** @type {?} */ var currentSlideIndex_1 = this.getCurrentSlideIndex(); setTimeout((/** * @return {?} */ function () { // after removing, need to actualize index of current active slide _this._currentActiveSlide = currentSlideIndex_1; _this.activeSlideChange.emit(_this._currentActiveSlide); }), 0); } }; /** * @param {?=} force * @return {?} */ CarouselComponent.prototype.nextSlideFromInterval = /** * @param {?=} force * @return {?} */ function (force) { if (force === void 0) { force = false; } this.move(Direction.NEXT, force); }; /** * Rolling to next slide * @param force: {boolean} if true - will ignore noWrap flag */ /** * Rolling to next slide * @param {?=} force * @return {?} */ CarouselComponent.prototype.nextSlide = /** * Rolling to next slide * @param {?=} force * @return {?} */ function (force) { if (force === void 0) { force = false; } if (this.isPlaying) { this.restartTimer(); } this.move(Direction.NEXT, force); }; /** * Rolling to previous slide * @param force: {boolean} if true - will ignore noWrap flag */ /** * Rolling to previous slide * @param {?=} force * @return {?} */ CarouselComponent.prototype.previousSlide = /** * Rolling to previous slide * @param {?=} force * @return {?} */ function (force) { if (force === void 0) { force = false; } if (this.isPlaying) { this.restartTimer(); } this.move(Direction.PREV, force); }; /** * @return {?} */ CarouselComponent.prototype.getFirstVisibleIndex = /** * @return {?} */ function () { return this.slides.findIndex(this.getActive); }; /** * @return {?} */ CarouselComponent.prototype.getLastVisibleIndex = /** * @return {?} */ function () { return findLastIndex(this.slides, this.getActive); }; /** * @param {?} direction * @param {?=} force * @return {?} */ CarouselComponent.prototype.move = /** * @param {?} direction * @param {?=} force * @return {?} */ function (direction, force) { if (force === void 0) { force = false; } /** @type {?} */ var firstVisibleIndex = this.getFirstVisibleIndex(); /** @type {?} */ var 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 */ /** * Swith slides by enter, space and arrows keys * \@internal * @param {?} event * @return {?} */ CarouselComponent.prototype.keydownPress = /** * Swith slides by enter, space and arrows keys * \@internal * @param {?} event * @return {?} */ function (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 */ /** * Play on mouse leave * \@internal * @return {?} */ CarouselComponent.prototype.onMouseLeave = /** * Play on mouse leave * \@internal * @return {?} */ function () { if (!this.pauseOnFocus) { this.play(); } }; /** * Play on mouse up * @internal */ /** * Play on mouse up * \@internal * @return {?} */ CarouselComponent.prototype.onMouseUp = /** * Play on mouse up * \@internal * @return {?} */ function () { if (!this.pauseOnFocus) { this.play(); } }; /** * When slides on focus autoplay is stopped(optional) * @internal */ /** * When slides on focus autoplay is stopped(optional) * \@internal * @return {?} */ CarouselComponent.prototype.pauseFocusIn = /** * When slides on focus autoplay is stopped(optional) * \@internal * @return {?} */ function () { if (this.pauseOnFocus) { this.isPlaying = false; this.resetTimer(); } }; /** * When slides out of focus autoplay is started * @internal */ /** * When slides out of focus autoplay is started * \@internal * @return {?} */ CarouselComponent.prototype.pauseFocusOut = /** * When slides out of focus autoplay is started * \@internal * @return {?} */ function () { this.play(); }; /** * Rolling to specified slide * @param index: {number} index of slide, which must be shown */ /** * Rolling to specified slide * @param {?} index * @return {?} */ CarouselComponent.prototype.selectSlide = /** * Rolling to specified slide * @param {?} index * @return {?} */ function (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 */ /** * Starts a auto changing of slides * @return {?} */ CarouselComponent.prototype.play = /** * Starts a auto changing of slides * @return {?} */ function () { if (!this.isPlaying) { this.isPlaying = true; this.restartTimer(); } }; /** * Stops a auto changing of slides */ /** * Stops a auto changing of slides * @return {?} */ CarouselComponent.prototype.pause = /** * Stops a auto changing of slides * @return {?} */ function () { if (!this.noPause) { this.isPlaying = false; this.resetTimer(); } }; /** * Finds and returns index of currently displayed slide */ /** * Finds and returns index of currently displayed slide * @return {?} */ CarouselComponent.prototype.getCurrentSlideIndex = /** * Finds and returns index of currently displayed slide * @return {?} */ function () { return this._slides.findIndex(this.getActive); }; /** * Defines, whether the specified index is last in collection * @param index */ /** * Defines, whether the specified index is last in collection * @param {?} index * @return {?} */ CarouselComponent.prototype.isLast = /** * Defines, whether the specified index is last in collection * @param {?} index * @return {?} */ function (index) { return index + 1 >= this._slides.length; }; /** * Defines, whether the specified index is first in collection * @param index */ /** * Defines, whether the specified index is first in collection * @param {?} index * @return {?} */ CarouselComponent.prototype.isFirst = /** * Defines, whether the specified index is first in collection * @param {?} index * @return {?} */ function (index) { return index === 0; }; /** * @return {?} */ CarouselComponent.prototype.indicatorsSlides = /** * @return {?} */ function () { var _this = this; return this.slides.filter((/** * @param {?} slide * @param {?} index * @return {?} */ function (slide, index) { return !_this.indicatorsByChunk || index % _this.itemsPerSlide === 0; })); }; /** * @private * @return {?} */ CarouselComponent.prototype.selectInitialSlides = /** * @private * @return {?} */ function () { /** @type {?} */ var 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 {?} */ var slidesToAppend = this._slidesWithIndexes.slice(0, startIndex); this._slidesWithIndexes = __spread(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 {?} */ function (slide) { return slide.item.active = true; })); this.makeSlidesConsistent(this._slidesWithIndexes); } else { this.selectRangeByNestedIndex(startIndex); } this.slideRangeChange.emit(this.getVisibleIndexes()); }; /** * Defines next slide index, depending of direction * @param direction: Direction(UNKNOWN|PREV|NEXT) * @param force: {boolean} if TRUE - will ignore noWrap flag, else will * return undefined if next slide require wrapping */ /** * Defines next slide index, depending of direction * @private * @param {?} direction * @param {?} force * @return {?} */ CarouselComponent.prototype.findNextSlideIndex = /** * Defines next slide index, depending of direction * @private * @param {?} direction * @param {?} force * @return {?} */ function (direction, force) { /** @type {?} */ var 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 {?} */ CarouselComponent.prototype.mapSlidesAndIndexes = /** * @private * @return {?} */ function () { return this.slides .slice() .map((/** * @param {?} slide * @param {?} index * @return {?} */ function (slide, index) { return { index: index, item: slide }; })); }; /** * @private * @param {?} index * @return {?} */ CarouselComponent.prototype.selectSlideRange = /** * @private * @param {?} index * @return {?} */ function (index) { if (this.isIndexInRange(index)) { return; } this.hideSlides(); if (!this.singleSlideOffset) { this.selectRangeByNestedIndex(index); } else { /** @type {?} */ var startIndex = this.isIndexOnTheEdges(index) ? index : index - this.itemsPerSlide + 1; /** @type {?} */ var 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 {?} */ function (slide) { return slide.item.active = true; })); } this.slideRangeChange.emit(this.getVisibleIndexes()); }; /** * @private * @param {?} index * @return {?} */ CarouselComponent.prototype.selectRangeByNestedIndex = /** * @private * @param {?} index * @return {?} */ function (index) { /** @type {?} */ var selectedRange = this._chunkedSlides .map((/** * @param {?} slidesList * @param {?} i * @return {?} */ function (slidesList, i) { return { index: i, list: slidesList }; })) .find((/** * @param {?} slidesList * @return {?} */ function (slidesList) { return slidesList.list.find((/** * @param {?} slide * @return {?} */ function (slide) { return slide.index === index; })) !== undefined; })); this._currentVisibleSlidesIndex = selectedRange.index; this._chunkedSlides[selectedRange.index].forEach((/** * @param {?} slide * @return {?} */ function (slide) { slide.item.active = true; })); }; /** * @private * @param {?} index * @return {?} */ CarouselComponent.prototype.isIndexOnTheEdges = /** * @private * @param {?} index * @return {?} */ function (index) { return (index + 1 - this.itemsPerSlide <= 0 || index + this.itemsPerSlide <= this._slides.length); }; /** * @private * @param {?} index * @return {?} */ CarouselComponent.prototype.isIndexInRange = /** * @private * @param {?} index * @return {?} */ function (index) { if (this.singleSlideOffset) { /** @type {?} */ var visibleIndexes = this._slidesWithIndexes.map((/** * @param {?} slide * @return {?} */ function (slide) { return slide.index; })); return visibleIndexes.indexOf(index) >= 0; } return (index <= this.getLastVisibleIndex() && index >= this.getFirstVisibleIndex()); }; /** * @private * @return {?} */ CarouselComponent.prototype.hideSlides = /** * @private * @return {?} */ function () { this.slides.forEach((/** * @param {?} slide * @return {?} */ function (slide) { return slide.active = false; })); }; /** * @private * @return {?} */ CarouselComponent.prototype.isVisibleSlideListLast = /** * @private * @return {?} */ function () { return this._currentVisibleSlidesIndex === this._chunkedSlides.length - 1; }; /** * @private * @return {?} */ CarouselComponent.prototype.isVisibleSlideListFirst = /** * @private * @return {?} */ function () { return this._currentVisibleSlidesIndex === 0; }; /** * @private * @param {?} direction * @return {?} */ CarouselComponent.prototype.moveSliderByOneItem = /** * @private * @param {?} direction * @return {?} */ function (direction) { /** @type {?} */ var firstVisibleIndex; /** @type {?} */ var lastVisibleIndex; /** @type {?} */ var indexToHide; /** @type {?} */ var 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 {?} */ var slidesToReorder = this.mapSlidesAndIndexes().filter((/** * @param {?} slide * @return {?} */ function (slide) { return slide.item.active; })); this.makeSlidesConsistent(slidesToReorder); this.slideRangeChange.emit(this.getVisibleIndexes()); } else { /** @type {?} */ var displayedIndex = void 0; 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 = __spread([{ index: displayedIndex, item: this._slides.get(displayedIndex) }], this._slidesWithIndexes); } this.hideSlides(); this._slidesWithIndexes.forEach((/** * @param {?} slide * @return {?} */ function (slide) { return slide.item.active = true; })); this.makeSlidesConsistent(this._slidesWithIndexes); this.slideRangeChange.emit(this._slidesWithIndexes.map((/** * @param {?} slide * @return {?} */ function (slide) { return slide.index; }))); } }; /** * @private * @param {?} direction * @return {?} */ CarouselComponent.prototype.moveMultilist = /** * @private * @param {?} direction * @return {?} */ function (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 {?} */ function (slide) { return slide.item.active = true; })); this.slideRangeChange.emit(this.getVisibleIndexes()); } }; /** * @private * @return {?} */ CarouselComponent.prototype.getVisibleIndexes = /** * @private * @return {?} */ function () { if (!this.singleSlideOffset) { return this._chunkedSlides[this._currentVisibleSlidesIndex] .map((/** * @param {?} slide * @return {?} */ function (slide) { return slide.index; })); } else { return this._slidesWithIndexes.map((/** * @param {?} slide * @return {?} */ function (slide) { return slide.index; })); } }; /** * Sets a slide, which specified through index, as active * @param index */ /** * Sets a slide, which specified through index, as active * @private * @param {?} index * @return {?} */ CarouselComponent.prototype._select = /** * Sets a slide, which specified through index, as active * @private * @param {?} index * @return {?} */ function (index) { if (isNaN(index)) { this.pause(); return; } if (!this.multilist) { /** @type {?} */ var currentSlide = this._slides.get(this._currentActiveSlide); if (currentSlide) { currentSlide.active = false; } } /** @type {?} */ var 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 */ /** * Starts loop of auto changing of slides * @private * @return {?} */ CarouselComponent.prototype.restartTimer = /** * Starts loop of auto changing of slides * @private * @return {?} */ function () { var _this = this; this.resetTimer(); /** @type {?} */ var interval = +this.interval; if (!isNaN(interval) && interval > 0) { this.currentInterval = this.ngZone.runOutsideAngular((/** * @return {?} */ function () { return setInterval((/** * @return {?} */ function () { /** @type {?} */ var nInterval = +_this.interval; _this.ngZone.run((/** * @return {?} */ function () { if (_this.isPlaying && !isNaN(_this.interval) && nInterval > 0 && _this.slides.length) { _this.nextSlideFromInterval(); } else { _this.pause(); } })); }), interval); })); } }; Object.defineProperty(CarouselCompo