Mercurial > hg > digilib
annotate client/digitallibrary/baselib.js @ 449:6b90a62afad1
ongoing experimental intermediary release
- more cleanup on object stuff
- new mark image
- menu is now fixed and tries to work in IE
| author | robcast |
|---|---|
| date | Tue, 24 Jan 2006 21:17:44 +0100 |
| parents | ef1519f9cf42 |
| children | a9d7a406d85e |
| rev | line source |
|---|---|
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
1 /* Copyright (C) 2003,2004 IT-Group MPIWG, WTWG Uni Bern and others |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
2 |
| 233 | 3 This program is free software; you can redistribute it and/or |
| 4 modify it under the terms of the GNU General Public License | |
| 5 as published by the Free Software Foundation; either version 2 | |
| 6 of the License, or (at your option) any later version. | |
| 7 | |
| 8 This program is distributed in the hope that it will be useful, | |
| 9 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 GNU General Public License for more details. | |
| 12 | |
| 13 You should have received a copy of the GNU General Public License | |
| 14 along with this program; if not, write to the Free Software | |
| 15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
| 16 | |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
17 Authors: |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
18 Christian Luginbuehl, 01.05.2003 (first version) |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
19 DW 24.03.2004 (Changed for digiLib in Zope) |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
20 Robert Casties, 2.11.2004 |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
21 |
| 233 | 22 */ |
| 23 | |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
24 function base_init() { |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
25 // init function |
| 382 | 26 baseScriptVersion = "1.2"; |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
27 dlParams = new Object(); |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
28 browserType = getBrowserType(); |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
29 } |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
30 |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
31 |
| 237 | 32 function getInt(n) { |
| 233 | 33 // returns always an integer |
| 237 | 34 n = parseInt(n); |
| 35 if (isNaN(n)) return 0; | |
| 233 | 36 return n; |
| 37 } | |
| 38 | |
| 39 function defined(x) { | |
| 40 // returns if x is defined | |
| 41 return (typeof arguments[0] != "undefined"); | |
| 42 } | |
| 43 | |
| 44 function cropFloat(x) { | |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
45 // auxiliary function to crop senseless precision |
| 233 | 46 return parseInt(10000*x)/10000; |
| 47 } | |
| 48 | |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
49 function getBrowserType() { |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
50 // browser sniffer |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
51 var bt = Object(); |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
52 bt.doDHTML = false; |
|
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
53 bt.versIE = 0; |
| 233 | 54 |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
55 if ((! document.cssonly && document.layers) || document.all || document.getElementById) { |
| 382 | 56 var vers = navigator.appVersion.split('MSIE '); |
| 57 vers = vers[vers.length - 1]; | |
| 58 bt.versIE = getInt(vers); | |
| 59 bt.isIE = navigator.userAgent.indexOf('MSIE') >= 0; | |
| 60 bt.isMac = navigator.platform.indexOf('Mac') >= 0; | |
| 61 bt.isWin = navigator.platform.indexOf('Win') >= 0; | |
| 62 bt.isN4 = (navigator.userAgent.indexOf('Mozilla/4.') >= 0) && ! bt.isIE; | |
| 63 bt.isIEWin = bt.versIE > 0 && bt.isWin; | |
| 64 if (navigator.appVersion.indexOf('MSIE') < 0 || ! bt.isMac || bt.versIE >= 5) { | |
| 65 bt.doDHTML = true; | |
| 66 bt.isOpera = navigator.userAgent.indexOf(' Opera ') >= 0; | |
| 67 bt.isKonq = navigator.userAgent.indexOf(' Konqueror') >= 0; | |
| 68 } | |
| 233 | 69 } |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
70 return bt; |
| 233 | 71 } |
| 72 | |
| 73 // fixes for javascript < 1.2 | |
| 74 if (! Array.prototype.push) { | |
| 75 Array.prototype.push = function(val) { | |
| 382 | 76 this[this.length] = val; |
| 77 return this.length; | |
| 233 | 78 } |
| 79 Array.prototype.pop = function() { | |
| 382 | 80 var val = this[this.length-1]; |
| 81 this.length -= 1; | |
| 82 return val; | |
| 233 | 83 } |
| 84 } | |
| 85 | |
| 86 | |
| 87 /* ********************************************** | |
| 88 * geometry classes | |
| 89 * ******************************************** */ | |
| 90 | |
| 91 /* | |
| 92 * Size class | |
| 93 */ | |
| 94 function Size(w, h) { | |
| 95 this.width = parseFloat(w); | |
| 96 this.height = parseFloat(h); | |
| 97 return this; | |
| 98 } | |
| 316 | 99 Size.prototype.toString = function() { |
| 100 return this.width + "x" + this.height; | |
| 101 } | |
| 102 | |
| 233 | 103 |
| 104 /* | |
| 105 * Position class | |
| 106 */ | |
| 107 function Position(x, y) { | |
| 108 this.x = parseFloat(x); | |
| 109 this.y = parseFloat(y); | |
| 110 return this; | |
| 111 } | |
| 316 | 112 Position.prototype.toString = function() { |
| 113 return this.x + "," + this.y; | |
| 114 } | |
| 233 | 115 |
| 116 /* | |
| 117 * Rectangle class | |
| 118 */ | |
| 119 function Rectangle(x, y, w, h) { | |
| 120 this.x = parseFloat(x); | |
| 121 this.y = parseFloat(y); | |
| 122 this.width = parseFloat(w); | |
| 123 this.height = parseFloat(h); | |
| 124 return this; | |
| 125 } | |
| 316 | 126 Rectangle.prototype.toString = function() { |
| 127 return this.width+"x"+this.height+"@"+this.x+","+this.y; | |
| 128 } | |
| 233 | 129 Rectangle.prototype.copy = function() { |
| 130 // returns a copy of this Rectangle | |
| 131 return new Rectangle(this.x, this.y, this.width, this.height); | |
| 132 } | |
| 133 Rectangle.prototype.getPosition = function() { | |
| 134 // returns the position of this Rectangle | |
| 135 return new Position(this.x, this.y); | |
| 136 } | |
| 137 Rectangle.prototype.getSize = function() { | |
| 138 // returns the size of this Rectangle | |
| 139 return new Size(this.width, this.height); | |
| 140 } | |
| 141 Rectangle.prototype.getArea = function() { | |
| 142 // returns the area of this Rectangle | |
| 143 return (this.width * this.height); | |
| 144 } | |
| 145 Rectangle.prototype.containsPosition = function(pos) { | |
| 146 // returns if the given Position lies in this Rectangle | |
| 147 return ((pos.x >= this.x)&&(pos.y >= this.y)&&(pos.x <= this.x+this.width)&&(pos.y <= this.y+this.width)); | |
| 148 } | |
| 149 Rectangle.prototype.intersect = function(rect) { | |
| 150 // returns the intersection of the given Rectangle and this one | |
| 151 var sec = rect.copy(); | |
| 152 if (sec.x < this.x) { | |
| 382 | 153 sec.width = sec.width - (this.x - sec.x); |
| 154 sec.x = this.x; | |
| 233 | 155 } |
| 156 if (sec.y < this.y) { | |
| 382 | 157 sec.height = sec.height - (this.y - sec.y); |
| 158 sec.y = this.y; | |
| 233 | 159 } |
| 160 if (sec.x + sec.width > this.x + this.width) { | |
| 382 | 161 sec.width = (this.x + this.width) - sec.x; |
| 233 | 162 } |
| 163 if (sec.y + sec.height > this.y + this.height) { | |
| 382 | 164 sec.height = (this.y + this.height) - sec.y; |
| 233 | 165 } |
| 166 return sec; | |
| 167 } | |
| 168 Rectangle.prototype.fit = function(rect) { | |
| 169 // returns a Rectangle that fits into this one (by moving first) | |
| 170 var sec = rect.copy(); | |
| 171 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) { | |
| 382 | 174 sec.x = this.x + this.width - sec.width; |
| 233 | 175 } |
| 176 if (sec.y + sec.height > this.y + this.height) { | |
| 382 | 177 sec.y = this.y + this.height - sec.height; |
| 233 | 178 } |
| 179 return sec.intersect(this); | |
| 180 } | |
| 181 | |
| 182 /* | |
| 183 * Transform class | |
| 184 * | |
| 185 * defines a class of affine transformations | |
| 186 */ | |
| 187 function Transform() { | |
| 188 this.m00 = 1.0; | |
| 189 this.m01 = 0.0; | |
| 190 this.m02 = 0.0; | |
| 191 this.m10 = 0.0; | |
| 192 this.m11 = 1.0; | |
| 193 this.m12 = 0.0; | |
| 194 this.m20 = 0.0; | |
| 195 this.m21 = 0.0; | |
| 196 this.m22 = 1.0; | |
| 197 return this; | |
| 198 } | |
| 199 Transform.prototype.concat = function(traf) { | |
| 200 // add Transform traf to this Transform | |
| 201 for (var i = 0; i < 3; i++) { | |
| 382 | 202 for (var j = 0; j < 3; j++) { |
| 203 var c = 0.0; | |
| 204 for (var k = 0; k < 3; k++) { | |
| 205 c += traf["m"+i+k] * this["m"+k+j]; | |
| 206 } | |
| 207 this["m"+i+j] = c; | |
| 208 } | |
| 233 | 209 } |
| 210 return this; | |
| 211 } | |
| 212 Transform.prototype.transform = function(rect) { | |
| 213 // returns transformed Rectangle or Position with this Transform applied | |
| 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; | |
| 216 if (rect.width) { | |
| 382 | 217 var width = this.m00 * rect.width + this.m01 * rect.height; |
| 218 var height = this.m10 * rect.width + this.m11 * rect.height; | |
| 219 return new Rectangle(x, y, width, height); | |
| 233 | 220 } |
| 221 return new Position(x, y); | |
| 222 } | |
| 223 Transform.prototype.invtransform = function(pos) { | |
| 224 // returns transformed Position pos with the inverse of this Transform applied | |
| 225 var det = this.m00 * this.m11 - this.m01 * this.m10; | |
| 226 var x = (this.m11 * pos.x - this.m01 * pos.y - this.m11 * this.m02 + this.m01 * this.m12) / det; | |
| 227 var y = (- this.m10 * pos.x + this.m00 * pos.y + this.m10 * this.m02 - this.m00 * this.m12) / det; | |
| 228 return new Position(x, y); | |
| 229 } | |
| 230 function getRotation(angle, pos) { | |
| 231 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y] | |
| 232 var traf = new Transform(); | |
| 233 if (angle != 0) { | |
| 382 | 234 var t = 2.0 * Math.PI * parseFloat(angle) / 360.0; |
| 235 traf.m00 = Math.cos(t); | |
| 236 traf.m01 = - Math.sin(t); | |
| 237 traf.m10 = Math.sin(t); | |
| 238 traf.m11 = Math.cos(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); | |
| 233 | 241 } |
| 242 return traf; | |
| 243 } | |
| 244 function getTranslation(pos) { | |
| 245 // returns a Transform that is a translation by [pos.x, pos,y] | |
| 246 var traf = new Transform(); | |
| 247 traf.m02 = pos.x; | |
| 248 traf.m12 = pos.y; | |
| 249 return traf; | |
| 250 } | |
| 251 function getScale(size) { | |
| 252 // returns a Transform that is a scale by [size.width, size.height] | |
| 253 var traf = new Transform(); | |
| 254 traf.m00 = size.width; | |
| 255 traf.m11 = size.height; | |
| 256 return traf; | |
| 257 } | |
| 258 | |
| 259 | |
| 260 /* ********************************************** | |
| 261 * parameter routines | |
| 262 * ******************************************** */ | |
| 263 | |
| 264 function newParameter(name, defaultValue, detail) { | |
| 265 // create a new parameter with a name and a default value | |
| 266 if (defined(dlParams[name])) { | |
| 382 | 267 alert("Fatal: An object with name '" + name + "' already exists - cannot recreate!"); |
| 268 return false; | |
| 233 | 269 } else { |
| 382 | 270 dlParams[name] = new Object(); |
| 271 dlParams[name].defaultValue = defaultValue; | |
| 272 dlParams[name].hasValue = false; | |
| 273 dlParams[name].value = defaultValue; | |
| 274 dlParams[name].detail = detail; | |
| 275 return dlParams[name]; | |
| 233 | 276 } |
| 277 } | |
| 278 | |
| 279 function getParameter(name) { | |
| 280 // returns the named parameter value or its default value | |
| 382 | 281 if (defined(dlParams[name])) { |
| 282 if (dlParams[name].hasValue) { | |
| 283 return dlParams[name].value; | |
| 284 } else { | |
| 285 return dlParams[name].defaultValue; | |
| 286 } | |
| 233 | 287 } else { |
| 382 | 288 return null; |
| 233 | 289 } |
| 290 } | |
| 291 | |
| 382 | 292 function setParameter(name, value, relative) { |
| 293 // sets parameter value (relative values with +/- unless literal) | |
| 233 | 294 if (defined(dlParams[name])) { |
| 382 | 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; | |
| 233 | 309 } |
| 310 return false; | |
| 311 } | |
| 312 | |
| 316 | 313 function hasParameter(name) { |
| 314 // returns if the parameter's value has been set | |
| 315 if (defined(dlParams[name])) { | |
| 382 | 316 return dlParams[name].hasValue; |
| 316 | 317 } |
| 318 return false; | |
| 319 } | |
| 320 | |
| 233 | 321 function getAllParameters(detail) { |
| 322 // returns a string of all parameters in query format | |
| 323 if (! detail) { | |
| 382 | 324 detail = 255; |
| 233 | 325 } |
| 326 var params = new Array(); | |
| 382 | 327 for (param in dlParams) { |
| 328 if (((dlParams[param].detail & detail) > 0)&&(dlParams[param].hasValue)) { | |
| 329 var val = getParameter(param); | |
| 330 if (val != "") { | |
| 331 params.push(param + "=" + val); | |
| 332 } | |
| 333 } | |
| 233 | 334 } |
| 335 return params.join("&"); | |
| 336 } | |
| 337 | |
| 338 function parseParameters(query) { | |
| 339 // gets parameter values from query format string | |
| 340 var params = query.split("&"); | |
| 341 for (var i = 0; i < params.length; i++) { | |
| 382 | 342 var keyval = params[i].split("="); |
| 343 if (keyval.length == 2) { | |
| 344 setParameter(keyval[0], keyval[1]); | |
| 345 } | |
| 233 | 346 } |
| 347 } | |
| 348 | |
| 349 | |
| 350 /* ********************************************** | |
| 351 * HTML/DOM routines | |
| 352 * ******************************************** */ | |
| 353 | |
| 354 function getElement(tagid, quiet) { | |
| 355 // returns the element object with the id tagid | |
| 356 var e; | |
| 357 if (document.getElementById) { | |
| 382 | 358 e = document.getElementById(tagid); |
| 233 | 359 } else if (document.all) { |
| 382 | 360 alert("document.all!"); |
| 361 e = document.all[tagid]; | |
| 233 | 362 } else if (document.layers) { |
| 363 e = document.layers[tagid]; | |
| 364 } | |
| 365 if (e) { | |
| 382 | 366 return e; |
| 233 | 367 } else { |
| 382 | 368 if (! quiet) { |
| 369 alert("unable to find element: "+tagid); | |
| 370 } | |
| 371 return null; | |
| 233 | 372 } |
| 373 } | |
| 374 | |
| 375 function getElementPosition(elem) { | |
| 376 // returns a Position with the position of the element | |
| 377 var x = 0; | |
| 378 var y = 0; | |
| 379 if (defined(elem.offsetLeft)) { | |
| 382 | 380 var e = elem; |
| 381 while (e) { | |
| 382 if (defined(e.clientLeft)) { | |
| 383 // special for IE | |
| 384 if (browserType.isMac) { | |
| 385 if (e.offsetParent.tagName == "BODY") { | |
| 386 // IE for Mac extraspecial | |
| 387 x += e.clientLeft; | |
| 388 y += e.clientTop; | |
| 389 break; | |
| 390 } | |
| 391 } else { | |
| 392 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) { | |
| 393 x += e.clientLeft; | |
| 394 y += e.clientTop; | |
| 395 } | |
| 396 } | |
| 397 } | |
| 398 x += e.offsetLeft; | |
| 399 y += e.offsetTop; | |
| 400 e = e.offsetParent; | |
| 401 } | |
| 233 | 402 } else if (defined(elem.x)) { |
| 382 | 403 x = elem.x; |
| 404 y = elem.y; | |
| 233 | 405 } else if (defined(elem.pageX)) { |
| 382 | 406 x = elem.pageX; |
| 407 y = elem.pageY; | |
| 233 | 408 } else { |
| 382 | 409 alert("unable to get position of "+elem+" (id:"+elem.id+")"); |
| 233 | 410 } |
| 411 return new Position(getInt(x), getInt(y)); | |
| 412 } | |
| 413 | |
| 414 function getElementSize(elem) { | |
| 415 // returns a Rectangle with the size of the element | |
| 416 var width = 0; | |
| 417 var height = 0; | |
| 418 if (defined(elem.offsetWidth)) { | |
| 382 | 419 width = elem.offsetWidth; |
| 420 height = elem.offsetHeight; | |
| 233 | 421 } else if (defined(elem.width)) { |
| 382 | 422 width = elem.width; |
| 423 height = elem.height; | |
| 233 | 424 } else if (defined(elem.clip.width)) { |
| 382 | 425 width = elem.clip.width; |
| 426 height = elem.clip.height; | |
| 233 | 427 } else { |
| 382 | 428 alert("unable to get size of "+elem+" (id:"+elem.id+")"); |
| 233 | 429 } |
| 430 return new Size(getInt(width), getInt(height)); | |
| 431 } | |
| 432 | |
| 433 function getElementRect(elem) { | |
| 434 // returns a Rectangle with the size and position of the element | |
| 435 var pos = getElementPosition(elem); | |
| 436 var size = getElementSize(elem); | |
| 437 return new Rectangle(pos.x, pos.y, size.width, size.height); | |
| 438 } | |
| 439 | |
| 440 | |
| 441 | |
| 442 function moveElement(elem, rect) { | |
| 443 // moves and sizes the element | |
| 444 if (elem.style) { | |
| 382 | 445 if (defined(rect.x)) { |
| 446 elem.style.left = Math.round(rect.x) + "px"; | |
| 447 elem.style.top = Math.round(rect.y) + "px"; | |
| 448 } | |
| 449 if (defined(rect.width)) { | |
| 450 elem.style.width = Math.round(rect.width) + "px"; | |
| 451 elem.style.height = Math.round(rect.height) + "px"; | |
| 452 } | |
| 233 | 453 } else if (document.layers) { |
| 382 | 454 if (defined(rect.x)) { |
| 455 elem.pageX = getInt(rect.x); | |
| 456 elem.pageY = getInt(rect.y); | |
| 457 } | |
| 458 if (defined(rect.width)) { | |
| 459 elem.clip.width = getInt(rect.width); | |
| 460 elem.clip.height = getInt(rect.height); | |
| 461 } | |
| 233 | 462 } else { |
| 382 | 463 alert("moveelement: no style nor layer property!"); |
| 464 return false; | |
| 233 | 465 } |
| 466 return true; | |
| 467 } | |
| 468 | |
| 469 function showElement(elem, show) { | |
| 470 // shows or hides the element | |
| 471 if (elem.style) { | |
| 382 | 472 if (show) { |
| 473 elem.style.visibility = "visible"; | |
| 474 } else { | |
| 475 elem.style.visibility = "hidden"; | |
| 476 } | |
| 233 | 477 } else if (defined(elem.visibility)) { |
| 382 | 478 if (show) { |
| 479 elem.visibility = "show"; | |
| 480 } else { | |
| 481 elem.visibility = "hide"; | |
| 482 } | |
| 233 | 483 } else { |
| 382 | 484 alert("showelement: no style nor layer property!"); |
| 233 | 485 } |
| 486 return true; | |
| 487 } | |
| 488 | |
| 489 function evtPosition(evt) { | |
| 490 // returns the on-screen Position of the Event | |
| 491 var x; | |
| 492 var y; | |
| 493 evt = (evt) ? evt : window.event; | |
| 494 if (!evt) { | |
| 382 | 495 alert("no event found! "+evt); |
| 496 return; | |
| 233 | 497 } |
| 498 if (defined(evt.pageX)) { | |
| 382 | 499 x = parseInt(evt.pageX); |
| 500 y = parseInt(evt.pageY); | |
| 233 | 501 } else if (defined(evt.clientX)) { |
| 382 | 502 x = parseInt(document.body.scrollLeft+evt.clientX); |
| 503 y = parseInt(document.body.scrollTop+evt.clientY); | |
| 233 | 504 } else { |
| 382 | 505 alert("evtPosition: don't know how to deal with "+evt); |
| 233 | 506 } |
| 507 return new Position(x, y); | |
| 508 } | |
| 509 | |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
510 function registerEvent(type, elem, handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
511 // register the given event handler on the indicated element |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
512 if (elem.addEventListener) { |
| 382 | 513 elem.addEventListener(type, handler, false); |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
514 } else { |
| 382 | 515 if (type == "mousedown") { |
| 516 if (elem.captureEvents) { | |
| 517 elem.captureEvents(Event.MOUSEDOWN); | |
| 518 } | |
| 519 elem.onmousedown = handler; | |
| 520 } else if (type == "mouseup") { | |
| 521 if (elem.captureEvents) { | |
| 522 elem.captureEvents(Event.MOUSEUP); | |
| 523 } | |
| 524 elem.onmouseup = handler; | |
| 525 } else if (type == "mousemove") { | |
| 526 if (elem.captureEvents) { | |
| 527 elem.captureEvents(Event.MOUSEMOVE); | |
| 528 } | |
| 529 elem.onmousemove = handler; | |
| 530 } else if (type == "keypress") { | |
| 531 if (elem.captureEvents) { | |
| 532 elem.captureEvents(Event.KEYPRESS); | |
| 533 } | |
| 534 elem.onkeypress = handler; | |
| 535 } else { | |
| 536 alert("registerEvent: unknown event type "+type); | |
| 537 return false; | |
| 538 } | |
| 233 | 539 } |
| 540 return true; | |
| 541 } | |
| 542 | |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
543 function unregisterEvent(type, elem, handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
544 // unregister the given event handler from the indicated element |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
545 if (elem.removeEventListener) { |
| 382 | 546 elem.removeEventListener(type, handler, false); |
|
324
a6dc20bae2fd
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
316
diff
changeset
|
547 } else { |
| 382 | 548 if (type == "mousedown") { |
| 549 if (elem.releaseEvents) { | |
| 550 elem.releaseEvents(Event.MOUSEDOWN); | |
| 551 } | |
| 552 elem.onmousedown = null; | |
| 553 } else if (type == "mouseup") { | |
| 554 if (elem.releaseEvents) { | |
| 555 elem.releaseEvents(Event.MOUSEUP); | |
| 556 } | |
| 557 elem.onmouseup = null; | |
| 558 } else if (type == "mousemove") { | |
| 559 if (elem.releaseEvents) { | |
| 560 elem.releaseEvents(Event.MOUSEMOVE); | |
| 561 } | |
| 562 elem.onmousemove = null; | |
| 563 } else if (type == "keypress") { | |
| 564 if (elem.releaseEvents) { | |
| 565 elem.releaseEvents(Event.KEYPRESS); | |
| 566 } | |
| 567 elem.onkeypress = null; | |
| 568 } else { | |
| 569 alert("unregisterEvent: unknown event type "+type); | |
| 570 return false; | |
| 571 } | |
| 233 | 572 } |
| 573 return true; | |
| 574 } | |
| 575 | |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
576 |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
577 // old registerXXYY API for compatibility |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
578 function registerMouseDown(elem, handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
579 return registerEvent("mousedown", elem, handler); |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
580 } |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
581 function unregisterMouseDown(elem, handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
582 return unregisterEvent("mousedown", elem, handler); |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
583 } |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
584 function registerMouseMove(elem, handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
585 return registerEvent("mousemove", elem, handler); |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
586 } |
| 233 | 587 function unregisterMouseMove(elem, handler) { |
|
238
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
588 return unregisterEvent("mousemove", elem, handler); |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
589 } |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
590 function registerKeyDown(handler) { |
|
20c43a06076a
new digimage with red triangles for moving the zoomed area
robcast
parents:
237
diff
changeset
|
591 return registerEvent("keypress", elem, handler); |
| 233 | 592 } |
| 593 | |
| 594 | |
| 595 function getWinSize() { | |
| 596 // returns a Size with the current window size (mostly from www.quirksmode.org) | |
| 597 var wsize = new Size(100, 100); | |
| 598 if (defined(self.innerHeight)) { | |
| 382 | 599 // all except Explorer |
| 600 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { | |
| 601 // Safari 1.2 bug | |
| 602 if (parent) { | |
| 603 parent.innerHeight; | |
| 604 parent.innerWidth; | |
| 605 } | |
| 606 } | |
| 607 wsize.width = self.innerWidth; | |
| 608 wsize.height = self.innerHeight; | |
| 233 | 609 } else if (document.documentElement && document.documentElement.clientHeight) { |
| 382 | 610 // Explorer 6 Strict Mode |
| 611 wsize.width = document.documentElement.clientWidth; | |
| 612 wsize.height = document.documentElement.clientHeight; | |
| 233 | 613 } else if (document.body) { |
| 382 | 614 // other Explorers |
| 615 wsize.width = document.body.clientWidth; | |
| 616 wsize.height = document.body.clientHeight; | |
| 233 | 617 } |
| 618 return wsize; | |
| 619 } | |
| 620 | |
| 311 | 621 function openWin(url, name, params) { |
| 233 | 622 // open browser window |
| 311 | 623 var ow = window.open(url, name, params); |
| 233 | 624 ow.focus(); |
| 625 } |
