Mercurial > hg > digilib-old
annotate client/digitallibrary/baselib.js @ 344:735ea8bab962
with version number
| author | robcast |
|---|---|
| date | Wed, 23 Feb 2005 17:53:56 +0100 |
| parents | d4c302cdeed1 |
| children | 3b710e39823b |
| 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) |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
20 Robert Casties, 2.11.2004 |
|
242
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
21 |
| 237 | 22 */ |
| 23 | |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
24 function base_init() { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
25 // init function |
| 344 | 26 baseScriptVersion = "1.1.1b"; |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
27 dlParams = new Object(); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
28 browserType = getBrowserType(); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
29 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
30 |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
31 |
| 241 | 32 function getInt(n) { |
| 237 | 33 // returns always an integer |
| 241 | 34 n = parseInt(n); |
| 35 if (isNaN(n)) return 0; | |
| 237 | 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) { | |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
45 // auxiliary function to crop senseless precision |
| 237 | 46 return parseInt(10000*x)/10000; |
| 47 } | |
| 48 | |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
49 function getBrowserType() { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
50 // browser sniffer |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
51 var bt = Object(); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
52 bt.doDHTML = false; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
53 bt.versIE = 0; |
| 237 | 54 |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
55 if ((! document.cssonly && document.layers) || document.all || document.getElementById) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
56 var vers = navigator.appVersion.split('MSIE '); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
57 vers = vers[vers.length - 1]; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
58 bt.versIE = getInt(vers); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
59 bt.isIE = navigator.userAgent.indexOf('MSIE') >= 0; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
60 bt.isMac = navigator.platform.indexOf('Mac') >= 0; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
61 bt.isWin = navigator.platform.indexOf('Win') >= 0; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
62 bt.isN4 = (navigator.userAgent.indexOf('Mozilla/4.') >= 0) && ! bt.isIE; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
63 bt.isIEWin = bt.versIE > 0 && bt.isWin; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
64 if (navigator.appVersion.indexOf('MSIE') < 0 || ! bt.isMac || bt.versIE >= 5) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
65 bt.doDHTML = true; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
66 bt.isOpera = navigator.userAgent.indexOf(' Opera ') >= 0; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
67 bt.isKonq = navigator.userAgent.indexOf(' Konqueror') >= 0; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
68 } |
| 237 | 69 } |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
70 return bt; |
| 237 | 71 } |
| 72 | |
| 73 // fixes for javascript < 1.2 | |
| 74 if (! Array.prototype.push) { | |
| 75 Array.prototype.push = function(val) { | |
| 76 this[this.length] = val; | |
| 77 return this.length; | |
| 78 } | |
| 79 Array.prototype.pop = function() { | |
| 80 var val = this[this.length-1]; | |
| 81 this.length -= 1; | |
| 82 return val; | |
| 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 } | |
| 320 | 99 Size.prototype.toString = function() { |
| 100 return this.width + "x" + this.height; | |
| 101 } | |
| 102 | |
| 237 | 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 } | |
| 320 | 112 Position.prototype.toString = function() { |
| 113 return this.x + "," + this.y; | |
| 114 } | |
| 237 | 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 } | |
| 320 | 126 Rectangle.prototype.toString = function() { |
| 127 return this.width+"x"+this.height+"@"+this.x+","+this.y; | |
| 128 } | |
| 237 | 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) { | |
| 153 sec.width = sec.width - (this.x - sec.x); | |
| 154 sec.x = this.x; | |
| 155 } | |
| 156 if (sec.y < this.y) { | |
| 157 sec.height = sec.height - (this.y - sec.y); | |
| 158 sec.y = this.y; | |
| 159 } | |
| 160 if (sec.x + sec.width > this.x + this.width) { | |
| 161 sec.width = (this.x + this.width) - sec.x; | |
| 162 } | |
| 163 if (sec.y + sec.height > this.y + this.height) { | |
| 164 sec.height = (this.y + this.height) - sec.y; | |
| 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) { | |
| 174 sec.x = this.x + this.width - sec.width; | |
| 175 } | |
| 176 if (sec.y + sec.height > this.y + this.height) { | |
| 177 sec.y = this.y + this.height - sec.height; | |
| 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++) { | |
| 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 } | |
| 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) { | |
| 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); | |
| 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) { | |
| 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); | |
| 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])) { | |
| 267 alert("Fatal: An object with name '" + name + "' already exists - cannot recreate!"); | |
| 268 return false; | |
| 269 } else { | |
| 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]; | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 function getParameter(name) { | |
| 280 // returns the named parameter value or its default value | |
|
343
d4c302cdeed1
small fix for getParameter before setup (hopefully)
robcast
parents:
328
diff
changeset
|
281 if (defined(dlParams) && defined(dlParams[name])) { |
| 237 | 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])) { | |
| 295 dlParams[name].value = value; | |
| 296 dlParams[name].hasValue = true; | |
| 297 return true; | |
| 298 } | |
| 299 return false; | |
| 300 } | |
| 301 | |
| 320 | 302 function hasParameter(name) { |
| 303 // returns if the parameter's value has been set | |
| 304 if (defined(dlParams[name])) { | |
| 305 return dlParams[name].hasValue; | |
| 306 } | |
| 307 return false; | |
| 308 } | |
| 309 | |
| 237 | 310 function getAllParameters(detail) { |
| 311 // returns a string of all parameters in query format | |
| 312 if (! detail) { | |
| 313 detail = 10; | |
| 314 } | |
| 315 var params = new Array(); | |
| 316 for ( param in dlParams ) { | |
| 317 if ((dlParams[param].detail <= detail)&&(dlParams[param].hasValue)) { | |
| 318 var val = getParameter(param); | |
| 319 if (val != "") { | |
| 320 params.push(param + "=" + val); | |
| 321 } | |
| 322 } | |
| 323 } | |
| 324 return params.join("&"); | |
| 325 } | |
| 326 | |
| 327 function parseParameters(query) { | |
| 328 // gets parameter values from query format string | |
| 329 var params = query.split("&"); | |
| 330 for (var i = 0; i < params.length; i++) { | |
| 331 var keyval = params[i].split("="); | |
| 332 if (keyval.length == 2) { | |
| 333 setParameter(keyval[0], keyval[1]); | |
| 334 } | |
| 335 } | |
| 336 } | |
| 337 | |
| 338 | |
| 339 /* ********************************************** | |
| 340 * HTML/DOM routines | |
| 341 * ******************************************** */ | |
| 342 | |
| 343 function getElement(tagid, quiet) { | |
| 344 // returns the element object with the id tagid | |
| 345 var e; | |
| 346 if (document.getElementById) { | |
| 347 e = document.getElementById(tagid); | |
| 348 } else if (document.all) { | |
| 349 alert("document.all!"); | |
| 350 e = document.all[tagid]; | |
| 351 } else if (document.layers) { | |
| 352 e = document.layers[tagid]; | |
| 353 } | |
| 354 if (e) { | |
| 355 return e; | |
| 356 } else { | |
| 357 if (! quiet) { | |
| 358 alert("unable to find element: "+tagid); | |
| 359 } | |
| 360 return null; | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 function getElementPosition(elem) { | |
| 365 // returns a Position with the position of the element | |
| 366 var x = 0; | |
| 367 var y = 0; | |
| 368 if (defined(elem.offsetLeft)) { | |
| 369 var e = elem; | |
| 370 while (e) { | |
| 371 if (defined(e.clientLeft)) { | |
| 372 // special for IE | |
| 373 if (browserType.isMac) { | |
| 374 if (e.offsetParent.tagName == "BODY") { | |
| 375 // IE for Mac extraspecial | |
| 376 x += e.clientLeft; | |
| 377 y += e.clientTop; | |
| 378 break; | |
| 379 } | |
| 380 } else { | |
| 381 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) { | |
| 382 x += e.clientLeft; | |
| 383 y += e.clientTop; | |
| 384 } | |
| 385 } | |
| 386 } | |
| 387 x += e.offsetLeft; | |
| 388 y += e.offsetTop; | |
| 389 e = e.offsetParent; | |
| 390 } | |
| 391 } else if (defined(elem.x)) { | |
| 392 x = elem.x; | |
| 393 y = elem.y; | |
| 394 } else if (defined(elem.pageX)) { | |
| 395 x = elem.pageX; | |
| 396 y = elem.pageY; | |
| 397 } else { | |
| 398 alert("unable to get position of "+elem+" (id:"+elem.id+")"); | |
| 399 } | |
| 400 return new Position(getInt(x), getInt(y)); | |
| 401 } | |
| 402 | |
| 403 function getElementSize(elem) { | |
| 404 // returns a Rectangle with the size of the element | |
| 405 var width = 0; | |
| 406 var height = 0; | |
| 407 if (defined(elem.offsetWidth)) { | |
| 408 width = elem.offsetWidth; | |
| 409 height = elem.offsetHeight; | |
| 410 } else if (defined(elem.width)) { | |
| 411 width = elem.width; | |
| 412 height = elem.height; | |
| 413 } else if (defined(elem.clip.width)) { | |
| 414 width = elem.clip.width; | |
| 415 height = elem.clip.height; | |
| 416 } else { | |
| 417 alert("unable to get size of "+elem+" (id:"+elem.id+")"); | |
| 418 } | |
| 419 return new Size(getInt(width), getInt(height)); | |
| 420 } | |
| 421 | |
| 422 function getElementRect(elem) { | |
| 423 // returns a Rectangle with the size and position of the element | |
| 424 var pos = getElementPosition(elem); | |
| 425 var size = getElementSize(elem); | |
| 426 return new Rectangle(pos.x, pos.y, size.width, size.height); | |
| 427 } | |
| 428 | |
| 429 | |
| 430 | |
| 431 function moveElement(elem, rect) { | |
| 432 // moves and sizes the element | |
| 433 if (elem.style) { | |
| 434 if (defined(rect.x)) { | |
| 435 elem.style.left = Math.round(rect.x) + "px"; | |
| 436 elem.style.top = Math.round(rect.y) + "px"; | |
| 437 } | |
| 438 if (defined(rect.width)) { | |
| 439 elem.style.width = Math.round(rect.width) + "px"; | |
| 440 elem.style.height = Math.round(rect.height) + "px"; | |
| 441 } | |
| 442 } else if (document.layers) { | |
| 443 if (defined(rect.x)) { | |
| 444 elem.pageX = getInt(rect.x); | |
| 445 elem.pageY = getInt(rect.y); | |
| 446 } | |
| 447 if (defined(rect.width)) { | |
| 448 elem.clip.width = getInt(rect.width); | |
| 449 elem.clip.height = getInt(rect.height); | |
| 450 } | |
| 451 } else { | |
| 452 alert("moveelement: no style nor layer property!"); | |
| 453 return false; | |
| 454 } | |
| 455 return true; | |
| 456 } | |
| 457 | |
| 458 function showElement(elem, show) { | |
| 459 // shows or hides the element | |
| 460 if (elem.style) { | |
| 461 if (show) { | |
| 462 elem.style.visibility = "visible"; | |
| 463 } else { | |
| 464 elem.style.visibility = "hidden"; | |
| 465 } | |
| 466 } else if (defined(elem.visibility)) { | |
| 467 if (show) { | |
| 468 elem.visibility = "show"; | |
| 469 } else { | |
| 470 elem.visibility = "hide"; | |
| 471 } | |
| 472 } else { | |
| 473 alert("showelement: no style nor layer property!"); | |
| 474 } | |
| 475 return true; | |
| 476 } | |
| 477 | |
| 478 function evtPosition(evt) { | |
| 479 // returns the on-screen Position of the Event | |
| 480 var x; | |
| 481 var y; | |
| 482 evt = (evt) ? evt : window.event; | |
| 483 if (!evt) { | |
| 484 alert("no event found! "+evt); | |
| 485 return; | |
| 486 } | |
| 487 if (defined(evt.pageX)) { | |
| 488 x = parseInt(evt.pageX); | |
| 489 y = parseInt(evt.pageY); | |
| 490 } else if (defined(evt.clientX)) { | |
| 491 x = parseInt(document.body.scrollLeft+evt.clientX); | |
| 492 y = parseInt(document.body.scrollTop+evt.clientY); | |
| 493 } else { | |
| 494 alert("evtPosition: don't know how to deal with "+evt); | |
| 495 } | |
| 496 return new Position(x, y); | |
| 497 } | |
| 498 | |
|
242
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
499 function registerEvent(type, elem, handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
500 // register the given event handler on the indicated element |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
501 if (elem.addEventListener) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
502 elem.addEventListener(type, handler, false); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
503 } else { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
504 if (type == "mousedown") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
505 if (elem.captureEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
506 elem.captureEvents(Event.MOUSEDOWN); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
507 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
508 elem.onmousedown = handler; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
509 } else if (type == "mouseup") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
510 if (elem.captureEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
511 elem.captureEvents(Event.MOUSEUP); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
512 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
513 elem.onmouseup = handler; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
514 } else if (type == "mousemove") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
515 if (elem.captureEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
516 elem.captureEvents(Event.MOUSEMOVE); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
517 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
518 elem.onmousemove = handler; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
519 } else if (type == "keypress") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
520 if (elem.captureEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
521 elem.captureEvents(Event.KEYPRESS); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
522 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
523 elem.onkeypress = handler; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
524 } else { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
525 alert("registerEvent: unknown event type "+type); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
526 return false; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
527 } |
| 237 | 528 } |
| 529 return true; | |
| 530 } | |
| 531 | |
|
242
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
532 function unregisterEvent(type, elem, handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
533 // unregister the given event handler from the indicated element |
|
328
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
534 if (elem.removeEventListener) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
535 elem.removeEventListener(type, handler, false); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
536 } else { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
537 if (type == "mousedown") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
538 if (elem.releaseEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
539 elem.releaseEvents(Event.MOUSEDOWN); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
540 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
541 elem.onmousedown = null; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
542 } else if (type == "mouseup") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
543 if (elem.releaseEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
544 elem.releaseEvents(Event.MOUSEUP); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
545 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
546 elem.onmouseup = null; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
547 } else if (type == "mousemove") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
548 if (elem.releaseEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
549 elem.releaseEvents(Event.MOUSEMOVE); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
550 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
551 elem.onmousemove = null; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
552 } else if (type == "keypress") { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
553 if (elem.releaseEvents) { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
554 elem.releaseEvents(Event.KEYPRESS); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
555 } |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
556 elem.onkeypress = null; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
557 } else { |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
558 alert("unregisterEvent: unknown event type "+type); |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
559 return false; |
|
3e0f2fb67d0b
fixed problems with Netscape4 (silly error by me partly :-)
robcast
parents:
320
diff
changeset
|
560 } |
| 237 | 561 } |
| 562 return true; | |
| 563 } | |
| 564 | |
|
242
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
565 |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
566 // old registerXXYY API for compatibility |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
567 function registerMouseDown(elem, handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
568 return registerEvent("mousedown", elem, handler); |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
569 } |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
570 function unregisterMouseDown(elem, handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
571 return unregisterEvent("mousedown", elem, handler); |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
572 } |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
573 function registerMouseMove(elem, handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
574 return registerEvent("mousemove", elem, handler); |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
575 } |
| 237 | 576 function unregisterMouseMove(elem, handler) { |
|
242
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
577 return unregisterEvent("mousemove", elem, handler); |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
578 } |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
579 function registerKeyDown(handler) { |
|
e2c455c2a0d0
new digimage with red triangles for moving the zoomed area
robcast
parents:
241
diff
changeset
|
580 return registerEvent("keypress", elem, handler); |
| 237 | 581 } |
| 582 | |
| 583 | |
| 584 function getWinSize() { | |
| 585 // returns a Size with the current window size (mostly from www.quirksmode.org) | |
| 586 var wsize = new Size(100, 100); | |
| 587 if (defined(self.innerHeight)) { | |
| 588 // all except Explorer | |
| 320 | 589 if ((self.innerWidth == 0)||(self.innerHeight == 0)) { |
| 590 // Safari 1.2 bug | |
| 591 if (parent) { | |
| 592 parent.innerHeight; | |
| 593 parent.innerWidth; | |
| 594 } | |
| 595 } | |
| 237 | 596 wsize.width = self.innerWidth; |
| 597 wsize.height = self.innerHeight; | |
| 598 } else if (document.documentElement && document.documentElement.clientHeight) { | |
| 599 // Explorer 6 Strict Mode | |
| 600 wsize.width = document.documentElement.clientWidth; | |
| 601 wsize.height = document.documentElement.clientHeight; | |
| 602 } else if (document.body) { | |
| 603 // other Explorers | |
| 604 wsize.width = document.body.clientWidth; | |
| 605 wsize.height = document.body.clientHeight; | |
| 606 } | |
| 607 return wsize; | |
| 608 } | |
| 609 | |
| 315 | 610 function openWin(url, name, params) { |
| 237 | 611 // open browser window |
| 315 | 612 var ow = window.open(url, name, params); |
| 237 | 613 ow.focus(); |
| 614 } |
