--- zogiLib/js/baselib.js 2007/09/11 15:40:30 1.8 +++ zogiLib/js/baselib.js 2011/02/14 16:33:43 1.14 @@ -17,13 +17,13 @@ Foundation, Inc., 59 Temple Place - Suit Authors: Christian Luginbuehl, 01.05.2003 (first version) DW 24.03.2004 (Changed for digiLib in Zope) - Robert Casties, 11.9.2007 + Robert Casties, 22.1.2008 */ function base_init() { // init function - baseScriptVersion = "1.2.2"; + baseScriptVersion = "1.2.5"; dlParams = new Object(); browserType = getBrowserType(); } @@ -31,7 +31,7 @@ function base_init() { function getInt(n) { // returns always an integer - n = parseInt(n); + var n = parseInt(n); if (isNaN(n)) return 0; return n; } @@ -48,9 +48,10 @@ function cropFloat(x) { function getBrowserType() { // browser sniffer - var bt = Object(); - bt.doDHTML = false; - bt.versIE = 0; + var bt = { + doDHTML: false, + versIE: 0 + }; if ((! document.cssonly && document.layers) || document.all || document.getElementById) { var vers = navigator.appVersion.split('MSIE '); @@ -70,19 +71,6 @@ function getBrowserType() { return bt; } -// fixes for javascript < 1.2 -if (! Array.prototype.push) { - Array.prototype.push = function(val) { - this[this.length] = val; - return this.length; - } - Array.prototype.pop = function() { - var val = this[this.length-1]; - this.length -= 1; - return val; - } -} - /* ********************************************** * geometry classes @@ -96,6 +84,10 @@ function Size(w, h) { this.height = parseFloat(h); return this; } +Size.prototype.copy = function() { + // returns a copy of this Rectangle + return new Size(this.width, this.height); +} Size.prototype.toString = function() { return this.width + "x" + this.height; } @@ -109,6 +101,10 @@ function Position(x, y) { this.y = parseFloat(y); return this; } +Position.prototype.copy = function() { + // returns a copy of this Rectangle + return new Rectangle(this.x, this.y); +} Position.prototype.toString = function() { return this.x + "," + this.y; } @@ -319,29 +315,35 @@ function hasParameter(name) { } function getAllParameters(detail) { - // returns a string of all parameters in query format + // returns a string of all (set) parameters in query format if (! detail) { detail = 255; } var params = new Array(); - for (param in dlParams) { - if (((dlParams[param].detail & detail) > 0)&&(dlParams[param].hasValue)) { - var val = getParameter(param); + for (var p in dlParams) { + var param = dlParams[p]; + if (((param.detail & detail) > 0)&&(param.hasValue)) { + var val = param.value; if (val != "") { - params.push(param + "=" + val); + params.push(p + "=" + val); } } } return params.join("&"); } -function parseParameters(query) { +function parseParameters(query,newParamDetail) { // gets parameter values from query format string var params = query.split("&"); for (var i = 0; i < params.length; i++) { var keyval = params[i].split("="); if (keyval.length == 2) { - setParameter(keyval[0], keyval[1]); + var ex = setParameter(keyval[0], keyval[1]); + if ((!ex) && newParamDetail) { + // setParameter returned false = parameter doesn't exist -- add it + newParameter(keyval[0], null, newParamDetail); + setParameter(keyval[0], keyval[1]); + } } } } @@ -376,7 +378,7 @@ function getElementPosition(elem) { // returns a Position with the position of the element var x = 0; var y = 0; - if (elem.offsetParent) { + if (defined(elem.offsetParent)) { // use .offsetLeft for most browsers var e = elem; while (e) { @@ -607,17 +609,18 @@ function registerKeyDown(handler) { function getWinSize() { // returns a Size with the current window size (mostly from www.quirksmode.org) var wsize = new Size(100, 100); - if (defined(self.innerHeight)) { + if (!browserType.isIE) { // all except Explorer if ((self.innerWidth == 0)||(self.innerHeight == 0)) { - // Safari 1.2 bug + // Safari 1.2 (and other) bug if (parent) { - parent.innerHeight; - parent.innerWidth; + wsize.height = parent.innerHeight; + wsize.width = parent.innerWidth; } + } else { + wsize.width = self.innerWidth; + wsize.height = self.innerHeight; } - wsize.width = self.innerWidth; - wsize.height = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode wsize.width = document.documentElement.clientWidth;