[Common UI] Use popupService from mct-popup

This commit is contained in:
Victor Woeltjen 2015-10-02 10:48:41 -07:00
parent 73dc16d398
commit 1ad0bf337c
2 changed files with 7 additions and 22 deletions

View File

@ -133,7 +133,7 @@
{
"key": "mctPopup",
"implementation": "directives/MCTPopup.js",
"depends": [ "$window", "$document", "$compile", "$interval" ]
"depends": [ "$compile", "popupService" ]
},
{
"key": "mctScrollX",

View File

@ -41,37 +41,22 @@ define(
*
* @constructor
* @memberof platform/commonUI/general
* @param $window the window object (as injected by Angular)
* @param $document the jqLite-wrapped document
* @param $compile Angular's $compile service
* @param {platform/commonUI/general.PopupService} popupService
*/
function MCTPopup($window, $document, $compile) {
function MCTPopup($compile, popupService) {
function link(scope, element, attrs, ctrl, transclude) {
var body = $document.find('body'),
popup = $compile(TEMPLATE)(scope),
winDim = [$window.innerWidth, $window.innerHeight],
var div = $compile(TEMPLATE)(scope),
rect = element.parent()[0].getBoundingClientRect(),
position = [ rect.left, rect.top ],
isLeft = position[0] <= (winDim[0] / 2),
isTop = position[1] <= (winDim[1] / 2);
popup.css('position', 'absolute');
popup.css(
isLeft ? 'left' : 'right',
(isLeft ? position[0] : (winDim[0] - position[0])) + 'px'
);
popup.css(
isTop ? 'top' : 'bottom',
(isTop ? position[1] : (winDim[1] - position[1])) + 'px'
);
body.append(popup);
popup = popupService.display(div, position);
transclude(function (clone) {
popup.append(clone);
div.append(clone);
});
scope.$on('$destroy', function () {
popup.remove();
popup.dismiss();
});
}