Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / js / persist_table_header.js
1         function UpdateTableHeaders() {
2             $("div.divTableWithFloatingHeader").each(function() {
3                 var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
4                 var floatingHeaderRow = $(".tableFloatingHeader", this);
5                 var offset = $(this).offset();
6                 var scrollTop = $(window).scrollTop();
7                 if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
8                     floatingHeaderRow.css("visibility", "visible");
9                     floatingHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + "px");
10                     floatingHeaderRow.css("z-index", "20");
11
12                     // Copy cell widths from original header
13                     $("th", floatingHeaderRow).each(function(index) {
14                         var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
15                         $(this).css('width', cellWidth);
16                     });
17
18                     // Copy row width from whole table
19                     floatingHeaderRow.css("width", $(this).css("width"));
20                 }
21                 else {
22                     floatingHeaderRow.css("visibility", "hidden");
23                     floatingHeaderRow.css("top", "0px");
24                 }
25             });
26         }
27
28         $(document).ready(function() {
29             $("table.tableWithFloatingHeader").each(function() {
30                 $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
31
32                 var originalHeaderRow = $("tr:first", this)
33                 originalHeaderRow.before(originalHeaderRow.clone());
34                 var clonedHeaderRow = $("tr:first", this)
35
36                 clonedHeaderRow.addClass("tableFloatingHeader");
37                 clonedHeaderRow.css("position", "absolute");
38                 clonedHeaderRow.css("top", "0px");
39                 clonedHeaderRow.css("left", $(this).css("margin-left"));
40                 clonedHeaderRow.css("visibility", "hidden");
41
42                 originalHeaderRow.addClass("tableFloatingHeaderOriginal");
43             });
44             UpdateTableHeaders();
45             $(window.parent).scroll(UpdateTableHeaders);
46             $(window.parent).resize(UpdateTableHeaders);
47         });