|
|
@@ -7,40 +7,48 @@ import coreModule from 'app/core/core_module';
|
|
|
import Drop from 'tether-drop';
|
|
|
|
|
|
/** @ngInject **/
|
|
|
-function popoverSrv($templateCache, $timeout, $q, $http, $compile) {
|
|
|
-
|
|
|
- this.getTemplate = function(url) {
|
|
|
- return $q.when($templateCache.get(url) || $http.get(url, {cache: true}));
|
|
|
- };
|
|
|
+function popoverSrv($compile, $rootScope) {
|
|
|
|
|
|
this.show = function(options) {
|
|
|
+ var popoverScope = _.extend($rootScope.$new(true), options.model);
|
|
|
+ var drop;
|
|
|
+
|
|
|
+ function destroyDrop() {
|
|
|
+ setTimeout(function() {
|
|
|
+ if (drop.tether) {
|
|
|
+ drop.destroy();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ popoverScope.dismiss = function() {
|
|
|
+ popoverScope.$destroy();
|
|
|
+ destroyDrop();
|
|
|
+ };
|
|
|
+
|
|
|
+ var contentElement = document.createElement('div');
|
|
|
+ contentElement.innerHTML = options.template;
|
|
|
|
|
|
- options.scope.dismiss = function() {
|
|
|
- var popover = options.element.data('popover');
|
|
|
- if (popover) {
|
|
|
- popover.destroy();
|
|
|
+ $compile(contentElement)(popoverScope);
|
|
|
+
|
|
|
+ drop = new Drop({
|
|
|
+ target: options.element,
|
|
|
+ content: contentElement,
|
|
|
+ position: options.position,
|
|
|
+ classes: 'drop-popover',
|
|
|
+ openOn: options.openOn || 'hover',
|
|
|
+ hoverCloseDelay: 200,
|
|
|
+ tetherOptions: {
|
|
|
+ constraints: [{to: 'window', pin: true, attachment: "both"}]
|
|
|
}
|
|
|
- options.scope.$destroy();
|
|
|
- };
|
|
|
+ });
|
|
|
|
|
|
- this.getTemplate(options.templateUrl).then(function(result) {
|
|
|
- $timeout(function() {
|
|
|
- var template = _.isString(result) ? result : result.data;
|
|
|
-
|
|
|
- var drop = new Drop({
|
|
|
- target: options.element[0],
|
|
|
- content: template,
|
|
|
- position: 'bottom top',
|
|
|
- classes: 'drop-help',
|
|
|
- openOn: 'click',
|
|
|
- tetherOptions: {
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- drop.open();
|
|
|
- //$compile(popover.$tip)(popover.scope);
|
|
|
- }, 1);
|
|
|
+ drop.on('close', () => {
|
|
|
+ popoverScope.dismiss({fromDropClose: true});
|
|
|
+ destroyDrop();
|
|
|
});
|
|
|
+
|
|
|
+ drop.open();
|
|
|
};
|
|
|
}
|
|
|
|