0badf122efde5faeec8c4a78ab448daec7e35969
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / media / scripts / jsfunc.layermenu.js
1 /***************************************************************
2 *
3 * JavaScript DHTML layer menu
4 *
5 * $Id$
6 *
7 *
8 *
9 * Copyright notice
10 *
11 * (c) 1998-2003 Kasper Skårhøj
12 * All rights reserved
13 *
14 * This script is part of the TYPO3 tslib/ library provided by
15 * Kasper Skårhøj <kasper@typo3.com> together with TYPO3
16 *
17 * Released under GNU/GPL (see license file in tslib/)
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 *
23 * This copyright notice MUST APPEAR in all copies of this script
24 ***************************************************************/
25
26 var GLV_x=0;
27 var GLV_y=0;
28 var GLV_curLayerWidth = new Array();
29 var GLV_curLayerHeight = new Array();
30 var GLV_curLayerX = new Array();
31 var GLV_curLayerY = new Array();
32 var GLV_menuOn = new Array();
33 var GLV_gap = new Array();
34 var GLV_currentLayer = new Array();
35 var GLV_currentROitem = new Array();
36 var GLV_hasBeenOver = new Array();
37 var GLV_doReset = new Array();
38 var GLV_lastKey = new Array();
39 var GLV_menuXY = new Array();
40 var GLV_date = new Array();
41 var GLV_timeout = new Array();
42 var GLV_timeoutRef = new Array();
43 var GLV_onlyOnLoad = new Array();
44 var GLV_dontHideOnMouseUp = new Array();
45 var GLV_date = new Date();
46 var GLV_restoreMenu = new Array();
47 var GLV_timeout_count=0;
48 var GLV_timeout_pointers = new Array();
49 var GLV_dontFollowMouse = new Array();
50
51 //browsercheck...
52 function GL_checkBrowser(){
53 this.dom= (document.getElementById);
54 this.op=this.opera= (navigator.userAgent.indexOf("Opera")>-1);
55 this.konq= (navigator.userAgent.indexOf("Konq")>-1);
56 this.ie4= (document.all && !this.dom && !this.op && !this.konq);
57 this.ie5= (document.all && this.dom && !this.op && !this.konq);
58 this.ns4= (document.layers && !this.dom && !this.konq);
59 this.ns5= (!document.all && this.dom && !this.op && !this.konq);
60 this.ns6= (this.ns5);
61 this.bw= (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
62 return this;
63 }
64 bw= new GL_checkBrowser();
65
66 //NS4 resize fix.
67 if(document.layers){
68 scrX= innerWidth; scrY= innerHeight;
69 onresize= function() {if(scrX!= innerWidth || scrY!= innerHeight) {history.go(0);}};
70 }
71 //Returns css
72 function GL_getObjCss(obj){
73 return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
74 };
75 function GL_isObjCss(obj){
76 flag = bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
77 if (flag) return true;
78 };
79 function GL_getObj(obj){
80 // nest= (!nest)?"":"document."+nest+".";
81 nest="";
82 this.el= bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document."+obj):document.getElementById(obj);
83 this.css= bw.ns4?this.el:this.el.style;
84 this.ref= bw.ns4?this.el.document:document;
85 this.x= (bw.ns4||bw.op)?this.css.left:this.el.offsetLeft;
86 this.y= (bw.ns4||bw.op)?this.css.top:this.el.offsetTop;
87 this.height= (bw.ie4||bw.ie5||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.op?this.css.pixelHeight:0;
88 this.width= (bw.ie4||bw.ie5||bw.ns6)?this.el.offsetWidth:bw.ns4?this.ref.width:bw.op?this.css.pixelWidth:0;
89 return this;
90 }
91 function GL_initLayers() {
92 if(bw.ns4) document.captureEvents(Event.MOUSEMOVE);
93 GL_timeout_func();
94 }
95 function GL_updateTime(WMid) {
96 GLV_date = new Date();
97 GLV_timeout[WMid] = GLV_date.getTime();
98 }
99 function GL_doResetAll(WMid) {
100 var resetSubMenus="";
101 eval('resetSubMenus = GL'+WMid+'_resetSubMenus();');
102 if (GLV_doReset[WMid] && resetSubMenus) {
103 GLV_doReset[WMid] = false;
104 GL_hideAll(WMid);
105 if (GLV_onlyOnLoad[WMid]) GL_restoreMenu(WMid);
106 }
107 }
108 function GL_timeout_func() {
109 GLV_date = new Date();
110 var stuff="";
111 for (var a=0;a<GLV_timeout_count;a++) {
112 WMid = GLV_timeout_pointers[a];
113 if (GLV_date.getTime()-GLV_timeout[WMid] > GLV_timeoutRef[WMid]) {
114 GL_doResetAll(WMid);
115 }
116 }
117 //window.status = GLV_date.getTime()-GLV_timeout[WMid]-GLV_timeoutRef[WMid]
118 window.setTimeout("GL_timeout_func();",200);
119 }
120 function GL_resetAll(WMid) {
121 if (!GLV_doReset[WMid]) {
122 GL_updateTime(WMid);
123 GLV_doReset[WMid] = true;
124 }
125 }
126 function GL_mouseUp(WMid,e) {
127 GLV_doReset[WMid] = false;
128 if (!GLV_dontHideOnMouseUp[WMid]) {
129 GL_hideAll(WMid);
130 if (GLV_onlyOnLoad[WMid]) GL_restoreMenu(WMid);
131 }
132 }
133 function GL_stopMove(WMid) {
134 GLV_menuOn[WMid] = null;
135 }
136 function GL_restoreMenu(WMid) {
137 eval('GL'+WMid+'_restoreMenu()');
138 }
139 function GL_doTop(WMid,id) {
140 GL_hideAll(WMid);
141 if (GL_isObjCss(id)) {
142 GLV_menuOn[WMid] = GL_getObjCss(id);
143 GLV_menuOn[WMid].visibility = "visible";
144
145 eval('GL'+WMid+'_doTop(WMid,id)');
146
147 var layerObj = GL_getObj(id);
148 GLV_curLayerHeight[WMid] = layerObj.height;
149 GLV_curLayerWidth[WMid] = layerObj.width;
150 GLV_curLayerX[WMid] = layerObj.x;
151 GLV_curLayerY[WMid] = layerObj.y;
152 GLV_currentLayer[WMid] = id;
153 GLV_hasBeenOver[WMid]=0;
154 }
155 }
156 //Capturing mousemove
157 function GL_getMouse(e) {
158 GLV_x= (bw.ns4||bw.ns5)?e.pageX:(bw.ie4||bw.op)?event.x:(event.x-2)+document.body.scrollLeft;
159 GLV_y= (bw.ns4||bw.ns5)?e.pageY:(bw.ie4||bw.op)?event.y:(event.y-2)+document.body.scrollTop;
160 }
161 function GL_mouseMoveEvaluate(WMid) {
162 if (GLV_gap[WMid] && GLV_currentLayer[WMid]!=null) {
163 if ( GLV_x+GLV_gap[WMid]-GLV_curLayerX[WMid] <0 || GLV_y+GLV_gap[WMid]-GLV_curLayerY[WMid] <0 || GLV_curLayerX[WMid]+GLV_curLayerWidth[WMid]+GLV_gap[WMid]-GLV_x <0 || GLV_curLayerY[WMid]+GLV_curLayerHeight[WMid]+GLV_gap[WMid]-GLV_y <0) {
164 if (GLV_hasBeenOver[WMid]) {
165 GLV_doReset[WMid]=true;
166 }
167 } else {
168 GL_updateTime(WMid);
169 GLV_hasBeenOver[WMid]=1;
170 GLV_doReset[WMid]=false; // Added 120902: When on the layer we do not want the layer to be reset...
171 }
172 }
173 }
174 function GL_hideAll(WMid) {
175 GLV_doReset[WMid] = false;
176 GLV_currentLayer[WMid] = null;
177 if (GL_isObjCss(GLV_lastKey[WMid]) && GL_getObjCss(GLV_lastKey[WMid])) { eval('GL'+WMid+'_hideCode()'); }
178 GLV_hasBeenOver[WMid]=0;
179 }
180
181 function GL_iframer(WMid,id,state) {
182 if (bw.ie4||bw.ie5) {
183 ifrmObj = bw.ie4?document.all["Iframe"+WMid]:document.getElementById("Iframe"+WMid);
184 if (state) {
185 parentObj = bw.ie4?document.all[id]:document.getElementById(id);
186 ifrmObj.style.filter='Alpha(opacity=0)';
187 ifrmObj.style.width = parentObj.offsetWidth + "px";
188 ifrmObj.style.height = parentObj.offsetHeight + "px";
189 ifrmObj.style.left = parentObj.offsetLeft + "px";
190 ifrmObj.style.top = parentObj.offsetTop + "px";
191 ifrmObj.style.zIndex = parentObj.style.zIndex-1;
192 ifrmObj.style.display = "";
193 }
194 else ifrmObj.style.display = "none";
195 }
196 }
197