Browse Source

feature(core): add new input visibility directive for no listen to dom

pull/1775/head
mehmet-erim 7 years ago
parent
commit
a5ce9559e5
  1. 55
      npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts
  2. 2
      npm/ng-packs/packages/theme-shared/package.json

55
npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts

@ -9,34 +9,49 @@ export class VisibilityDirective implements AfterViewInit {
@Input('abpVisibility')
focusedElement: HTMLElement;
@Input()
mutationObserverEnabled: boolean = true;
completed$ = new Subject<boolean>();
constructor(@Optional() private elRef: ElementRef, private renderer: Renderer2) {}
ngAfterViewInit() {
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (!mutation.target) return;
let observer: MutationObserver;
if (this.mutationObserverEnabled) {
observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (!mutation.target) return;
const htmlNodes = snq(
() => Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement),
[],
);
const htmlNodes = snq(
() => Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement),
[],
);
if (!htmlNodes.length) {
this.renderer.removeChild(this.elRef.nativeElement.parentElement, this.elRef.nativeElement);
this.disconnect();
} else {
setTimeout(() => {
if (!htmlNodes.length) {
this.removeFromDOM();
this.disconnect();
}, 0);
}
} else {
setTimeout(() => {
this.disconnect();
}, 0);
}
});
});
});
observer.observe(this.focusedElement, {
childList: true,
});
observer.observe(this.focusedElement, {
childList: true,
});
} else {
setTimeout(() => {
const htmlNodes = snq(
() => Array.from(this.focusedElement.childNodes).filter(node => node instanceof HTMLElement),
[],
);
if (!htmlNodes.length) this.removeFromDOM();
}, 0);
}
this.completed$.subscribe(() => observer.disconnect());
}
@ -45,4 +60,8 @@ export class VisibilityDirective implements AfterViewInit {
this.completed$.next();
this.completed$.complete();
}
removeFromDOM() {
this.renderer.removeChild(this.elRef.nativeElement.parentElement, this.elRef.nativeElement);
}
}

2
npm/ng-packs/packages/theme-shared/package.json

@ -5,7 +5,7 @@
"@abp/ng.core": "^0.8.3",
"@angular/cdk": "^8.0.1",
"@ng-bootstrap/ng-bootstrap": "^5.1.0",
"@ngx-validate/core": "^0.0.4",
"@ngx-validate/core": "^0.0.5",
"bootstrap": "^4.3.1",
"chart.js": "^2.8.0",
"font-awesome": "^4.7.0",

Loading…
Cancel
Save