104 lines
3.6 KiB
JavaScript
104 lines
3.6 KiB
JavaScript
import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, ChangeDetectorRef, Input, ContentChildren, ViewChild, NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { DomHandler } from 'primeng/dom';
|
|
import { PrimeTemplate } from 'primeng/api';
|
|
|
|
class BlockUI {
|
|
constructor(el, cd) {
|
|
this.el = el;
|
|
this.cd = cd;
|
|
this.autoZIndex = true;
|
|
this.baseZIndex = 0;
|
|
}
|
|
get blocked() {
|
|
return this._blocked;
|
|
}
|
|
set blocked(val) {
|
|
this._blocked = val;
|
|
if (this.mask && this.mask.nativeElement) {
|
|
if (this._blocked)
|
|
this.block();
|
|
else
|
|
this.unblock();
|
|
}
|
|
}
|
|
ngAfterViewInit() {
|
|
if (this.target && !this.target.getBlockableElement) {
|
|
throw 'Target of BlockUI must implement BlockableUI interface';
|
|
}
|
|
}
|
|
ngAfterContentInit() {
|
|
this.templates.forEach((item) => {
|
|
switch (item.getType()) {
|
|
case 'content':
|
|
this.contentTemplate = item.template;
|
|
break;
|
|
default:
|
|
this.contentTemplate = item.template;
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
block() {
|
|
if (this.target) {
|
|
this.target.getBlockableElement().appendChild(this.mask.nativeElement);
|
|
this.target.getBlockableElement().style.position = 'relative';
|
|
}
|
|
else {
|
|
document.body.appendChild(this.mask.nativeElement);
|
|
}
|
|
if (this.autoZIndex) {
|
|
this.mask.nativeElement.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex));
|
|
}
|
|
}
|
|
unblock() {
|
|
this.el.nativeElement.appendChild(this.mask.nativeElement);
|
|
}
|
|
ngOnDestroy() {
|
|
this.unblock();
|
|
}
|
|
}
|
|
BlockUI.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-blockUI',
|
|
template: `
|
|
<div #mask [class]="styleClass" [ngClass]="{'p-blockui-document':!target, 'p-blockui p-component-overlay': true}" [ngStyle]="{display: blocked ? 'flex' : 'none'}">
|
|
<ng-content></ng-content>
|
|
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
|
|
</div>
|
|
`,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None,
|
|
styles: [".p-blockui{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;background-color:rgba(0,0,0,0);display:-ms-flexbox;display:flex;height:100%;justify-content:center;left:0;top:0;transition-property:background-color;width:100%}.p-blockui,.p-blockui.p-component-overlay{position:absolute}.p-blockui-document.p-component-overlay{position:fixed}.p-blockui-leave.p-component-overlay{background-color:rgba(0,0,0,0)}"]
|
|
},] }
|
|
];
|
|
BlockUI.ctorParameters = () => [
|
|
{ type: ElementRef },
|
|
{ type: ChangeDetectorRef }
|
|
];
|
|
BlockUI.propDecorators = {
|
|
target: [{ type: Input }],
|
|
autoZIndex: [{ type: Input }],
|
|
baseZIndex: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
templates: [{ type: ContentChildren, args: [PrimeTemplate,] }],
|
|
mask: [{ type: ViewChild, args: ['mask',] }],
|
|
blocked: [{ type: Input }]
|
|
};
|
|
class BlockUIModule {
|
|
}
|
|
BlockUIModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule],
|
|
exports: [BlockUI],
|
|
declarations: [BlockUI]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { BlockUI, BlockUIModule };
|
|
//# sourceMappingURL=primeng-blockui.js.map
|