Code

Udpated JS focus,
[gosa.git] / html / include / focus.js
index 954d2f7afa005ac8c473a124ed7db8e6d74b3bc3..99e73b14c1c847d0f97eeab6b77ee34b569f6f8b 100644 (file)
@@ -1,4 +1,5 @@
 var browserType;
+var timeout;
 
 if (document.layers) {browserType = "nn4"}
 if (document.all) {browserType = "ie"}
@@ -14,14 +15,45 @@ for (iln = 0; iln < len; iln++){
 }
 netscape= (ver.charAt(iln+1).toUpperCase() != "C");
 
+function toggle_all_(regex,state_object)
+{
+    state = document.getElementById(state_object).checked;
+    chk_set_all(regex, state);
+}
+
+
+/* Toggle checkbox that matches regex */
+function chk_set_all(regex,value)
+{
+                               for (var i = 0; i < document.mainform.elements.length; i++) {
+                                                               var _id=document.mainform.elements[i].id;
+                                                               if(_id.match(regex)) {
+                                                                                               document.getElementById(_id).checked= value;
+                                                               }
+                               }
+}
+
+
+function scrollDown() {
+       document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
+       timeout= setTimeout("scrollDown()", 500);
+}
+
+/* Scroll down the body frame */
+function scrollDown2() 
+{
+               document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
+}
+
+
 function keyPress(DnEvents) {
   // determines whether Netscape or Internet Explorer
-  k = (netscape) ? DnEvents.which : window.event.keyCode;
+  k = (netscape) ? DnEvents.keyCode : window.event.keyCode;
   if (k == 13) { // enter key pressed
                if(typeof(nextfield)!='undefined') {
                        if(nextfield == 'login') {
          return true; // submit, we finished all fields
-       } else { // we're not done yet, send focus to next box
+       } else { // we are not done yet, send focus to next box
        eval('document.mainform.' + nextfield + '.focus()');
        return false;
        }
@@ -44,6 +76,9 @@ function keyPress(DnEvents) {
                                } else {
                                        return true;
                                }
+                       // Check for konqueror
+                       } else if(document.clientWidth) {
+                               // do nothing ATM
                        } else {
                                if(window.event.srcElement.type == 'textarea') {
                                        return true;
@@ -64,13 +99,39 @@ function keyPress(DnEvents) {
                                }
                        }
                }
+       } else if (k==9) {
+               // Tab key pressed
+               if(netscape) {
+                       if(DnEvents.target.type == 'textarea') {
+                               document.getElementById(DnEvents.target.id).value+="\t";
+                               return false;
+                       }
+               // Check for konqueror
+               } else if(document.clientWidth) {
+                       // do nothing ATM
+               } else {
+                       if(window.event.srcElement.type == 'textarea') {
+                               document.getElementById(window.event.srcElement.id).value+="\t";
+                               return false;
+                       }
+               }
        }
 }
 
 function changeState(myField) {
-  document.getElementById(myField).disabled=(document.getElementById(myField).disabled)?false:true;
+       if(document.getElementById(myField) != null){
+         document.getElementById(myField).disabled=(document.getElementById(myField).disabled)?false:true;
+       }
 }
 
