-
Notifications
You must be signed in to change notification settings - Fork 8
/
popover-toggle.js
44 lines (34 loc) · 1.26 KB
/
popover-toggle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function(angular){
'use strict';
var POPOVER_SHOW = 'popoverToggleShow';
var POPOVER_HIDE = 'popoverToggleHide';
var module = angular.module('popoverToggle', ['ui.bootstrap']);
module.config(['$tooltipProvider', function($tooltipProvider) {
var triggers = {};
triggers[POPOVER_SHOW] = POPOVER_HIDE;
$tooltipProvider.setTriggers(triggers);
}]);
module.directive('popoverToggle', ['$timeout', function($timeout) {
return {
restrict: 'A',
link: link
};
function link($scope, $element, $attrs) {
$attrs.popoverTrigger = POPOVER_SHOW;
$scope.$watch($attrs.popoverToggle, function(newValue) {
$timeout(function(){
if(newValue) {
dispatchEvent(POPOVER_SHOW, $element);
} else {
dispatchEvent(POPOVER_HIDE, $element);
}
});
function dispatchEvent(eventName, $element) {
var event = document.createEvent('Event');
event.initEvent(eventName, true, true);
$element[0].dispatchEvent(event);
}
})
}
}]);
})(angular);