2013-12-03 07:15:10 -05:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var angular = require('angular');
|
|
|
|
|
|
|
|
//
|
|
|
|
// Controller
|
|
|
|
//
|
|
|
|
|
|
|
|
var PopoverCtrl = function($scope) {
|
|
|
|
$scope.state.popover = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Directives
|
|
|
|
//
|
|
|
|
|
|
|
|
var ngModule = angular.module('popover', []);
|
2013-12-04 05:50:20 -05:00
|
|
|
ngModule.directive('popover', function() {
|
2013-12-03 07:15:10 -05:00
|
|
|
return function(scope, elm, attrs) {
|
2013-12-04 08:47:04 -05:00
|
|
|
var selector = attrs.popover;
|
|
|
|
var popover = angular.element(document.querySelector(selector));
|
2013-12-04 05:50:20 -05:00
|
|
|
|
2013-12-03 07:15:10 -05:00
|
|
|
elm.on('mouseover', function() {
|
2013-12-04 05:50:20 -05:00
|
|
|
// set popover position
|
|
|
|
var top = elm[0].offsetTop;
|
|
|
|
var left = elm[0].offsetLeft;
|
|
|
|
var width = elm[0].offsetWidth;
|
|
|
|
var height = elm[0].offsetHeight;
|
|
|
|
|
|
|
|
popover[0].style.transition = 'opacity 0.3s linear';
|
|
|
|
popover[0].style.top = (top + height / 2 - popover[0].offsetHeight / 2) + 'px';
|
|
|
|
popover[0].style.left = (left + width) + 'px';
|
|
|
|
popover[0].style.opacity = '1';
|
2013-12-03 07:15:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
elm.on('mouseout', function() {
|
2013-12-04 05:50:20 -05:00
|
|
|
popover[0].style.transition = 'opacity 0.3s linear, top 0.3s step-end, left 0.3s step-end';
|
2013-12-03 07:15:10 -05:00
|
|
|
popover[0].style.opacity = '0';
|
2013-12-04 05:18:31 -05:00
|
|
|
popover[0].style.top = '-9999px';
|
|
|
|
popover[0].style.left = '-9999px';
|
2013-12-03 07:15:10 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return PopoverCtrl;
|
|
|
|
});
|