+function setHidden(str) {
+       type = document.getElementById(str).style.display;
+       if((type=='')||(type=='block')) {
+               document.getElementById(str).style.display='none';
+       }else{
+               document.getElementById(str).style.display='block';
+       }
+}
 function changeSelectState(triggerField, myField) {
   if (document.getElementById(triggerField).value != 2){
          document.getElementById(myField).disabled= true;
@@ -112,7 +173,7 @@ if (netscape){
   document.captureEvents(Event.KEYPRESS);
        document.onkeypress= keyPress;
 } else {
-       document.onkeypress= keyPress;
+       document.onkeydown= keyPress;
 }
 
 function hide(element) {
@@ -122,7 +183,7 @@ function hide(element) {
      document.poppedLayer = document.all[element];
   else
      document.poppedLayer = document.layers[element];
-  document.poppedLayer.style.visibility = "hidden";
+       document.poppedLayer.style.visibility = "hidden";
 }
 
 function show(element) {
@@ -143,11 +204,11 @@ function toggle(element) {
   else
      document.poppedLayer = document.layers[element];
 
-  if (document.poppedLayer.style.visibility == "visible")
+  if (document.poppedLayer.style.visibility == "visible") {
          hide (element);
-  else
+       } else {
          show (element);
-
+       }
 }
 
 function popup(target, name) {
@@ -164,3 +225,147 @@ function popup(target, name) {
 function js_check(form) {
        form.javascript.value = 'true';
 }
+
+window.onload = adjust;
+window.onresize = adjust;
+
+function adjust (e) {
+       adjust_height(e);
+       adjust_width(e);
+}
+
+// Automatic resize (height) of divlists
+function adjust_height(e) {
+       if (!e) e=window.event;
+       if (document.getElementById("menucell") && document.getElementById("d_scrollbody")) {
+               var inner_height= window.innerHeight;
+               var min_height= 450;
+               var px_height= min_height;
+               var suggested= px_height;
+       
+               // document.defaultView allows access to the rendered size of elements and should be supported by modern browsers
+               if(document.defaultView) {
+                       var menu_height=parseInt(document.defaultView.getComputedStyle(document.getElementById("menucell"),"").getPropertyValue('height'));
+       
+                       // Minimum height for divlist should be the bottom edge of the menu
+                       min_height= menu_height-197;
+                       suggested= min_height;
+                       if((inner_height-230)-suggested>0) {
+                               suggested= inner_height-230;
+                       }
+       
+               // IE uses other height specifications
+               } else if (browserType == "ie") {
+                       suggested= document.all.menucell.offsetHeight;
+                       offset= absTop(d_scrollbody);
+                       suggested-= offset;
+                       if((inner_height-230)-suggested>0) {
+                               suggested= inner_height-230;
+                       }
+               }
+               document.getElementById("d_scrollbody").style.height=suggested+"px";
+       }
+       return true;
+}
+
+function absTop(e) {
+       return (e.offsetParent)?e.offsetTop+absTop(e.offsetParent) : e.offsetTop;
+}
+
+// Automatic resize (width) of divlists
+function adjust_width(e) {
+       if (!e) e=window.event;
+
+       // Known to not work with IE
+       if(document.defaultView && document.getElementById("t_scrolltable")) {
+               // Resize the div
+               var div_width=parseInt(document.defaultView.getComputedStyle(document.getElementById("t_scrolltable"),"").getPropertyValue('width'));
+               var width= parseInt(window.innerWidth);
+
+               // Resize the body cells
+               var diff= width-div_width-470;
+               
+               // window has been upscaled
+               if(div_width+diff>=600) {
+                       document.getElementById('d_scrollbody').style.width=div_width+diff+"px";
+                       document.getElementById('t_scrollbody').style.width=(div_width-19)+diff+"px";
+       
+                       // Resize the Header cells (only the relative-width ones)
+                       document.getElementById('t_scrollhead').style.width=div_width+diff+"px";
+
+               // window has been downscaled, we must reset the div to 600px
+               } else if (width < 930) {
+                       // Reset layout (set width to 600px)
+                       div_width=600;
+                       document.getElementById('d_scrollbody').style.width=div_width+"px";
+                       document.getElementById('t_scrollbody').style.width=(div_width-19)+"px";
+       
+                       // Resize the Header cells (only the relative-width ones)
+                       document.getElementById('t_scrollhead').style.width=div_width+"px";
+               }
+       } else if(document.defaultView && document.getElementById("t_scrolltable_onlywidth")) {
+               // Resize the div
+               var div_width=parseInt(document.defaultView.getComputedStyle(document.getElementById("t_scrolltable_onlywidth"),"").getPropertyValue('width'));
+               var width= parseInt(window.innerWidth);
+
+               // Resize the body cells
+               var diff= width-div_width-470;
+               
+               // window has been upscaled
+               if(div_width+diff>=600) {
+                       document.getElementById('d_scrollbody_onlywidth').style.width=div_width+diff+"px";
+                       document.getElementById('t_scrollbody_onlywidth').style.width=(div_width-19)+diff+"px";
+       
+                       // Resize the Header cells (only the relative-width ones)
+                       document.getElementById('t_scrollhead_onlywidth').style.width=div_width+diff+"px";
+
+               // window has been downscaled, we must reset the div to 600px
+               } else if (width < 930) {
+                       // Reset layout (set width to 600px)
+                       div_width=600;
+                       document.getElementById('d_scrollbody_onlywidth').style.width=div_width+"px";
+                       document.getElementById('t_scrollbody_onlywidth').style.width=(div_width-19)+"px";
+       
+                       // Resize the Header cells (only the relative-width ones)
+                       document.getElementById('t_scrollhead_onlywidth').style.width=div_width+"px";
+               }
+       } else {
+               // IE
+
+       }
+}
+
+
+
+/* Set focus to first valid input field 
+               avoid IExplorer warning about hidding or disabled fields 
+*/
+function focus_field()
+{      
+               var i = 0;
+               while(focus_field.arguments[i] && document.getElementById(focus_field.arguments[i]).disabled == true) {
+                       i++;
+               }
+               if(focus_field.arguments[i]){
+
+                               var name                = focus_field.arguments[i];
+                               var element = document.getElementsByName(name);
+
+                               for(i = 0; i < element.length; i++) {
+                                               if(element[i].id == name && (
+                                                               element[i].type != 'none' || 
+                                                               element[i].type != 'hidden')
+                                               ) {
+                                                       element[i].blur();              
+                                                       element[i].focus();             
+                                                       break;
+                                               }
+                               }
+               }
+}
+
+
+
+
+
+// vim:ts=2:syntax