Created
December 22, 2016 10:42
-
-
Save DanAtkinson/e51f8e96bcf57271e4ff1c6a1779f790 to your computer and use it in GitHub Desktop.
Really simple Angular tooltip directive that makes use of PNotify.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*globals angular:false */ | |
/* Tooltip directive */ | |
(function (angular) { | |
'use strict'; | |
var app = angular.module('app'); | |
//Actions are performed in here. | |
app.directive('tooltip', function ($sce, $compile) { | |
return { | |
restrict: 'A', | |
scope: { | |
type: '=tooltipType', | |
title: '=tooltipTitle', | |
text: '=tooltipText' | |
}, | |
link: function (scope, element, attributes) { | |
var tooltip = null, | |
notifyOptions = { | |
delay: 2000, | |
icon: 'fa fa-icon', | |
addclass: 'stack-bottomright', | |
stack: false, | |
animate_speed: 0, | |
auto_display: false, | |
type: $sce.valueOf($sce.trustAsHtml(scope.type || 'info')), //notice, info, success, or error | |
title: $sce.valueOf($sce.trustAsHtml(scope.title || 'Info')), | |
text: $sce.valueOf($sce.trustAsHtml(scope.text || 'Information')) | |
}; | |
/* Bindings */ | |
element | |
.on('mouseenter', function (event) { | |
//Copy the base so that we don't pollute it. | |
var options = angular.copy(notifyOptions); | |
tooltip = new PNotify(options); | |
tooltip.open(); | |
scope.$digest(); | |
}) | |
.on('mousemove', function (event) { | |
tooltip.get().css({ | |
'top': event.clientY + 12, | |
'left': event.clientX + 12 | |
}); | |
}) | |
.on('mouseleave', function () { | |
tooltip.get().remove(); | |
tooltip = null; | |
scope.$digest(); | |
}); | |
/* Compile */ | |
$compile(tooltip)(scope); | |
} | |
}; | |
}); | |
}(angular)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment