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