Code

9df1d33cc3dadc62b852fba71d49017f95dc3895
[gosa.git] / tests / ListTest / ObjectListViewport.js
2 /* Register resize event to force redraw of all
3  *  displayed lists
4  */
5 window.onload = updateObjectListViewportSize;
6 window.onresize = updateObjectListViewportSize;
8    function updateObjectListViewportSize() {
10                 var header              = 0;
11                 var footer              = 0;
12                 var viewport    = 0;
13                 var viewport_w  = 0;
14                 var all                 = new Array();
15                 var i                   = 0;
16                 var list_id             = "";
17                 var calc                = 0;
18         
19         /* Somehow IE do not need to be resized
20          *  So skip the following part if the client uses ie
21          */
22         if(document.all && !window.opera){
23             all = getElementsByStyleClass('ObjectListViewport_Entry_Cover');
24             for (i = 0; i < all.length; ++i){
25                 document.getElementById(all[i].id).style.height= "100%";
26             }
27             return;
28         }
30         all = getElementsByStyleClass('ObjectListViewport');
31         for (i = 0; i < all.length; ++i){
33             list_id = all[i].id.replace(/[^0-9]*/,"");
35             /* Set Viewport to min height, to ensure
36              *  that resize will work correctly in konqueror
37              */
38             document.getElementById('ObjectListViewport_Entry_Cover' + list_id).style.height= "50px";
40             /* Get values of displayed header and footer heights to be
41              *  able to recalculate the Viewport
42              */
43             viewport    = getObjectHeight('ObjectListViewport_Table' + list_id);
45                         /* Get Header height for ViewPort height calculation */
46                         if(document.getElementById('ObjectListViewport_TD_Header' + list_id)){
47                 header = getObjectHeight('ObjectListViewport_TD_Header' + list_id);
48                         }else{
49                                 header =0;
50                         }
51                 
52                         /* Get Footer height for ViewPort height calculation */
53                         if(document.getElementById('ObjectListViewport_TD_Footer' + list_id)){
54                 footer = getObjectHeight('ObjectListViewport_TD_Footer' + list_id);
55                         }else{
56                                 footer = 0
57                         }
59             /* Calculate the new visible entry part height. */
60             calc = (viewport  - ( header + footer ));
61             document.getElementById('ObjectListViewport_Entry_Cover' + list_id).style.height = calc;
63             /* Reduce width of entry list, we need some space to
64              *  display the scrollbar without breaking the layout
65                          * Only required if a header is shown.
66              */
67                         if(document.getElementById('ObjectListViewport_TD_Header' + list_id)){
68                                 viewport_w = getObjectWidth('ObjectListViewport_Table' + list_id);
69                                 document.getElementById('ObjectListViewport_Entry_Table' + list_id).style.width = (viewport_w - 18) + 'px';
70                                 document.getElementById('ObjectListViewport_Header_Table' + list_id).style.width = (viewport_w - 18) + 'px';
71                         }
72         }
73     }
76     /* Return all elements of a specific class */
77     function getElementsByStyleClass (className) {
78         var all = document.all ? document.all : document.getElementsByTagName('*');
79         var elements = new Array();
80         for (var e = 0; e < all.length; e++)
81             if (all[e].className == className)
82                 elements[elements.length] = all[e];
83         return elements;
84     }
87     /* Return integer value of style attribute width for specified ID  */
88     function getObjectWidth(obj){
89                 if(document.getElementById(obj)){
90                         obj = getComputedStyle(document.getElementById(obj),"").width;
91                         return(parseInt(obj.replace(/px/,'')));
92                 }else{
93                         return(0);
94                 }
95     }
97     /* Return integer value of style attribute height for specified ID  */
98     function getObjectHeight(obj){
99                 if(document.getElementById(obj)){
100                         obj = getComputedStyle(document.getElementById(obj),"").height;
101                         return(parseInt(obj.replace(/px/,'')));
102                 }else{
103                         return(0);
104                 }
105     }