ng-pick-datetime
Version:
Angular Date Time Picker
210 lines (209 loc) • 10.1 kB
JavaScript
var __decorate = (this && this.__decorate) || function (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Inject, Injectable, InjectionToken, Injector, Optional, SkipSelf, TemplateRef } from '@angular/core';
import { Location } from '@angular/common';
import { OwlDialogConfig } from './dialog-config.class';
import { OwlDialogRef } from './dialog-ref.class';
import { OwlDialogContainerComponent } from './dialog-container.component';
import { extendObject } from '../utils';
import { defer, Subject } from 'rxjs';
import { startWith } from 'rxjs/operators';
import { Overlay, OverlayConfig, OverlayContainer } from '@angular/cdk/overlay';
import { ComponentPortal, PortalInjector } from '@angular/cdk/portal';
export var OWL_DIALOG_DATA = new InjectionToken('OwlDialogData');
export var OWL_DIALOG_SCROLL_STRATEGY = new InjectionToken('owl-dialog-scroll-strategy');
export function OWL_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) {
return function () { return overlay.scrollStrategies.block(); };
}
export var OWL_DIALOG_SCROLL_STRATEGY_PROVIDER = {
provide: OWL_DIALOG_SCROLL_STRATEGY,
deps: [Overlay],
useFactory: OWL_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY,
};
export var OWL_DIALOG_DEFAULT_OPTIONS = new InjectionToken('owl-dialog-default-options');
var OwlDialogService = (function () {
function OwlDialogService(overlay, injector, location, scrollStrategy, defaultOptions, parentDialog, overlayContainer) {
var _this = this;
this.overlay = overlay;
this.injector = injector;
this.location = location;
this.scrollStrategy = scrollStrategy;
this.defaultOptions = defaultOptions;
this.parentDialog = parentDialog;
this.overlayContainer = overlayContainer;
this.ariaHiddenElements = new Map();
this._openDialogsAtThisLevel = [];
this._afterOpenAtThisLevel = new Subject();
this._afterAllClosedAtThisLevel = new Subject();
this.afterAllClosed = defer(function () { return _this._openDialogsAtThisLevel.length ?
_this._afterAllClosed :
_this._afterAllClosed.pipe(startWith(undefined)); });
if (!parentDialog && location) {
location.subscribe(function () { return _this.closeAll(); });
}
}
Object.defineProperty(OwlDialogService.prototype, "openDialogs", {
get: function () {
return this.parentDialog ? this.parentDialog.openDialogs : this._openDialogsAtThisLevel;
},
enumerable: true,
configurable: true
});
Object.defineProperty(OwlDialogService.prototype, "afterOpen", {
get: function () {
return this.parentDialog ? this.parentDialog.afterOpen : this._afterOpenAtThisLevel;
},
enumerable: true,
configurable: true
});
Object.defineProperty(OwlDialogService.prototype, "_afterAllClosed", {
get: function () {
var parent = this.parentDialog;
return parent ? parent._afterAllClosed : this._afterAllClosedAtThisLevel;
},
enumerable: true,
configurable: true
});
OwlDialogService.prototype.open = function (componentOrTemplateRef, config) {
var _this = this;
config = applyConfigDefaults(config, this.defaultOptions);
if (config.id && this.getDialogById(config.id)) {
throw Error("Dialog with id \"" + config.id + "\" exists already. The dialog id must be unique.");
}
var overlayRef = this.createOverlay(config);
var dialogContainer = this.attachDialogContainer(overlayRef, config);
var dialogRef = this.attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config);
if (!this.openDialogs.length) {
this.hideNonDialogContentFromAssistiveTechnology();
}
this.openDialogs.push(dialogRef);
dialogRef.afterClosed().subscribe(function () { return _this.removeOpenDialog(dialogRef); });
this.afterOpen.next(dialogRef);
return dialogRef;
};
OwlDialogService.prototype.closeAll = function () {
var i = this.openDialogs.length;
while (i--) {
this.openDialogs[i].close();
}
};
OwlDialogService.prototype.getDialogById = function (id) {
return this.openDialogs.find(function (dialog) { return dialog.id === id; });
};
OwlDialogService.prototype.attachDialogContent = function (componentOrTemplateRef, dialogContainer, overlayRef, config) {
var dialogRef = new OwlDialogRef(overlayRef, dialogContainer, config.id, this.location);
if (config.hasBackdrop) {
overlayRef.backdropClick().subscribe(function () {
if (!dialogRef.disableClose) {
dialogRef.close();
}
});
}
if (componentOrTemplateRef instanceof TemplateRef) {
}
else {
var injector = this.createInjector(config, dialogRef, dialogContainer);
var contentRef = dialogContainer.attachComponentPortal(new ComponentPortal(componentOrTemplateRef, undefined, injector));
dialogRef.componentInstance = contentRef.instance;
}
dialogRef
.updateSize(config.width, config.height)
.updatePosition(config.position);
return dialogRef;
};
OwlDialogService.prototype.createInjector = function (config, dialogRef, dialogContainer) {
var userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
var injectionTokens = new WeakMap();
injectionTokens.set(OwlDialogRef, dialogRef);
injectionTokens.set(OwlDialogContainerComponent, dialogContainer);
injectionTokens.set(OWL_DIALOG_DATA, config.data);
return new PortalInjector(userInjector || this.injector, injectionTokens);
};
OwlDialogService.prototype.createOverlay = function (config) {
var overlayConfig = this.getOverlayConfig(config);
return this.overlay.create(overlayConfig);
};
OwlDialogService.prototype.attachDialogContainer = function (overlayRef, config) {
var containerPortal = new ComponentPortal(OwlDialogContainerComponent, config.viewContainerRef);
var containerRef = overlayRef.attach(containerPortal);
containerRef.instance.setConfig(config);
return containerRef.instance;
};
OwlDialogService.prototype.getOverlayConfig = function (dialogConfig) {
var state = new OverlayConfig({
positionStrategy: this.overlay.position().global(),
scrollStrategy: dialogConfig.scrollStrategy || this.scrollStrategy(),
panelClass: dialogConfig.paneClass,
hasBackdrop: dialogConfig.hasBackdrop,
minWidth: dialogConfig.minWidth,
minHeight: dialogConfig.minHeight,
maxWidth: dialogConfig.maxWidth,
maxHeight: dialogConfig.maxHeight
});
if (dialogConfig.backdropClass) {
state.backdropClass = dialogConfig.backdropClass;
}
return state;
};
OwlDialogService.prototype.removeOpenDialog = function (dialogRef) {
var index = this._openDialogsAtThisLevel.indexOf(dialogRef);
if (index > -1) {
this.openDialogs.splice(index, 1);
if (!this.openDialogs.length) {
this.ariaHiddenElements.forEach(function (previousValue, element) {
if (previousValue) {
element.setAttribute('aria-hidden', previousValue);
}
else {
element.removeAttribute('aria-hidden');
}
});
this.ariaHiddenElements.clear();
this._afterAllClosed.next();
}
}
};
OwlDialogService.prototype.hideNonDialogContentFromAssistiveTechnology = function () {
var overlayContainer = this.overlayContainer.getContainerElement();
if (overlayContainer.parentElement) {
var siblings = overlayContainer.parentElement.children;
for (var i = siblings.length - 1; i > -1; i--) {
var sibling = siblings[i];
if (sibling !== overlayContainer &&
sibling.nodeName !== 'SCRIPT' &&
sibling.nodeName !== 'STYLE' &&
!sibling.hasAttribute('aria-live')) {
this.ariaHiddenElements.set(sibling, sibling.getAttribute('aria-hidden'));
sibling.setAttribute('aria-hidden', 'true');
}
}
}
};
OwlDialogService = __decorate([
Injectable(),
__param(2, Optional()),
__param(3, Inject(OWL_DIALOG_SCROLL_STRATEGY)),
__param(4, Optional()), __param(4, Inject(OWL_DIALOG_DEFAULT_OPTIONS)),
__param(5, Optional()), __param(5, SkipSelf()),
__metadata("design:paramtypes", [Overlay,
Injector,
Location, Function, OwlDialogConfig,
OwlDialogService,
OverlayContainer])
], OwlDialogService);
return OwlDialogService;
}());
export { OwlDialogService };
function applyConfigDefaults(config, defaultOptions) {
return extendObject(new OwlDialogConfig(), config, defaultOptions);
}