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
diff
changeset
+ − 161
if (ns4)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
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
diff
changeset
+ − 165
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 166
else
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 167
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 168
if(document.getElementById)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
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
diff
changeset
+ − 171
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 172
else if (document.all)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
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
diff
changeset
+ − 176
if (op5)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
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
diff
changeset
+ − 179
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 180
else
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
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
+ − 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
265
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
diff
changeset
+ − 237
* 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
diff
changeset
+ − 238
* 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
diff
changeset
+ − 239
* 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
diff
changeset
+ − 240
* Enano.
1
+ − 241
**************************************************/
+ − 242
+ − 243
var Drag = {
+ − 244
+ − 245
obj : null,
+ − 246
+ − 247
init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
+ − 248
{
+ − 249
o.onmousedown = Drag.start;
+ − 250
+ − 251
o.hmode = bSwapHorzRef ? false : true ;
+ − 252
o.vmode = bSwapVertRef ? false : true ;
+ − 253
+ − 254
o.root = oRoot && oRoot != null ? oRoot : o ;
+ − 255
+ − 256
if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
+ − 257
if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
+ − 258
if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
+ − 259
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
+ − 260
+ − 261
o.minX = typeof minX != 'undefined' ? minX : null;
+ − 262
o.minY = typeof minY != 'undefined' ? minY : null;
+ − 263
o.maxX = typeof maxX != 'undefined' ? maxX : null;
+ − 264
o.maxY = typeof maxY != 'undefined' ? maxY : null;
+ − 265
+ − 266
o.xMapper = fXMapper ? fXMapper : null;
+ − 267
o.yMapper = fYMapper ? fYMapper : null;
+ − 268
+ − 269
o.root.onDragStart = new Function();
+ − 270
o.root.onDragEnd = new Function();
+ − 271
o.root.onDrag = new Function();
+ − 272
},
+ − 273
+ − 274
start : function(e)
+ − 275
{
+ − 276
var o = Drag.obj = this;
+ − 277
e = Drag.fixE(e);
+ − 278
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
+ − 279
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
+ − 280
o.root.onDragStart(x, y);
+ − 281
+ − 282
o.lastMouseX = e.clientX;
+ − 283
o.lastMouseY = e.clientY;
+ − 284
+ − 285
if (o.hmode) {
+ − 286
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
+ − 287
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
+ − 288
} else {
+ − 289
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
+ − 290
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
+ − 291
}
+ − 292
+ − 293
if (o.vmode) {
+ − 294
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
+ − 295
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
+ − 296
} else {
+ − 297
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
+ − 298
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
+ − 299
}
+ − 300
+ − 301
document.onmousemove = Drag.drag;
+ − 302
document.onmouseup = Drag.end;
+ − 303
+ − 304
return false;
+ − 305
},
+ − 306
+ − 307
drag : function(e)
+ − 308
{
+ − 309
e = Drag.fixE(e);
+ − 310
var o = Drag.obj;
+ − 311
+ − 312
var ey = e.clientY;
+ − 313
var ex = e.clientX;
+ − 314
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
+ − 315
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
+ − 316
var nx, ny;
+ − 317
+ − 318
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
+ − 319
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
+ − 320
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
+ − 321
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
+ − 322
+ − 323
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
+ − 324
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
+ − 325
+ − 326
if (o.xMapper) nx = o.xMapper(y)
+ − 327
else if (o.yMapper) ny = o.yMapper(x)
+ − 328
+ − 329
Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
+ − 330
Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
+ − 331
Drag.obj.lastMouseX = ex;
+ − 332
Drag.obj.lastMouseY = ey;
+ − 333
+ − 334
Drag.obj.root.onDrag(nx, ny);
+ − 335
return false;
+ − 336
},
+ − 337
+ − 338
end : function()
+ − 339
{
+ − 340
document.onmousemove = getMouseXY;
+ − 341
document.onmouseup = null;
+ − 342
Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
+ − 343
parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
+ − 344
Drag.obj = null;
+ − 345
},
+ − 346
+ − 347
fixE : function(e)
+ − 348
{
+ − 349
if (typeof e == 'undefined') e = window.event;
+ − 350
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
+ − 351
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
+ − 352
return e;
+ − 353
}
+ − 354
};
+ − 355