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