Skip to content

Instantly share code, notes, and snippets.

@jdivock
Created May 14, 2014 21:46
Show Gist options
  • Save jdivock/ecb86168ef7d11d2c436 to your computer and use it in GitHub Desktop.
Save jdivock/ecb86168ef7d11d2c436 to your computer and use it in GitHub Desktop.
Tooltip directive, some day I'll bring you back to life old friend
'use strict';
angular.module('app.sell').directive('tooltip', function() {
return {
restrict: 'EA',
transclude: true,
scope: {
text: '@'
},
template: '<span ng-transclude ng-click="state.toggle()"></span><i class="tooltip-arrow icon-arrow-up2" ng-show="state.display"></i><div class="tooltip-container" ng-show="state.display">' + '<span class="tooltip-close" ng-click="state.hide(); $event.stopPropagation();">X</span>' + '<p>{{text}}</p></div>',
controller: function($scope, $element, $rootScope) {
$scope.state = {
display: false,
};
$scope.$on('close-all-tooltips', function() {
$scope.state.display = false;
});
$scope.state.toggle = function() {
if(!$scope.state.display){
$rootScope.$broadcast('close-all-tooltips');
}
$scope.state.display = !$scope.state.display;
};
$scope.state.show = function() {
$rootScope.$broadcast('close-all-tooltips');
$scope.state.display = true;
};
$scope.state.hide = function() {
$scope.state.display = false;
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment