Diff for /zogiLib/js/baselib.js between versions 1.4 and 1.14

version 1.4, 2004/11/03 15:24:46 version 1.14, 2011/02/14 16:33:43
Line 17  Foundation, Inc., 59 Temple Place - Suit Line 17  Foundation, Inc., 59 Temple Place - Suit
 Authors:   Authors: 
   Christian Luginbuehl, 01.05.2003 (first version)    Christian Luginbuehl, 01.05.2003 (first version)
   DW 24.03.2004 (Changed for digiLib in Zope)    DW 24.03.2004 (Changed for digiLib in Zope)
   Robert Casties, 2.11.2004    Robert Casties, 22.1.2008
   
 */  */
   
 function base_init() {  function base_init() {
     // init function      // init function
     baseScriptVersion = "1.1b";      baseScriptVersion = "1.2.5";
     dlParams = new Object();      dlParams = new Object();
     browserType = getBrowserType();      browserType = getBrowserType();
 }  }
Line 31  function base_init() { Line 31  function base_init() {
   
 function getInt(n) {  function getInt(n) {
     // returns always an integer      // returns always an integer
     n = parseInt(n);      var n = parseInt(n);
     if (isNaN(n)) return 0;      if (isNaN(n)) return 0;
     return n;      return n;
 }  }
Line 48  function cropFloat(x) { Line 48  function cropFloat(x) {
   
 function getBrowserType() {  function getBrowserType() {
     // browser sniffer      // browser sniffer
     var bt = Object();      var bt = {
     bt.doDHTML = false;              doDHTML: false,
     bt.versIE = 0;              versIE: 0
       };
   
     if ((! document.cssonly && document.layers) || document.all || document.getElementById) {      if ((! document.cssonly && document.layers) || document.all || document.getElementById) {
     var vers = navigator.appVersion.split('MSIE ');      var vers = navigator.appVersion.split('MSIE ');
Line 70  function getBrowserType() { Line 71  function getBrowserType() {
     return bt;      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   *     geometry classes
Line 96  function Size(w, h) { Line 84  function Size(w, h) {
     this.height = parseFloat(h);      this.height = parseFloat(h);
     return this;      return this;
 }  }
   Size.prototype.copy = function() {
       // returns a copy of this Rectangle
       return new Size(this.width, this.height);
   }
 Size.prototype.toString = function() {  Size.prototype.toString = function() {
     return this.width + "x" + this.height;      return this.width + "x" + this.height;
 }  }
Line 109  function Position(x, y) { Line 101  function Position(x, y) {
     this.y = parseFloat(y);      this.y = parseFloat(y);
     return this;      return this;
 }  }
   Position.prototype.copy = function() {
       // returns a copy of this Rectangle
       return new Rectangle(this.x, this.y);
   }
 Position.prototype.toString = function() {  Position.prototype.toString = function() {
     return this.x + "," + this.y;      return this.x + "," + this.y;
 }  }
Line 289  function getParameter(name) { Line 285  function getParameter(name) {
     }      }
 }  }
   
 function setParameter(name, value) {  function setParameter(name, value, relative) {
     // sets parameter value      // sets parameter value (relative values with +/- unless literal)
     if (defined(dlParams[name])) {      if (defined(dlParams[name])) {
           if ((relative)&&(value.slice)) {
               var sign = value.slice(0,1);
               if (sign == '+') {
                   dlParams[name].value = parseFloat(dlParams[name].value) + parseFloat(value.slice(1));
               } else if (sign == '-') {
                   dlParams[name].value = parseFloat(dlParams[name].value) - parseFloat(value.slice(1));
               } else {
                   dlParams[name].value = value;
               }
           } else {
     dlParams[name].value = value;      dlParams[name].value = value;
           }
     dlParams[name].hasValue = true;      dlParams[name].hasValue = true;
     return true;      return true;
     }      }
Line 308  function hasParameter(name) { Line 315  function hasParameter(name) {
 }  }
   
 function getAllParameters(detail) {  function getAllParameters(detail) {
     // returns a string of all parameters in query format      // returns a string of all (set) parameters in query format
     if (! detail) {      if (! detail) {
     detail = 10;          detail = 255;
     }      }
     var params = new Array();      var params = new Array();
     for ( param in dlParams ) {      for (var p in dlParams) {
     if ((dlParams[param].detail <= detail)&&(dlParams[param].hasValue)) {          var param = dlParams[p];
         var val = getParameter(param);          if (((param.detail & detail) > 0)&&(param.hasValue)) {
               var val = param.value;
         if (val != "") {          if (val != "") {
         params.push(param + "=" + val);                  params.push(p + "=" + val);
         }          }
     }      }
     }      }
     return params.join("&");      return params.join("&");
 }  }
   
 function parseParameters(query) {  function parseParameters(query,newParamDetail) {
     // gets parameter values from query format string      // gets parameter values from query format string
     var params = query.split("&");      var params = query.split("&");
     for (var i = 0; i < params.length; i++) {      for (var i = 0; i < params.length; i++) {
     var keyval = params[i].split("=");      var keyval = params[i].split("=");
     if (keyval.length == 2) {      if (keyval.length == 2) {
               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]);          setParameter(keyval[0], keyval[1]);
     }      }
     }      }
 }  }
   }
   
   
 /* **********************************************  /* **********************************************
Line 365  function getElementPosition(elem) { Line 378  function getElementPosition(elem) {
     // returns a Position with the position of the element      // returns a Position with the position of the element
     var x = 0;      var x = 0;
     var y = 0;      var y = 0;
     if (defined(elem.offsetLeft)) {      if (defined(elem.offsetParent)) {
           // use .offsetLeft for most browsers
     var e = elem;      var e = elem;
     while (e) {      while (e) {
         if (defined(e.clientLeft)) {              if (browserType.isIE) {
         // special for IE  
         if (browserType.isMac) {          if (browserType.isMac) {
             if (e.offsetParent.tagName == "BODY") {  
             // IE for Mac extraspecial              // IE for Mac extraspecial
                       if (e.offsetParent.tagName == "BODY") {
             x += e.clientLeft;              x += e.clientLeft;
             y += e.clientTop;              y += e.clientTop;
             break;              break;
             }              }
         } else {          } else {
                       // special for IE
             if ((e.tagName != "TABLE") && (e.tagName != "BODY")) {              if ((e.tagName != "TABLE") && (e.tagName != "BODY")) {
             x += e.clientLeft;              x += e.clientLeft;
             y += e.clientTop;              y += e.clientTop;
Line 389  function getElementPosition(elem) { Line 403  function getElementPosition(elem) {
         e = e.offsetParent;          e = e.offsetParent;
     }      }
     } else if (defined(elem.x)) {      } else if (defined(elem.x)) {
           // use .x for other (which?)
     x = elem.x;      x = elem.x;
     y = elem.y;      y = elem.y;
     } else if (defined(elem.pageX)) {      } else if (defined(elem.pageX)) {
           // use pageX for N4
     x = elem.pageX;      x = elem.pageX;
     y = elem.pageY;      y = elem.pageY;
     } else {      } else {
Line 426  function getElementRect(elem) { Line 442  function getElementRect(elem) {
     return new Rectangle(pos.x, pos.y, size.width, size.height);      return new Rectangle(pos.x, pos.y, size.width, size.height);
 }  }
   
   
   
 function moveElement(elem, rect) {  function moveElement(elem, rect) {
     // moves and sizes the element      // moves and sizes the element
     if (elem.style) {      if (elem.style) {
Line 475  function showElement(elem, show) { Line 489  function showElement(elem, show) {
     return true;      return true;
 }  }
   
   function isElementVisible(elem) {
       // returns of the is shown or hidden
       if (elem.style) {
           return (elem.style.visibility == "visible");
       } else if (defined(elem.visibility)) {
           return (elem.visibility == "show");
       } else {
           alert("iselementvisible: no style nor layer property!");
       }
   }
   
 function evtPosition(evt) {  function evtPosition(evt) {
     // returns the on-screen Position of the Event       // returns the on-screen Position of the Event 
     var x;      var x;
Line 584  function registerKeyDown(handler) { Line 609  function registerKeyDown(handler) {
 function getWinSize() {  function getWinSize() {
     // returns a Size with the current window size (mostly from www.quirksmode.org)      // returns a Size with the current window size (mostly from www.quirksmode.org)
     var wsize = new Size(100, 100);      var wsize = new Size(100, 100);
     if (defined(self.innerHeight))  {      if (!browserType.isIE)  {
     // all except Explorer      // all except Explorer
     if ((self.innerWidth == 0)||(self.innerHeight == 0)) {      if ((self.innerWidth == 0)||(self.innerHeight == 0)) {
         // Safari 1.2 bug              // Safari 1.2 (and other) bug
         if (parent) {          if (parent) {
         parent.innerHeight;                  wsize.height = parent.innerHeight;
         parent.innerWidth;                  wsize.width = parent.innerWidth;
         }  
     }      }
           } else {
     wsize.width = self.innerWidth;      wsize.width = self.innerWidth;
     wsize.height = self.innerHeight;      wsize.height = self.innerHeight;
           }
     } else if (document.documentElement && document.documentElement.clientHeight) {      } else if (document.documentElement && document.documentElement.clientHeight) {
     // Explorer 6 Strict Mode      // Explorer 6 Strict Mode
     wsize.width = document.documentElement.clientWidth;      wsize.width = document.documentElement.clientWidth;

Removed from v.1.4  
changed lines
  Added in v.1.14


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>