Mercurial > hg > digilib-old
comparison client/digitallibrary/baselib.js @ 386:3b710e39823b
latest version of baselib.js and dllib.js
author | robcast |
---|---|
date | Wed, 07 Dec 2005 16:13:49 +0100 |
parents | 735ea8bab962 |
children | d989a93d773b |
comparison
equal
deleted
inserted
replaced
385:0155f1c3f505 | 386:3b710e39823b |
---|---|
21 | 21 |
22 */ | 22 */ |
23 | 23 |
24 function base_init() { | 24 function base_init() { |
25 // init function | 25 // init function |
26 baseScriptVersion = "1.1.1b"; | 26 baseScriptVersion = "1.2"; |
27 dlParams = new Object(); | 27 dlParams = new Object(); |
28 browserType = getBrowserType(); | 28 browserType = getBrowserType(); |
29 } | 29 } |
30 | 30 |
31 | 31 |
51 var bt = Object(); | 51 var bt = Object(); |
52 bt.doDHTML = false; | 52 bt.doDHTML = false; |
53 bt.versIE = 0; | 53 bt.versIE = 0; |
54 | 54 |
55 if ((! document.cssonly && document.layers) || document.all || document.getElementById) { | 55 if ((! document.cssonly && document.layers) || document.all || document.getElementById) { |
56 var vers = navigator.appVersion.split('MSIE '); | 56 var vers = navigator.appVersion.split('MSIE '); |
57 vers = vers[vers.length - 1]; | 57 vers = vers[vers.length - 1]; |
58 bt.versIE = getInt(vers); | 58 bt.versIE = getInt(vers); |
59 bt.isIE = navigator.userAgent.indexOf('MSIE') >= 0; | 59 bt.isIE = navigator.userAgent.indexOf('MSIE') >= 0; |
60 bt.isMac = navigator.platform.indexOf('Mac') >= 0; | 60 bt.isMac = navigator.platform.indexOf('Mac') >= 0; |
61 bt.isWin = navigator.platform.indexOf('Win') >= 0; | 61 bt.isWin = navigator.platform.indexOf('Win') >= 0; |
62 bt.isN4 = (navigator.userAgent.indexOf('Mozilla/4.') >= 0) && ! bt.isIE; | 62 bt.isN4 = (navigator.userAgent.indexOf('Mozilla/4.') >= 0) && ! bt.isIE; |
63 bt.isIEWin = bt.versIE > 0 && bt.isWin; | 63 bt.isIEWin = bt.versIE > 0 && bt.isWin; |
64 if (navigator.appVersion.indexOf('MSIE') < 0 || ! bt.isMac || bt.versIE >= 5) { | 64 if (navigator.appVersion.indexOf('MSIE') < 0 || ! bt.isMac || bt.versIE >= 5) { |
65 bt.doDHTML = true; | 65 bt.doDHTML = true; |
66 bt.isOpera = navigator.userAgent.indexOf(' Opera ') >= 0; | 66 bt.isOpera = navigator.userAgent.indexOf(' Opera ') >= 0; |
67 bt.isKonq = navigator.userAgent.indexOf(' Konqueror') >= 0; | 67 bt.isKonq = navigator.userAgent.indexOf(' Konqueror') >= 0; |
68 } | 68 } |
69 } | 69 } |
70 return bt; | 70 return bt; |
71 } | 71 } |
72 | 72 |
73 // fixes for javascript < 1.2 | 73 // fixes for javascript < 1.2 |
74 if (! Array.prototype.push) { | 74 if (! Array.prototype.push) { |
75 Array.prototype.push = function(val) { | 75 Array.prototype.push = function(val) { |
76 this[this.length] = val; | 76 this[this.length] = val; |
77 return this.length; | 77 return this.length; |
78 } | 78 } |
79 Array.prototype.pop = function() { | 79 Array.prototype.pop = function() { |
80 var val = this[this.length-1]; | 80 var val = this[this.length-1]; |
81 this.length -= 1; | 81 this.length -= 1; |
82 return val; | 82 return val; |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 /* ********************************************** | 87 /* ********************************************** |
148 } | 148 } |
149 Rectangle.prototype.intersect = function(rect) { | 149 Rectangle.prototype.intersect = function(rect) { |
150 // returns the intersection of the given Rectangle and this one | 150 // returns the intersection of the given Rectangle and this one |
151 var sec = rect.copy(); | 151 var sec = rect.copy(); |
152 if (sec.x < this.x) { | 152 if (sec.x < this.x) { |
153 sec.width = sec.width - (this.x - sec.x); | 153 sec.width = sec.width - (this.x - sec.x); |
154 sec.x = this.x; | 154 sec.x = this.x; |
155 } | 155 } |
156 if (sec.y < this.y) { | 156 if (sec.y < this.y) { |
157 sec.height = sec.height - (this.y - sec.y); | 157 sec.height = sec.height - (this.y - sec.y); |
158 sec.y = this.y; | 158 sec.y = this.y; |
159 } | 159 } |
160 if (sec.x + sec.width > this.x + this.width) { | 160 if (sec.x + sec.width > this.x + this.width) { |
161 sec.width = (this.x + this.width) - sec.x; | 161 sec.width = (this.x + this.width) - sec.x; |
162 } | 162 } |
163 if (sec.y + sec.height > this.y + this.height) { | 163 if (sec.y + sec.height > this.y + this.height) { |
164 sec.height = (this.y + this.height) - sec.y; | 164 sec.height = (this.y + this.height) - sec.y; |
165 } | 165 } |
166 return sec; | 166 return sec; |
167 } | 167 } |
168 Rectangle.prototype.fit = function(rect) { | 168 Rectangle.prototype.fit = function(rect) { |
169 // returns a Rectangle that fits into this one (by moving first) | 169 // returns a Rectangle that fits into this one (by moving first) |
170 var sec = rect.copy(); | 170 var sec = rect.copy(); |
171 sec.x = Math.max(sec.x, this.x); | 171 sec.x = Math.max(sec.x, this.x); |
172 sec.x = Math.max(sec.x, this.x); | 172 sec.x = Math.max(sec.x, this.x); |
173 if (sec.x + sec.width > this.x + this.width) { | 173 if (sec.x + sec.width > this.x + this.width) { |
174 sec.x = this.x + this.width - sec.width; | 174 sec.x = this.x + this.width - sec.width; |
175 } | 175 } |
176 if (sec.y + sec.height > this.y + this.height) { | 176 if (sec.y + sec.height > this.y + this.height) { |
177 sec.y = this.y + this.height - sec.height; | 177 sec.y = this.y + this.height - sec.height; |
178 } | 178 } |
179 return sec.intersect(this); | 179 return sec.intersect(this); |
180 } | 180 } |
181 | 181 |
182 /* | 182 /* |
197 return this; | 197 return this; |
198 } | 198 } |
199 Transform.prototype.concat = function(traf) { | 199 Transform.prototype.concat = function(traf) { |
200 // add Transform traf to this Transform | 200 // add Transform traf to this Transform |
201 for (var i = 0; i < 3; i++) { | 201 for (var i = 0; i < 3; i++) { |
202 for (var j = 0; j < 3; j++) { | 202 for (var j = 0; j < 3; j++) { |
203 var c = 0.0; | 203 var c = 0.0; |
204 for (var k = 0; k < 3; k++) { | 204 for (var k = 0; k < 3; k++) { |
205 c += traf["m"+i+k] * this["m"+k+j]; | 205 c += traf["m"+i+k] * this["m"+k+j]; |
206 } | 206 } |
207 this["m"+i+j] = c; | 207 this["m"+i+j] = c; |
208 } | 208 } |
209 } | 209 } |
210 return this; | 210 return this; |
211 } | 211 } |
212 Transform.prototype.transform = function(rect) { | 212 Transform.prototype.transform = function(rect) { |
213 // returns transformed Rectangle or Position with this Transform applied | 213 // returns transformed Rectangle or Position with this Transform applied |
214 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02; | 214 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02; |
215 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12; | 215 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12; |
216 if (rect.width) { | 216 if (rect.width) { |
217 var width = this.m00 * rect.width + this.m01 * rect.height; | 217 var width = this.m00 * rect.width + this.m01 * rect.height; |
218 var height = this.m10 * rect.width + this.m11 * rect.height; | 218 var height = this.m10 * rect.width + this.m11 * rect.height; |
219 return new Rectangle(x, y, width, height); | 219 return new Rectangle(x, y, width, height); |
220 } | 220 } |
221 return new Position(x, y); | 221 return new Position(x, y); |
222 } | 222 } |
223 Transform.prototype.invtransform = function(pos) { | 223 Transform.prototype.invtransform = function(pos) { |
224 // returns transformed Position pos with the inverse of this Transform applied | 224 // returns transformed Position pos with the inverse of this Transform applied |
229 } | 229 } |
230 function getRotation(angle, pos) { | 230 function getRotation(angle, pos) { |
231 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y] | 231 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y] |
232 var traf = new Transform(); | 232 var traf = new Transform(); |
233 if (angle != 0) { | 233 if (angle != 0) { |
234 var t = 2.0 * Math.PI * parseFloat(angle) / 360.0; | 234 var t = 2.0 * Math.PI * parseFloat(angle) / 360.0; |
235 traf.m00 = Math.cos(t); | 235 traf.m00 = Math.cos(t); |
236 traf.m01 = - Math.sin(t); | 236 traf.m01 = - Math.sin(t); |
237 traf.m10 = Math.sin(t); | 237 traf.m10 = Math.sin(t); |
238 traf.m11 = Math.cos(t); | 238 traf.m11 = Math.cos(t); |
239 traf.m02 = pos.x - pos.x * Math.cos(t) + pos.y * Math.sin(t); | 239 traf.m02 = pos.x - pos.x * Math.cos(t) + pos.y * Math.sin(t); |
240 traf.m12 = pos.y - pos.x * Math.sin(t) - pos.y * Math.cos(t); | 240 traf.m12 = pos.y - pos.x * Math.sin(t) - pos.y * Math.cos(t); |
241 } | 241 } |
242 return traf; | 242 return traf; |
243 } | 243 } |
244 function getTranslation(pos) { | 244 function getTranslation(pos) { |
245 // returns a Transform that is a translation by [pos.x, pos,y] | 245 // returns a Transform that is a translation by [pos.x, pos,y] |
262 * ******************************************** */ | 262 * ******************************************** */ |
263 | 263 |
264 function newParameter(name, defaultValue, detail) { | 264 function newParameter(name, defaultValue, detail) { |
265 // create a new parameter with a name and a default value | 265 // create a new parameter with a name and a default value |
266 if (defined(dlParams[name])) { | 266 if (defined(dlParams[name])) { |
267 alert("Fatal: An object with name '" + name + "' already exists - cannot recreate!"); | 267 alert("Fatal: An object with name '" + name + "' already exists - cannot recreate!"); |
268 return false; | 268 return false; |
269 } else { | 269 } else { |
270 dlParams[name] = new Object(); | 270 dlParams[name] = new Object(); |
271 dlParams[name].defaultValue = defaultValue; | 271 dlParams[name].defaultValue = defaultValue; |
272 dlParams[name].hasValue = false; | 272 dlParams[name].hasValue = false; |
273 dlParams[name].value = defaultValue; | 273 dlParams[name].value = defaultValue; |
274 dlParams[name].detail = detail; | 274 dlParams[name].detail = detail; |
275 return dlParams[name]; | 275 return dlParams[name]; |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 function getParameter(name) { | 279 function getParameter(name) { |
280 // returns the named parameter value or its default value | 280 // returns the named parameter value or its default value |
281 if (defined(dlParams) && defined(dlParams[name])) { | |
282 if (dlParams[name].hasValue) { | |
283 return dlParams[name].value; | |
284 } else { | |
285 return dlParams[name].defaultValue; | |
286 } | |
287 } else { | |
288 return null; | |
289 } | |
290 } | |
291 | |
292 function setParameter(name, value) { | |
293 // sets parameter value | |
294 if (defined(dlParams[name])) { | 281 if (defined(dlParams[name])) { |
295 dlParams[name].value = value; | 282 if (dlParams[name].hasValue) { |
296 dlParams[name].hasValue = true; | 283 return dlParams[name].value; |
297 return true; | 284 } else { |
285 return dlParams[name].defaultValue; | |
286 } | |
287 } else { | |
288 return null; | |
289 } | |
290 } | |
291 | |
292 function setParameter(name, value, relative) { | |
293 // sets parameter value (relative values with +/- unless literal) | |
294 if (defined(dlParams[name])) { | |
295 if ((relative)&&(value.slice)) { | |
296 var sign = value.slice(0,1); | |
297 if (sign == '+') { | |
298 dlParams[name].value = parseFloat(dlParams[name].value) + parseFloat(value.slice(1)); | |
299 } else if (sign == '-') { | |
300 dlParams[name].value = parseFloat(dlParams[name].value) - parseFloat(value.slice(1)); | |
301 } else { | |
302 dlParams[name].value = value; | |
303 } | |
304 } else { | |
305 dlParams[name].value = value; | |
306 } | |
307 dlParams[name].hasValue = true; | |
308 return true; | |
298 } | 309 } |
299 return false; | 310 return false; |
300 } | 311 } |
301 | 312 |
302 function hasParameter(name) { | 313 function hasParameter(name) { |
303 // returns if the parameter's value has been set | 314 // returns if the parameter's value has been set |
304 if (defined(dlParams[name])) { | 315 if (defined(dlParams[name])) { |
305 return dlParams[name].hasValue; | 316 return dlParams[name].hasValue; |
306 } | 317 } |
307 return false; | 318 return false; |
308 } | 319 } |
309 | 320 |
310 function getAllParameters(detail) { | 321 function getAllParameters(detail) { |
311 // returns a string of all parameters in query format | 322 // returns a string of all parameters in query format |
312 if (! detail) { | 323 if (! detail) { |
313 detail = 10; | 324 detail = 255; |
314 } | 325 } |
315 var params = new Array(); | 326 var params = new Array(); |
316 for ( param in dlParams ) { | 327 for (param in dlParams) { |
317 if ((dlParams[param].detail <= detail)&&(dlParams[param].hasValue)) { | 328 if (((dlParams[param].detail & detail) > 0)&&(dlParams[param].hasValue)) { |
318 var val = getParameter(param); | 329 var val = getParameter(param); |
319 if (val != "") { | 330 if (val != "") { |
320 params.push(param + "=" + val); | 331 params.push(param + "=" + val); |
321 } | 332 } |
322 } | 333 } |
323 } | 334 } |
324 return params.join("&"); | 335 return params.join("&"); |
325 } | 336 } |
326 | 337 |
327 function parseParameters(query) { | 338 function parseParameters(query) { |
328 // gets parameter values from query format string | 339 // gets parameter values from query format string |
329 var params = query.split("&"); | 340 var params = query.split("&"); |
330 for (var i = 0; i < params.length; i++) { | 341 for (var i = 0; i < params.length; i++) { |
331 var keyval = params[i].split("="); | 342 var keyval = params[i].split("="); |
332 if (keyval.length == 2) { | 343 if (keyval.length == 2) { |
333 setParameter(keyval[0], keyval[1]); | 344 setParameter(keyval[0], keyval[1]); |
334 } | 345 } |
335 } | 346 } |
336 } | 347 } |
337 | 348 |
338 | 349 |
339 /* ********************************************** | 350 /* ********************************************** |
342 | 353 |
343 function getElement(tagid, quiet) { | 354 function getElement(tagid, quiet) { |
344 // returns the element object with the id tagid | 355 // returns the element object with the id tagid |
345 var e; | 356 var e; |
346 if (document.getElementById) { | 357 if (document.getElementById) { |
347 e = document.getElementById(tagid); | 358 e = document.getElementById(tagid); |
348 } else if (document.all) { | 359 } else if (document.all) { |
349 alert("document.all!"); | 360 alert("document.all!"); |
350 e = document.all[tagid]; | 361 e = document.all[tagid]; |
351 } else if (document.layers) { | 362 } else if (document.layers) { |
352 e = document.layers[tagid]; | 363 e = document.layers[tagid]; |
353 } | 364 } |
354 if (e) { | 365 if (e) { |
355 return e; | 366 return e; |
356 } else { | 367 } else { |
357 if (! quiet) { | 368 if (! quiet) { |
358 alert("unable to find element: "+tagid); | 369 alert("unable to find element: "+tagid); |
359 } | 370 } |
360 return null; | 371 return null; |
361 } | 372 } |
362 } | 373 } |
363 | 374 |
364 function getElementPosition(elem) { | 375 function getElementPosition(elem) { |
365 // returns a Position with the position of the element | 376 // returns a Position with the position of the element |
366 var x = 0; | 377 var x = 0; |
367 var y = 0; | 378 var y = 0; |
368 if (defined(elem.offsetLeft)) { | 379 if (defined(elem.offsetLeft)) { |
369 var e = elem; | 380 var e = elem; |
370 while (e) { | 381 while (e) { |
371 if (defined(e.clientLeft)) { | 382 if (defined(e.clientLeft)) { |
372 // special for IE | 383 // special for IE |
373 if (browserType.isMac) { | 384 if (browserType.isMac) { |
374 if (e.offsetParent.tagName == "BODY") { | 385 if (e.offsetParent.tagName == "BODY") { |
375 // IE for Mac extraspecial | 386 // IE for Mac extraspecial |
376 x += e.clientLeft; | 387 x += e.clientLeft; |
377 y += e.clientTop; | 388 y += e.clientTop; |
378 break; | 389 break; |
379 } | 390 } |
380 } else { | 391 } else { |
381 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) { | 392 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) { |
382 x += e.clientLeft; | 393 x += e.clientLeft; |
383 y += e.clientTop; | 394 y += e.clientTop; |
384 } | 395 } |
385 } | 396 } |
386 } | 397 } |
387 x += e.offsetLeft; | 398 x += e.offsetLeft; |
388 y += e.offsetTop; | 399 y += e.offsetTop; |
389 e = e.offsetParent; | 400 e = e.offsetParent; |
390 } | 401 } |
391 } else if (defined(elem.x)) { | 402 } else if (defined(elem.x)) { |
392 x = elem.x; | 403 x = elem.x; |
393 y = elem.y; | 404 y = elem.y; |
394 } else if (defined(elem.pageX)) { | 405 } else if (defined(elem.pageX)) { |
395 x = elem.pageX; | 406 x = elem.pageX; |
396 y = elem.pageY; | 407 y = elem.pageY; |
397 } else { | 408 } else { |
398 alert("unable to get position of "+elem+" (id:"+elem.id+")"); | 409 alert("unable to get position of "+elem+" (id:"+elem.id+")"); |
399 } | 410 } |
400 return new Position(getInt(x), getInt(y)); | 411 return new Position(getInt(x), getInt(y)); |
401 } | 412 } |
402 | 413 |
403 function getElementSize(elem) { | 414 function getElementSize(elem) { |
404 // returns a Rectangle with the size of the element | 415 // returns a Rectangle with the size of the element |
405 var width = 0; | 416 var width = 0; |
406 var height = 0; | 417 var height = 0; |
407 if (defined(elem.offsetWidth)) { | 418 if (defined(elem.offsetWidth)) { |
408 width = elem.offsetWidth; | 419 width = elem.offsetWidth; |
409 height = elem.offsetHeight; | 420 height = elem.offsetHeight; |
410 } else if (defined(elem.width)) { | 421 } else if (defined(elem.width)) { |
411 width = elem.width; | 422 width = elem.width; |
412 height = elem.height; | 423 height = elem.height; |
413 } else if (defined(elem.clip.width)) { | 424 } else if (defined(elem.clip.width)) { |
414 width = elem.clip.width; | 425 width = elem.clip.width; |
415 height = elem.clip.height; | 426 height = elem.clip.height; |
416 } else { | 427 } else { |
417 alert("unable to get size of "+elem+" (id:"+elem.id+")"); | 428 alert("unable to get size of "+elem+" (id:"+elem.id+")"); |
418 } | 429 } |
419 return new Size(getInt(width), getInt(height)); | 430 return new Size(getInt(width), getInt(height)); |
420 } | 431 } |
421 | 432 |
422 function getElementRect(elem) { | 433 function getElementRect(elem) { |
429 | 440 |
430 | 441 |
431 function moveElement(elem, rect) { | 442 function moveElement(elem, rect) { |
432 // moves and sizes the element | 443 // moves and sizes the element |
433 if (elem.style) { | 444 if (elem.style) { |
434 if (defined(rect.x)) { | 445 if (defined(rect.x)) { |
435 elem.style.left = Math.round(rect.x) + "px"; | 446 elem.style.left = Math.round(rect.x) + "px"; |
436 elem.style.top = Math.round(rect.y) + "px"; | 447 elem.style.top = Math.round(rect.y) + "px"; |
437 } | 448 } |
438 if (defined(rect.width)) { | 449 if (defined(rect.width)) { |
439 elem.style.width = Math.round(rect.width) + "px"; | 450 elem.style.width = Math.round(rect.width) + "px"; |
440 elem.style.height = Math.round(rect.height) + "px"; | 451 elem.style.height = Math.round(rect.height) + "px"; |
441 } | 452 } |
442 } else if (document.layers) { | 453 } else if (document.layers) { |
443 if (defined(rect.x)) { | 454 if (defined(rect.x)) { |
444 elem.pageX = getInt(rect.x); | 455 elem.pageX = getInt(rect.x); |
445 elem.pageY = getInt(rect.y); | 456 elem.pageY = getInt(rect.y); |
446 } | 457 } |
447 if (defined(rect.width)) { | 458 if (defined(rect.width)) { |
448 elem.clip.width = getInt(rect.width); | 459 elem.clip.width = getInt(rect.width); |
449 elem.clip.height = getInt(rect.height); | 460 elem.clip.height = getInt(rect.height); |
450 } | 461 } |
451 } else { | 462 } else { |
452 alert("moveelement: no style nor layer property!"); | 463 alert("moveelement: no style nor layer property!"); |
453 return false; | 464 return false; |
454 } | 465 } |
455 return true; | 466 return true; |
456 } | 467 } |
457 | 468 |
458 function showElement(elem, show) { | 469 function showElement(elem, show) { |
459 // shows or hides the element | 470 // shows or hides the element |
460 if (elem.style) { | 471 if (elem.style) { |
461 if (show) { | 472 if (show) { |
462 elem.style.visibility = "visible"; | 473 elem.style.visibility = "visible"; |
463 } else { | 474 } else { |
464 elem.style.visibility = "hidden"; | 475 elem.style.visibility = "hidden"; |
465 } | 476 } |
466 } else if (defined(elem.visibility)) { | 477 } else if (defined(elem.visibility)) { |
467 if (show) { | 478 if (show) { |
468 elem.visibility = "show"; | 479 elem.visibility = "show"; |
469 } else { | 480 } else { |
470 elem.visibility = "hide"; | 481 elem.visibility = "hide"; |
471 } | 482 } |
472 } else { | 483 } else { |
473 alert("showelement: no style nor layer property!"); | 484 alert("showelement: no style nor layer property!"); |
474 } | 485 } |
475 return true; | 486 return true; |
476 } | 487 } |
477 | 488 |
478 function evtPosition(evt) { | 489 function evtPosition(evt) { |
479 // returns the on-screen Position of the Event | 490 // returns the on-screen Position of the Event |
480 var x; | 491 var x; |
481 var y; | 492 var y; |
482 evt = (evt) ? evt : window.event; | 493 evt = (evt) ? evt : window.event; |
483 if (!evt) { | 494 if (!evt) { |
484 alert("no event found! "+evt); | 495 alert("no event found! "+evt); |
485 return; | 496 return; |
486 } | 497 } |
487 if (defined(evt.pageX)) { | 498 if (defined(evt.pageX)) { |
488 x = parseInt(evt.pageX); | 499 x = parseInt(evt.pageX); |
489 y = parseInt(evt.pageY); | 500 y = parseInt(evt.pageY); |
490 } else if (defined(evt.clientX)) { | 501 } else if (defined(evt.clientX)) { |
491 x = parseInt(document.body.scrollLeft+evt.clientX); | 502 x = parseInt(document.body.scrollLeft+evt.clientX); |
492 y = parseInt(document.body.scrollTop+evt.clientY); | 503 y = parseInt(document.body.scrollTop+evt.clientY); |
493 } else { | 504 } else { |
494 alert("evtPosition: don't know how to deal with "+evt); | 505 alert("evtPosition: don't know how to deal with "+evt); |
495 } | 506 } |
496 return new Position(x, y); | 507 return new Position(x, y); |
497 } | 508 } |
498 | 509 |
499 function registerEvent(type, elem, handler) { | 510 function registerEvent(type, elem, handler) { |
500 // register the given event handler on the indicated element | 511 // register the given event handler on the indicated element |
501 if (elem.addEventListener) { | 512 if (elem.addEventListener) { |
502 elem.addEventListener(type, handler, false); | 513 elem.addEventListener(type, handler, false); |
503 } else { | 514 } else { |
504 if (type == "mousedown") { | 515 if (type == "mousedown") { |
505 if (elem.captureEvents) { | 516 if (elem.captureEvents) { |
506 elem.captureEvents(Event.MOUSEDOWN); | 517 elem.captureEvents(Event.MOUSEDOWN); |
507 } | 518 } |
508 elem.onmousedown = handler; | 519 elem.onmousedown = handler; |
509 } else if (type == "mouseup") { | 520 } else if (type == "mouseup") { |
510 if (elem.captureEvents) { | 521 if (elem.captureEvents) { |
511 elem.captureEvents(Event.MOUSEUP); | 522 elem.captureEvents(Event.MOUSEUP); |
512 } | 523 } |
513 elem.onmouseup = handler; | 524 elem.onmouseup = handler; |
514 } else if (type == "mousemove") { | 525 } else if (type == "mousemove") { |
515 if (elem.captureEvents) { | 526 if (elem.captureEvents) { |
516 elem.captureEvents(Event.MOUSEMOVE); | 527 elem.captureEvents(Event.MOUSEMOVE); |
517 } | 528 } |
518 elem.onmousemove = handler; | 529 elem.onmousemove = handler; |
519 } else if (type == "keypress") { | 530 } else if (type == "keypress") { |
520 if (elem.captureEvents) { | 531 if (elem.captureEvents) { |
521 elem.captureEvents(Event.KEYPRESS); | 532 elem.captureEvents(Event.KEYPRESS); |
522 } | 533 } |
523 elem.onkeypress = handler; | 534 elem.onkeypress = handler; |
524 } else { | 535 } else { |
525 alert("registerEvent: unknown event type "+type); | 536 alert("registerEvent: unknown event type "+type); |
526 return false; | 537 return false; |
527 } | 538 } |
528 } | 539 } |
529 return true; | 540 return true; |
530 } | 541 } |
531 | 542 |
532 function unregisterEvent(type, elem, handler) { | 543 function unregisterEvent(type, elem, handler) { |
533 // unregister the given event handler from the indicated element | 544 // unregister the given event handler from the indicated element |
534 if (elem.removeEventListener) { | 545 if (elem.removeEventListener) { |
535 elem.removeEventListener(type, handler, false); | 546 elem.removeEventListener(type, handler, false); |
536 } else { | 547 } else { |
537 if (type == "mousedown") { | 548 if (type == "mousedown") { |
538 if (elem.releaseEvents) { | 549 if (elem.releaseEvents) { |
539 elem.releaseEvents(Event.MOUSEDOWN); | 550 elem.releaseEvents(Event.MOUSEDOWN); |
540 } | 551 } |
541 elem.onmousedown = null; | 552 elem.onmousedown = null; |
542 } else if (type == "mouseup") { | 553 } else if (type == "mouseup") { |
543 if (elem.releaseEvents) { | 554 if (elem.releaseEvents) { |
544 elem.releaseEvents(Event.MOUSEUP); | 555 elem.releaseEvents(Event.MOUSEUP); |
545 } | 556 } |
546 elem.onmouseup = null; | 557 elem.onmouseup = null; |
547 } else if (type == "mousemove") { | 558 } else if (type == "mousemove") { |
548 if (elem.releaseEvents) { | 559 if (elem.releaseEvents) { |
549 elem.releaseEvents(Event.MOUSEMOVE); | 560 elem.releaseEvents(Event.MOUSEMOVE); |
550 } | 561 } |
551 elem.onmousemove = null; | 562 elem.onmousemove = null; |
552 } else if (type == "keypress") { | 563 } else if (type == "keypress") { |
553 if (elem.releaseEvents) { | 564 if (elem.releaseEvents) { |
554 elem.releaseEvents(Event.KEYPRESS); | 565 elem.releaseEvents(Event.KEYPRESS); |
555 } | 566 } |
556 elem.onkeypress = null; | 567 elem.onkeypress = null; |
557 } else { | 568 } else { |
558 alert("unregisterEvent: unknown event type "+type); | 569 alert("unregisterEvent: unknown event type "+type); |
559 return false; | 570 return false; |
560 } | 571 } |
561 } | 572 } |
562 return true; | 573 return true; |
563 } | 574 } |
564 | 575 |
565 | 576 |
583 | 594 |
584 function getWinSize() { | 595 function getWinSize() { |
585 // returns a Size with the current window size (mostly from www.quirksmode.org) | 596 // returns a Size with the current window size (mostly from www.quirksmode.org) |
586 var wsize = new Size(100, 100); | 597 var wsize = new Size(100, 100); |
587 if (defined(self.innerHeight)) { | 598 if (defined(self.innerHeight)) { |
588 // all except Explorer | 599 // all except Explorer |
589 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { | 600 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { |
590 // Safari 1.2 bug | 601 // Safari 1.2 bug |
591 if (parent) { | 602 if (parent) { |
592 parent.innerHeight; | 603 parent.innerHeight; |
593 parent.innerWidth; | 604 parent.innerWidth; |
594 } | 605 } |
595 } | 606 } |
596 wsize.width = self.innerWidth; | 607 wsize.width = self.innerWidth; |
597 wsize.height = self.innerHeight; | 608 wsize.height = self.innerHeight; |
598 } else if (document.documentElement && document.documentElement.clientHeight) { | 609 } else if (document.documentElement && document.documentElement.clientHeight) { |
599 // Explorer 6 Strict Mode | 610 // Explorer 6 Strict Mode |
600 wsize.width = document.documentElement.clientWidth; | 611 wsize.width = document.documentElement.clientWidth; |
601 wsize.height = document.documentElement.clientHeight; | 612 wsize.height = document.documentElement.clientHeight; |
602 } else if (document.body) { | 613 } else if (document.body) { |
603 // other Explorers | 614 // other Explorers |
604 wsize.width = document.body.clientWidth; | 615 wsize.width = document.body.clientWidth; |
605 wsize.height = document.body.clientHeight; | 616 wsize.height = document.body.clientHeight; |
606 } | 617 } |
607 return wsize; | 618 return wsize; |
608 } | 619 } |
609 | 620 |
610 function openWin(url, name, params) { | 621 function openWin(url, name, params) { |