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