2016-06-26 15:31:58 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ariaNg').directive('ngTooltip', function () {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
scope: {
|
|
|
|
title: '@ngTooltip'
|
|
|
|
},
|
|
|
|
link: function (scope, element, attrs) {
|
|
|
|
var options = {
|
2016-07-16 15:47:02 +02:00
|
|
|
ngTooltipIf: true,
|
2016-06-26 15:31:58 +02:00
|
|
|
ngTooltipPlacement: 'top',
|
|
|
|
ngTooltipContainer: null,
|
|
|
|
ngTooltipTrigger: 'hover'
|
|
|
|
};
|
|
|
|
|
|
|
|
angular.extend(options, attrs);
|
|
|
|
|
2016-07-16 15:47:02 +02:00
|
|
|
var showTooltip = options.ngTooltipIf === true || options.ngTooltipIf === 'true';
|
2016-06-26 15:31:58 +02:00
|
|
|
|
2016-07-16 15:47:02 +02:00
|
|
|
var addTooltip = function () {
|
|
|
|
angular.element(element).tooltip({
|
|
|
|
title: scope.title,
|
|
|
|
placement: options.ngTooltipPlacement,
|
|
|
|
container: options.ngTooltipContainer,
|
2016-07-16 16:10:31 +02:00
|
|
|
trigger: options.ngTooltipTrigger,
|
|
|
|
delay: {
|
|
|
|
show: 100,
|
|
|
|
hide: 0
|
|
|
|
}
|
2016-07-16 15:47:02 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var refreshTooltip = function () {
|
2016-06-29 16:08:52 +02:00
|
|
|
angular.element(element).attr('title', scope.title).tooltip('fixTitle');
|
2016-07-16 15:47:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var removeTooltip = function () {
|
|
|
|
angular.element(element).tooltip('destroy');
|
|
|
|
};
|
|
|
|
|
|
|
|
if (showTooltip) {
|
|
|
|
addTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
scope.$watch('title', function () {
|
|
|
|
if (showTooltip) {
|
|
|
|
refreshTooltip();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
scope.$watch('ngTooltipIf', function (value) {
|
|
|
|
if (angular.isUndefined(value)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = (value === true || value === 'true');
|
|
|
|
|
2016-08-01 19:26:10 +02:00
|
|
|
if (showTooltip === value) {
|
2016-07-16 15:47:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
addTooltip();
|
|
|
|
} else {
|
|
|
|
removeTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
showTooltip = value;
|
2016-06-26 15:31:58 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2016-08-01 16:49:16 +02:00
|
|
|
}());
|