mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
* build(webpack): replace babel-loader with esbuild-loader * build(webpack): add esbuild minifier to production builds * Wip * Removed ngInject and replaced with manual inject params * chore: bump esbuild to 0.15.13 * Fixed angular issues * build(frontend): update esbuild to 0.16.16 * chore(webpack): support browserslist for esbuild * build(esbuild): unify versions of esbuild to 0.16.17 and esbuild-loader to 2.21.0 Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
82 lines
1.7 KiB
TypeScript
82 lines
1.7 KiB
TypeScript
import { extend } from 'lodash';
|
|
// @ts-ignore
|
|
import Drop from 'tether-drop';
|
|
|
|
import { GrafanaRootScope } from 'app/angular/GrafanaCtrl';
|
|
import coreModule from 'app/angular/core_module';
|
|
|
|
coreModule.service('popoverSrv', ['$compile', '$rootScope', '$timeout', popoverSrv]);
|
|
|
|
function popoverSrv(this: any, $compile: any, $rootScope: GrafanaRootScope, $timeout: any) {
|
|
let openDrop: any = null;
|
|
|
|
this.close = () => {
|
|
if (openDrop) {
|
|
openDrop.close();
|
|
}
|
|
};
|
|
|
|
this.show = (options: any) => {
|
|
if (openDrop) {
|
|
openDrop.close();
|
|
openDrop = null;
|
|
}
|
|
|
|
const scope = extend($rootScope.$new(true), options.model);
|
|
let drop: any;
|
|
|
|
const cleanUp = () => {
|
|
setTimeout(() => {
|
|
scope.$destroy();
|
|
|
|
if (drop.tether) {
|
|
drop.destroy();
|
|
}
|
|
|
|
if (options.onClose) {
|
|
options.onClose();
|
|
}
|
|
});
|
|
|
|
openDrop = null;
|
|
};
|
|
|
|
scope.dismiss = () => {
|
|
drop.close();
|
|
};
|
|
|
|
const contentElement = document.createElement('div');
|
|
contentElement.innerHTML = options.template;
|
|
|
|
$compile(contentElement)(scope);
|
|
|
|
$timeout(() => {
|
|
drop = new Drop({
|
|
target: options.element,
|
|
content: contentElement,
|
|
position: options.position,
|
|
classes: options.classNames || 'drop-popover',
|
|
openOn: options.openOn,
|
|
hoverCloseDelay: 200,
|
|
tetherOptions: {
|
|
constraints: [{ to: 'scrollParent', attachment: 'together' }],
|
|
},
|
|
});
|
|
|
|
drop.on('close', () => {
|
|
cleanUp();
|
|
});
|
|
|
|
openDrop = drop;
|
|
openDrop.open();
|
|
}, 100);
|
|
|
|
// return close function
|
|
return () => {
|
|
if (drop) {
|
|
drop.close();
|
|
}
|
|
};
|
|
};
|
|
}
|