ngx-bootstrap-product-tour
Version:
Angular product tour using ngx-bootstrap popover
1,359 lines (1,325 loc) • 608 kB
JavaScript
import { ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, ContentChild, Directive, ElementRef, EventEmitter, Host, HostBinding, HostListener, Inject, Injectable, Injector, Input, NgModule, NgZone, Optional, Output, ReflectiveInjector, Renderer2, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ViewEncapsulation, forwardRef, isDevMode } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import { BehaviorSubject as BehaviorSubject$1 } from 'rxjs/BehaviorSubject';
import { Observable as Observable$1 } from 'rxjs/Observable';
import { distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs/operator/distinctUntilChanged';
import { map as map$2 } from 'rxjs/operator/map';
import { observeOn as observeOn$1 } from 'rxjs/operator/observeOn';
import { scan as scan$1 } from 'rxjs/operator/scan';
import { Subject as Subject$1 } from 'rxjs/Subject';
import 'rxjs/add/observable/timer';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/toArray';
import { mergeStatic } from 'rxjs/operator/merge';
import 'rxjs/add/operator/first';
import { NavigationStart, Router } from '@angular/router';
/**
* Configuration service for the Popover directive.
* You can inject this service, typically in your root component, and customize
* the values of its properties in order to provide default values for all the
* popovers used in the application.
*/
var PopoverConfig = (function () {
function PopoverConfig() {
/**
* Placement of a popover. Accepts: "top", "bottom", "left", "right", "auto"
*/
this.placement = 'top';
/**
* Specifies events that should trigger. Supports a space separated list of
* event names.
*/
this.triggers = 'click';
this.outsideClick = false;
}
PopoverConfig.decorators = [
{ type: Injectable },
];
/** @nocollapse */
PopoverConfig.ctorParameters = function () { return []; };
return PopoverConfig;
}());
/**
* @copyright Valor Software
* @copyright Angular ng-bootstrap team
*/
var Trigger = (function () {
function Trigger(open, close) {
this.open = open;
this.close = close || open;
}
Trigger.prototype.isManual = function () {
return this.open === 'manual' || this.close === 'manual';
};
return Trigger;
}());
var DEFAULT_ALIASES = {
hover: ['mouseover', 'mouseout'],
focus: ['focusin', 'focusout']
};
function parseTriggers(triggers, aliases) {
if (aliases === void 0) { aliases = DEFAULT_ALIASES; }
var trimmedTriggers = (triggers || '').trim();
if (trimmedTriggers.length === 0) {
return [];
}
var parsedTriggers = trimmedTriggers
.split(/\s+/)
.map(function (trigger) { return trigger.split(':'); })
.map(function (triggerPair) {
var alias = aliases[triggerPair[0]] || triggerPair;
return new Trigger(alias[0], alias[1]);
});
var manualTriggers = parsedTriggers.filter(function (triggerPair) {
return triggerPair.isManual();
});
if (manualTriggers.length > 1) {
throw new Error('Triggers parse error: only one manual trigger is allowed');
}
if (manualTriggers.length === 1 && parsedTriggers.length > 1) {
throw new Error('Triggers parse error: manual trigger can\'t be mixed with other triggers');
}
return parsedTriggers;
}
function listenToTriggersV2(renderer, options) {
var parsedTriggers = parseTriggers(options.triggers);
var target = options.target;
// do nothing
if (parsedTriggers.length === 1 && parsedTriggers[0].isManual()) {
return Function.prototype;
}
// all listeners
var listeners = [];
// lazy listeners registration
var _registerHide = [];
var registerHide = function () {
// add hide listeners to unregister array
_registerHide.forEach(function (fn) { return listeners.push(fn()); });
// register hide events only once
_registerHide.length = 0;
};
// register open\close\toggle listeners
parsedTriggers.forEach(function (trigger) {
var useToggle = trigger.open === trigger.close;
var showFn = useToggle ? options.toggle : options.show;
if (!useToggle) {
_registerHide.push(function () {
return renderer.listen(target, trigger.close, options.hide);
});
}
listeners.push(renderer.listen(target, trigger.open, function () { return showFn(registerHide); }));
});
return function () {
listeners.forEach(function (unsubscribeFn) { return unsubscribeFn(); });
};
}
function registerOutsideClick(renderer, options) {
if (!options.outsideClick) {
return Function.prototype;
}
return renderer.listen('document', 'click', function (event) {
if (options.target && options.target.contains(event.target)) {
return;
}
if (options.targets &&
options.targets.some(function (target) { return target.contains(event.target); })) {
return;
}
options.hide();
});
}
/**
* @copyright Valor Software
* @copyright Angular ng-bootstrap team
*/
var ContentRef = (function () {
function ContentRef(nodes, viewRef, componentRef) {
this.nodes = nodes;
this.viewRef = viewRef;
this.componentRef = componentRef;
}
return ContentRef;
}());
// tslint:disable:max-file-line-count
// todo: add delay support
// todo: merge events onShow, onShown, etc...
// todo: add global positioning configuration?
var ComponentLoader = (function () {
/**
* Do not use this directly, it should be instanced via
* `ComponentLoadFactory.attach`
* @internal
*/
// tslint:disable-next-line
function ComponentLoader(_viewContainerRef, _renderer, _elementRef, _injector, _componentFactoryResolver, _ngZone, _applicationRef, _posService) {
this._viewContainerRef = _viewContainerRef;
this._renderer = _renderer;
this._elementRef = _elementRef;
this._injector = _injector;
this._componentFactoryResolver = _componentFactoryResolver;
this._ngZone = _ngZone;
this._applicationRef = _applicationRef;
this._posService = _posService;
this.onBeforeShow = new EventEmitter();
this.onShown = new EventEmitter();
this.onBeforeHide = new EventEmitter();
this.onHidden = new EventEmitter();
this._providers = [];
this._isHiding = false;
this._listenOpts = {};
this._globalListener = Function.prototype;
}
Object.defineProperty(ComponentLoader.prototype, "isShown", {
get: function () {
if (this._isHiding) {
return false;
}
return !!this._componentRef;
},
enumerable: true,
configurable: true
});
ComponentLoader.prototype.attach = function (compType) {
this._componentFactory = this._componentFactoryResolver
.resolveComponentFactory(compType);
return this;
};
// todo: add behaviour: to target element, `body`, custom element
ComponentLoader.prototype.to = function (container) {
this.container = container || this.container;
return this;
};
ComponentLoader.prototype.position = function (opts) {
this.attachment = opts.attachment || this.attachment;
this._elementRef = opts.target || this._elementRef;
return this;
};
ComponentLoader.prototype.provide = function (provider) {
this._providers.push(provider);
return this;
};
// todo: appendChild to element or document.querySelector(this.container)
ComponentLoader.prototype.show = function (opts) {
if (opts === void 0) { opts = {}; }
this._subscribePositioning();
this._innerComponent = null;
if (!this._componentRef) {
this.onBeforeShow.emit();
this._contentRef = this._getContentRef(opts.content, opts.context, opts.initialState);
var injector = ReflectiveInjector.resolveAndCreate(this._providers, this._injector);
this._componentRef = this._componentFactory.create(injector, this._contentRef.nodes);
this._applicationRef.attachView(this._componentRef.hostView);
// this._componentRef = this._viewContainerRef
// .createComponent(this._componentFactory, 0, injector, this._contentRef.nodes);
this.instance = this._componentRef.instance;
Object.assign(this._componentRef.instance, opts);
if (this.container instanceof ElementRef) {
this.container.nativeElement.appendChild(this._componentRef.location.nativeElement);
}
if (this.container === 'body' && typeof document !== 'undefined') {
document
.querySelector(this.container)
.appendChild(this._componentRef.location.nativeElement);
}
if (!this.container &&
this._elementRef &&
this._elementRef.nativeElement.parentElement) {
this._elementRef.nativeElement.parentElement.appendChild(this._componentRef.location.nativeElement);
}
// we need to manually invoke change detection since events registered
// via
// Renderer::listen() are not picked up by change detection with the
// OnPush strategy
if (this._contentRef.componentRef) {
this._innerComponent = this._contentRef.componentRef.instance;
this._contentRef.componentRef.changeDetectorRef.markForCheck();
this._contentRef.componentRef.changeDetectorRef.detectChanges();
}
this._componentRef.changeDetectorRef.markForCheck();
this._componentRef.changeDetectorRef.detectChanges();
this.onShown.emit(this._componentRef.instance);
}
this._registerOutsideClick();
return this._componentRef;
};
ComponentLoader.prototype.hide = function () {
if (!this._componentRef) {
return this;
}
this.onBeforeHide.emit(this._componentRef.instance);
var componentEl = this._componentRef.location.nativeElement;
componentEl.parentNode.removeChild(componentEl);
if (this._contentRef.componentRef) {
this._contentRef.componentRef.destroy();
}
this._componentRef.destroy();
if (this._viewContainerRef && this._contentRef.viewRef) {
this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._contentRef.viewRef));
}
if (this._contentRef.viewRef) {
this._contentRef.viewRef.destroy();
}
// this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._componentRef.hostView));
//
// if (this._contentRef.viewRef && this._viewContainerRef.indexOf(this._contentRef.viewRef) !== -1) {
// this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._contentRef.viewRef));
// }
this._contentRef = null;
this._componentRef = null;
this._removeGlobalListener();
this.onHidden.emit();
return this;
};
ComponentLoader.prototype.toggle = function () {
if (this.isShown) {
this.hide();
return;
}
this.show();
};
ComponentLoader.prototype.dispose = function () {
if (this.isShown) {
this.hide();
}
this._unsubscribePositioning();
if (this._unregisterListenersFn) {
this._unregisterListenersFn();
}
};
ComponentLoader.prototype.listen = function (listenOpts) {
var _this = this;
this.triggers = listenOpts.triggers || this.triggers;
this._listenOpts.outsideClick = listenOpts.outsideClick;
listenOpts.target = listenOpts.target || this._elementRef.nativeElement;
var hide = (this._listenOpts.hide = function () {
return listenOpts.hide ? listenOpts.hide() : void _this.hide();
});
var show = (this._listenOpts.show = function (registerHide) {
listenOpts.show ? listenOpts.show(registerHide) : _this.show(registerHide);
registerHide();
});
var toggle = function (registerHide) {
_this.isShown ? hide() : show(registerHide);
};
this._unregisterListenersFn = listenToTriggersV2(this._renderer, {
target: listenOpts.target,
triggers: listenOpts.triggers,
show: show,
hide: hide,
toggle: toggle
});
return this;
};
ComponentLoader.prototype._removeGlobalListener = function () {
if (this._globalListener) {
this._globalListener();
this._globalListener = null;
}
};
ComponentLoader.prototype.attachInline = function (vRef, template) {
this._inlineViewRef = vRef.createEmbeddedView(template);
return this;
};
ComponentLoader.prototype._registerOutsideClick = function () {
var _this = this;
if (!this._componentRef || !this._componentRef.location) {
return;
}
// why: should run after first event bubble
if (this._listenOpts.outsideClick) {
var target_1 = this._componentRef.location.nativeElement;
setTimeout(function () {
_this._globalListener = registerOutsideClick(_this._renderer, {
targets: [target_1, _this._elementRef.nativeElement],
outsideClick: _this._listenOpts.outsideClick,
hide: function () { return _this._listenOpts.hide(); }
});
});
}
};
ComponentLoader.prototype.getInnerComponent = function () {
return this._innerComponent;
};
ComponentLoader.prototype._subscribePositioning = function () {
var _this = this;
if (this._zoneSubscription || !this.attachment) {
return;
}
this._zoneSubscription = this._ngZone.onStable.subscribe(function () {
if (!_this._componentRef) {
return;
}
_this._posService.position({
element: _this._componentRef.location,
target: _this._elementRef,
attachment: _this.attachment,
appendToBody: _this.container === 'body'
});
});
};
ComponentLoader.prototype._unsubscribePositioning = function () {
if (!this._zoneSubscription) {
return;
}
this._zoneSubscription.unsubscribe();
this._zoneSubscription = null;
};
ComponentLoader.prototype._getContentRef = function (content, context, initialState) {
if (!content) {
return new ContentRef([]);
}
if (content instanceof TemplateRef) {
if (this._viewContainerRef) {
var _viewRef = this._viewContainerRef
.createEmbeddedView(content, context);
_viewRef.markForCheck();
return new ContentRef([_viewRef.rootNodes], _viewRef);
}
var viewRef = content.createEmbeddedView({});
this._applicationRef.attachView(viewRef);
return new ContentRef([viewRef.rootNodes], viewRef);
}
if (typeof content === 'function') {
var contentCmptFactory = this._componentFactoryResolver.resolveComponentFactory(content);
var modalContentInjector = ReflectiveInjector.resolveAndCreate(this._providers.slice(), this._injector);
var componentRef = contentCmptFactory.create(modalContentInjector);
Object.assign(componentRef.instance, initialState);
this._applicationRef.attachView(componentRef.hostView);
return new ContentRef([[componentRef.location.nativeElement]], componentRef.hostView, componentRef);
}
return new ContentRef([[this._renderer.createText("" + content)]]);
};
return ComponentLoader;
}());
/**
* @copyright Valor Software
* @copyright Angular ng-bootstrap team
*/
// previous version:
// https://github.com/angular-ui/bootstrap/blob/07c31d0731f7cb068a1932b8e01d2312b796b4ec/src/position/position.js
// tslint:disable
var Positioning = (function () {
function Positioning() {
}
Positioning.prototype.position = function (element, round) {
if (round === void 0) { round = true; }
var elPosition;
var parentOffset = {
width: 0,
height: 0,
top: 0,
bottom: 0,
left: 0,
right: 0
};
if (this.getStyle(element, 'position') === 'fixed') {
var bcRect = element.getBoundingClientRect();
elPosition = {
width: bcRect.width,
height: bcRect.height,
top: bcRect.top,
bottom: bcRect.bottom,
left: bcRect.left,
right: bcRect.right
};
}
else {
var offsetParentEl = this.offsetParent(element);
elPosition = this.offset(element, false);
if (offsetParentEl !== document.documentElement) {
parentOffset = this.offset(offsetParentEl, false);
}
parentOffset.top += offsetParentEl.clientTop;
parentOffset.left += offsetParentEl.clientLeft;
}
elPosition.top -= parentOffset.top;
elPosition.bottom -= parentOffset.top;
elPosition.left -= parentOffset.left;
elPosition.right -= parentOffset.left;
if (round) {
elPosition.top = Math.round(elPosition.top);
elPosition.bottom = Math.round(elPosition.bottom);
elPosition.left = Math.round(elPosition.left);
elPosition.right = Math.round(elPosition.right);
}
return elPosition;
};
Positioning.prototype.offset = function (element, round) {
if (round === void 0) { round = true; }
var elBcr = element.getBoundingClientRect();
var viewportOffset = {
top: window.pageYOffset - document.documentElement.clientTop,
left: window.pageXOffset - document.documentElement.clientLeft
};
var elOffset = {
height: elBcr.height || element.offsetHeight,
width: elBcr.width || element.offsetWidth,
top: elBcr.top + viewportOffset.top,
bottom: elBcr.bottom + viewportOffset.top,
left: elBcr.left + viewportOffset.left,
right: elBcr.right + viewportOffset.left
};
if (round) {
elOffset.height = Math.round(elOffset.height);
elOffset.width = Math.round(elOffset.width);
elOffset.top = Math.round(elOffset.top);
elOffset.bottom = Math.round(elOffset.bottom);
elOffset.left = Math.round(elOffset.left);
elOffset.right = Math.round(elOffset.right);
}
return elOffset;
};
Positioning.prototype.positionElements = function (hostElement, targetElement, placement, appendToBody) {
var hostElPosition = appendToBody
? this.offset(hostElement, false)
: this.position(hostElement, false);
var targetElStyles = this.getAllStyles(targetElement);
var shiftWidth = {
left: hostElPosition.left,
center: hostElPosition.left +
hostElPosition.width / 2 -
targetElement.offsetWidth / 2,
right: hostElPosition.left + hostElPosition.width
};
var shiftHeight = {
top: hostElPosition.top,
center: hostElPosition.top +
hostElPosition.height / 2 -
targetElement.offsetHeight / 2,
bottom: hostElPosition.top + hostElPosition.height
};
var targetElBCR = targetElement.getBoundingClientRect();
var placementPrimary = placement.split(' ')[0] || 'top';
var placementSecondary = placement.split(' ')[1] || 'center';
var targetElPosition = {
height: targetElBCR.height || targetElement.offsetHeight,
width: targetElBCR.width || targetElement.offsetWidth,
top: 0,
bottom: targetElBCR.height || targetElement.offsetHeight,
left: 0,
right: targetElBCR.width || targetElement.offsetWidth
};
if (placementPrimary === 'auto') {
var newPlacementPrimary = this.autoPosition(targetElPosition, hostElPosition, targetElement, placementSecondary);
if (!newPlacementPrimary)
newPlacementPrimary = this.autoPosition(targetElPosition, hostElPosition, targetElement);
if (newPlacementPrimary)
placementPrimary = newPlacementPrimary;
targetElement.classList.add(placementPrimary);
}
switch (placementPrimary) {
case 'top':
targetElPosition.top =
hostElPosition.top -
(targetElement.offsetHeight +
parseFloat(targetElStyles.marginBottom));
targetElPosition.bottom +=
hostElPosition.top - targetElement.offsetHeight;
targetElPosition.left = shiftWidth[placementSecondary];
targetElPosition.right += shiftWidth[placementSecondary];
break;
case 'bottom':
targetElPosition.top = shiftHeight[placementPrimary];
targetElPosition.bottom += shiftHeight[placementPrimary];
targetElPosition.left = shiftWidth[placementSecondary];
targetElPosition.right += shiftWidth[placementSecondary];
break;
case 'left':
targetElPosition.top = shiftHeight[placementSecondary];
targetElPosition.bottom += shiftHeight[placementSecondary];
targetElPosition.left =
hostElPosition.left -
(targetElement.offsetWidth + parseFloat(targetElStyles.marginRight));
targetElPosition.right +=
hostElPosition.left - targetElement.offsetWidth;
break;
case 'right':
targetElPosition.top = shiftHeight[placementSecondary];
targetElPosition.bottom += shiftHeight[placementSecondary];
targetElPosition.left = shiftWidth[placementPrimary];
targetElPosition.right += shiftWidth[placementPrimary];
break;
}
targetElPosition.top = Math.round(targetElPosition.top);
targetElPosition.bottom = Math.round(targetElPosition.bottom);
targetElPosition.left = Math.round(targetElPosition.left);
targetElPosition.right = Math.round(targetElPosition.right);
return targetElPosition;
};
Positioning.prototype.autoPosition = function (targetElPosition, hostElPosition, targetElement, preferredPosition) {
if ((!preferredPosition || preferredPosition === 'right') &&
targetElPosition.left + hostElPosition.left - targetElement.offsetWidth <
0) {
return 'right';
}
else if ((!preferredPosition || preferredPosition === 'top') &&
targetElPosition.bottom +
hostElPosition.bottom +
targetElement.offsetHeight >
window.innerHeight) {
return 'top';
}
else if ((!preferredPosition || preferredPosition === 'bottom') &&
targetElPosition.top + hostElPosition.top - targetElement.offsetHeight < 0) {
return 'bottom';
}
else if ((!preferredPosition || preferredPosition === 'left') &&
targetElPosition.right +
hostElPosition.right +
targetElement.offsetWidth >
window.innerWidth) {
return 'left';
}
return null;
};
Positioning.prototype.getAllStyles = function (element) {
return window.getComputedStyle(element);
};
Positioning.prototype.getStyle = function (element, prop) {
return this.getAllStyles(element)[prop];
};
Positioning.prototype.isStaticPositioned = function (element) {
return (this.getStyle(element, 'position') || 'static') === 'static';
};
Positioning.prototype.offsetParent = function (element) {
var offsetParentEl = element.offsetParent || document.documentElement;
while (offsetParentEl &&
offsetParentEl !== document.documentElement &&
this.isStaticPositioned(offsetParentEl)) {
offsetParentEl = offsetParentEl.offsetParent;
}
return offsetParentEl || document.documentElement;
};
return Positioning;
}());
var positionService = new Positioning();
function positionElements(hostElement, targetElement, placement, appendToBody) {
var pos = positionService.positionElements(hostElement, targetElement, placement, appendToBody);
targetElement.style.top = pos.top + "px";
targetElement.style.left = pos.left + "px";
}
var PositioningService = (function () {
function PositioningService() {
}
PositioningService.prototype.position = function (options) {
var element = options.element, target = options.target, attachment = options.attachment, appendToBody = options.appendToBody;
positionElements(_getHtmlElement(target), _getHtmlElement(element), attachment, appendToBody);
};
PositioningService.decorators = [
{ type: Injectable },
];
/** @nocollapse */
PositioningService.ctorParameters = function () { return []; };
return PositioningService;
}());
function _getHtmlElement(element) {
// it means that we got a selector
if (typeof element === 'string') {
return document.querySelector(element);
}
if (element instanceof ElementRef) {
return element.nativeElement;
}
return element;
}
var ComponentLoaderFactory = (function () {
function ComponentLoaderFactory(_componentFactoryResolver, _ngZone, _injector, _posService, _applicationRef) {
this._componentFactoryResolver = _componentFactoryResolver;
this._ngZone = _ngZone;
this._injector = _injector;
this._posService = _posService;
this._applicationRef = _applicationRef;
}
/**
*
* @param _elementRef
* @param _viewContainerRef
* @param _renderer
* @returns {ComponentLoader}
*/
ComponentLoaderFactory.prototype.createLoader = function (_elementRef, _viewContainerRef, _renderer) {
return new ComponentLoader(_viewContainerRef, _renderer, _elementRef, this._injector, this._componentFactoryResolver, this._ngZone, this._applicationRef, this._posService);
};
ComponentLoaderFactory.decorators = [
{ type: Injectable },
];
/** @nocollapse */
ComponentLoaderFactory.ctorParameters = function () { return [
{ type: ComponentFactoryResolver, },
{ type: NgZone, },
{ type: Injector, },
{ type: PositioningService, },
{ type: ApplicationRef, },
]; };
return ComponentLoaderFactory;
}());
/*tslint:disable */
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* JS version of browser APIs. This library can only run in the browser.
*/
var win = (typeof window !== 'undefined' && window) || {};
var document$1 = win.document;
var location = win.location;
var gc = win['gc'] ? function () { return win['gc'](); } : function () { return null; };
var performance = win['performance'] ? win['performance'] : null;
var Event = win['Event'];
var MouseEvent = win['MouseEvent'];
var KeyboardEvent = win['KeyboardEvent'];
var EventTarget = win['EventTarget'];
var History = win['History'];
var Location = win['Location'];
var EventListener = win['EventListener'];
var guessedVersion;
function _guessBsVersion() {
if (typeof document === 'undefined') {
return null;
}
var spanEl = document.createElement('span');
spanEl.innerText = 'test bs version';
document.body.appendChild(spanEl);
spanEl.classList.add('d-none');
var rect = spanEl.getBoundingClientRect();
document.body.removeChild(spanEl);
if (!rect) {
return 'bs3';
}
return rect.top === 0 ? 'bs4' : 'bs3';
}
// todo: in ngx-bootstrap, bs4 will became a default one
function isBs3() {
if (typeof win === 'undefined') {
return true;
}
if (typeof win.__theme === 'undefined') {
if (guessedVersion) {
return guessedVersion === 'bs3';
}
guessedVersion = _guessBsVersion();
return guessedVersion === 'bs3';
}
return win.__theme !== 'bs4';
}
var PopoverContainerComponent = (function () {
function PopoverContainerComponent(config) {
Object.assign(this, config);
}
Object.defineProperty(PopoverContainerComponent.prototype, "isBs3", {
get: function () {
return isBs3();
},
enumerable: true,
configurable: true
});
PopoverContainerComponent.decorators = [
{ type: Component, args: [{
selector: 'popover-container',
changeDetection: ChangeDetectionStrategy.OnPush,
// tslint:disable-next-line
host: {
'[class]': '"popover in popover-" + placement + " " + "bs-popover-" + placement + " " + placement + " " + containerClass',
'[class.show]': '!isBs3',
role: 'tooltip',
style: 'display:block;'
},
styles: [
"\n :host.bs-popover-top .arrow, :host.bs-popover-bottom .arrow {\n left: 50%;\n margin-left: -8px;\n }\n :host.bs-popover-left .arrow, :host.bs-popover-right .arrow {\n top: 50%;\n margin-top: -8px;\n }\n "
],
template: "<div class=\"popover-arrow arrow\"></div> <h3 class=\"popover-title popover-header\" *ngIf=\"title\">{{ title }}</h3> <div class=\"popover-content popover-body\"> <ng-content></ng-content> </div> "
},] },
];
/** @nocollapse */
PopoverContainerComponent.ctorParameters = function () { return [
{ type: PopoverConfig, },
]; };
PopoverContainerComponent.propDecorators = {
'placement': [{ type: Input },],
'title': [{ type: Input },],
};
return PopoverContainerComponent;
}());
/**
* A lightweight, extensible directive for fancy popover creation.
*/
var PopoverDirective = (function () {
function PopoverDirective(_elementRef, _renderer, _viewContainerRef, _config, cis) {
/**
* Close popover on outside click
*/
this.outsideClick = false;
/**
* Css class for popover container
*/
this.containerClass = '';
this._isInited = false;
this._popover = cis
.createLoader(_elementRef, _viewContainerRef, _renderer)
.provide({ provide: PopoverConfig, useValue: _config });
Object.assign(this, _config);
this.onShown = this._popover.onShown;
this.onHidden = this._popover.onHidden;
// fix: no focus on button on Mac OS #1795
if (typeof window !== 'undefined') {
_elementRef.nativeElement.addEventListener('click', function () {
try {
_elementRef.nativeElement.focus();
}
catch (err) {
return;
}
});
}
}
Object.defineProperty(PopoverDirective.prototype, "isOpen", {
/**
* Returns whether or not the popover is currently being shown
*/
get: function () {
return this._popover.isShown;
},
set: function (value) {
if (value) {
this.show();
}
else {
this.hide();
}
},
enumerable: true,
configurable: true
});
/**
* Opens an element’s popover. This is considered a “manual” triggering of
* the popover.
*/
PopoverDirective.prototype.show = function () {
if (this._popover.isShown || !this.popover) {
return;
}
this._popover
.attach(PopoverContainerComponent)
.to(this.container)
.position({ attachment: this.placement })
.show({
content: this.popover,
context: this.popoverContext,
placement: this.placement,
title: this.popoverTitle,
containerClass: this.containerClass
});
this.isOpen = true;
};
/**
* Closes an element’s popover. This is considered a “manual” triggering of
* the popover.
*/
PopoverDirective.prototype.hide = function () {
if (this.isOpen) {
this._popover.hide();
this.isOpen = false;
}
};
/**
* Toggles an element’s popover. This is considered a “manual” triggering of
* the popover.
*/
PopoverDirective.prototype.toggle = function () {
if (this.isOpen) {
return this.hide();
}
this.show();
};
PopoverDirective.prototype.ngOnInit = function () {
var _this = this;
// fix: seems there are an issue with `routerLinkActive`
// which result in duplicated call ngOnInit without call to ngOnDestroy
// read more: https://github.com/valor-software/ngx-bootstrap/issues/1885
if (this._isInited) {
return;
}
this._isInited = true;
this._popover.listen({
triggers: this.triggers,
outsideClick: this.outsideClick,
show: function () { return _this.show(); }
});
};
PopoverDirective.prototype.ngOnDestroy = function () {
this._popover.dispose();
};
PopoverDirective.decorators = [
{ type: Directive, args: [{ selector: '[popover]', exportAs: 'bs-popover' },] },
];
/** @nocollapse */
PopoverDirective.ctorParameters = function () { return [
{ type: ElementRef, },
{ type: Renderer2, },
{ type: ViewContainerRef, },
{ type: PopoverConfig, },
{ type: ComponentLoaderFactory, },
]; };
PopoverDirective.propDecorators = {
'popover': [{ type: Input },],
'popoverContext': [{ type: Input },],
'popoverTitle': [{ type: Input },],
'placement': [{ type: Input },],
'outsideClick': [{ type: Input },],
'triggers': [{ type: Input },],
'container': [{ type: Input },],
'containerClass': [{ type: Input },],
'isOpen': [{ type: Input },],
'onShown': [{ type: Output },],
'onHidden': [{ type: Output },],
};
return PopoverDirective;
}());
var PopoverModule = (function () {
function PopoverModule() {
}
PopoverModule.forRoot = function () {
return {
ngModule: PopoverModule,
providers: [PopoverConfig, ComponentLoaderFactory, PositioningService]
};
};
PopoverModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule],
declarations: [PopoverDirective, PopoverContainerComponent],
exports: [PopoverDirective],
entryComponents: [PopoverContainerComponent]
},] },
];
/** @nocollapse */
PopoverModule.ctorParameters = function () { return []; };
return PopoverModule;
}());
function createUTCDate(y, m, d) {
var date = new Date(Date.UTC.apply(null, arguments));
// the Date.UTC function remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
date.setUTCFullYear(y);
}
return date;
}
function createDate(y, m, d, h, M, s, ms) {
if (m === void 0) { m = 0; }
if (d === void 0) { d = 1; }
if (h === void 0) { h = 0; }
if (M === void 0) { M = 0; }
if (s === void 0) { s = 0; }
if (ms === void 0) { ms = 0; }
var date = new Date(y, m, d, h, M, s, ms);
// the date constructor remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
date.setFullYear(y);
}
return date;
}
function zeroFill(num, targetLength, forceSign) {
var absNumber = "" + Math.abs(num);
var zerosToFill = targetLength - absNumber.length;
var sign = num >= 0;
var _sign = sign ? (forceSign ? '+' : '') : '-';
// todo: this is crazy slow
var _zeros = Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1);
return (_sign + _zeros + absNumber);
}
function mod(n, x) {
return (n % x + x) % x;
}
function absFloor(num) {
return num < 0 ? Math.ceil(num) || 0 : Math.floor(num);
}
function isString(str) {
return typeof str === 'string';
}
function isDate(value) {
return value instanceof Date || Object.prototype.toString.call(value) === '[object Date]';
}
function isDateValid(date) {
return date && date.getTime && !isNaN(date.getTime());
}
function isFunction(fn) {
return (fn instanceof Function ||
Object.prototype.toString.call(fn) === '[object Function]');
}
function isNumber(value) {
return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]';
}
function isArray(input) {
return (input instanceof Array ||
Object.prototype.toString.call(input) === '[object Array]');
}
function hasOwnProp(a /*object*/, b) {
return Object.prototype.hasOwnProperty.call(a, b);
}
function isObject(input /*object*/) {
// IE8 will treat undefined and null as object if it wasn't for
// input != null
return (input != null && Object.prototype.toString.call(input) === '[object Object]');
}
function isObjectEmpty(obj) {
if (Object.getOwnPropertyNames) {
return (Object.getOwnPropertyNames(obj).length === 0);
}
var k;
for (k in obj) {
if (obj.hasOwnProperty(k)) {
return false;
}
}
return true;
}
function isUndefined(input) {
return input === void 0;
}
function toInt(argumentForCoercion) {
var coercedNumber = +argumentForCoercion;
var value = 0;
if (coercedNumber !== 0 && isFinite(coercedNumber)) {
value = absFloor(coercedNumber);
}
return value;
}
var formatFunctions = {};
var formatTokenFunctions = {};
// tslint:disable-next-line
var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
// token: 'M'
// padded: ['MM', 2]
// ordinal: 'Mo'
// callback: function () { this.month() + 1 }
function addFormatToken(token, padded, ordinal, callback) {
if (token) {
formatTokenFunctions[token] = callback;
}
if (padded) {
formatTokenFunctions[padded[0]] = function () {
return zeroFill(callback.apply(null, arguments), padded[1], padded[2]);
};
}
if (ordinal) {
formatTokenFunctions[ordinal] = function (date, opts) {
return opts.locale.ordinal(callback.apply(null, arguments), token);
};
}
}
function makeFormatFunction(format) {
var array = format.match(formattingTokens);
var length = array.length;
var formatArr = new Array(length);
for (var i = 0; i < length; i++) {
formatArr[i] = formatTokenFunctions[array[i]]
? formatTokenFunctions[array[i]]
: removeFormattingTokens(array[i]);
}
return function (date, locale, isUTC, offset) {
if (offset === void 0) { offset = 0; }
var output = '';
for (var j = 0; j < length; j++) {
output += isFunction(formatArr[j])
? formatArr[j].call(null, date, { format: format, locale: locale, isUTC: isUTC, offset: offset })
: formatArr[j];
}
return output;
};
}
function removeFormattingTokens(input) {
if (input.match(/\[[\s\S]/)) {
return input.replace(/^\[|\]$/g, '');
}
return input.replace(/\\/g, '');
}
function getHours(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCHours() : date.getHours();
}
function getMinutes(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCMinutes() : date.getMinutes();
}
function getSeconds(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCSeconds() : date.getSeconds();
}
function getMilliseconds(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCMilliseconds() : date.getMilliseconds();
}
function getTime(date) {
return date.getTime();
}
function getDay(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCDay() : date.getDay();
}
function getDate(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCDate() : date.getDate();
}
function getMonth(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCMonth() : date.getMonth();
}
function getFullYear(date, isUTC) {
if (isUTC === void 0) { isUTC = false; }
return isUTC ? date.getUTCFullYear() : date.getFullYear();
}
function unix(date) {
return Math.floor(date.valueOf() / 1000);
}
function getFirstDayOfMonth(date) {
return createDate(date.getFullYear(), date.getMonth(), 1, date.getHours(), date.getMinutes(), date.getSeconds());
}
function isFirstDayOfWeek(date, firstDayOfWeek) {
return date.getDay() === firstDayOfWeek;
}
function isSameMonth(date1, date2) {
if (!date1 || !date2) {
return false;
}
return isSameYear(date1, date2) && getMonth(date1) === getMonth(date2);
}
function isSameYear(date1, date2) {
if (!date1 || !date2) {
return false;
}
return getFullYear(date1) === getFullYear(date2);
}
function isSameDay(date1, date2) {
if (!date1 || !date2) {
return false;
}
return (isSameYear(date1, date2) &&
isSameMonth(date1, date2) &&
getDate(date1) === getDate(date2));
}
var match1 = /\d/; // 0 - 9
var match2 = /\d\d/; // 00 - 99
var match3 = /\d{3}/; // 000 - 999
var match4 = /\d{4}/; // 0000 - 9999
var match6 = /[+-]?\d{6}/; // -999999 - 999999
var match1to2 = /\d\d?/; // 0 - 99
var match3to4 = /\d\d\d\d?/; // 999 - 9999
var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
var match1to3 = /\d{1,3}/; // 0 - 999
var match1to4 = /\d{1,4}/; // 0 - 9999
var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
var matchUnsigned = /\d+/; // 0 - inf
var matchSigned = /[+-]?\d+/; // -inf - inf
// +00:00 -00:00 +0000 -0000 or Z
var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
// any word (or two) characters or numbers including two/three word month in arabic.
// includes scottish gaelic two word and hyphenated months
// tslint:disable-next-line
var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;
var regexes = {};
function addRegexToken(token, regex, strictRegex) {
if (isFunction(regex)) {
regexes[token] = regex;
return;
}
regexes[token] = function (isStrict, locale) {
return (isStrict && strictRegex) ? strictRegex : regex;
};
}
function getParseRegexForToken(token, locale) {
var _strict = false;
if (!hasOwnProp(regexes, token)) {
return new RegExp(unescapeFormat(token));
}
return regexes[token](_strict, locale);
}
// Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
function unescapeFormat(str) {
// tslint:disable-next-line
return regexEscape(str
.replace('\\', '')
.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { return p1 || p2 || p3 || p4; }));
}
function regexEscape(str) {
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
// tslint:disable:max-line-length
var tokens = {};
function addParseToken(token, callback) {
var _token = isString(token) ? [token] : token;
var func = callback;
if (isNumber(callback)) {
func = function (input, array, config) {
array[callback] = toInt(input);
return config;
};
}
if (isArray(_token) && isFunction(func)) {
var i = void 0;
for (i = 0; i < _token.length; i++) {
tokens[_token[i]] = func;
}
}
}
function addWeekParseToken(token, callback) {
addParseToken(token, function (input, array, config, _token) {
config._w = config._w || {};
return callback(input, config._w, config, _token);
});
}
function addTimeToArrayFromToken(token, input, config) {
if (input != null && hasOwnProp(tokens, token)) {
tokens[token](input, config._a, config, token);
}
return config;
}
// place in new Date([array])
var YEAR = 0;
var MONTH = 1;
var DATE = 2;
var HOUR = 3;
var MINUTE = 4;
var SECOND = 5;
var MILLISECOND = 6;
var WEEK = 7;
var WEEKDAY = 8;
/*
export function getPrioritizedUnits(unitsObj) {
const units = [];
let unit;
for (unit in unitsObj) {
if (unitsObj.hasOwnProperty(unit)) {
units.push({ unit, priority: priorities[unit] });
}
}
units.sort(function (a, b) {
return a.priority - b.priority;
});
return units;
}
*/
var aliases = {};
var _mapUnits = {
date: 'day',
hour: 'hours',
minute: 'minutes',
second: 'seconds',
millisecond: 'milliseconds'
};
function addUnitAlias(unit, shorthand) {
var lowerCase = unit.toLowerCase();
var _unit = unit;
if (lowerCase in _mapUnits) {
_unit = _mapUnits[lowerCase];
}
aliases[lowerCase] = aliases[lowerCase + "s"] = aliases[shorthand] = _unit;
}
function normalizeUnits(units) {
return isString(units) ? aliases[units] || aliases[units.toLowerCase()] : undefined;
}
function normalizeObjectUnits(inputObject) {
var normalizedInput = {};
var normalizedProp;
var prop;
for (prop in inputObject) {
if (hasOwnProp(inputObject, prop)) {
normalizedProp = normalizeUnits(prop);
if (normalizedProp) {
normalizedInput[normalizedProp] = inputObject[prop];
}
}
}
return normalizedInput;
}
// FORMATTING
function getYear(date, opts) {
return getFullYear(date, opts.isUTC).toString();
}
addFormatToken('Y', null, null, function (date, opts) {
var y = getFullYear(date, opts.isUTC);
return y <= 9999 ? y.toString(10) : "+" + y;
});
addFormatToken(null, ['YY', 2, false], null, function (date, opts) {
return (getFullYear(date, opts.isUTC) % 100).toString(10);
});
addFormatToken(null, ['YYYY', 4, false], null, getYear);
addFormatToken(null, ['YYYYY', 5, false], null, getYear);
addFormatToken(null, ['YYYYYY', 6, true], null, getYear);
// ALIASES
addUnitAlias('year', 'y');
// PARSING
addRegexToken('Y', matchSigned);
addRegexToken('YY', match1to2, match2);
addRegexToken('YYYY', match1to4, match4);
addRegexToken('YYYYY', match1to6, match6);
addRegexToken('YYYYYY', match1to6, match6);
addParseToken(['YYYYY', 'YYYYYY'], YEAR);
addParseToken('YYYY', function (input, array, config) {
array[YEAR] = input.length === 2 ? parseTwoDigitYear(input) : toInt(input);
return config;
});
addParseToken('YY', function (input, array, config) {
array[YEAR] = parseTwoDigitYear(input);
return config;
});
addParseToken('Y', function (input, array, config) {
array[YEAR] = parseInt(input, 10);
return config;
});
function parseTwoDigitYear(input) {
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
}
function daysInYear(year) {
return isLeapYear(year) ? 366 : 365;
}
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}
function defaultParsingFlags() {
// We need to deep clone this object.
return {
empty: false,
unusedTokens: [],
unusedInput: [],
overflow: -2,
charsLeftOver: 0,
nullInput: false,
invalidMonth: null,
invalidFormat: false,
userInvalidated: false,
iso: false,
parsedDateParts: [],
meridiem: null,
rfc2822: false,
weekdayMismatch: false
};
}
function getParsingFlags(config) {
if (config._pf == null) {
config._pf = defaultParsingFlags();
}
return config._pf;
}
// todo: this is duplicate, source in date-getters.ts
function daysInMonth$1(year, month) {
if (isNaN(year) || isNaN(month)) {
return NaN;
}
var modMonth = mod(month, 12);
var _year = year + (month - modMonth) / 12;
return modMonth === 1
? isLeapYear(_year) ? 29 : 28
: (31 - modMonth % 7 % 2);
}
// FOR