author | Dan |
Sat, 25 Aug 2007 12:11:31 -0400 | |
changeset 98 | 6457a9b983c6 |
parent 76 | 608dee512bf0 |
child 265 | 915d399dfdbf |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2 |
* Enano JWS - Javascript Windowing System |
|
3 |
* Sorry if I stole the name ;) |
|
4 |
* Copyright (C) 2006-2007 Dan Fuhry |
|
5 |
* Yes, it's part of Enano, so it's GPL |
|
6 |
*/ |
|
7 |
||
8 |
var position; |
|
9 |
function getScrollOffset() |
|
10 |
{ |
|
11 |
var position; |
|
12 |
if (self.pageYOffset) |
|
13 |
{ |
|
14 |
position = self.pageYOffset; |
|
15 |
} |
|
16 |
else if (document.documentElement && document.documentElement.scrollTop) |
|
17 |
{ |
|
18 |
position = document.documentElement.scrollTop; |
|
19 |
} |
|
20 |
else if (document.body) |
|
21 |
{ |
|
22 |
position = document.body.scrollTop; |
|
23 |
} |
|
24 |
return position; |
|
25 |
} |
|
26 |
position = getScrollOffset(); |
|
27 |
||
28 |
var jws = { |
|
29 |
position : position, |
|
30 |
obj : null, |
|
31 |
startup : function() { |
|
32 |
jws.debug('jws.startup()'); |
|
33 |
var divs = document.getElementsByTagName('div'); |
|
34 |
if(IE) { position = document.body.scrollTop; } |
|
35 |
else { position = window.pageYOffset; } |
|
36 |
for(i=0;i<divs.length;i++) { |
|
37 |
if(divs[i].id && divs[i].id.substr(0, 4) == 'root') { |
|
38 |
divs[i].onClick = 'jws.focus(\''+divs[i].id+'\')'; |
|
39 |
var tb = i + 1 |
|
40 |
tb = divs[tb]; |
|
41 |
tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div align="center" class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');">X</div></td></tr></table>'; |
|
42 |
divs[i].style.width = '640px'; |
|
43 |
divs[i].style.height = '480px'; |
|
44 |
Drag.init(tb, divs[i]); |
|
45 |
} |
|
46 |
} |
|
47 |
}, |
|
48 |
initWindow : function(o) { |
|
49 |
jws.debug('jws.initWindow('+o+' ['+o.id+'])'); |
|
50 |
var divs = document.getElementsByTagName('div'); |
|
51 |
for(i=0;i<divs.length;i++) { |
|
52 |
if(divs[i].id && divs[i].id == o.id) { |
|
53 |
var tb = i + 1 |
|
54 |
tb = divs[tb]; |
|
55 |
tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');"></div></td></tr></table>'; |
|
56 |
divs[i].style.width = '640px'; |
|
57 |
divs[i].style.height = '480px'; |
|
58 |
Drag.init(tb, divs[i]); |
|
59 |
} |
|
60 |
} |
|
61 |
}, |
|
62 |
closeWin : function(id) { |
|
63 |
jws.debug('jws.closeWin(\''+id+'\')'); |
|
64 |
document.getElementById(id).style.display = 'none'; |
|
65 |
enlighten(); |
|
66 |
}, |
|
67 |
openWin : function(id, x, y) { |
|
68 |
darken(); |
|
69 |
var e = document.getElementById(id); |
|
70 |
if(!x) x = 640; |
|
71 |
if(!y) y = 480; |
|
72 |
jws.debug('jws.openWin(\''+id+'\', '+x+', '+y+')'); |
|
73 |
e.style.display = 'block'; |
|
74 |
e.style.width = x+'px'; |
|
75 |
e.style.height = y+'px'; |
|
76 |
||
77 |
var divs = document.getElementsByTagName('div'); |
|
78 |
for(i=0;i<divs.length;i++) { |
|
79 |
if(divs[i].id && divs[i].id == e.id) { |
|
80 |
var cn = i + 3; |
|
81 |
cn = divs[cn]; |
|
82 |
||
83 |
var h = getElementHeight(e.id) - 53; |
|
84 |
var w = getElementWidth(cn.id) - 20; |
|
85 |
cn.style.width = w + 'px'; |
|
86 |
cn.style.height = h + 'px'; |
|
87 |
cn.style.clip.top = 0 + 'px'; |
|
88 |
cn.style.clip.left = 0 + 'px'; |
|
89 |
cn.style.clip.right = w + 'px'; |
|
90 |
cn.style.clip.bottom = h + 'px'; |
|
91 |
cn.style.overflow = 'auto'; |
|
92 |
} |
|
93 |
} |
|
94 |
jws.setpos(id); |
|
95 |
jws.focus(id); |
|
96 |
}, |
|
97 |
setpos : function(el) { |
|
98 |
jws.debug('jws.setpos(\''+el+'\')'); |
|
99 |
el = document.getElementById(el); |
|
100 |
var w = getWidth(); |
|
101 |
var h = getHeight(); |
|
102 |
var ew = getElementWidth(el.id); |
|
103 |
var eh = getElementHeight(el.id); |
|
104 |
px = (w/2) - (ew/2); |
|
105 |
py = (h/2) - (eh/2); |
|
106 |
if (IE) { position = document.body.scrollTop; } |
|
107 |
else { position = window.pageYOffset; } |
|
108 |
py=py+0; |
|
109 |
if ( IE ) |
|
110 |
el.style.position = "absolute"; |
|
111 |
else |
|
112 |
el.style.position = "fixed"; |
|
113 |
el.style.left=px+'px'; |
|
114 |
el.style.top =py+'px'; |
|
115 |
}, |
|
116 |
scrollHandler : function() { |
|
117 |
var divs = document.getElementsByTagName('div'); |
|
118 |
for(i=0;i<divs.length;i++) { |
|
119 |
if(divs[i].id && divs[i].id.substr(0, 4) == 'root' && divs[i].style.display == 'block') { |
|
120 |
c = divs[i]; |
|
121 |
jws.debug('jws.scrollHandler(): moving element: '+c.id); |
|
122 |
var t = c.style.top; |
|
123 |
var py = t.substr(0, t.length - 2); |
|
124 |
py = parseInt(py); |
|
125 |
if(jws.position) { py = py - jws.position; } |
|
126 |
position = getScrollOffset(); |
|
127 |
py=py+position; |
|
128 |
c.style.position = "absolute"; |
|
129 |
if(!isNaN(py)) c.style.top =py+'px'; |
|
130 |
jws.debug('jws.scrollHandler(): value of py: '+py); |
|
131 |
} |
|
132 |
} |
|
133 |
jws.position = position; |
|
134 |
}, |
|
135 |
focus : function(e) { |
|
136 |
e = document.getElementById(e); |
|
137 |
if(e.style.zindex) z = e.style.zindex; |
|
138 |
else z = 1; |
|
139 |
z=z+5; |
|
140 |
e.style.zIndex = z; |
|
141 |
}, |
|
142 |
debug : function(t) { |
|
143 |
if(document.getElementById('jsw-debug-console')) { |
|
144 |
dbg = document.getElementById('jsw-debug-console'); |
|
145 |
debugdata = dbg.innerHTML; |
|
146 |
dbg.innerHTML = debugdata+"<br />"+t; |
|
147 |
} |
|
148 |
} |
|
149 |
} // class jws |
|
150 |
||
151 |
//window.onscroll=jws['scrollHandler']; |
|
152 |
||
153 |
/* |
|
154 |
* Utility functions |
|
155 |
*/ |
|
156 |
||
157 |
// getElementWidth() and getElementHeight() |
|
158 |
// Source: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp |
|
159 |
||
160 |
function getElementHeight(Elem) { |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
161 |
if (ns4) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
162 |
{ |
1 | 163 |
var elem = getObjNN4(document, Elem); |
164 |
return elem.clip.height; |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
165 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
166 |
else |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
167 |
{ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
168 |
if(document.getElementById) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
169 |
{ |
1 | 170 |
var elem = document.getElementById(Elem); |
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
171 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
172 |
else if (document.all) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
173 |
{ |
1 | 174 |
var elem = document.all[Elem]; |
175 |
} |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
176 |
if (op5) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
177 |
{ |
1 | 178 |
xPos = elem.style.pixelHeight; |
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
179 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
180 |
else |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
181 |
{ |
1 | 182 |
xPos = elem.offsetHeight; |
183 |
} |
|
184 |
return xPos; |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
function getElementWidth(Elem) { |
|
189 |
if (ns4) { |
|
190 |
var elem = getObjNN4(document, Elem); |
|
191 |
return elem.clip.width; |
|
192 |
} else { |
|
193 |
if(document.getElementById) { |
|
194 |
var elem = document.getElementById(Elem); |
|
195 |
} else if (document.all){ |
|
196 |
var elem = document.all[Elem]; |
|
197 |
} |
|
198 |
if (op5) { |
|
199 |
xPos = elem.style.pixelWidth; |
|
200 |
} else { |
|
201 |
xPos = elem.offsetWidth; |
|
202 |
} |
|
203 |
return xPos; |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
function getHeight() { |
|
208 |
var myHeight = 0; |
|
209 |
if( typeof( window.innerWidth ) == 'number' ) { |
|
210 |
myHeight = window.innerHeight; |
|
211 |
} else if( document.documentElement && |
|
212 |
( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { |
|
213 |
myHeight = document.documentElement.clientHeight; |
|
214 |
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { |
|
215 |
myHeight = document.body.clientHeight; |
|
216 |
} |
|
217 |
return myHeight; |
|
76
608dee512bf0
Work started on page tags, still aways to go, but syncing to Nighthawk
Dan
parents:
14
diff
changeset
|
218 |
} |
1 | 219 |
|
220 |
function getWidth() { |
|
221 |
var myWidth = 0; |
|
222 |
if( typeof( window.innerWidth ) == 'number' ) { |
|
223 |
myWidth = window.innerWidth; |
|
224 |
} else if( document.documentElement && |
|
225 |
( document.documentElement.clientWidth || document.documentElement.clientWidth ) ) { |
|
226 |
myWidth = document.documentElement.clientWidth; |
|
227 |
} else if( document.body && ( document.body.clientWidth || document.body.clientWidth ) ) { |
|
228 |
myWidth = document.body.clientWidth; |
|
229 |
} |
|
230 |
return myWidth; |
|
231 |
} |
|
232 |
||
233 |
/************************************************** |
|
234 |
* dom-drag.js |
|
235 |
* 09.25.2001 |
|
236 |
* www.youngpup.net |
|
237 |
**************************************************/ |
|
238 |
||
239 |
var Drag = { |
|
240 |
||
241 |
obj : null, |
|
242 |
||
243 |
init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) |
|
244 |
{ |
|
245 |
o.onmousedown = Drag.start; |
|
246 |
||
247 |
o.hmode = bSwapHorzRef ? false : true ; |
|
248 |
o.vmode = bSwapVertRef ? false : true ; |
|
249 |
||
250 |
o.root = oRoot && oRoot != null ? oRoot : o ; |
|
251 |
||
252 |
if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px"; |
|
253 |
if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px"; |
|
254 |
if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; |
|
255 |
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; |
|
256 |
||
257 |
o.minX = typeof minX != 'undefined' ? minX : null; |
|
258 |
o.minY = typeof minY != 'undefined' ? minY : null; |
|
259 |
o.maxX = typeof maxX != 'undefined' ? maxX : null; |
|
260 |
o.maxY = typeof maxY != 'undefined' ? maxY : null; |
|
261 |
||
262 |
o.xMapper = fXMapper ? fXMapper : null; |
|
263 |
o.yMapper = fYMapper ? fYMapper : null; |
|
264 |
||
265 |
o.root.onDragStart = new Function(); |
|
266 |
o.root.onDragEnd = new Function(); |
|
267 |
o.root.onDrag = new Function(); |
|
268 |
}, |
|
269 |
||
270 |
start : function(e) |
|
271 |
{ |
|
272 |
var o = Drag.obj = this; |
|
273 |
e = Drag.fixE(e); |
|
274 |
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); |
|
275 |
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); |
|
276 |
o.root.onDragStart(x, y); |
|
277 |
||
278 |
o.lastMouseX = e.clientX; |
|
279 |
o.lastMouseY = e.clientY; |
|
280 |
||
281 |
if (o.hmode) { |
|
282 |
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; |
|
283 |
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; |
|
284 |
} else { |
|
285 |
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; |
|
286 |
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; |
|
287 |
} |
|
288 |
||
289 |
if (o.vmode) { |
|
290 |
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; |
|
291 |
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; |
|
292 |
} else { |
|
293 |
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; |
|
294 |
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; |
|
295 |
} |
|
296 |
||
297 |
document.onmousemove = Drag.drag; |
|
298 |
document.onmouseup = Drag.end; |
|
299 |
||
300 |
return false; |
|
301 |
}, |
|
302 |
||
303 |
drag : function(e) |
|
304 |
{ |
|
305 |
e = Drag.fixE(e); |
|
306 |
var o = Drag.obj; |
|
307 |
||
308 |
var ey = e.clientY; |
|
309 |
var ex = e.clientX; |
|
310 |
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); |
|
311 |
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); |
|
312 |
var nx, ny; |
|
313 |
||
314 |
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); |
|
315 |
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); |
|
316 |
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); |
|
317 |
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); |
|
318 |
||
319 |
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); |
|
320 |
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); |
|
321 |
||
322 |
if (o.xMapper) nx = o.xMapper(y) |
|
323 |
else if (o.yMapper) ny = o.yMapper(x) |
|
324 |
||
325 |
Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; |
|
326 |
Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; |
|
327 |
Drag.obj.lastMouseX = ex; |
|
328 |
Drag.obj.lastMouseY = ey; |
|
329 |
||
330 |
Drag.obj.root.onDrag(nx, ny); |
|
331 |
return false; |
|
332 |
}, |
|
333 |
||
334 |
end : function() |
|
335 |
{ |
|
336 |
document.onmousemove = getMouseXY; |
|
337 |
document.onmouseup = null; |
|
338 |
Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), |
|
339 |
parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); |
|
340 |
Drag.obj = null; |
|
341 |
}, |
|
342 |
||
343 |
fixE : function(e) |
|
344 |
{ |
|
345 |
if (typeof e == 'undefined') e = window.event; |
|
346 |
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; |
|
347 |
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; |
|
348 |
return e; |
|
349 |
} |
|
350 |
}; |
|
351 |