UNPKG

ngx-joyride

Version:

[![npm version](https://badge.fury.io/js/ngx-joyride.svg)](https://badge.fury.io/js/ngx-joyride) [![Build Status](https://travis-ci.org/tnicola/ngx-joyride.svg?branch=master)](https://travis-ci.org/tnicola/ngx-joyride) [![codecov](https://codecov.io/gh/

1,046 lines (1,033 loc) 105 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs'), require('@angular/router'), require('rxjs/operators')) : typeof define === 'function' && define.amd ? define('ngx-joyride', ['exports', '@angular/core', '@angular/common', 'rxjs', '@angular/router', 'rxjs/operators'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-joyride'] = {}, global.ng.core, global.ng.common, global.rxjs, global.ng.router, global.rxjs.operators)); }(this, (function (exports, core, common, rxjs, router, operators) { 'use strict'; var JoyrideStep = /** @class */ (function () { function JoyrideStep() { this.title = new rxjs.ReplaySubject(); this.text = new rxjs.ReplaySubject(); } return JoyrideStep; }()); var DEFAULT_THEME_COLOR = '#3b5560'; var STEP_DEFAULT_POSITION = 'bottom'; var DEFAULT_TIMEOUT_BETWEEN_STEPS = 1; var ObservableCustomTexts = /** @class */ (function () { function ObservableCustomTexts() { } return ObservableCustomTexts; }()); var DEFAULT_TEXTS = { prev: rxjs.of('prev'), next: rxjs.of('next'), done: rxjs.of('done'), close: rxjs.of(null) }; var JoyrideOptionsService = /** @class */ (function () { function JoyrideOptionsService() { this.themeColor = DEFAULT_THEME_COLOR; this.stepDefaultPosition = STEP_DEFAULT_POSITION; this.logsEnabled = false; this.showCounter = true; this.showPrevButton = true; this.stepsOrder = []; } JoyrideOptionsService.prototype.setOptions = function (options) { this.stepsOrder = options.steps; this.stepDefaultPosition = options.stepDefaultPosition ? options.stepDefaultPosition : this.stepDefaultPosition; this.logsEnabled = typeof options.logsEnabled !== 'undefined' ? options.logsEnabled : this.logsEnabled; this.showCounter = typeof options.showCounter !== 'undefined' ? options.showCounter : this.showCounter; this.showPrevButton = typeof options.showPrevButton !== 'undefined' ? options.showPrevButton : this.showPrevButton; this.themeColor = options.themeColor ? options.themeColor : this.themeColor; this.firstStep = options.startWith; this.waitingTime = typeof options.waitingTime !== 'undefined' ? options.waitingTime : DEFAULT_TIMEOUT_BETWEEN_STEPS; typeof options.customTexts !== 'undefined' ? this.setCustomText(options.customTexts) : this.setCustomText(DEFAULT_TEXTS); }; JoyrideOptionsService.prototype.getBackdropColor = function () { return this.hexToRgb(this.themeColor); }; JoyrideOptionsService.prototype.getThemeColor = function () { return this.themeColor; }; JoyrideOptionsService.prototype.getStepDefaultPosition = function () { return this.stepDefaultPosition; }; JoyrideOptionsService.prototype.getStepsOrder = function () { return this.stepsOrder; }; JoyrideOptionsService.prototype.getFirstStep = function () { return this.firstStep; }; JoyrideOptionsService.prototype.getWaitingTime = function () { return this.waitingTime; }; JoyrideOptionsService.prototype.areLogsEnabled = function () { return this.logsEnabled; }; JoyrideOptionsService.prototype.isCounterVisible = function () { return this.showCounter; }; JoyrideOptionsService.prototype.isPrevButtonVisible = function () { return this.showPrevButton; }; JoyrideOptionsService.prototype.getCustomTexts = function () { return this.customTexts; }; JoyrideOptionsService.prototype.setCustomText = function (texts) { var prev; var next; var done; var close; prev = texts.prev ? texts.prev : DEFAULT_TEXTS.prev; next = texts.next ? texts.next : DEFAULT_TEXTS.next; done = texts.done ? texts.done : DEFAULT_TEXTS.done; close = texts.close ? texts.close : DEFAULT_TEXTS.close; this.customTexts = { prev: this.toObservable(prev), next: this.toObservable(next), done: this.toObservable(done), close: this.toObservable(close) }; }; JoyrideOptionsService.prototype.toObservable = function (value) { return value instanceof rxjs.Observable ? value : rxjs.of(value); }; JoyrideOptionsService.prototype.hexToRgb = function (hex) { var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; hex = hex.replace(shorthandRegex, function (m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) : null; }; return JoyrideOptionsService; }()); JoyrideOptionsService.decorators = [ { type: core.Injectable } ]; var JOYRIDE = 'ngx-joyride:::'; var LoggerService = /** @class */ (function () { function LoggerService(optionService) { this.optionService = optionService; } LoggerService.prototype.debug = function (message, data) { if (data === void 0) { data = ""; } if (this.optionService.areLogsEnabled()) { console.debug(JOYRIDE + message, data); } }; LoggerService.prototype.info = function (message, data) { if (data === void 0) { data = ""; } if (this.optionService.areLogsEnabled()) { console.info(JOYRIDE + message, data); } }; LoggerService.prototype.warn = function (message, data) { if (data === void 0) { data = ""; } if (this.optionService.areLogsEnabled()) { console.warn(JOYRIDE + message, data); } }; LoggerService.prototype.error = function (message, data) { if (data === void 0) { data = ""; } if (this.optionService.areLogsEnabled()) { console.error(JOYRIDE + message, data); } }; return LoggerService; }()); LoggerService.decorators = [ { type: core.Injectable } ]; LoggerService.ctorParameters = function () { return [ { type: JoyrideOptionsService } ]; }; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 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 && Object.prototype.propertyIsEnumerable.call(s, p[i])) 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) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(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 }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } 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; } /** @deprecated */ function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** @deprecated */ function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } function __spreadArray(to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; } 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; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); } function __classPrivateFieldSet(receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; } var JoyrideError = /** @class */ (function (_super) { __extends(JoyrideError, _super); function JoyrideError(message) { var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, JoyrideError.prototype); return _this; } return JoyrideError; }(Error)); var JoyrideStepDoesNotExist = /** @class */ (function (_super) { __extends(JoyrideStepDoesNotExist, _super); function JoyrideStepDoesNotExist(message) { var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, JoyrideStepDoesNotExist.prototype); return _this; } return JoyrideStepDoesNotExist; }(Error)); var JoyrideStepOutOfRange = /** @class */ (function (_super) { __extends(JoyrideStepOutOfRange, _super); function JoyrideStepOutOfRange(message) { var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, JoyrideStepOutOfRange.prototype); return _this; } return JoyrideStepOutOfRange; }(Error)); var ROUTE_SEPARATOR = '@'; var Step = /** @class */ (function () { function Step() { } return Step; }()); (function (StepActionType) { StepActionType["NEXT"] = "NEXT"; StepActionType["PREV"] = "PREV"; })(exports.StepActionType || (exports.StepActionType = {})); var JoyrideStepsContainerService = /** @class */ (function () { function JoyrideStepsContainerService(stepOptions, logger) { this.stepOptions = stepOptions; this.logger = logger; this.tempSteps = []; this.currentStepIndex = -2; this.stepHasBeenModified = new rxjs.Subject(); } JoyrideStepsContainerService.prototype.getFirstStepIndex = function () { var firstStep = this.stepOptions.getFirstStep(); var stepIds = this.stepOptions.getStepsOrder(); var index = stepIds.indexOf(firstStep); if (index < 0) { index = 0; if (firstStep !== undefined) this.logger.warn("The step " + firstStep + " does not exist. Check in your step list if it's present."); } return index; }; JoyrideStepsContainerService.prototype.init = function () { var _this = this; this.logger.info('Initializing the steps array.'); this.steps = []; this.currentStepIndex = this.getFirstStepIndex() - 1; var stepIds = this.stepOptions.getStepsOrder(); stepIds.forEach(function (stepId) { return _this.steps.push({ id: stepId, step: null }); }); }; JoyrideStepsContainerService.prototype.addStep = function (stepToAdd) { var stepExist = this.tempSteps.filter(function (step) { return step.name === stepToAdd.name; }).length > 0; if (!stepExist) { this.logger.info("Adding step " + stepToAdd.name + " to the steps list."); this.tempSteps.push(stepToAdd); } else { var stepIndexToReplace = this.tempSteps.findIndex(function (step) { return step.name === stepToAdd.name; }); this.tempSteps[stepIndexToReplace] = stepToAdd; } }; JoyrideStepsContainerService.prototype.get = function (action) { if (action === exports.StepActionType.NEXT) this.currentStepIndex++; else this.currentStepIndex--; if (this.currentStepIndex < 0 || this.currentStepIndex >= this.steps.length) throw new JoyrideStepOutOfRange('The first or last step of the tour cannot be found!'); var stepName = this.getStepName(this.steps[this.currentStepIndex].id); var index = this.tempSteps.findIndex(function (step) { return step.name === stepName; }); var stepFound = this.tempSteps[index]; this.steps[this.currentStepIndex].step = stepFound; if (stepFound == null) { this.logger.warn("Step " + this.steps[this.currentStepIndex].id + " not found in the DOM. Check if it's hidden by *ngIf directive."); } return stepFound; }; JoyrideStepsContainerService.prototype.getStepRoute = function (action) { var stepID; if (action === exports.StepActionType.NEXT) { stepID = this.steps[this.currentStepIndex + 1] ? this.steps[this.currentStepIndex + 1].id : null; } else { stepID = this.steps[this.currentStepIndex - 1] ? this.steps[this.currentStepIndex - 1].id : null; } var stepRoute = stepID && stepID.includes(ROUTE_SEPARATOR) ? stepID.split(ROUTE_SEPARATOR)[1] : ''; return stepRoute; }; JoyrideStepsContainerService.prototype.updatePosition = function (stepName, position) { var index = this.getStepIndex(stepName); if (this.steps[index].step) { this.steps[index].step.position = position; this.stepHasBeenModified.next(this.steps[index].step); } else { this.logger.warn("Trying to modify the position of " + stepName + " to " + position + ". Step not found!Is this step located in a different route?"); } }; JoyrideStepsContainerService.prototype.getStepNumber = function (stepName) { return this.getStepIndex(stepName) + 1; }; JoyrideStepsContainerService.prototype.getStepsCount = function () { var stepsOrder = this.stepOptions.getStepsOrder(); return stepsOrder.length; }; JoyrideStepsContainerService.prototype.getStepIndex = function (stepName) { var index = this.steps .map(function (step) { return (step.id.includes(ROUTE_SEPARATOR) ? step.id.split(ROUTE_SEPARATOR)[0] : step.id); }) .findIndex(function (name) { return stepName === name; }); if (index === -1) throw new JoyrideError("The step with name: " + stepName + " does not exist in the step list."); return index; }; JoyrideStepsContainerService.prototype.getStepName = function (stepID) { var stepName = stepID && stepID.includes(ROUTE_SEPARATOR) ? stepID.split(ROUTE_SEPARATOR)[0] : stepID; return stepName; }; return JoyrideStepsContainerService; }()); JoyrideStepsContainerService.decorators = [ { type: core.Injectable } ]; JoyrideStepsContainerService.ctorParameters = function () { return [ { type: JoyrideOptionsService }, { type: LoggerService } ]; }; var DomRefService = /** @class */ (function () { function DomRefService(platformId) { this.platformId = platformId; this.fakeDocument = { body: {}, documentElement: {} }; this.fakeWindow = { document: this.fakeDocument, navigator: {} }; } DomRefService.prototype.getNativeWindow = function () { if (common.isPlatformBrowser(this.platformId)) return window; else return this.fakeWindow; }; DomRefService.prototype.getNativeDocument = function () { if (common.isPlatformBrowser(this.platformId)) return document; else return this.fakeDocument; }; return DomRefService; }()); DomRefService.decorators = [ { type: core.Injectable } ]; DomRefService.ctorParameters = function () { return [ { type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] } ]; }; var TemplatesService = /** @class */ (function () { function TemplatesService() { } TemplatesService.prototype.setPrevButton = function (template) { this._prevButton = template; }; TemplatesService.prototype.getPrevButton = function () { return this._prevButton; }; TemplatesService.prototype.setNextButton = function (template) { this._nextButton = template; }; TemplatesService.prototype.getNextButton = function () { return this._nextButton; }; TemplatesService.prototype.setDoneButton = function (template) { this._doneButton = template; }; TemplatesService.prototype.getDoneButton = function () { return this._doneButton; }; TemplatesService.prototype.setCounter = function (template) { this._counter = template; }; TemplatesService.prototype.getCounter = function () { return this._counter; }; return TemplatesService; }()); TemplatesService.decorators = [ { type: core.Injectable } ]; var NO_POSITION = 'NO_POSITION'; var JoyrideDirective = /** @class */ (function () { function JoyrideDirective(joyrideStepsContainer, viewContainerRef, domService, router, templateService, platformId) { this.joyrideStepsContainer = joyrideStepsContainer; this.viewContainerRef = viewContainerRef; this.domService = domService; this.router = router; this.templateService = templateService; this.platformId = platformId; this.stepPosition = NO_POSITION; this.prev = new core.EventEmitter(); this.next = new core.EventEmitter(); this.done = new core.EventEmitter(); this.subscriptions = []; this.windowRef = this.domService.getNativeWindow(); this.step = new JoyrideStep(); } JoyrideDirective.prototype.ngAfterViewInit = function () { if (!common.isPlatformBrowser(this.platformId)) return; if (this.prevTemplate) this.templateService.setPrevButton(this.prevTemplate); if (this.nextTemplate) this.templateService.setNextButton(this.nextTemplate); if (this.doneTemplate) this.templateService.setDoneButton(this.doneTemplate); if (this.counterTemplate) this.templateService.setCounter(this.counterTemplate); this.step.position = this.stepPosition; this.step.targetViewContainer = this.viewContainerRef; this.setAsyncFields(this.step); this.step.stepContent = this.stepContent; this.step.stepContentParams = this.stepContentParams; this.step.nextClicked = this.next; this.step.prevCliked = this.prev; this.step.tourDone = this.done; if (!this.name) throw new JoyrideError("All the steps should have the 'joyrideStep' property set with a custom name."); this.step.name = this.name; this.step.route = this.router.url.substr(0, 1) === '/' ? this.router.url.substr(1) : this.router.url; this.step.transformCssStyle = this.windowRef.getComputedStyle(this.viewContainerRef.element.nativeElement).transform; this.step.isElementOrAncestorFixed = this.isElementFixed(this.viewContainerRef.element) || this.isAncestorsFixed(this.viewContainerRef.element.nativeElement.parentElement); this.joyrideStepsContainer.addStep(this.step); }; JoyrideDirective.prototype.ngOnChanges = function (changes) { if (changes['title'] || changes['text']) { this.setAsyncFields(this.step); } }; JoyrideDirective.prototype.isElementFixed = function (element) { return this.windowRef.getComputedStyle(element.nativeElement).position === 'fixed'; }; JoyrideDirective.prototype.setAsyncFields = function (step) { if (this.title instanceof rxjs.Observable) { this.subscriptions.push(this.title.subscribe(function (title) { step.title.next(title); })); } else { step.title.next(this.title); } if (this.text instanceof rxjs.Observable) { this.subscriptions.push(this.text.subscribe(function (text) { step.text.next(text); })); } else { step.text.next(this.text); } }; JoyrideDirective.prototype.isAncestorsFixed = function (nativeElement) { if (!nativeElement || !nativeElement.parentElement) return false; var isElementFixed = this.windowRef.getComputedStyle(nativeElement.parentElement).position === 'fixed'; if (nativeElement.nodeName === 'BODY') { return isElementFixed; } if (isElementFixed) return true; else return this.isAncestorsFixed(nativeElement.parentElement); }; JoyrideDirective.prototype.ngOnDestroy = function () { this.subscriptions.forEach(function (sub) { sub.unsubscribe(); }); }; return JoyrideDirective; }()); JoyrideDirective.decorators = [ { type: core.Directive, args: [{ selector: 'joyrideStep, [joyrideStep]' },] } ]; JoyrideDirective.ctorParameters = function () { return [ { type: JoyrideStepsContainerService }, { type: core.ViewContainerRef }, { type: DomRefService }, { type: router.Router }, { type: TemplatesService }, { type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] } ]; }; JoyrideDirective.propDecorators = { name: [{ type: core.Input, args: ['joyrideStep',] }], nextStep: [{ type: core.Input }], title: [{ type: core.Input }], text: [{ type: core.Input }], stepPosition: [{ type: core.Input }], stepContent: [{ type: core.Input }], stepContentParams: [{ type: core.Input }], prevTemplate: [{ type: core.Input }], nextTemplate: [{ type: core.Input }], doneTemplate: [{ type: core.Input }], counterTemplate: [{ type: core.Input }], prev: [{ type: core.Output }], next: [{ type: core.Output }], done: [{ type: core.Output }] }; var DocumentService = /** @class */ (function () { function DocumentService(DOMService, platformId) { this.DOMService = DOMService; if (!common.isPlatformBrowser(platformId)) { return; } this.setDocumentHeight(); var doc = DOMService.getNativeDocument(); if (doc && !doc.elementsFromPoint) { // IE 11 - Edge browsers doc.elementsFromPoint = this.elementsFromPoint.bind(this); } } DocumentService.prototype.getElementFixedTop = function (elementRef) { return elementRef.nativeElement.getBoundingClientRect().top; }; DocumentService.prototype.getElementFixedLeft = function (elementRef) { return elementRef.nativeElement.getBoundingClientRect().left; }; DocumentService.prototype.getElementAbsoluteTop = function (elementRef) { var scrollOffsets = this.getScrollOffsets(); return (elementRef.nativeElement.getBoundingClientRect().top + scrollOffsets.y); }; DocumentService.prototype.getElementAbsoluteLeft = function (elementRef) { var scrollOffsets = this.getScrollOffsets(); return (elementRef.nativeElement.getBoundingClientRect().left + scrollOffsets.x); }; DocumentService.prototype.setDocumentHeight = function () { this.documentHeight = this.calculateDocumentHeight(); }; DocumentService.prototype.getDocumentHeight = function () { return this.documentHeight; }; DocumentService.prototype.isParentScrollable = function (elementRef) { return (this.getFirstScrollableParent(elementRef.nativeElement) !== this.DOMService.getNativeDocument().body); }; DocumentService.prototype.isElementBeyondOthers = function (elementRef, isElementFixed, keywordToDiscard) { var x1 = isElementFixed ? this.getElementFixedLeft(elementRef) : this.getElementAbsoluteLeft(elementRef); var y1 = isElementFixed ? this.getElementFixedTop(elementRef) : this.getElementAbsoluteTop(elementRef); var x2 = x1 + elementRef.nativeElement.getBoundingClientRect().width - 1; var y2 = y1 + elementRef.nativeElement.getBoundingClientRect().height - 1; var elements1 = this.DOMService.getNativeDocument().elementsFromPoint(x1, y1); var elements2 = this.DOMService.getNativeDocument().elementsFromPoint(x2, y2); if (elements1.length === 0 && elements2.length === 0) return 1; if (this.getFirstElementWithoutKeyword(elements1, keywordToDiscard) !== elementRef.nativeElement || this.getFirstElementWithoutKeyword(elements2, keywordToDiscard) !== elementRef.nativeElement) { return 2; } return 3; }; DocumentService.prototype.scrollIntoView = function (elementRef, isElementFixed) { var firstScrollableParent = this.getFirstScrollableParent(elementRef.nativeElement); var top = isElementFixed ? this.getElementFixedTop(elementRef) : this.getElementAbsoluteTop(elementRef); if (firstScrollableParent !== this.DOMService.getNativeDocument().body) { if (firstScrollableParent.scrollTo) { firstScrollableParent.scrollTo(0, top - 150); } else { // IE 11 - Edge browsers firstScrollableParent.scrollTop = top - 150; } } else { this.DOMService.getNativeWindow().scrollTo(0, top - 150); } }; DocumentService.prototype.scrollToTheTop = function (elementRef) { var firstScrollableParent = this.getFirstScrollableParent(elementRef.nativeElement); if (firstScrollableParent !== this.DOMService.getNativeDocument().body) { if (firstScrollableParent.scrollTo) { firstScrollableParent.scrollTo(0, 0); } else { // IE 11 - Edge browsers firstScrollableParent.scrollTop = 0; } } else { this.DOMService.getNativeWindow().scrollTo(0, 0); } }; DocumentService.prototype.scrollToTheBottom = function (elementRef) { var firstScrollableParent = this.getFirstScrollableParent(elementRef.nativeElement); if (firstScrollableParent !== this.DOMService.getNativeDocument().body) { if (firstScrollableParent.scrollTo) { firstScrollableParent.scrollTo(0, this.DOMService.getNativeDocument().body.scrollHeight); } else { // IE 11 - Edge browsers firstScrollableParent.scrollTop = firstScrollableParent.scrollHeight - firstScrollableParent.clientHeight; } } else { this.DOMService.getNativeWindow().scrollTo(0, this.DOMService.getNativeDocument().body.scrollHeight); } }; DocumentService.prototype.getFirstScrollableParent = function (node) { var _this = this; var regex = /(auto|scroll|overlay)/; var style = function (node, prop) { return _this.DOMService.getNativeWindow() .getComputedStyle(node, null) .getPropertyValue(prop); }; var scroll = function (node) { return regex.test(style(node, 'overflow') + style(node, 'overflow-y') + style(node, 'overflow-x')); }; var scrollparent = function (node) { return !node || node === _this.DOMService.getNativeDocument().body ? _this.DOMService.getNativeDocument().body : scroll(node) ? node : scrollparent(node.parentNode); }; return scrollparent(node); }; DocumentService.prototype.calculateDocumentHeight = function () { var documentRef = this.DOMService.getNativeDocument(); return Math.max(documentRef.body.scrollHeight, documentRef.documentElement.scrollHeight, documentRef.body.offsetHeight, documentRef.documentElement.offsetHeight, documentRef.body.clientHeight, documentRef.documentElement.clientHeight); }; DocumentService.prototype.getScrollOffsets = function () { var winReference = this.DOMService.getNativeWindow(); var docReference = this.DOMService.getNativeDocument(); // This works for all browsers except IE versions 8 and before if (winReference.pageXOffset != null) return { x: winReference.pageXOffset, y: winReference.pageYOffset }; // For IE (or any browser) in Standards mode if (docReference.compatMode == 'CSS1Compat') return { x: docReference.documentElement.scrollLeft, y: docReference.documentElement.scrollTop }; // For browsers in Quirks mode return { x: docReference.body.scrollLeft, y: docReference.body.scrollTop }; }; DocumentService.prototype.elementsFromPoint = function (x, y) { var parents = []; var parent = void 0; do { var elem = this.DOMService.getNativeDocument().elementFromPoint(x, y); if (elem && parent !== elem) { parent = elem; parents.push(parent); parent.style.pointerEvents = 'none'; } else { parent = false; } } while (parent); parents.forEach(function (parent) { return (parent.style.pointerEvents = 'all'); }); return parents; }; DocumentService.prototype.getFirstElementWithoutKeyword = function (elements, keyword) { while (elements[0] && elements[0].classList.toString().includes(keyword)) { elements.shift(); } return elements[0]; }; return DocumentService; }()); DocumentService.decorators = [ { type: core.Injectable } ]; DocumentService.ctorParameters = function () { return [ { type: DomRefService }, { type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] } ]; }; var JoyrideBackdropService = /** @class */ (function () { function JoyrideBackdropService(documentService, optionsService, rendererFactory) { this.documentService = documentService; this.optionsService = optionsService; this.rendererFactory = rendererFactory; this.lastXScroll = 0; this.lastYScroll = 0; this.setRenderer(); } JoyrideBackdropService.prototype.setRenderer = function () { this.renderer = this.rendererFactory.createRenderer(null, null); }; JoyrideBackdropService.prototype.draw = function (step) { this.elementRef = step.targetViewContainer; this.targetAbsoluteTop = this.getTargetTotalTop(step); this.targetAbsoluteLeft = this.getTargetTotalLeft(step); this.currentBackdropContainer = this.renderer.createElement('div'); this.renderer.addClass(this.currentBackdropContainer, 'backdrop-container'); this.renderer.setStyle(this.currentBackdropContainer, 'position', 'fixed'); this.renderer.setStyle(this.currentBackdropContainer, 'top', '0px'); this.renderer.setStyle(this.currentBackdropContainer, 'left', '0px'); this.renderer.setStyle(this.currentBackdropContainer, 'width', '100%'); this.renderer.setStyle(this.currentBackdropContainer, 'height', '100%'); this.renderer.setStyle(this.currentBackdropContainer, 'z-index', '1000'); this.renderer.setAttribute(this.currentBackdropContainer, 'id', 'backdrop-' + step.name); this.backdropContent = this.renderer.createElement('div'); this.renderer.addClass(this.backdropContent, 'backdrop-content'); this.renderer.setStyle(this.backdropContent, 'position', 'relative'); this.renderer.setStyle(this.backdropContent, 'height', '100%'); this.renderer.setStyle(this.backdropContent, 'display', 'flex'); this.renderer.setStyle(this.backdropContent, 'flex-direction', 'column'); this.renderer.appendChild(this.currentBackdropContainer, this.backdropContent); this.backdropTop = this.renderer.createElement('div'); this.renderer.addClass(this.backdropTop, 'joyride-backdrop'); this.renderer.addClass(this.backdropTop, 'backdrop-top'); this.renderer.setStyle(this.backdropTop, 'width', '100%'); this.renderer.setStyle(this.backdropTop, 'height', this.targetAbsoluteTop - this.lastYScroll + 'px'); this.renderer.setStyle(this.backdropTop, 'flex-shrink', '0'); this.renderer.setStyle(this.backdropTop, 'background-color', "rgba(" + this.optionsService.getBackdropColor() + ", 0.7)"); this.renderer.appendChild(this.backdropContent, this.backdropTop); this.backdropMiddleContainer = this.renderer.createElement('div'); this.renderer.addClass(this.backdropMiddleContainer, 'backdrop-middle-container'); this.renderer.setStyle(this.backdropMiddleContainer, 'height', this.elementRef.element.nativeElement.offsetHeight + 'px'); this.renderer.setStyle(this.backdropMiddleContainer, 'width', '100%'); this.renderer.setStyle(this.backdropMiddleContainer, 'flex-shrink', '0'); this.renderer.appendChild(this.backdropContent, this.backdropMiddleContainer); this.backdropMiddleContent = this.renderer.createElement('div'); this.renderer.addClass(this.backdropMiddleContent, 'backdrop-middle-content'); this.renderer.setStyle(this.backdropMiddleContent, 'display', 'flex'); this.renderer.setStyle(this.backdropMiddleContent, 'width', '100%'); this.renderer.setStyle(this.backdropMiddleContent, 'height', '100%'); this.renderer.appendChild(this.backdropMiddleContainer, this.backdropMiddleContent); this.leftBackdrop = this.renderer.createElement('div'); this.renderer.addClass(this.leftBackdrop, 'joyride-backdrop'); this.renderer.addClass(this.leftBackdrop, 'backdrop-left'); this.renderer.setStyle