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() {
|
433
|
26 baseLibVersion = "2.006";
|
407
|
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 }
|
433
|
141 Rectangle.prototype.getPt1 = Rectangle.prototype.getPosition;
|
|
142
|
|
143 Rectangle.prototype.getPt2 = function() {
|
|
144 // returns the second point position of this Rectangle
|
|
145 return new Position(this.x + this.width, this.y + this.height);
|
|
146 }
|
|
147 Rectangle.prototype.setPt1 = function(pos) {
|
|
148 // sets the first point to position pos
|
|
149 this.x = pos.x;
|
|
150 this.y = pos.y;
|
|
151 return this;
|
|
152 }
|
|
153 Rectangle.prototype.setPt2 = function(pos) {
|
|
154 // sets the second point to position pos
|
|
155 this.width = pos.x - this.x;
|
|
156 this.height = pos.y - this.y;
|
|
157 return this;
|
|
158 }
|
|
159 Rectangle.prototype.getCenter = function() {
|
|
160 // returns the center position of this Rectangle
|
|
161 return new Position(this.x + this.width / 2, this.y + this.height / 2);
|
|
162 }
|
|
163 Rectangle.prototype.setCenter = function(pos) {
|
|
164 // moves this Rectangle's center to position pos
|
|
165 this.x = pos.x - this.width / 2;
|
|
166 this.y = pos.y - this.height / 2;
|
|
167 return this;
|
|
168 }
|
398
|
169 Rectangle.prototype.getSize = function() {
|
|
170 // returns the size of this Rectangle
|
|
171 return new Size(this.width, this.height);
|
|
172 }
|
426
|
173 Rectangle.prototype.equals = function(other) {
|
|
174 // equal props
|
|
175 return (this.getPosition().equals(other.getPosition())
|
|
176 && this.getSize().equals(other.getSize())
|
|
177 );
|
|
178 }
|
398
|
179 Rectangle.prototype.getArea = function() {
|
|
180 // returns the area of this Rectangle
|
|
181 return (this.width * this.height);
|
|
182 }
|
433
|
183 Rectangle.prototype.normalize = function() {
|
|
184 // eliminates negative width and height
|
|
185 var p = this.getPt2();
|
|
186 this.x = Math.min(this.x, p.x);
|
|
187 this.y = Math.min(this.y, p.y);
|
|
188 this.width = Math.abs(this.width);
|
|
189 this.height = Math.abs(this.height);
|
|
190 return this;
|
|
191 }
|
398
|
192 Rectangle.prototype.containsPosition = function(pos) {
|
412
|
193 // returns if Position "pos" lies inside of this rectangle
|
|
194 return ((pos.x >= this.x)
|
|
195 && (pos.y >= this.y)
|
|
196 && (pos.x <= this.x + this.width)
|
|
197 && (pos.y <= this.y + this.width)
|
|
198 );
|
|
199 }
|
|
200 Rectangle.prototype.containsRect = function(rect) {
|
|
201 // returns if rectangle "rect" is contained in this rectangle
|
|
202 return (this.containsPosition(rect)
|
|
203 && this.containsPosition(new Position(
|
|
204 rect.x + rect.width,
|
|
205 rect.y + rect.height
|
|
206 )));
|
|
207 }
|
|
208 Rectangle.prototype.stayInside = function(rect) {
|
|
209 // changes this rectangle's x/y values so it stays inside of rectangle rect
|
433
|
210 // keeping the proportions
|
412
|
211 if (this.x < rect.x) this.x = rect.x;
|
|
212 if (this.y < rect.y) this.y = rect.y;
|
|
213 if (this.x + this.width > rect.x + rect.width)
|
|
214 this.x = rect.x + rect.width - this.width;
|
|
215 if (this.y + this.height > rect.y + rect.height)
|
|
216 this.y = rect.y + rect.height - this.height;
|
|
217 return this;
|
398
|
218 }
|
433
|
219 Rectangle.prototype.clipTo = function(rect) {
|
|
220 // clips this rectangle so it stays inside of rectangle rect
|
|
221 p1 = rect.getPt1();
|
|
222 p2 = rect.getPt2();
|
|
223 this2 = this.getPt2();
|
|
224 this.setPt1(new Position(Math.max(this.x, p1.x), Math.max(this.y, p1.y)));
|
|
225 this.setPt2(new Position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y)));
|
|
226 return this;
|
|
227 }
|
398
|
228 Rectangle.prototype.intersect = function(rect) {
|
|
229 // returns the intersection of the given Rectangle and this one
|
412
|
230 // FIX ME: not really, it should return null if there is no overlap
|
398
|
231 var sec = rect.copy();
|
|
232 if (sec.x < this.x) {
|
|
233 sec.width = sec.width - (this.x - sec.x);
|
|
234 sec.x = this.x;
|
|
235 }
|
|
236 if (sec.y < this.y) {
|
|
237 sec.height = sec.height - (this.y - sec.y);
|
|
238 sec.y = this.y;
|
|
239 }
|
|
240 if (sec.x + sec.width > this.x + this.width) {
|
|
241 sec.width = (this.x + this.width) - sec.x;
|
|
242 }
|
|
243 if (sec.y + sec.height > this.y + this.height) {
|
|
244 sec.height = (this.y + this.height) - sec.y;
|
|
245 }
|
|
246 return sec;
|
|
247 }
|
|
248 Rectangle.prototype.fit = function(rect) {
|
|
249 // returns a Rectangle that fits into this one (by moving first)
|
|
250 var sec = rect.copy();
|
|
251 sec.x = Math.max(sec.x, this.x);
|
426
|
252 sec.y = Math.max(sec.y, this.x);
|
398
|
253 if (sec.x + sec.width > this.x + this.width) {
|
|
254 sec.x = this.x + this.width - sec.width;
|
|
255 }
|
|
256 if (sec.y + sec.height > this.y + this.height) {
|
|
257 sec.y = this.y + this.height - sec.height;
|
|
258 }
|
|
259 return sec.intersect(this);
|
|
260 }
|
|
261
|
|
262 /*
|
|
263 * Transform class
|
|
264 *
|
|
265 * defines a class of affine transformations
|
|
266 */
|
|
267 function Transform() {
|
|
268 this.m00 = 1.0;
|
|
269 this.m01 = 0.0;
|
|
270 this.m02 = 0.0;
|
|
271 this.m10 = 0.0;
|
|
272 this.m11 = 1.0;
|
|
273 this.m12 = 0.0;
|
|
274 this.m20 = 0.0;
|
|
275 this.m21 = 0.0;
|
|
276 this.m22 = 1.0;
|
|
277 return this;
|
|
278 }
|
|
279 Transform.prototype.concat = function(traf) {
|
|
280 // add Transform traf to this Transform
|
|
281 for (var i = 0; i < 3; i++) {
|
|
282 for (var j = 0; j < 3; j++) {
|
|
283 var c = 0.0;
|
|
284 for (var k = 0; k < 3; k++) {
|
|
285 c += traf["m"+i+k] * this["m"+k+j];
|
|
286 }
|
|
287 this["m"+i+j] = c;
|
|
288 }
|
|
289 }
|
|
290 return this;
|
|
291 }
|
|
292 Transform.prototype.transform = function(rect) {
|
|
293 // returns transformed Rectangle or Position with this Transform applied
|
|
294 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02;
|
|
295 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12;
|
|
296 if (rect.width) {
|
|
297 var width = this.m00 * rect.width + this.m01 * rect.height;
|
|
298 var height = this.m10 * rect.width + this.m11 * rect.height;
|
|
299 return new Rectangle(x, y, width, height);
|
|
300 }
|
|
301 return new Position(x, y);
|
|
302 }
|
|
303 Transform.prototype.invtransform = function(pos) {
|
|
304 // returns transformed Position pos with the inverse of this Transform applied
|
|
305 var det = this.m00 * this.m11 - this.m01 * this.m10;
|
|
306 var x = (this.m11 * pos.x - this.m01 * pos.y - this.m11 * this.m02 + this.m01 * this.m12) / det;
|
|
307 var y = (- this.m10 * pos.x + this.m00 * pos.y + this.m10 * this.m02 - this.m00 * this.m12) / det;
|
|
308 return new Position(x, y);
|
|
309 }
|
|
310 function getRotation(angle, pos) {
|
|
311 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y]
|
|
312 var traf = new Transform();
|
|
313 if (angle != 0) {
|
|
314 var t = 2.0 * Math.PI * parseFloat(angle) / 360.0;
|
|
315 traf.m00 = Math.cos(t);
|
|
316 traf.m01 = - Math.sin(t);
|
|
317 traf.m10 = Math.sin(t);
|
|
318 traf.m11 = Math.cos(t);
|
|
319 traf.m02 = pos.x - pos.x * Math.cos(t) + pos.y * Math.sin(t);
|
|
320 traf.m12 = pos.y - pos.x * Math.sin(t) - pos.y * Math.cos(t);
|
|
321 }
|
|
322 return traf;
|
|
323 }
|
|
324 function getTranslation(pos) {
|
|
325 // returns a Transform that is a translation by [pos.x, pos,y]
|
|
326 var traf = new Transform();
|
|
327 traf.m02 = pos.x;
|
|
328 traf.m12 = pos.y;
|
|
329 return traf;
|
|
330 }
|
|
331 function getScale(size) {
|
|
332 // returns a Transform that is a scale by [size.width, size.height]
|
|
333 var traf = new Transform();
|
|
334 traf.m00 = size.width;
|
|
335 traf.m11 = size.height;
|
|
336 return traf;
|
|
337 }
|
|
338
|
|
339
|
|
340 /* **********************************************
|
|
341 * parameter routines
|
|
342 * ******************************************** */
|
407
|
343 dlParams = new Object();
|
398
|
344
|
|
345 function newParameter(name, defaultValue, detail) {
|
|
346 // create a new parameter with a name and a default value
|
|
347 if (!defined(dlParams[name])) dlParams[name] = new Object(); // no error condition
|
|
348 //alert("Fatal: An object with name '" + name + "' already exists - cannot recreate!");
|
|
349 //return false;
|
|
350 dlParams[name].defaultValue = defaultValue;
|
|
351 dlParams[name].hasValue = false;
|
|
352 dlParams[name].value = defaultValue;
|
|
353 dlParams[name].detail = detail;
|
|
354 return dlParams[name];
|
|
355 }
|
|
356
|
412
|
357 function resetParameter(name) {
|
|
358 // resets the given parameter to its default value
|
|
359 if (!defined(dlParams[name])) {
|
|
360 alert("Could not reset non-existing parameter '" + name + "'");
|
|
361 return false;
|
|
362 }
|
|
363 dlParams[name].hasValue = false;
|
|
364 dlParams[name].value = defaultValue;
|
|
365 return dlParams[name];
|
|
366 }
|
|
367
|
|
368 function deleteParameter(name) {
|
|
369 // create a new parameter with a name and a default value
|
|
370 if (!defined(dlParams[name])) return false;
|
|
371 delete dlParams[name];
|
|
372 return true;
|
|
373 }
|
|
374
|
398
|
375 function getParameter(name) {
|
|
376 // returns the named parameter value or its default value
|
407
|
377 if (!defined(dlParams[name])) return null;
|
|
378 if (dlParams[name].hasValue)
|
412
|
379 return dlParams[name].value;
|
407
|
380 else
|
398
|
381 return dlParams[name].defaultValue;
|
|
382 }
|
|
383
|
|
384 function setParameter(name, value, relative) {
|
|
385 // sets parameter value (relative values with +/- unless literal)
|
412
|
386 if (!defined(dlParams[name])) return null;
|
|
387 var p = dlParams[name];
|
|
388 if (relative && value.slice) {
|
|
389 var sign = value.slice(0, 1);
|
|
390 if (sign == '+') {
|
|
391 p.value = parseFloat(p.value) + parseFloat(value.slice(1));
|
|
392 } else if (sign == '-') {
|
|
393 p.value = parseFloat(p.value) - parseFloat(value.slice(1));
|
|
394 } else {
|
|
395 p.value = value;
|
|
396 }
|
|
397 } else p.value = value;
|
|
398 p.hasValue = true;
|
|
399 return p.value;
|
|
400 }
|
398
|
401
|
|
402 function hasParameter(name) {
|
412
|
403 // returns if the parameter's value has been set
|
|
404 if (!defined(dlParams[name])) return null;
|
|
405 return dlParams[name].hasValue;
|
|
406 }
|
398
|
407
|
|
408 function getAllParameters(detail) {
|
|
409 // returns a string of all parameters in query format
|
|
410 if (! detail) {
|
|
411 detail = 255;
|
|
412 }
|
|
413 var params = new Array();
|
|
414 for (param in dlParams) {
|
435
|
415 if (((dlParams[param].detail & detail) > 0)
|
|
416 && (dlParams[param].hasValue)) {
|
398
|
417 var val = getParameter(param);
|
|
418 if (val != "") {
|
|
419 params.push(param + "=" + val);
|
|
420 }
|
|
421 }
|
|
422 }
|
|
423 return params.join("&");
|
|
424 }
|
|
425
|
|
426 function parseParameters(query) {
|
|
427 // gets parameter values from query format string
|
|
428 var params = query.split("&");
|
|
429 for (var i = 0; i < params.length; i++) {
|
|
430 var keyval = params[i].split("=");
|
|
431 if (keyval.length == 2) {
|
|
432 setParameter(keyval[0], keyval[1]);
|
|
433 }
|
|
434 }
|
|
435 }
|
|
436
|
407
|
437 getQueryString = getAllParameters;
|
398
|
438
|
|
439 /* **********************************************
|
|
440 * HTML/DOM routines
|
|
441 * ******************************************** */
|
|
442
|
|
443 function getElement(tagid, quiet) {
|
|
444 // returns the element object with the id tagid
|
|
445 var e;
|
|
446 if (document.getElementById) {
|
|
447 e = document.getElementById(tagid);
|
|
448 } else if (document.all) {
|
|
449 alert("document.all!");
|
|
450 e = document.all[tagid];
|
|
451 } else if (document.layers) {
|
|
452 e = document.layers[tagid];
|
|
453 }
|
|
454 if (e) {
|
|
455 return e;
|
|
456 } else {
|
|
457 if (! quiet) {
|
|
458 alert("unable to find element: "+tagid);
|
|
459 }
|
|
460 return null;
|
|
461 }
|
|
462 }
|
|
463
|
|
464 function getElementPosition(elem) {
|
|
465 // returns a Position with the position of the element
|
|
466 var x = 0;
|
|
467 var y = 0;
|
|
468 if (defined(elem.offsetLeft)) {
|
|
469 var e = elem;
|
|
470 while (e) {
|
|
471 if (defined(e.clientLeft)) {
|
|
472 // special for IE
|
|
473 if (browserType.isMac) {
|
|
474 if (e.offsetParent.tagName == "BODY") {
|
|
475 // IE for Mac extraspecial
|
|
476 x += e.clientLeft;
|
|
477 y += e.clientTop;
|
|
478 break;
|
|
479 }
|
|
480 } else {
|
|
481 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) {
|
|
482 x += e.clientLeft;
|
|
483 y += e.clientTop;
|
|
484 }
|
|
485 }
|
|
486 }
|
|
487 x += e.offsetLeft;
|
|
488 y += e.offsetTop;
|
|
489 e = e.offsetParent;
|
|
490 }
|
|
491 } else if (defined(elem.x)) {
|
|
492 x = elem.x;
|
|
493 y = elem.y;
|
|
494 } else if (defined(elem.pageX)) {
|
|
495 x = elem.pageX;
|
|
496 y = elem.pageY;
|
|
497 } else {
|
|
498 alert("unable to get position of "+elem+" (id:"+elem.id+")");
|
|
499 }
|
|
500 return new Position(getInt(x), getInt(y));
|
|
501 }
|
|
502
|
|
503 function getElementSize(elem) {
|
|
504 // returns a Rectangle with the size of the element
|
|
505 var width = 0;
|
|
506 var height = 0;
|
|
507 if (defined(elem.offsetWidth)) {
|
|
508 width = elem.offsetWidth;
|
|
509 height = elem.offsetHeight;
|
|
510 } else if (defined(elem.width)) {
|
|
511 width = elem.width;
|
|
512 height = elem.height;
|
|
513 } else if (defined(elem.clip.width)) {
|
|
514 width = elem.clip.width;
|
|
515 height = elem.clip.height;
|
|
516 } else {
|
|
517 alert("unable to get size of "+elem+" (id:"+elem.id+")");
|
|
518 }
|
|
519 return new Size(getInt(width), getInt(height));
|
|
520 }
|
|
521
|
|
522 function getElementRect(elem) {
|
|
523 // returns a Rectangle with the size and position of the element
|
412
|
524 // FIX ME: what about borders?
|
398
|
525 var pos = getElementPosition(elem);
|
|
526 var size = getElementSize(elem);
|
|
527 return new Rectangle(pos.x, pos.y, size.width, size.height);
|
|
528 }
|
|
529
|
|
530 function moveElement(elem, rect) {
|
|
531 // moves and sizes the element
|
|
532 if (elem.style) {
|
|
533 if (defined(rect.x)) {
|
|
534 elem.style.left = Math.round(rect.x) + "px";
|
|
535 elem.style.top = Math.round(rect.y) + "px";
|
|
536 }
|
|
537 if (defined(rect.width)) {
|
|
538 elem.style.width = Math.round(rect.width) + "px";
|
|
539 elem.style.height = Math.round(rect.height) + "px";
|
|
540 }
|
|
541 } else if (document.layers) {
|
|
542 if (defined(rect.x)) {
|
|
543 elem.pageX = getInt(rect.x);
|
|
544 elem.pageY = getInt(rect.y);
|
|
545 }
|
|
546 if (defined(rect.width)) {
|
|
547 elem.clip.width = getInt(rect.width);
|
|
548 elem.clip.height = getInt(rect.height);
|
|
549 }
|
|
550 } else {
|
|
551 alert("moveelement: no style nor layer property!");
|
|
552 return false;
|
|
553 }
|
|
554 return true;
|
|
555 }
|
|
556
|
|
557 function showElement(elem, show) {
|
|
558 // shows or hides the element
|
435
|
559 if (elem.style)
|
|
560 elem.style.visibility = show ? "visible" : "hidden";
|
|
561 } else if (defined(elem.visibility))
|
|
562 elem.visibility = show ? "show" : "hide";
|
|
563 } else
|
|
564 alert("showElement(): element has no style or layer property!");
|
398
|
565 return true;
|
|
566 }
|
|
567
|
|
568 function evtPosition(evt) {
|
|
569 // returns the on-screen Position of the Event
|
|
570 var x;
|
|
571 var y;
|
|
572 evt = (evt) ? evt : window.event;
|
|
573 if (!evt) {
|
435
|
574 alert("no event found! " + evt);
|
398
|
575 return;
|
435
|
576 }
|
398
|
577 if (defined(evt.pageX)) {
|
|
578 x = parseInt(evt.pageX);
|
|
579 y = parseInt(evt.pageY);
|
|
580 } else if (defined(evt.clientX)) {
|
435
|
581 x = parseInt(document.body.scrollLeft + evt.clientX);
|
|
582 y = parseInt(document.body.scrollTop + evt.clientY);
|
398
|
583 } else {
|
435
|
584 alert("evtPosition(): don't know how to deal with " + evt);
|
|
585 }
|
398
|
586 return new Position(x, y);
|
|
587 }
|
|
588
|
|
589 function registerEvent(type, elem, handler) {
|
412
|
590 // register the given event handler on the indicated element
|
|
591 if (elem.addEventListener) {
|
|
592 elem.addEventListener(type, handler, false); // bubble
|
|
593 }
|
|
594 else if (elem.attachEvent) {
|
|
595 elem.attachEvent("on" + type, handler);
|
|
596 }
|
|
597 else if (elem.captureEvents) {
|
|
598 if (Event) {
|
|
599 t = type.toUpperCase();
|
|
600 elem.captureEvents(Event[t]);
|
|
601 elem[ "on" + t ] = handler;
|
|
602 }
|
|
603 }
|
|
604 else {
|
|
605 alert("Could not register event of type " + type);
|
|
606 return false;
|
|
607 }
|
|
608 return true;
|
|
609 }
|
|
610
|
407
|
611 function unregisterEvent(type, elem, handler) {
|
412
|
612 // unregister the given event handler from the indicated element
|
|
613 if (elem.removeEventListener) {
|
|
614 elem.removeEventListener(type, handler, false);
|
|
615 }
|
|
616 else if (elem.detachEvent) {
|
|
617 elem.detachEvent('on' + type, handler);
|
|
618 }
|
|
619 else if (elem.releaseEvents) {
|
|
620 if (Event) {
|
|
621 t = type.toUpperCase();
|
|
622 elem.releaseEvents(Event[t]);
|
|
623 elem[ "on" + t ] = null;
|
|
624 }
|
|
625 }
|
|
626 else {
|
|
627 alert("Could not register event of type " + type);
|
|
628 return false;
|
|
629 }
|
|
630 return true;
|
398
|
631 }
|
|
632
|
407
|
633 function registerEventById(type, id, handler) {
|
412
|
634 registerEvent(type, document.getElementById(id), handler);
|
|
635 }
|
407
|
636
|
|
637 function unregisterEventById(type, id, handler) {
|
412
|
638 unregisterEvent(type, document.getElementById(id), handler);
|
|
639 }
|
407
|
640
|
|
641 function stopEvent(e) {
|
412
|
642 if (!e) var e = window.event;
|
|
643 e.cancelBubble = true;
|
|
644 if (e.stopPropagation) e.stopPropagation();
|
|
645 return false;
|
398
|
646 }
|
|
647
|
407
|
648 function getEventSrc(e) {
|
412
|
649 if (e.target) return e.target;
|
|
650 if (e.srcElement) return e.srcElement;
|
407
|
651 }
|
398
|
652
|
|
653 // old registerXXYY API for compatibility
|
|
654 function registerMouseDown(elem, handler) {
|
|
655 return registerEvent("mousedown", elem, handler);
|
|
656 }
|
|
657 function unregisterMouseDown(elem, handler) {
|
|
658 return unregisterEvent("mousedown", elem, handler);
|
|
659 }
|
|
660 function registerMouseMove(elem, handler) {
|
|
661 return registerEvent("mousemove", elem, handler);
|
|
662 }
|
|
663 function unregisterMouseMove(elem, handler) {
|
|
664 return unregisterEvent("mousemove", elem, handler);
|
|
665 }
|
|
666 function registerKeyDown(handler) {
|
|
667 return registerEvent("keypress", elem, handler);
|
|
668 }
|
|
669
|
|
670
|
|
671 function getWinSize() {
|
|
672 // returns a Size with the current window size (mostly from www.quirksmode.org)
|
|
673 var wsize = new Size(100, 100);
|
|
674 if (defined(self.innerHeight)) {
|
|
675 // all except Explorer
|
|
676 if ((self.innerWidth == 0)||(self.innerHeight == 0)) {
|
|
677 // Safari 1.2 bug
|
|
678 if (parent) {
|
|
679 parent.innerHeight;
|
|
680 parent.innerWidth;
|
|
681 }
|
|
682 }
|
|
683 wsize.width = self.innerWidth;
|
|
684 wsize.height = self.innerHeight;
|
|
685 } else if (document.documentElement && document.documentElement.clientHeight) {
|
|
686 // Explorer 6 Strict Mode
|
|
687 wsize.width = document.documentElement.clientWidth;
|
|
688 wsize.height = document.documentElement.clientHeight;
|
|
689 } else if (document.body) {
|
|
690 // other Explorers
|
|
691 wsize.width = document.body.clientWidth;
|
|
692 wsize.height = document.body.clientHeight;
|
|
693 }
|
|
694 return wsize;
|
|
695 }
|
|
696
|
433
|
697 function getWinRect() {
|
|
698 var size = getWinSize();
|
|
699 return new Rectangle(0, 0, size.width, size.height);
|
|
700 }
|
|
701
|
398
|
702 function openWin(url, name, params) {
|
|
703 // open browser window
|
|
704 var ow = window.open(url, name, params);
|
|
705 ow.focus();
|
|
706 }
|
433
|
707
|
|
708 /* **********************************************
|
|
709 * cookie class
|
|
710 * ******************************************** */
|
|
711
|
|
712 function Cookie() {
|
|
713 return this.read();
|
|
714 }
|
|
715
|
|
716 Cookie.prototype.read = function() {
|
|
717 var s = document.cookie;
|
435
|
718 var lines = s.split("; "); // semicolon and space for all browsers?
|
433
|
719 for (var i in lines) {
|
|
720 var line = lines[i];
|
|
721 var sep = line.indexOf("=");
|
|
722 if (sep != -1) this.add(
|
|
723 line.substr(0, sep),
|
|
724 line.substr(sep + 1)
|
|
725 );
|
|
726 }
|
|
727 return this;
|
|
728 }
|
|
729
|
|
730 Cookie.prototype.store = function() {
|
|
731 var lines = new Array();
|
|
732 for (var i in this) {
|
|
733 var item = this[i];
|
|
734 if (typeof(item) == typeof(lines)) // Array
|
|
735 lines.push(i + "=" + item.join(","));
|
|
736 else if (typeof(item) != "function") // single item
|
|
737 lines.push(i + "=" + item);
|
|
738 }
|
|
739 // var s = lines.join(";")
|
|
740 for (line in lines) document.cookie = lines[line];
|
|
741 return this;
|
|
742 }
|
|
743
|
|
744 Cookie.prototype.add = function(key, value) {
|
|
745 if (value.indexOf(",") == -1)
|
|
746 this[key] = value; // single value
|
|
747 else
|
|
748 this[key] = value.split(","); // list of values
|
|
749 return this[key];
|
|
750 }
|
|
751
|
|
752 Cookie.prototype.get = function(key) {
|
|
753 return this[key];
|
|
754 }
|
|
755
|
|
756 Cookie.prototype.addbool = function(key, value) {
|
|
757 this[key] = Boolean(value).toString();
|
|
758 return this[key];
|
|
759 }
|
|
760
|
|
761 Cookie.prototype.getbool = function(key) {
|
|
762 var val = this[key];
|
|
763 return (val > "") && (val != "0") && (val != "false");
|
|
764 }
|
|
765
|
|
766 Cookie.prototype.remove = function(key) {
|
|
767 delete this[key];
|
|
768 }
|
|
769
|
|
770 // :tabSize=4:indentSize=4:noTabs=true:
|
|
771
|