|
@@ -7,41 +7,49 @@ import coreModule from 'app/core/core_module';
|
|
|
import Drop from 'tether-drop';
|
|
import Drop from 'tether-drop';
|
|
|
|
|
|
|
|
/** @ngInject **/
|
|
/** @ngInject **/
|
|
|
-function popoverSrv($compile, $rootScope) {
|
|
|
|
|
|
|
+function popoverSrv($compile, $rootScope, $timeout) {
|
|
|
|
|
+ let openDrop = null;
|
|
|
|
|
+
|
|
|
|
|
+ this.close = function() {
|
|
|
|
|
+ if (openDrop) {
|
|
|
|
|
+ openDrop.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
this.show = function(options) {
|
|
this.show = function(options) {
|
|
|
- var classNames = 'drop-popover';
|
|
|
|
|
- var popoverScope = _.extend($rootScope.$new(true), options.model);
|
|
|
|
|
|
|
+ if (openDrop) {
|
|
|
|
|
+ openDrop.close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var scope = _.extend($rootScope.$new(true), options.model);
|
|
|
var drop;
|
|
var drop;
|
|
|
|
|
|
|
|
- if (options.classNames) {
|
|
|
|
|
- classNames = options.classNames;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var cleanUp = () => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ scope.$destroy();
|
|
|
|
|
+ drop.destroy();
|
|
|
|
|
|
|
|
- function destroyDrop() {
|
|
|
|
|
- setTimeout(function() {
|
|
|
|
|
- if (drop.tether) {
|
|
|
|
|
- drop.destroy();
|
|
|
|
|
|
|
+ if (options.onClose) {
|
|
|
|
|
+ options.onClose();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- popoverScope.dismiss = function() {
|
|
|
|
|
- popoverScope.$destroy();
|
|
|
|
|
- destroyDrop();
|
|
|
|
|
|
|
+ scope.dismiss = () => {
|
|
|
|
|
+ drop.close();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
var contentElement = document.createElement('div');
|
|
var contentElement = document.createElement('div');
|
|
|
contentElement.innerHTML = options.template;
|
|
contentElement.innerHTML = options.template;
|
|
|
|
|
|
|
|
- $compile(contentElement)(popoverScope);
|
|
|
|
|
|
|
+ $compile(contentElement)(scope);
|
|
|
|
|
|
|
|
drop = new Drop({
|
|
drop = new Drop({
|
|
|
target: options.element,
|
|
target: options.element,
|
|
|
content: contentElement,
|
|
content: contentElement,
|
|
|
position: options.position,
|
|
position: options.position,
|
|
|
- classes: classNames,
|
|
|
|
|
- openOn: options.openOn || 'hover',
|
|
|
|
|
|
|
+ classes: options.classNames || 'drop-popover',
|
|
|
|
|
+ openOn: options.openOn,
|
|
|
hoverCloseDelay: 200,
|
|
hoverCloseDelay: 200,
|
|
|
tetherOptions: {
|
|
tetherOptions: {
|
|
|
constraints: [{to: 'scrollParent', attachment: "none both"}]
|
|
constraints: [{to: 'scrollParent', attachment: "none both"}]
|
|
@@ -49,14 +57,11 @@ function popoverSrv($compile, $rootScope) {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
drop.on('close', () => {
|
|
drop.on('close', () => {
|
|
|
- popoverScope.dismiss({fromDropClose: true});
|
|
|
|
|
- destroyDrop();
|
|
|
|
|
- if (options.onClose) {
|
|
|
|
|
- options.onClose();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ cleanUp();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- setTimeout(() => { drop.open(); }, 10);
|
|
|
|
|
|
|
+ openDrop = drop;
|
|
|
|
|
+ $timeout(() => { drop.open(); }, 10);
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|