Updated the 19 build version to 20090123
[moodle.git] / lib / overlib / overlib_hideform.js
blob783d93634c2e7b36908850d63f480145d20acfb6
1 //\/////
2 //\  overLIB Hide Form Plugin
3 //\
4 //\  Uses an iframe shim to mask system controls for IE v5.5 or higher as suggested in
5 //\  http://dotnetjunkies.com/weblog/jking/posts/488.aspx
6 //\  This file requires overLIB 4.10 or later.
7 //\
8 //\  overLIB 4.05 - You may not remove or change this notice.
9 //\  Copyright Erik Bosrup 1998-2004. All rights reserved.
10 //\  Contributors are listed on the homepage.
11 //\  See http://www.bosrup.com/web/overlib/ for details.
12 //   $Revision$                $Date$
13 //\/////
14 //\mini
15 if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the HideForm Plugin.');
16 else {
18 // Function which generates the popup with an IFRAME shim
19 function generatePopUp(content) {
20         if(!olIe4||olOp||!olIe55||(typeof o3_shadow != 'undefined' && o3_shadow)||(typeof o3_bubble != 'undefined' && o3_bubble)) return;
22         var wd,ht,txt, zIdx =  0;
24         wd =  parseInt(o3_width);
25         ht =  over.offsetHeight;
26         txt =  backDropSource(wd,ht,zIdx++);
27         txt += '<div style="position: absolute; top: 0; left: 0; width: '+ wd+'px; z-index: ' + zIdx + ';">' + content + '</div>';
28         layerWrite(txt);
31 // Code for the IFRAME which is used in other places
32 function backDropSource(width, height, Z) {
33         return '<iframe frameborder="0" scrolling="no" src="javascript:false;" width="' + width + '" height="' + height + '" style="z-index: ' + Z + '; filter: Beta(Style=0,Opacity=0);"></iframe>';
36 // Hides SELECT boxes that will be under the popup
37 // Checking Gecko version number to try to include other browsers based on the Gecko engine
38 function hideSelectBox() {
39         if(olNs4 || olOp || olIe55) return;
40         var px, py, pw, ph, sx, sw, sy, sh, selEl, v;
42         if(olIe4) v = 0;
43         else {
44                 v = navigator.userAgent.match(/Gecko\/(\d{8})/i);
45                 if(!v) return;   // return if no string match
46                 v = parseInt(v[1]);
47         }
49         if (v < 20030624) {  // versions less than June 24, 2003 were earlier Netscape browsers
50                 px = parseInt(over.style.left);
51                 py = parseInt(over.style.top);
52                 pw = o3_width;
53                 ph = (o3_aboveheight ? parseInt(o3_aboveheight) : over.offsetHeight);
54                 selEl = (olIe4) ? o3_frame.document.all.tags("SELECT") : o3_frame.document.getElementsByTagName("SELECT");
55                 for (var i=0; i<selEl.length; i++) {
56                         if(!olIe4 && selEl[i].size < 2) continue;  // Not IE and SELECT size is 1 or not specified
57                         sx = pageLocation(selEl[i],'Left');
58                         sy = pageLocation(selEl[i],'Top');
59                         sw = selEl[i].offsetWidth;
60                         sh = selEl[i].offsetHeight;
61                         if((px+pw) < sx || px > (sx+sw) || (py+ph) < sy || py > (sy+sh)) continue;
62                         selEl[i].isHidden = 1;
63                         selEl[i].style.visibility = 'hidden';
64                 }
65         }
68 // Shows previously hidden SELECT Boxes
69 function showSelectBox() {
70         if(olNs4 || olOp || olIe55) return;
71         var selEl, v;
73         if(olIe4) v = 0;
74         else {
75                 v = navigator.userAgent.match(/Gecko\/(\d{8})/i);
76                 if(!v) return; 
77                 v = parseInt(v[1]);
78         }
80         if(v < 20030624) {
81                 selEl = (olIe4) ? o3_frame.document.all.tags("SELECT") : o3_frame.document.getElementsByTagName("SELECT");
82                 for (var i=0; i<selEl.length; i++) {
83                         if(typeof selEl[i].isHidden !=  'undefined' && selEl[i].isHidden) {
84                                 selEl[i].isHidden = 0;
85                                 selEl[i].style.visibility = 'visible';
86                         }
87                 }
88         }
91 // function gets the total offset properties of an element
92 // this same function occurs in overlib_mark.js.
93 function pageLocation(o,t){
94         var x = 0
96         while(o.offsetParent){
97                 x += o['offset'+t]
98                 o = o.offsetParent
99         }
101         x += o['offset'+t]
103         return x
106 // reset mouse move routine for NS7 but not NS7.1,Opera, or IE5.5+
107 // It also bypasses Netscape 6 since the modifications mess up the display of popups
108 // and don't work anyways.
109 // Modify mouse move routine while loading so that hideSelectBox()
110 // can be called from the correct location
111 if (!(olNs4 || olOp || olIe55 || navigator.userAgent.indexOf('Netscape6') != -1)) {
112         var MMStr = olMouseMove.toString();
113         var strRe = /(if\s*\(o3_allowmove\s*==\s*1.*\)\s*)/;
114         var f = MMStr.match(strRe);
116         if (f) {
117                 var ls = MMStr.search(strRe);
118                 ls += f[1].length;
119                 var le = MMStr.substring(ls).search(/[;|}]\n/);
120                 MMStr = MMStr.substring(0,ls) + ' { runHook("placeLayer",FREPLACE); if(olHideForm) hideSelectBox(); ' + MMStr.substring(ls + (le != -1 ? le+3 : 0));
121                 document.writeln('<script type="text/javascript">\n<!--\n' + MMStr + '\n//-->\n</' + 'script>');
122         }
124         f = capExtent.onmousemove.toString().match(/function[ ]+(\w*)\(/);
125         if (f&&f[1] != 'anonymous') capExtent.onmousemove = olMouseMove;
129 ////////
130 // PLUGIN REGISTRATIONS
131 ////////
132 registerHook("createPopup",generatePopUp,FAFTER);
133 registerHook("hideObject",showSelectBox,FAFTER);
134 olHideForm=1;