"use strict"; (function () { 'use strict'; angular.module('myitsmApp') .directive('emailAccelerators', ['$window', function ($window) { return { restrict: 'E', replace: true, templateUrl: 'components/email/email-accelerators.html', link: function postLink(scope, $element) { $element.show(function () { var $parent = $element.parent(), popupWidth = $element[0].offsetWidth, popupHeight = $element[0].offsetHeight; var spaceRight, spaceLeft, spaceTop; spaceRight = ($(window).width() - ($parent.offset().left + $parent.outerWidth())); spaceLeft = $parent.offset().left; spaceTop = $parent.offset().top; if (spaceRight >= popupWidth) { $element.css({ left: '100%', right: 'auto' }); } else if (spaceLeft >= popupWidth) { $element.css({ right: '100%', left: 'auto' }); } else { if (spaceTop >= popupHeight) { $element.css({ left: 'auto', right: 'auto', top: '-100%' }); } else { $element.css({ maxWidth: spaceLeft, right: 'auto', left: 'auto' }); } } }); } }; }]); }());