446
|
1 /* Copyright (C) 2003-2006 IT-Group MPIWG, WTWG Uni Bern and others
|
394
|
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)
|
446
|
20 Robert Casties, 2.11.2004 (almost complete rewrite)
|
403
|
21 Martin Raspe, 12.12.2005 (changes for Digilib NG)
|
394
|
22
|
|
23 */
|
|
24
|
403
|
25 // was: function base_init() {
|
446
|
26 baseLibVersion = "2.010";
|
403
|
27 browserType = getBrowserType();
|
394
|
28
|
440
|
29 sliders = {};
|
|
30 activeSlider = null;
|
394
|
31
|
|
32 function getInt(n) {
|
|
33 // returns always an integer
|
|
34 n = parseInt(n);
|
446
|
35 return (isNaN(n)) ? 0 : n;
|
394
|
36 }
|
|
37
|
|
38 function defined(x) {
|
|
39 // returns if x is defined
|
|
40 return (typeof arguments[0] != "undefined");
|
|
41 }
|
|
42
|
|
43 function cropFloat(x) {
|
|
44 // auxiliary function to crop senseless precision
|
403
|
45 return parseInt(10000 * x) / 10000;
|
394
|
46 }
|
|
47
|
|
48 function getBrowserType() {
|
|
49 // browser sniffer
|
|
50 var bt = Object();
|
|
51 bt.doDHTML = false;
|
|
52 bt.versIE = 0;
|
|
53
|
|
54 if ((! document.cssonly && document.layers) || document.all || document.getElementById) {
|
|
55 var vers = navigator.appVersion.split('MSIE ');
|
|
56 vers = vers[vers.length - 1];
|
|
57 bt.versIE = getInt(vers);
|
|
58 bt.isIE = navigator.userAgent.indexOf('MSIE') >= 0;
|
|
59 bt.isMac = navigator.platform.indexOf('Mac') >= 0;
|
|
60 bt.isWin = navigator.platform.indexOf('Win') >= 0;
|
|
61 bt.isN4 = (navigator.userAgent.indexOf('Mozilla/4.') >= 0) && ! bt.isIE;
|
|
62 bt.isIEWin = bt.versIE > 0 && bt.isWin;
|
|
63 if (navigator.appVersion.indexOf('MSIE') < 0 || ! bt.isMac || bt.versIE >= 5) {
|
|
64 bt.doDHTML = true;
|
|
65 bt.isOpera = navigator.userAgent.indexOf(' Opera ') >= 0;
|
|
66 bt.isKonq = navigator.userAgent.indexOf(' Konqueror') >= 0;
|
|
67 }
|
|
68 }
|
|
69 return bt;
|
|
70 }
|
|
71
|
|
72 // fixes for javascript < 1.2
|
|
73 if (! Array.prototype.push) {
|
|
74 Array.prototype.push = function(val) {
|
|
75 this[this.length] = val;
|
|
76 return this.length;
|
|
77 }
|
|
78 Array.prototype.pop = function() {
|
|
79 var val = this[this.length-1];
|
|
80 this.length -= 1;
|
|
81 return val;
|
|
82 }
|
|
83 }
|
|
84
|
|
85
|
|
86 /* **********************************************
|
|
87 * geometry classes
|
|
88 * ******************************************** */
|
|
89
|
|
90 /*
|
|
91 * Size class
|
|
92 */
|
|
93 function Size(w, h) {
|
|
94 this.width = parseFloat(w);
|
|
95 this.height = parseFloat(h);
|
|
96 return this;
|
|
97 }
|
|
98 Size.prototype.toString = function() {
|
|
99 return this.width + "x" + this.height;
|
|
100 }
|
422
|
101 Size.prototype.equals = function(other) {
|
|
102 return (this.width == other.width
|
|
103 && this.height == other.height)
|
|
104 }
|
394
|
105
|
|
106 /*
|
|
107 * Position class
|
|
108 */
|
|
109 function Position(x, y) {
|
|
110 this.x = parseFloat(x);
|
|
111 this.y = parseFloat(y);
|
|
112 return this;
|
|
113 }
|
|
114 Position.prototype.toString = function() {
|
|
115 return this.x + "," + this.y;
|
|
116 }
|
422
|
117 Position.prototype.equals = function(other) {
|
|
118 return (this.x == other.x
|
|
119 && this.y == other.y)
|
446
|
120 }
|
394
|
121 /*
|
|
122 * Rectangle class
|
|
123 */
|
|
124 function Rectangle(x, y, w, h) {
|
446
|
125 if (typeof x == "object") {
|
|
126 // assume x and y are Position
|
|
127 this.x = x.x;
|
|
128 this.y = x.y;
|
|
129 this.width = y.x - x.x;
|
|
130 this.height = y.y - x.y;
|
|
131 return this;
|
|
132 }
|
394
|
133 this.x = parseFloat(x);
|
|
134 this.y = parseFloat(y);
|
|
135 this.width = parseFloat(w);
|
|
136 this.height = parseFloat(h);
|
|
137 return this;
|
|
138 }
|
|
139 Rectangle.prototype.toString = function() {
|
|
140 return this.width+"x"+this.height+"@"+this.x+","+this.y;
|
|
141 }
|
|
142 Rectangle.prototype.copy = function() {
|
|
143 // returns a copy of this Rectangle
|
|
144 return new Rectangle(this.x, this.y, this.width, this.height);
|
|
145 }
|
|
146 Rectangle.prototype.getPosition = function() {
|
|
147 // returns the position of this Rectangle
|
|
148 return new Position(this.x, this.y);
|
|
149 }
|
429
|
150 Rectangle.prototype.getPt1 = Rectangle.prototype.getPosition;
|
446
|
151 // returns the upper left corner position
|
429
|
152
|
|
153 Rectangle.prototype.getPt2 = function() {
|
446
|
154 // returns the lower right corner position of this Rectangle
|
429
|
155 return new Position(this.x + this.width, this.y + this.height);
|
|
156 }
|
|
157 Rectangle.prototype.setPt1 = function(pos) {
|
446
|
158 // sets the upper left corner to position pos
|
429
|
159 this.x = pos.x;
|
|
160 this.y = pos.y;
|
|
161 return this;
|
|
162 }
|
|
163 Rectangle.prototype.setPt2 = function(pos) {
|
446
|
164 // sets the lower right corner to position pos
|
429
|
165 this.width = pos.x - this.x;
|
|
166 this.height = pos.y - this.y;
|
|
167 return this;
|
|
168 }
|
|
169 Rectangle.prototype.getCenter = function() {
|
|
170 // returns the center position of this Rectangle
|
|
171 return new Position(this.x + this.width / 2, this.y + this.height / 2);
|
|
172 }
|
|
173 Rectangle.prototype.setCenter = function(pos) {
|
|
174 // moves this Rectangle's center to position pos
|
|
175 this.x = pos.x - this.width / 2;
|
|
176 this.y = pos.y - this.height / 2;
|
|
177 return this;
|
|
178 }
|
394
|
179 Rectangle.prototype.getSize = function() {
|
|
180 // returns the size of this Rectangle
|
|
181 return new Size(this.width, this.height);
|
|
182 }
|
422
|
183 Rectangle.prototype.equals = function(other) {
|
|
184 // equal props
|
|
185 return (this.getPosition().equals(other.getPosition())
|
|
186 && this.getSize().equals(other.getSize())
|
|
187 );
|
|
188 }
|
394
|
189 Rectangle.prototype.getArea = function() {
|
|
190 // returns the area of this Rectangle
|
|
191 return (this.width * this.height);
|
|
192 }
|
429
|
193 Rectangle.prototype.normalize = function() {
|
|
194 // eliminates negative width and height
|
|
195 var p = this.getPt2();
|
|
196 this.x = Math.min(this.x, p.x);
|
|
197 this.y = Math.min(this.y, p.y);
|
|
198 this.width = Math.abs(this.width);
|
|
199 this.height = Math.abs(this.height);
|
|
200 return this;
|
|
201 }
|
394
|
202 Rectangle.prototype.containsPosition = function(pos) {
|
408
|
203 // returns if Position "pos" lies inside of this rectangle
|
|
204 return ((pos.x >= this.x)
|
|
205 && (pos.y >= this.y)
|
|
206 && (pos.x <= this.x + this.width)
|
|
207 && (pos.y <= this.y + this.width)
|
|
208 );
|
|
209 }
|
|
210 Rectangle.prototype.containsRect = function(rect) {
|
|
211 // returns if rectangle "rect" is contained in this rectangle
|
446
|
212 return (this.containsPosition(rect.getPt1())
|
|
213 && this.containsPosition(rect.getPt2()));
|
408
|
214 }
|
|
215 Rectangle.prototype.stayInside = function(rect) {
|
|
216 // changes this rectangle's x/y values so it stays inside of rectangle rect
|
429
|
217 // keeping the proportions
|
408
|
218 if (this.x < rect.x) this.x = rect.x;
|
|
219 if (this.y < rect.y) this.y = rect.y;
|
|
220 if (this.x + this.width > rect.x + rect.width)
|
|
221 this.x = rect.x + rect.width - this.width;
|
|
222 if (this.y + this.height > rect.y + rect.height)
|
|
223 this.y = rect.y + rect.height - this.height;
|
|
224 return this;
|
394
|
225 }
|
429
|
226 Rectangle.prototype.clipTo = function(rect) {
|
|
227 // clips this rectangle so it stays inside of rectangle rect
|
446
|
228 var p1 = rect.getPt1();
|
|
229 var p2 = rect.getPt2();
|
|
230 var this2 = this.getPt2();
|
429
|
231 this.setPt1(new Position(Math.max(this.x, p1.x), Math.max(this.y, p1.y)));
|
|
232 this.setPt2(new Position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y)));
|
|
233 return this;
|
|
234 }
|
394
|
235 Rectangle.prototype.intersect = function(rect) {
|
|
236 // returns the intersection of the given Rectangle and this one
|
408
|
237 // FIX ME: not really, it should return null if there is no overlap
|
394
|
238 var sec = rect.copy();
|
|
239 if (sec.x < this.x) {
|
|
240 sec.width = sec.width - (this.x - sec.x);
|
|
241 sec.x = this.x;
|
|
242 }
|
|
243 if (sec.y < this.y) {
|
|
244 sec.height = sec.height - (this.y - sec.y);
|
|
245 sec.y = this.y;
|
|
246 }
|
|
247 if (sec.x + sec.width > this.x + this.width) {
|
|
248 sec.width = (this.x + this.width) - sec.x;
|
|
249 }
|
|
250 if (sec.y + sec.height > this.y + this.height) {
|
|
251 sec.height = (this.y + this.height) - sec.y;
|
|
252 }
|
|
253 return sec;
|
|
254 }
|
|
255 Rectangle.prototype.fit = function(rect) {
|
|
256 // returns a Rectangle that fits into this one (by moving first)
|
|
257 var sec = rect.copy();
|
|
258 sec.x = Math.max(sec.x, this.x);
|
422
|
259 sec.y = Math.max(sec.y, this.x);
|
394
|
260 if (sec.x + sec.width > this.x + this.width) {
|
|
261 sec.x = this.x + this.width - sec.width;
|
|
262 }
|
|
263 if (sec.y + sec.height > this.y + this.height) {
|
|
264 sec.y = this.y + this.height - sec.height;
|
|
265 }
|
|
266 return sec.intersect(this);
|
|
267 }
|
|
268
|
|
269 /*
|
|
270 * Transform class
|
|
271 *
|
|
272 * defines a class of affine transformations
|
|
273 */
|
|
274 function Transform() {
|
|
275 this.m00 = 1.0;
|
|
276 this.m01 = 0.0;
|
|
277 this.m02 = 0.0;
|
|
278 this.m10 = 0.0;
|
|
279 this.m11 = 1.0;
|
|
280 this.m12 = 0.0;
|
|
281 this.m20 = 0.0;
|
|
282 this.m21 = 0.0;
|
|
283 this.m22 = 1.0;
|
|
284 return this;
|
|
285 }
|
|
286 Transform.prototype.concat = function(traf) {
|
|
287 // add Transform traf to this Transform
|
|
288 for (var i = 0; i < 3; i++) {
|
|
289 for (var j = 0; j < 3; j++) {
|
|
290 var c = 0.0;
|
|
291 for (var k = 0; k < 3; k++) {
|
|
292 c += traf["m"+i+k] * this["m"+k+j];
|
|
293 }
|
|
294 this["m"+i+j] = c;
|
|
295 }
|
|
296 }
|
|
297 return this;
|
|
298 }
|
|
299 Transform.prototype.transform = function(rect) {
|
|
300 // returns transformed Rectangle or Position with this Transform applied
|
|
301 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02;
|
|
302 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12;
|
|
303 if (rect.width) {
|
|
304 var width = this.m00 * rect.width + this.m01 * rect.height;
|
|
305 var height = this.m10 * rect.width + this.m11 * rect.height;
|
|
306 return new Rectangle(x, y, width, height);
|
|
307 }
|
|
308 return new Position(x, y);
|
|
309 }
|
|
310 Transform.prototype.invtransform = function(pos) {
|
|
311 // returns transformed Position pos with the inverse of this Transform applied
|
|
312 var det = this.m00 * this.m11 - this.m01 * this.m10;
|
|
313 var x = (this.m11 * pos.x - this.m01 * pos.y - this.m11 * this.m02 + this.m01 * this.m12) / det;
|
|
314 var y = (- this.m10 * pos.x + this.m00 * pos.y + this.m10 * this.m02 - this.m00 * this.m12) / det;
|
446
|
315 if (pos.width) {
|
|
316 var width = (this.m11 * pos.width - this.m01 * pos.height - this.m11 * this.m02 + this.m01 * this.m12) / det;
|
|
317 var height = (- this.m10 * pos.width + this.m00 * pos.height + this.m10 * this.m02 - this.m00 * this.m12) / det;
|
|
318 return new Rectangle(x, y, width, height);
|
|
319 }
|
394
|
320 return new Position(x, y);
|
|
321 }
|
|
322 function getRotation(angle, pos) {
|
|
323 // returns a Transform that is a rotation by angle degrees around [pos.x, pos.y]
|
|
324 var traf = new Transform();
|
|
325 if (angle != 0) {
|
|
326 var t = 2.0 * Math.PI * parseFloat(angle) / 360.0;
|
|
327 traf.m00 = Math.cos(t);
|
|
328 traf.m01 = - Math.sin(t);
|
|
329 traf.m10 = Math.sin(t);
|
|
330 traf.m11 = Math.cos(t);
|
|
331 traf.m02 = pos.x - pos.x * Math.cos(t) + pos.y * Math.sin(t);
|
|
332 traf.m12 = pos.y - pos.x * Math.sin(t) - pos.y * Math.cos(t);
|
|
333 }
|
|
334 return traf;
|
|
335 }
|
|
336 function getTranslation(pos) {
|
|
337 // returns a Transform that is a translation by [pos.x, pos,y]
|
|
338 var traf = new Transform();
|
|
339 traf.m02 = pos.x;
|
|
340 traf.m12 = pos.y;
|
|
341 return traf;
|
|
342 }
|
|
343 function getScale(size) {
|
|
344 // returns a Transform that is a scale by [size.width, size.height]
|
|
345 var traf = new Transform();
|
|
346 traf.m00 = size.width;
|
|
347 traf.m11 = size.height;
|
|
348 return traf;
|
|
349 }
|
|
350
|
|
351
|
446
|
352 /*
|
|
353 * parameters class
|
|
354 */
|
394
|
355
|
446
|
356 function Parameters() {
|
|
357 this.params = new Object();
|
|
358 return this;
|
|
359 }
|
|
360 Parameters.prototype.define = function(name, defaultValue, detail) {
|
394
|
361 // create a new parameter with a name and a default value
|
446
|
362 if (!this.params[name]) this.params[name] = new Object();
|
|
363 this.params[name].defaultValue = defaultValue;
|
|
364 this.params[name].hasValue = false;
|
|
365 this.params[name].value = defaultValue;
|
|
366 this.params[name].detail = detail;
|
|
367 return this.params[name];
|
|
368 }
|
|
369 Parameters.prototype.reset = function(name) {
|
408
|
370 // resets the given parameter to its default value
|
446
|
371 if (!this.params[name]) {
|
|
372 alert("Could not reset non-existing parameter '" + name + "'");
|
|
373 return false;
|
408
|
374 }
|
446
|
375 this.params[name].hasValue = false;
|
|
376 this.params[name].value = this.params[name].defaultValue;
|
|
377 return this.params[name];
|
|
378 }
|
|
379 Parameters.prototype.resetAll = function() {
|
|
380 // resets all parameters to their default values
|
|
381 for (var p in this.params) {
|
|
382 this.reset(p);
|
|
383 }
|
|
384 return true;
|
|
385 }
|
|
386 Parameters.prototype.remove = function(name) {
|
|
387 if (!defined(this.params[name])) return false;
|
|
388 delete this.params[name];
|
|
389 return true;
|
|
390 }
|
|
391 Parameters.prototype.get = function(name) {
|
394
|
392 // returns the named parameter value or its default value
|
446
|
393 if (!defined(this.params[name])) return null;
|
|
394 return this.params[name].hasValue ? this.params[name].value : this.params[name].defaultValue;
|
|
395 }
|
|
396 Parameters.prototype.set = function(name, value, relative) {
|
|
397 // sets parameter value (relative values with +/- if relative=true)
|
|
398 if (!defined(this.params[name])) return null;
|
|
399 var p = this.params[name];
|
408
|
400 if (relative && value.slice) {
|
446
|
401 // value is a string -- check if it starts with +/-
|
408
|
402 var sign = value.slice(0, 1);
|
|
403 if (sign == '+') {
|
|
404 p.value = parseFloat(p.value) + parseFloat(value.slice(1));
|
|
405 } else if (sign == '-') {
|
|
406 p.value = parseFloat(p.value) - parseFloat(value.slice(1));
|
|
407 } else {
|
|
408 p.value = value;
|
|
409 }
|
446
|
410 } else {
|
|
411 p.value = value;
|
|
412 }
|
408
|
413 p.hasValue = true;
|
|
414 return p.value;
|
446
|
415 }
|
|
416 Parameters.prototype.isSet = function(name) {
|
408
|
417 // returns if the parameter's value has been set
|
446
|
418 if (!defined(this.params[name])) return null;
|
|
419 return this.params[name].hasValue;
|
|
420 }
|
|
421 Parameters.prototype.getAll = function(detail) {
|
394
|
422 // returns a string of all parameters in query format
|
446
|
423 if (!detail) detail = 255;
|
|
424 var pa = new Array();
|
|
425 for (p in this.params) {
|
|
426 if (((this.params[p].detail & detail) > 0)
|
|
427 && (this.params[p].hasValue)) {
|
|
428 var val = this.params[p].value;
|
394
|
429 if (val != "") {
|
446
|
430 pa.push(p + "=" + val);
|
394
|
431 }
|
|
432 }
|
|
433 }
|
446
|
434 return pa.join("&");
|
394
|
435 }
|
446
|
436 Parameters.prototype.parse = function(query) {
|
394
|
437 // gets parameter values from query format string
|
446
|
438 var pa = query.split("&");
|
|
439 for (var i = 0; i < pa.length; i++) {
|
|
440 var keyval = pa[i].split("=");
|
394
|
441 if (keyval.length == 2) {
|
446
|
442 this.set(keyval[0], keyval[1]);
|
394
|
443 }
|
|
444 }
|
|
445 }
|
|
446
|
446
|
447 /*
|
|
448 * Flags class
|
|
449 *
|
|
450 * Flags are (hash-) collections of unique strings.
|
|
451 */
|
|
452 function Flags() {
|
|
453 this.flags = new Object();
|
|
454 return this;
|
|
455 }
|
|
456 Flags.prototype.define = function(name, detail) {
|
|
457 // create a new flag with a name and detail level
|
|
458 this.flags[name] = new Object();
|
|
459 this.flags[name].set = false;
|
|
460 this.flags[name].detail = detail;
|
|
461 return this.flags[name];
|
|
462 }
|
|
463 Flags.prototype.get = function(name) {
|
|
464 return (this.flags[name]) ? this.flags[name].set : false;
|
|
465 }
|
|
466 Flags.prototype.set = function(name, value) {
|
|
467 if (!defined(value)) value = true;
|
|
468 if (!this.flags[name]) this.flags[name] = new Object;
|
|
469 this.flags[name].set = value;
|
|
470 }
|
|
471 Flags.prototype.reset = function(name) {
|
|
472 if (!this.flags[name]) this.flags[name] = new Object;
|
|
473 this.flags[name].set = false;
|
|
474 }
|
|
475 Flags.prototype.toggle = function(name) {
|
|
476 if (!this.flags[name]) this.flags[name] = new Object;
|
|
477 this.flags[name].set = !this.flags[name].set;
|
|
478 }
|
|
479 Flags.prototype.resetAll = function() {
|
|
480 for (var f in this.flags) {
|
|
481 this.flags[f].set = false;
|
|
482 }
|
|
483 }
|
|
484 Flags.prototype.parse = function(query, sep) {
|
|
485 // sets the flags from the string query
|
|
486 if (!sep) sep = ",";
|
|
487 var fa = query.split(sep);
|
|
488 for (var i = 0; i < fa.length ; i++) {
|
|
489 var f = fa[i];
|
|
490 if (f != "") {
|
|
491 this.set(f);
|
|
492 }
|
|
493 }
|
|
494 }
|
|
495 Flags.prototype.getAll = function(detail, sep) {
|
|
496 // returns a string of all flags in query format
|
|
497 if (!detail) detail = 255;
|
|
498 if (!sep) sep = ",";
|
|
499 var fa = new Array();
|
|
500 for (f in this.flags) {
|
|
501 if (this.flags[f].set) {
|
|
502 // if the flag has a detail level it must match
|
|
503 // otherwise we assume detail=128
|
|
504 if (this.flags[f].detail) {
|
|
505 if ((this.flags[f].detail & detail) > 0) {
|
|
506 fa.push(f);
|
|
507 }
|
|
508 } else {
|
|
509 if ((detail & 128) > 0) {
|
|
510 fa.push(f);
|
|
511 }
|
|
512 }
|
|
513 }
|
|
514 }
|
|
515 return fa.join(sep);
|
|
516 }
|
|
517
|
394
|
518
|
|
519 /* **********************************************
|
|
520 * HTML/DOM routines
|
|
521 * ******************************************** */
|
|
522
|
|
523 function getElement(tagid, quiet) {
|
|
524 // returns the element object with the id tagid
|
|
525 var e;
|
|
526 if (document.getElementById) {
|
|
527 e = document.getElementById(tagid);
|
|
528 } else if (document.all) {
|
|
529 alert("document.all!");
|
|
530 e = document.all[tagid];
|
|
531 } else if (document.layers) {
|
|
532 e = document.layers[tagid];
|
|
533 }
|
|
534 if (e) {
|
|
535 return e;
|
|
536 } else {
|
|
537 if (! quiet) {
|
|
538 alert("unable to find element: "+tagid);
|
|
539 }
|
|
540 return null;
|
|
541 }
|
|
542 }
|
|
543
|
|
544 function getElementPosition(elem) {
|
|
545 // returns a Position with the position of the element
|
|
546 var x = 0;
|
|
547 var y = 0;
|
|
548 if (defined(elem.offsetLeft)) {
|
|
549 var e = elem;
|
|
550 while (e) {
|
|
551 if (defined(e.clientLeft)) {
|
|
552 // special for IE
|
|
553 if (browserType.isMac) {
|
|
554 if (e.offsetParent.tagName == "BODY") {
|
|
555 // IE for Mac extraspecial
|
|
556 x += e.clientLeft;
|
|
557 y += e.clientTop;
|
|
558 break;
|
|
559 }
|
|
560 } else {
|
|
561 if ((e.tagName != "TABLE") && (e.tagName != "BODY")) {
|
|
562 x += e.clientLeft;
|
|
563 y += e.clientTop;
|
|
564 }
|
|
565 }
|
|
566 }
|
|
567 x += e.offsetLeft;
|
|
568 y += e.offsetTop;
|
|
569 e = e.offsetParent;
|
|
570 }
|
|
571 } else if (defined(elem.x)) {
|
|
572 x = elem.x;
|
|
573 y = elem.y;
|
|
574 } else if (defined(elem.pageX)) {
|
|
575 x = elem.pageX;
|
|
576 y = elem.pageY;
|
|
577 } else {
|
434
|
578 alert("unable to get position of " + elem + " (id:" + elem.id + ")");
|
394
|
579 }
|
|
580 return new Position(getInt(x), getInt(y));
|
|
581 }
|
|
582
|
|
583 function getElementSize(elem) {
|
|
584 // returns a Rectangle with the size of the element
|
|
585 var width = 0;
|
|
586 var height = 0;
|
|
587 if (defined(elem.offsetWidth)) {
|
|
588 width = elem.offsetWidth;
|
|
589 height = elem.offsetHeight;
|
|
590 } else if (defined(elem.width)) {
|
|
591 width = elem.width;
|
|
592 height = elem.height;
|
|
593 } else if (defined(elem.clip.width)) {
|
|
594 width = elem.clip.width;
|
|
595 height = elem.clip.height;
|
|
596 } else {
|
434
|
597 alert("unable to get size of " + elem + " (id:" + elem.id + ")");
|
394
|
598 }
|
|
599 return new Size(getInt(width), getInt(height));
|
|
600 }
|
|
601
|
|
602 function getElementRect(elem) {
|
|
603 // returns a Rectangle with the size and position of the element
|
408
|
604 // FIX ME: what about borders?
|
394
|
605 var pos = getElementPosition(elem);
|
|
606 var size = getElementSize(elem);
|
|
607 return new Rectangle(pos.x, pos.y, size.width, size.height);
|
|
608 }
|
|
609
|
|
610 function moveElement(elem, rect) {
|
|
611 // moves and sizes the element
|
|
612 if (elem.style) {
|
|
613 if (defined(rect.x)) {
|
|
614 elem.style.left = Math.round(rect.x) + "px";
|
|
615 elem.style.top = Math.round(rect.y) + "px";
|
|
616 }
|
|
617 if (defined(rect.width)) {
|
|
618 elem.style.width = Math.round(rect.width) + "px";
|
|
619 elem.style.height = Math.round(rect.height) + "px";
|
|
620 }
|
|
621 } else if (document.layers) {
|
|
622 if (defined(rect.x)) {
|
|
623 elem.pageX = getInt(rect.x);
|
|
624 elem.pageY = getInt(rect.y);
|
|
625 }
|
|
626 if (defined(rect.width)) {
|
|
627 elem.clip.width = getInt(rect.width);
|
|
628 elem.clip.height = getInt(rect.height);
|
|
629 }
|
|
630 } else {
|
434
|
631 alert("moveElement(): element has no style or layer property!");
|
394
|
632 return false;
|
|
633 }
|
|
634 return true;
|
|
635 }
|
|
636
|
|
637 function showElement(elem, show) {
|
|
638 // shows or hides the element
|
431
|
639 if (elem.style)
|
|
640 elem.style.visibility = show ? "visible" : "hidden";
|
434
|
641 else if (defined(elem.visibility))
|
431
|
642 elem.visibility = show ? "show" : "hide";
|
434
|
643 else
|
431
|
644 alert("showElement(): element has no style or layer property!");
|
394
|
645 return true;
|
|
646 }
|
|
647
|
|
648 function evtPosition(evt) {
|
|
649 // returns the on-screen Position of the Event
|
|
650 var x;
|
|
651 var y;
|
|
652 evt = (evt) ? evt : window.event;
|
|
653 if (!evt) {
|
431
|
654 alert("no event found! " + evt);
|
394
|
655 return;
|
431
|
656 }
|
394
|
657 if (defined(evt.pageX)) {
|
|
658 x = parseInt(evt.pageX);
|
|
659 y = parseInt(evt.pageY);
|
|
660 } else if (defined(evt.clientX)) {
|
431
|
661 x = parseInt(document.body.scrollLeft + evt.clientX);
|
|
662 y = parseInt(document.body.scrollTop + evt.clientY);
|
394
|
663 } else {
|
431
|
664 alert("evtPosition(): don't know how to deal with " + evt);
|
|
665 }
|
394
|
666 return new Position(x, y);
|
|
667 }
|
|
668
|
|
669 function registerEvent(type, elem, handler) {
|
408
|
670 // register the given event handler on the indicated element
|
|
671 if (elem.addEventListener) {
|
|
672 elem.addEventListener(type, handler, false); // bubble
|
|
673 }
|
|
674 else if (elem.attachEvent) {
|
|
675 elem.attachEvent("on" + type, handler);
|
|
676 }
|
|
677 else if (elem.captureEvents) {
|
|
678 if (Event) {
|
|
679 t = type.toUpperCase();
|
|
680 elem.captureEvents(Event[t]);
|
434
|
681 elem[ "on" + type ] = handler;
|
408
|
682 }
|
|
683 }
|
|
684 else {
|
|
685 alert("Could not register event of type " + type);
|
|
686 return false;
|
|
687 }
|
|
688 return true;
|
|
689 }
|
|
690
|
403
|
691 function unregisterEvent(type, elem, handler) {
|
408
|
692 // unregister the given event handler from the indicated element
|
|
693 if (elem.removeEventListener) {
|
|
694 elem.removeEventListener(type, handler, false);
|
|
695 }
|
|
696 else if (elem.detachEvent) {
|
434
|
697 elem.detachEvent("on" + type, handler);
|
408
|
698 }
|
|
699 else if (elem.releaseEvents) {
|
|
700 if (Event) {
|
|
701 t = type.toUpperCase();
|
|
702 elem.releaseEvents(Event[t]);
|
434
|
703 elem[ "on" + type ] = null;
|
408
|
704 }
|
|
705 }
|
|
706 else {
|
|
707 alert("Could not register event of type " + type);
|
|
708 return false;
|
|
709 }
|
|
710 return true;
|
394
|
711 }
|
|
712
|
403
|
713 function registerEventById(type, id, handler) {
|
438
|
714 registerEvent(type, getElement(id), handler);
|
408
|
715 }
|
403
|
716
|
|
717 function unregisterEventById(type, id, handler) {
|
438
|
718 unregisterEvent(type, getElement(id), handler);
|
408
|
719 }
|
403
|
720
|
|
721 function stopEvent(e) {
|
408
|
722 if (!e) var e = window.event;
|
|
723 e.cancelBubble = true;
|
|
724 if (e.stopPropagation) e.stopPropagation();
|
|
725 return false;
|
394
|
726 }
|
|
727
|
403
|
728 function getEventSrc(e) {
|
408
|
729 if (e.target) return e.target;
|
|
730 if (e.srcElement) return e.srcElement;
|
403
|
731 }
|
394
|
732
|
|
733 // old registerXXYY API for compatibility
|
|
734 function registerMouseDown(elem, handler) {
|
|
735 return registerEvent("mousedown", elem, handler);
|
|
736 }
|
|
737 function unregisterMouseDown(elem, handler) {
|
|
738 return unregisterEvent("mousedown", elem, handler);
|
|
739 }
|
|
740 function registerMouseMove(elem, handler) {
|
|
741 return registerEvent("mousemove", elem, handler);
|
|
742 }
|
|
743 function unregisterMouseMove(elem, handler) {
|
|
744 return unregisterEvent("mousemove", elem, handler);
|
|
745 }
|
|
746 function registerKeyDown(handler) {
|
|
747 return registerEvent("keypress", elem, handler);
|
|
748 }
|
|
749
|
|
750
|
|
751 function getWinSize() {
|
|
752 // returns a Size with the current window size (mostly from www.quirksmode.org)
|
|
753 var wsize = new Size(100, 100);
|
|
754 if (defined(self.innerHeight)) {
|
|
755 // all except Explorer
|
|
756 if ((self.innerWidth == 0)||(self.innerHeight == 0)) {
|
|
757 // Safari 1.2 bug
|
|
758 if (parent) {
|
|
759 parent.innerHeight;
|
|
760 parent.innerWidth;
|
|
761 }
|
|
762 }
|
|
763 wsize.width = self.innerWidth;
|
|
764 wsize.height = self.innerHeight;
|
|
765 } else if (document.documentElement && document.documentElement.clientHeight) {
|
|
766 // Explorer 6 Strict Mode
|
|
767 wsize.width = document.documentElement.clientWidth;
|
|
768 wsize.height = document.documentElement.clientHeight;
|
|
769 } else if (document.body) {
|
|
770 // other Explorers
|
|
771 wsize.width = document.body.clientWidth;
|
|
772 wsize.height = document.body.clientHeight;
|
|
773 }
|
|
774 return wsize;
|
|
775 }
|
|
776
|
429
|
777 function getWinRect() {
|
|
778 var size = getWinSize();
|
|
779 return new Rectangle(0, 0, size.width, size.height);
|
|
780 }
|
|
781
|
394
|
782 function openWin(url, name, params) {
|
|
783 // open browser window
|
|
784 var ow = window.open(url, name, params);
|
|
785 ow.focus();
|
|
786 }
|
429
|
787
|
|
788 /* **********************************************
|
|
789 * cookie class
|
|
790 * ******************************************** */
|
|
791
|
|
792 function Cookie() {
|
|
793 return this.read();
|
|
794 }
|
|
795
|
|
796 Cookie.prototype.read = function() {
|
|
797 var s = document.cookie;
|
431
|
798 var lines = s.split("; "); // semicolon and space for all browsers?
|
429
|
799 for (var i in lines) {
|
|
800 var line = lines[i];
|
|
801 var sep = line.indexOf("=");
|
|
802 if (sep != -1) this.add(
|
|
803 line.substr(0, sep),
|
|
804 line.substr(sep + 1)
|
|
805 );
|
|
806 }
|
|
807 return this;
|
|
808 }
|
|
809
|
|
810 Cookie.prototype.store = function() {
|
|
811 var lines = new Array();
|
|
812 for (var i in this) {
|
|
813 var item = this[i];
|
|
814 if (typeof(item) == typeof(lines)) // Array
|
|
815 lines.push(i + "=" + item.join(","));
|
|
816 else if (typeof(item) != "function") // single item
|
|
817 lines.push(i + "=" + item);
|
|
818 }
|
|
819 // var s = lines.join(";")
|
|
820 for (line in lines) document.cookie = lines[line];
|
|
821 return this;
|
|
822 }
|
|
823
|
|
824 Cookie.prototype.add = function(key, value) {
|
434
|
825 value = value.toString();
|
429
|
826 if (value.indexOf(",") == -1)
|
|
827 this[key] = value; // single value
|
|
828 else
|
|
829 this[key] = value.split(","); // list of values
|
|
830 return this[key];
|
|
831 }
|
|
832
|
|
833 Cookie.prototype.get = function(key) {
|
|
834 return this[key];
|
|
835 }
|
|
836
|
|
837 Cookie.prototype.addbool = function(key, value) {
|
|
838 this[key] = Boolean(value).toString();
|
|
839 return this[key];
|
|
840 }
|
|
841
|
|
842 Cookie.prototype.getbool = function(key) {
|
|
843 var val = this[key];
|
|
844 return (val > "") && (val != "0") && (val != "false");
|
|
845 }
|
|
846
|
|
847 Cookie.prototype.remove = function(key) {
|
|
848 delete this[key];
|
|
849 }
|
|
850
|
438
|
851 function Slider(id, valMin, valMax, valStart, stepSize, onChange) {
|
|
852 // a (horizontal) slider widget
|
|
853 this.id = id;
|
|
854 this.elem = getElement(id);
|
440
|
855 this.slider = getElement(id + "-slider"); // the slider handle
|
|
856 this.input = getElement(id + "-input", 1); // optional input field
|
|
857 this.bar = getElement(id + "-bar"); // the slider bar
|
438
|
858 this.barRect = getElementRect(this.bar);
|
440
|
859 this.sliderRect = getElementRect(this.slider);
|
|
860 this.xMin = this.barRect.x;
|
|
861 this.xMax = this.xMin + this.barRect.width;
|
|
862 this.xDiff = this.xMax - this.xMin;
|
|
863 this.Y = this.barRect.getCenter().y; // middle axis of bar
|
438
|
864 this.valMin = valMin;
|
|
865 this.valMax = valMax;
|
440
|
866 this.valDiff = Math.abs(valMax - valMin);
|
438
|
867 this.valStart = valStart;
|
|
868 this.value = valStart;
|
|
869 this.stepSize = stepSize;
|
440
|
870 this.valueLabel = getElement(id + "-value", 1);
|
|
871 this.valMinLabel = getElement(id + "-valmin", 1);
|
|
872 this.valMaxLabel = getElement(id + "-valmax", 1);
|
438
|
873 this.onChange = onChange ? onChange : function() {};
|
440
|
874 this.update();
|
|
875 this.activate();
|
|
876 sliders[id + '-slider'] = this; // make a handle to the object
|
438
|
877 return this;
|
|
878 }
|
|
879
|
|
880 Slider.prototype.show = function(show) {
|
|
881 showElement(this.elem, show);
|
440
|
882 this.activate();
|
438
|
883 }
|
|
884
|
|
885 Slider.prototype.activate = function() {
|
440
|
886 this.setupEvents();
|
438
|
887 }
|
|
888
|
440
|
889 Slider.prototype.deactivate = function() {
|
|
890 unregisterEvent("mousedown", this.slider, this.onDragStart);
|
438
|
891 }
|
|
892
|
|
893 Slider.prototype.reset = function() {
|
|
894 this.setValue(this.startVal);
|
|
895 }
|
|
896
|
|
897 Slider.prototype.setValue = function(newVal) {
|
|
898 // sets slider to new value and updates
|
|
899 this.value = newVal;
|
440
|
900 this.update();
|
|
901 }
|
|
902
|
|
903 Slider.prototype.calcValue = function() {
|
|
904 // calculates value from slider position
|
|
905 var xSlider = this.sliderRect.getCenter().x - this.xMin;
|
|
906 this.value = xSlider * this.valDiff / this.xDiff;
|
|
907 return this.value;
|
438
|
908 }
|
|
909
|
|
910 Slider.prototype.update = function() {
|
|
911 // updates slider position to new value
|
440
|
912 var xSlider = this.value * this.xDiff / this.valDiff;
|
|
913 moveElement(this.slider, this.sliderRect.setCenter(
|
|
914 new Position(xSlider + this.xMin, this.Y)));
|
|
915 var strVal = this.value.toString();
|
|
916 if (this.valueLabel) this.valueLabel.innerHTML = strVal;
|
|
917 if (this.input) this.input.value = strVal;
|
438
|
918 }
|
|
919
|
|
920 Slider.prototype.setupEvents = function() {
|
|
921 // installs all event callbacks
|
|
922 registerEvent("mousedown", this.slider, this.onDragStart);
|
|
923 }
|
|
924
|
|
925 Slider.prototype.onDragStart = function(evt) {
|
440
|
926 var slider = sliders[this.id];
|
|
927 activeSlider = slider;
|
|
928 unregisterEvent("mousedown", slider.slider, slider.onDragStart);
|
|
929 registerEvent("mousemove", document, slider.onDrag);
|
|
930 registerEvent("mouseup", document, slider.onDragEnd);
|
|
931 slider.startPos = evtPosition(evt);
|
|
932 slider.startX = slider.sliderRect.getCenter().x;
|
438
|
933 return stopEvent(evt);
|
|
934 }
|
|
935
|
|
936 Slider.prototype.onDrag = function(evt) {
|
440
|
937 var slider = activeSlider;
|
438
|
938 var pos = evtPosition(evt);
|
440
|
939 var currX = slider.slider
|
|
940 var newX = pos.x - slider.startPos + slider.startX;
|
|
941 if (newX < slider.xMin) newX = slider.xMin;
|
|
942 if (newX > slider.xMax) newX = slider.xMax;
|
|
943 moveElement(slider.slider, slider.sliderRect.setCenter(
|
|
944 new Position(newX, slider.Y)));
|
438
|
945 return stopEvent(evt);
|
|
946 }
|
|
947
|
|
948 Slider.prototype.onDragEnd = function(evt) {
|
440
|
949 var slider = activeSlider;
|
|
950 unregisterEvent("mousemove", document, slider.onDrag);
|
|
951 unregisterEvent("mouseup", document, slider.onDragEnd);
|
|
952 slider.onChange(slider.calcValue());
|
|
953 activeSlider = null;
|
438
|
954 return stopEvent(evt);
|
|
955 }
|
|
956
|
|
957 Slider.prototype.onInputChange = function() {
|
440
|
958 var slider = activeSlider;
|
|
959 slider.onChange(s.value);
|
438
|
960 }
|
|
961
|
440
|
962 // :tabSize=4:indentSize=4:noTabs=true:
|
|
963
|