UNPKG

@progress/kendo-angular-map

Version:
103 lines (102 loc) 4.1 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, Input, TemplateRef, ViewChild } from '@angular/core'; import { PopupService } from '@progress/kendo-angular-popup'; import { LocalizationService } from '@progress/kendo-angular-l10n'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-popup"; import * as i2 from "@progress/kendo-angular-l10n"; const POSITION_MODE = 'absolute'; const COLLISION = { horizontal: "fit", vertical: "fit" }; /** * @hidden */ export class BaseTooltip { popupService; localizationService; animate = true; style = { position: 'relative' }; templateRef; popupRef = null; popupSettings; constructor(popupService, localizationService) { this.popupService = popupService; this.localizationService = localizationService; } get active() { return this.popupRef !== null; } show(e) { const offset = this.position(e.anchor); if (!this.popupRef) { this.popupRef = this.popupService.open(Object.assign({ offset: offset, popupAlign: { vertical: 'bottom', horizontal: 'center' }, animate: this.animate, content: this.templateRef, collision: COLLISION, positionMode: POSITION_MODE }, this.popupSettings)); if (this.localizationService.rtl) { this.popupRef.popupElement.setAttribute('dir', 'rtl'); } this.onInit(); } else { const popup = this.popupRef.popup.instance; popup.offset = offset; } } hide() { if (this.popupRef) { this.popupRef.close(); this.popupRef = null; } } onInit() { //calling on init } ngOnDestroy() { this.hide(); } position(offset) { if (!this.popupSettings || !this.popupSettings.appendTo) { return offset; } const appendTo = this.popupSettings.appendTo.element.nativeElement; const bbox = appendTo.getBoundingClientRect(); const { scrollLeft, scrollTop } = this.scrollOffset(appendTo); return { left: offset.left - bbox.left - scrollLeft, top: offset.top - bbox.top - scrollTop }; } scrollOffset(element) { if (!element) { return null; } let scrollLeft = element.scrollLeft; let scrollTop = element.scrollTop; let parent = element.parentElement; while (parent) { scrollLeft += parent.scrollLeft; scrollTop += parent.scrollTop; parent = parent.parentElement; } return { scrollLeft, scrollTop }; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseTooltip, deps: [{ token: i1.PopupService }, { token: i2.LocalizationService }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: BaseTooltip, inputs: { popupSettings: "popupSettings" }, viewQueries: [{ propertyName: "templateRef", first: true, predicate: ["content"], descendants: true, static: true }], ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseTooltip, decorators: [{ type: Directive }], ctorParameters: function () { return [{ type: i1.PopupService }, { type: i2.LocalizationService }]; }, propDecorators: { templateRef: [{ type: ViewChild, args: ['content', { static: true }] }], popupSettings: [{ type: Input }] } });