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) {
|
|
415 if (((dlParams[param].detail & detail) > 0)&&(dlParams[param].hasValue)) {
|
|
416 var val = getParameter(param);
|
|
417 if (val != "") {
|
|
418 params.push(param + "=" + val);
|
|
419 }
|
|
420 }
|
|
421 }
|
|
422 return params.join("&");
|
|
423 }
|
|
424
|
|
425 function parseParameters(query) {
|
|
426 // gets parameter values from query format string
|
|
427 var params = query.split("&");
|
|
428 for (var i = 0; i < params.length; i++) {
|
|
429 var keyval = params[i].split("=");
|
|
430 if (keyval.length == 2) {
|
|
431 setParameter(keyval[0], keyval[1]);
|
|
432 }
|
|
433 }
|
|
434 }
|
|
435
|
407
|
436 getQueryString = getAllParameters;
|
398
|
437
|
|
438 /* **********************************************
|
|
439 * HTML/DOM routines
|
|
440 * ******************************************** */
|
|
441
|
|
442 function getElement(tagid, quiet) {
|
|
443 // returns the element object with the id tagid
|
|
444 var e;
|
|
445 if (document.getElementById) {
|
|
446 e = document.getElementById(tagid);
|
|
447 } else if (document.all) {
|
|
448 alert("document.all!");
|
|
449 e = document.all[tagid];
|
|
450 } else if (document.layers) {
|
|
451 e = document.layers[tagid];
|
|
452 }
|
|
453 if (e) {
|
|
454 return e;
|
|
455 } else {
|
|
456 if (! quiet) {
|
|
457 alert("unable to find element: "+tagid);
|
|
458 }
|
|
459 return null;
|
|
460 }
|
|
461 }
|
|
462
|
|
463 function getElementPosition(elem) {
|
|
464 // returns a Position with the position of the element
|
|
465 var x = 0;
|
|
466 var y = 0;
|
|
467 if (defined(elem.offsetLeft)) {
|
|
468 var e = elem;
|
|
469 while (e) {
|
|
470 if (defined(e.clientLeft)) {
|
|
471 // special for IE
|
|
472 if (browserType.isMac) {
|
|
473 if (e.offsetParent.tagName == "BODY") {
|
|
474 // IE for Mac extraspecial
|
|
475 x += e.clientLeft;
|
|
476 y += e.clientTop;
|
|
477 break;
|
|
478 }
|
|
479 } else {
|
|
480 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) {
|
|
481 x += e.clientLeft;
|
|
482 y += e.clientTop;
|
|
483 }
|
|
484 }
|
|
485 }
|
|
486 x += e.offsetLeft;
|
|
487 y += e.offsetTop;
|
|
488 e = e.offsetParent;
|
|
489 }
|
|
490 } else if (defined(elem.x)) {
|
|
491 x = elem.x;
|
|
492 y = elem.y;
|
|
493 } else if (defined(elem.pageX)) {
|
|
494 x = elem.pageX;
|
|
495 y = elem.pageY;
|
|
496 } else {
|
|
497 alert("unable to get position of "+elem+" (id:"+elem.id+")");
|
|
498 }
|
|
499 return new Position(getInt(x), getInt(y));
|
|
500 }
|
|
501
|
|
502 function getElementSize(elem) {
|
|
503 // returns a Rectangle with the size of the element
|
|
504 var width = 0;
|
|
505 var height = 0;
|
|
506 if (defined(elem.offsetWidth)) {
|
|
507 width = elem.offsetWidth;
|
|
508 height = elem.offsetHeight;
|
|
509 } else if (defined(elem.width)) {
|
|
510 width = elem.width;
|
|
511 height = elem.height;
|
|
512 } else if (defined(elem.clip.width)) {
|
|
513 width = elem.clip.width;
|
|
514 height = elem.clip.height;
|
|
515 } else {
|
|
516 alert("unable to get size of "+elem+" (id:"+elem.id+")");
|
|
517 }
|
|
518 return new Size(getInt(width), getInt(height));
|
|
519 }
|
|
520
|
|
521 function getElementRect(elem) {
|
|
522 // returns a Rectangle with the size and position of the element
|
412
|
523 // FIX ME: what about borders?
|
398
|
524 var pos = getElementPosition(elem);
|
|
525 var size = getElementSize(elem);
|
|
526 return new Rectangle(pos.x, pos.y, size.width, size.height);
|
|
527 }
|
|
528
|
|
529 function moveElement(elem, rect) {
|
|
530 // moves and sizes the element
|
|
531 if (elem.style) {
|
|
532 if (defined(rect.x)) {
|
|
533 elem.style.left = Math.round(rect.x) + "px";
|
|
534 elem.style.top = Math.round(rect.y) + "px";
|
|
535 }
|
|
536 if (defined(rect.width)) {
|
|
537 elem.style.width = Math.round(rect.width) + "px";
|
|
538 elem.style.height = Math.round(rect.height) + "px";
|
|
539 }
|
|
540 } else if (document.layers) {
|
|
541 if (defined(rect.x)) {
|
|
542 elem.pageX = getInt(rect.x);
|
|
543 elem.pageY = getInt(rect.y);
|
|
544 }
|
|
545 if (defined(rect.width)) {
|
|
546 elem.clip.width = getInt(rect.width);
|
|
547 elem.clip.height = getInt(rect.height);
|
|
548 }
|
|
549 } else {
|
|
550 alert("moveelement: no style nor layer property!");
|
|
551 return false;
|
|
552 }
|
|
553 return true;
|
|
554 }
|
|
555
|
|
556 function showElement(elem, show) {
|
|
557 // shows or hides the element
|
|
558 if (elem.style) {
|
|
559 if (show) {
|
|
560 elem.style.visibility = "visible";
|
|
561 } else {
|
|
562 elem.style.visibility = "hidden";
|
|
563 }
|
|
564 } else if (defined(elem.visibility)) {
|
|
565 if (show) {
|
|
566 elem.visibility = "show";
|
|
567 } else {
|
|
568 elem.visibility = "hide";
|
|
569 }
|
|
570 } else {
|
|
571 alert("showelement: no style nor layer property!");
|
|
572 }
|
|
573 return true;
|
|
574 }
|
|
575
|
|
576 function evtPosition(evt) {
|
|
577 // returns the on-screen Position of the Event
|
|
578 var x;
|
|
579 var y;
|
|
580 evt = (evt) ? evt : window.event;
|
|
581 if (!evt) {
|
|
582 alert("no event found! "+evt);
|
|
583 return;
|
|
584 }
|
|
585 if (defined(evt.pageX)) {
|
|
586 x = parseInt(evt.pageX);
|
|
587 y = parseInt(evt.pageY);
|
|
588 } else if (defined(evt.clientX)) {
|
|
589 x = parseInt(document.body.scrollLeft+evt.clientX);
|
|
590 y = parseInt(document.body.scrollTop+evt.clientY);
|
|
591 } else {
|
|
592 alert("evtPosition: don't know how to deal with "+evt);
|
|
593 }
|
|
594 return new Position(x, y);
|
|
595 }
|
|
596
|
|
597 function registerEvent(type, elem, handler) {
|
412
|
598 // register the given event handler on the indicated element
|
|
599 if (elem.addEventListener) {
|
|
600 elem.addEventListener(type, handler, false); // bubble
|
|
601 }
|
|
602 else if (elem.attachEvent) {
|
|
603 elem.attachEvent("on" + type, handler);
|
|
604 }
|
|
605 else if (elem.captureEvents) {
|
|
606 if (Event) {
|
|
607 t = type.toUpperCase();
|
|
608 elem.captureEvents(Event[t]);
|
|
609 elem[ "on" + t ] = handler;
|
|
610 }
|
|
611 }
|
|
612 else {
|
|
613 alert("Could not register event of type " + type);
|
|
614 return false;
|
|
615 }
|
|
616 return true;
|
|
617 }
|
|
618
|
407
|
619 function unregisterEvent(type, elem, handler) {
|
412
|
620 // unregister the given event handler from the indicated element
|
|
621 if (elem.removeEventListener) {
|
|
622 elem.removeEventListener(type, handler, false);
|
|
623 }
|
|
624 else if (elem.detachEvent) {
|
|
625 elem.detachEvent('on' + type, handler);
|
|
626 }
|
|
627 else if (elem.releaseEvents) {
|
|
628 if (Event) {
|
|
629 t = type.toUpperCase();
|
|
630 elem.releaseEvents(Event[t]);
|
|
631 elem[ "on" + t ] = null;
|
|
632 }
|
|
633 }
|
|
634 else {
|
|
635 alert("Could not register event of type " + type);
|
|
636 return false;
|
|
637 }
|
|
638 return true;
|
398
|
639 }
|
|
640
|
407
|
641 function registerEventById(type, id, handler) {
|
412
|
642 registerEvent(type, document.getElementById(id), handler);
|
|
643 }
|
407
|
644
|
|
645 function unregisterEventById(type, id, handler) {
|
412
|
646 unregisterEvent(type, document.getElementById(id), handler);
|
|
647 }
|
407
|
648
|
|
649 function stopEvent(e) {
|
412
|
650 if (!e) var e = window.event;
|
|
651 e.cancelBubble = true;
|
|
652 if (e.stopPropagation) e.stopPropagation();
|
|
653 return false;
|
398
|
654 }
|
|
655
|
407
|
656 function getEventSrc(e) {
|
412
|
657 if (e.target) return e.target;
|
|
658 if (e.srcElement) return e.srcElement;
|
407
|
659 }
|
398
|
660
|
|
661 // old registerXXYY API for compatibility
|
|
662 function registerMouseDown(elem, handler) {
|
|
663 return registerEvent("mousedown", elem, handler);
|
|
664 }
|
|
665 function unregisterMouseDown(elem, handler) {
|
|
666 return unregisterEvent("mousedown", elem, handler);
|
|
667 }
|
|
668 function registerMouseMove(elem, handler) {
|
|
669 return registerEvent("mousemove", elem, handler);
|
|
670 }
|
|
671 function unregisterMouseMove(elem, handler) {
|
|
672 return unregisterEvent("mousemove", elem, handler);
|
|
673 }
|
|
674 function registerKeyDown(handler) {
|
|
675 return registerEvent("keypress", elem, handler);
|
|
676 }
|
|
677
|
|
678
|
|
679 function getWinSize() {
|
|
680 // returns a Size with the current window size (mostly from www.quirksmode.org)
|
|
681 var wsize = new Size(100, 100);
|
|
682 if (defined(self.innerHeight)) {
|
|
683 // all except Explorer
|
|
684 if ((self.innerWidth == 0)||(self.innerHeight == 0)) {
|
|
685 // Safari 1.2 bug
|
|
686 if (parent) {
|
|
687 parent.innerHeight;
|
|
688 parent.innerWidth;
|
|
689 }
|
|
690 }
|
|
691 wsize.width = self.innerWidth;
|
|
692 wsize.height = self.innerHeight;
|
|
693 } else if (document.documentElement && document.documentElement.clientHeight) {
|
|
694 // Explorer 6 Strict Mode
|
|
695 wsize.width = document.documentElement.clientWidth;
|
|
696 wsize.height = document.documentElement.clientHeight;
|
|
697 } else if (document.body) {
|
|
698 // other Explorers
|
|
699 wsize.width = document.body.clientWidth;
|
|
700 wsize.height = document.body.clientHeight;
|
|
701 }
|
|
702 return wsize;
|
|
703 }
|
|
704
|
433
|
705 function getWinRect() {
|
|
706 var size = getWinSize();
|
|
707 return new Rectangle(0, 0, size.width, size.height);
|
|
708 }
|
|
709
|
398
|
710 function openWin(url, name, params) {
|
|
711 // open browser window
|
|
712 var ow = window.open(url, name, params);
|
|
713 ow.focus();
|
|
714 }
|
433
|
715
|
|
716 /* **********************************************
|
|
717 * cookie class
|
|
718 * ******************************************** */
|
|
719
|
|
720 function Cookie() {
|
|
721 return this.read();
|
|
722 }
|
|
723
|
|
724 Cookie.prototype.read = function() {
|
|
725 var s = document.cookie;
|
|
726 var lines = s.split("; ");
|
|
727 for (var i in lines) {
|
|
728 var line = lines[i];
|
|
729 var sep = line.indexOf("=");
|
|
730 if (sep != -1) this.add(
|
|
731 line.substr(0, sep),
|
|
732 line.substr(sep + 1)
|
|
733 );
|
|
734 }
|
|
735 return this;
|
|
736 }
|
|
737
|
|
738 Cookie.prototype.store = function() {
|
|
739 var lines = new Array();
|
|
740 for (var i in this) {
|
|
741 var item = this[i];
|
|
742 if (typeof(item) == typeof(lines)) // Array
|
|
743 lines.push(i + "=" + item.join(","));
|
|
744 else if (typeof(item) != "function") // single item
|
|
745 lines.push(i + "=" + item);
|
|
746 }
|
|
747 // var s = lines.join(";")
|
|
748 for (line in lines) document.cookie = lines[line];
|
|
749 return this;
|
|
750 }
|
|
751
|
|
752 Cookie.prototype.add = function(key, value) {
|
|
753 if (value.indexOf(",") == -1)
|
|
754 this[key] = value; // single value
|
|
755 else
|
|
756 this[key] = value.split(","); // list of values
|
|
757 return this[key];
|
|
758 }
|
|
759
|
|
760 Cookie.prototype.get = function(key) {
|
|
761 return this[key];
|
|
762 }
|
|
763
|
|
764 Cookie.prototype.addbool = function(key, value) {
|
|
765 this[key] = Boolean(value).toString();
|
|
766 return this[key];
|
|
767 }
|
|
768
|
|
769 Cookie.prototype.getbool = function(key) {
|
|
770 var val = this[key];
|
|
771 return (val > "") && (val != "0") && (val != "false");
|
|
772 }
|
|
773
|
|
774 Cookie.prototype.remove = function(key) {
|
|
775 delete this[key];
|
|
776 }
|
|
777
|
|
778 // :tabSize=4:indentSize=4:noTabs=true:
|
|
779
|