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