author | Dan |
Sun, 04 Jan 2009 00:55:40 -0500 | |
changeset 801 | eb8b23f11744 |
parent 420 | 301f546688d1 |
child 1227 | bdac73ed481e |
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 |
position = getScrollOffset(); |
|
10 |
||
11 |
var jws = { |
|
12 |
position : position, |
|
13 |
obj : null, |
|
14 |
startup : function() { |
|
15 |
jws.debug('jws.startup()'); |
|
16 |
var divs = document.getElementsByTagName('div'); |
|
17 |
if(IE) { position = document.body.scrollTop; } |
|
18 |
else { position = window.pageYOffset; } |
|
19 |
for(i=0;i<divs.length;i++) { |
|
20 |
if(divs[i].id && divs[i].id.substr(0, 4) == 'root') { |
|
21 |
divs[i].onClick = 'jws.focus(\''+divs[i].id+'\')'; |
|
22 |
var tb = i + 1 |
|
23 |
tb = divs[tb]; |
|
24 |
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>'; |
|
25 |
divs[i].style.width = '640px'; |
|
26 |
divs[i].style.height = '480px'; |
|
27 |
Drag.init(tb, divs[i]); |
|
28 |
} |
|
29 |
} |
|
30 |
}, |
|
31 |
initWindow : function(o) { |
|
32 |
jws.debug('jws.initWindow('+o+' ['+o.id+'])'); |
|
33 |
var divs = document.getElementsByTagName('div'); |
|
34 |
for(i=0;i<divs.length;i++) { |
|
35 |
if(divs[i].id && divs[i].id == o.id) { |
|
36 |
var tb = i + 1 |
|
37 |
tb = divs[tb]; |
|
38 |
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>'; |
|
39 |
divs[i].style.width = '640px'; |
|
40 |
divs[i].style.height = '480px'; |
|
41 |
Drag.init(tb, divs[i]); |
|
42 |
} |
|
43 |
} |
|
44 |
}, |
|
45 |
closeWin : function(id) { |
|
46 |
jws.debug('jws.closeWin(\''+id+'\')'); |
|
47 |
document.getElementById(id).style.display = 'none'; |
|
48 |
enlighten(); |
|
49 |
}, |
|
50 |
openWin : function(id, x, y) { |
|
51 |
darken(); |
|
52 |
var e = document.getElementById(id); |
|
53 |
if(!x) x = 640; |
|
54 |
if(!y) y = 480; |
|
55 |
jws.debug('jws.openWin(\''+id+'\', '+x+', '+y+')'); |
|
56 |
e.style.display = 'block'; |
|
57 |
e.style.width = x+'px'; |
|
58 |
e.style.height = y+'px'; |
|
59 |
||
60 |
var divs = document.getElementsByTagName('div'); |
|
61 |
for(i=0;i<divs.length;i++) { |
|
62 |
if(divs[i].id && divs[i].id == e.id) { |
|
63 |
var cn = i + 3; |
|
64 |
cn = divs[cn]; |
|
65 |
||
66 |
var h = getElementHeight(e.id) - 53; |
|
67 |
var w = getElementWidth(cn.id) - 20; |
|
68 |
cn.style.width = w + 'px'; |
|
69 |
cn.style.height = h + 'px'; |
|
70 |
cn.style.clip.top = 0 + 'px'; |
|
71 |
cn.style.clip.left = 0 + 'px'; |
|
72 |
cn.style.clip.right = w + 'px'; |
|
73 |
cn.style.clip.bottom = h + 'px'; |
|
74 |
cn.style.overflow = 'auto'; |
|
75 |
} |
|
76 |
} |
|
77 |
jws.setpos(id); |
|
78 |
jws.focus(id); |
|
79 |
}, |
|
80 |
setpos : function(el) { |
|
81 |
jws.debug('jws.setpos(\''+el+'\')'); |
|
82 |
el = document.getElementById(el); |
|
83 |
var w = getWidth(); |
|
84 |
var h = getHeight(); |
|
85 |
var ew = getElementWidth(el.id); |
|
86 |
var eh = getElementHeight(el.id); |
|
87 |
px = (w/2) - (ew/2); |
|
88 |
py = (h/2) - (eh/2); |
|
89 |
if (IE) { position = document.body.scrollTop; } |
|
90 |
else { position = window.pageYOffset; } |
|
91 |
py=py+0; |
|
92 |
if ( IE ) |
|
93 |
el.style.position = "absolute"; |
|
94 |
else |
|
95 |
el.style.position = "fixed"; |
|
96 |
el.style.left=px+'px'; |
|
97 |
el.style.top =py+'px'; |
|
98 |
}, |
|
99 |
scrollHandler : function() { |
|
100 |
var divs = document.getElementsByTagName('div'); |
|
101 |
for(i=0;i<divs.length;i++) { |
|
102 |
if(divs[i].id && divs[i].id.substr(0, 4) == 'root' && divs[i].style.display == 'block') { |
|
103 |
c = divs[i]; |
|
104 |
jws.debug('jws.scrollHandler(): moving element: '+c.id); |
|
105 |
var t = c.style.top; |
|
106 |
var py = t.substr(0, t.length - 2); |
|
107 |
py = parseInt(py); |
|
108 |
if(jws.position) { py = py - jws.position; } |
|
109 |
position = getScrollOffset(); |
|
110 |
py=py+position; |
|
111 |
c.style.position = "absolute"; |
|
112 |
if(!isNaN(py)) c.style.top =py+'px'; |
|
113 |
jws.debug('jws.scrollHandler(): value of py: '+py); |
|
114 |
} |
|
115 |
} |
|
116 |
jws.position = position; |
|
117 |
}, |
|
118 |
focus : function(e) { |
|
119 |
e = document.getElementById(e); |
|
120 |
if(e.style.zindex) z = e.style.zindex; |
|
121 |
else z = 1; |
|
122 |
z=z+5; |
|
123 |
e.style.zIndex = z; |
|
124 |
}, |
|
125 |
debug : function(t) { |
|
126 |
if(document.getElementById('jsw-debug-console')) { |
|
127 |
dbg = document.getElementById('jsw-debug-console'); |
|
128 |
debugdata = dbg.innerHTML; |
|
129 |
dbg.innerHTML = debugdata+"<br />"+t; |
|
130 |
} |
|
131 |
} |
|
132 |
} // class jws |
|
133 |
||
134 |
//window.onscroll=jws['scrollHandler']; |
|
135 |
||
136 |
/************************************************** |
|
137 |
* dom-drag.js |
|
138 |
* 09.25.2001 |
|
139 |
* www.youngpup.net |
|
338
915d399dfdbf
Corrected licensing issue on YoungPup's DOM-Drag (it is now public domain -> GPLv2+ for Enano); fixed wrongful access denial under specific circumstances (fetch_page_acl() on nonexistent page + wiki mode)
Dan
parents:
76
diff
changeset
|
140 |
* The original version of this code is in the |
915d399dfdbf
Corrected licensing issue on YoungPup's DOM-Drag (it is now public domain -> GPLv2+ for Enano); fixed wrongful access denial under specific circumstances (fetch_page_acl() on nonexistent page + wiki mode)
Dan
parents:
76
diff
changeset
|
141 |
* public domain. We have relicensed this modified |
915d399dfdbf
Corrected licensing issue on YoungPup's DOM-Drag (it is now public domain -> GPLv2+ for Enano); fixed wrongful access denial under specific circumstances (fetch_page_acl() on nonexistent page + wiki mode)
Dan
parents:
76
diff
changeset
|
142 |
* version under the GPL version 2 or later for |
915d399dfdbf
Corrected licensing issue on YoungPup's DOM-Drag (it is now public domain -> GPLv2+ for Enano); fixed wrongful access denial under specific circumstances (fetch_page_acl() on nonexistent page + wiki mode)
Dan
parents:
76
diff
changeset
|
143 |
* Enano. |
1 | 144 |
**************************************************/ |
145 |
||
146 |
var Drag = { |
|
147 |
||
148 |
obj : null, |
|
149 |
||
150 |
init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) |
|
151 |
{ |
|
152 |
o.onmousedown = Drag.start; |
|
153 |
||
154 |
o.hmode = bSwapHorzRef ? false : true ; |
|
155 |
o.vmode = bSwapVertRef ? false : true ; |
|
156 |
||
157 |
o.root = oRoot && oRoot != null ? oRoot : o ; |
|
158 |
||
159 |
if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px"; |
|
160 |
if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px"; |
|
161 |
if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; |
|
162 |
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; |
|
163 |
||
164 |
o.minX = typeof minX != 'undefined' ? minX : null; |
|
165 |
o.minY = typeof minY != 'undefined' ? minY : null; |
|
166 |
o.maxX = typeof maxX != 'undefined' ? maxX : null; |
|
167 |
o.maxY = typeof maxY != 'undefined' ? maxY : null; |
|
168 |
||
169 |
o.xMapper = fXMapper ? fXMapper : null; |
|
170 |
o.yMapper = fYMapper ? fYMapper : null; |
|
171 |
||
172 |
o.root.onDragStart = new Function(); |
|
173 |
o.root.onDragEnd = new Function(); |
|
174 |
o.root.onDrag = new Function(); |
|
175 |
}, |
|
176 |
||
177 |
start : function(e) |
|
178 |
{ |
|
179 |
var o = Drag.obj = this; |
|
180 |
e = Drag.fixE(e); |
|
181 |
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); |
|
182 |
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); |
|
183 |
o.root.onDragStart(x, y); |
|
184 |
||
185 |
o.lastMouseX = e.clientX; |
|
186 |
o.lastMouseY = e.clientY; |
|
187 |
||
188 |
if (o.hmode) { |
|
189 |
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; |
|
190 |
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; |
|
191 |
} else { |
|
192 |
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; |
|
193 |
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; |
|
194 |
} |
|
195 |
||
196 |
if (o.vmode) { |
|
197 |
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; |
|
198 |
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; |
|
199 |
} else { |
|
200 |
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; |
|
201 |
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; |
|
202 |
} |
|
203 |
||
204 |
document.onmousemove = Drag.drag; |
|
205 |
document.onmouseup = Drag.end; |
|
206 |
||
207 |
return false; |
|
208 |
}, |
|
209 |
||
210 |
drag : function(e) |
|
211 |
{ |
|
212 |
e = Drag.fixE(e); |
|
213 |
var o = Drag.obj; |
|
214 |
||
215 |
var ey = e.clientY; |
|
216 |
var ex = e.clientX; |
|
217 |
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); |
|
218 |
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); |
|
219 |
var nx, ny; |
|
220 |
||
221 |
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); |
|
222 |
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); |
|
223 |
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); |
|
224 |
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); |
|
225 |
||
226 |
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); |
|
227 |
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); |
|
228 |
||
229 |
if (o.xMapper) nx = o.xMapper(y) |
|
230 |
else if (o.yMapper) ny = o.yMapper(x) |
|
231 |
||
232 |
Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; |
|
233 |
Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; |
|
234 |
Drag.obj.lastMouseX = ex; |
|
235 |
Drag.obj.lastMouseY = ey; |
|
236 |
||
237 |
Drag.obj.root.onDrag(nx, ny); |
|
238 |
return false; |
|
239 |
}, |
|
240 |
||
241 |
end : function() |
|
242 |
{ |
|
243 |
document.onmousemove = getMouseXY; |
|
244 |
document.onmouseup = null; |
|
245 |
Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), |
|
246 |
parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); |
|
247 |
Drag.obj = null; |
|
248 |
}, |
|
249 |
||
250 |
fixE : function(e) |
|
251 |
{ |
|
252 |
if (typeof e == 'undefined') e = window.event; |
|
253 |
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; |
|
254 |
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; |
|
255 |
return e; |
|
256 |
} |
|
257 |
}; |
|
258 |