actually adding the files to the initial commit
[vid.git] / vid / src / main / webapp / app / vid / scripts / directives / popupWindowDirective.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 "use strict";
22
23 var popupWindowDirective = function($log, $window) {
24
25     function getZIndex(element) {
26         var maxZIndex = 0;
27         $(window.document).find("*").each(function() {
28             var zIndex = parseInt($(this).css("z-index"));
29             if (zIndex > maxZIndex) {
30                 maxZIndex = zIndex;
31             }
32         });
33
34         return maxZIndex;
35     }
36
37     var scrollPosition = {
38         x : 0,
39         y : 0
40     };
41
42     var link = function(scope, element, attrs, controller, transcludeFn) {
43
44         var zIndex = getZIndex(element.parent()) + 1;
45
46         element.css("z-index", zIndex + 1);
47
48         var backgroundStyle = "display: none; position: fixed; z-index:"
49                 + zIndex + ";" + "top: 0; left: 0; width: 100%; height: 100%;"
50                 + "background-color: #000000; opacity: 0.5";
51
52         var className = attrs["class"];
53         var classString = "";
54         if (className !== undefined && className !== null && className !== "") {
55             element.children().children().children().children().addClass(
56                     className);
57             element.removeClass(className);
58         }
59
60         element.before("<div style='" + backgroundStyle + "'></div>");
61
62         attrs.$observe("ngxShow", function(value) {
63             if (value === "true") {
64                 scrollPosition = {
65                     x : $window.pageXOffset,
66                     y : $window.pageYOffset
67                 }
68                 $window.scrollTo(0, 0);
69                 element.css("display", "table");
70                 element.prev().css("display", "block");
71             } else if (value === "false") {
72                 element.css("display", "none");
73                 element.prev().css("display", "none");
74                 $window.scrollTo(scrollPosition.x, scrollPosition.y);
75             }
76         });
77     }
78
79     return {
80         restrict : "EA",
81         transclude : true,
82         replace : true,
83         link : link,
84         templateUrl : "app/vid/scripts/view-models/popupWindow.htm"
85     };
86 }
87
88 app.directive("popupWindow", [ "$log", "$window", popupWindowDirective ]);