[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/js/jsapi/ -> jsapi.js (source)

   1    /***************************************************************************\
   2    * eGroupWare - JavaScript API                                               *
   3    * http://www.egroupware.org                                                 *
   4    * Written by:                                                               *
   5    *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
   6    *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
   7    *  - Vinicus Cubas Brand <viniciuscb@users.sourceforge.net>                 *
   8    *  sponsored by Thyamad - http://www.thyamad.com                            *
   9    * ------------------------------------------------------------------------- *
  10    *  This program is free software; you can redistribute it and/or modify it  *
  11    *  under the terms of the GNU Lesser General Public License as published by *
  12    *  the Free Software Foundation; either version 2 of the License, or (at    *
  13    *  your option) any later version.                                          *
  14    \***************************************************************************/
  15  
  16  /***********************************************\
  17  *               INITIALIZATION                  *
  18  \***********************************************/
  19  if (document.all)
  20  {
  21      navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
  22      is_ie = true;
  23      is_moz1_6 = false;
  24      is_mozilla = false;
  25      is_ns4 = false;
  26  }
  27  else if (document.getElementById)
  28  {
  29      navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false;
  30      is_ie = false;
  31      is_ie5 = false;
  32      is_mozilla = true;
  33      is_ns4 = false;
  34  }
  35  else if (document.layers)
  36  {
  37      is_ie = false;
  38      is_ie5 = false
  39      is_moz1_6 = false;
  40      is_mozilla = false;
  41      is_ns4 = true;
  42  }
  43  
  44  // DO NOT CHANGE THIS!!! Enable DEBUG inside Application!
  45  var DEBUG = false;
  46  
  47  /***********************************************\
  48   *                DATA FUNCTIONS               *
  49  \***********************************************/
  50  
  51  function serialize(data)
  52  {
  53      var f = function(data)
  54      {
  55          var str_data;
  56  
  57          if (data == null || 
  58              (typeof(data) == 'string' && data == ''))
  59          {
  60              str_data = 'N;';
  61          }
  62  
  63          else switch(typeof(data))
  64          {
  65              case 'object':
  66                  var arrayCount = 0;
  67  
  68                  str_data = '';
  69  
  70                  for (i in data)
  71                  {
  72                      if (i == 'length')
  73                      {
  74                          continue;
  75                      }
  76                      
  77                      arrayCount++;
  78                      switch (typeof(i))
  79                      {
  80                          case 'number':
  81                              str_data += 'i:' + i + ';' + serialize(data[i]);
  82                              break;
  83  
  84                          case 'string':
  85                              str_data += 's:' + i.length + ':"' + i + '";' + serialize(data[i]);
  86                              break;
  87  
  88                          default:
  89                              showMessage(Element('cc_msg_err_serialize_data_unknown').value);
  90                              break;
  91                      }
  92                  }
  93  
  94                  if (!arrayCount)
  95                  {
  96                      str_data = 'N;';    
  97                  }
  98                  else
  99                  {
 100                      str_data = 'a:' + arrayCount + ':{' + str_data + '}';
 101                  }
 102                  
 103                  break;
 104          
 105              case 'string':
 106                  str_data = 's:' + data.length + ':"' + data + '";';
 107                  break;
 108                  
 109              case 'number':
 110                  str_data = 'i:' + data + ';';
 111                  break;
 112  
 113              case 'boolean':
 114                  str_data = 'b:' + (data ? '1' : '0') + ';';
 115                  break;
 116  
 117              default:
 118                  showMessage(Element('cc_msg_err_serialize_data_unknown').value);
 119                  return null;
 120          }
 121  
 122          return str_data;
 123      }
 124  
 125      var sdata = f(data);
 126      return sdata;
 127  }
 128  
 129  function unserialize(str)
 130  {
 131      var f = function (str)
 132      {
 133          switch (str.charAt(0))
 134          {
 135              case 'a':
 136                  
 137                  var data = new Array();
 138                  var n = parseInt( str.substring( str.indexOf(':')+1, str.indexOf(':',2) ) );
 139                  var arrayContent = str.substring(str.indexOf('{')+1, str.lastIndexOf('}'));
 140              
 141                  for (var i = 0; i < n; i++)
 142                  {
 143                      var pos = 0;
 144  
 145                      /* Process Index */
 146                      var indexStr = arrayContent.substr(pos, arrayContent.indexOf(';')+1);
 147                      var index = unserialize(indexStr);
 148                      pos = arrayContent.indexOf(';', pos)+1;
 149                      
 150                      /* Process Content */
 151                      var part = null;
 152                      switch (arrayContent.charAt(pos))
 153                      {
 154                          case 'a':
 155                              var pos_ = matchBracket(arrayContent, arrayContent.indexOf('{', pos))+1;
 156                              part = arrayContent.substring(pos, pos_);
 157                              pos = pos_;
 158                              data[index] = unserialize(part);
 159                              break;
 160                      
 161                          case 's':
 162                              var pval = arrayContent.indexOf(':', pos+2);
 163                              var val  = parseInt(arrayContent.substring(pos+2, pval));
 164                              pos = pval + val + 4;
 165                              data[index] = arrayContent.substr(pval+2, val);
 166                              break;
 167  
 168                          default:
 169                              part = arrayContent.substring(pos, arrayContent.indexOf(';', pos)+1);
 170                              pos = arrayContent.indexOf(';', pos)+1;
 171                              data[index] = unserialize(part);
 172                              break;
 173                      }
 174                      arrayContent = arrayContent.substr(pos);
 175                  }
 176                  break;
 177                  
 178              case 's':
 179                  var pos = str.indexOf(':', 2);
 180                  var val = parseInt(str.substring(2,pos));
 181                  var data = str.substr(pos+2, val);
 182                  str = str.substr(pos + 4 + val);
 183                  break;
 184  
 185              case 'i':
 186              case 'd':
 187                  var pos = str.indexOf(';');
 188                  var data = parseInt(str.substring(2,pos));
 189                  str = str.substr(pos + 1);
 190                  break;
 191              
 192              case 'N':
 193                  var data = null;
 194                  str = str.substr(str.indexOf(';') + 1);
 195                  break;
 196  
 197              case 'b':
 198                  var data = str.charAt(2) == '1' ? true : false;
 199                  break;
 200          }
 201          
 202          return data;
 203      }
 204  
 205      return f(str);
 206  }
 207  
 208  function matchBracket(strG, iniPosG)
 209  {
 210      var f = function (str, iniPos)
 211      {
 212          var nOpen, nClose = iniPos;
 213          
 214          do 
 215          {
 216              nOpen = str.indexOf('{', nClose+1);
 217              nClose = str.indexOf('}', nClose+1);
 218  
 219              if (nOpen == -1)
 220              {
 221                  return nClose;
 222              }
 223              
 224              if (nOpen < nClose )
 225              {
 226                  nClose = matchBracket(str, nOpen);
 227              }
 228              
 229          } while (nOpen < nClose);
 230  
 231          return nClose;
 232      }
 233  
 234      return f(strG, iniPosG);
 235  }
 236  
 237  /***********************************************\
 238  *                 DATE FUNCTIONS                *
 239  \***********************************************/
 240  
 241      /**
 242      * Converts a date string into an object second to a php date() date format.
 243      *
 244      * The result object have three indexes: day, month and year; (now currently
 245      * only accepts d , m , and Y in any position and with any separator in the
 246      * (input) date description string).
 247      *
 248      * @author Vinicius Cubas Brand <vinicius@users.sourceforge.net>
 249      *
 250      * @param string dateString  The date string in a format described in
 251      *   phpDateFormat, like for instance '2005/02/09'
 252      * @param string phpDateFormat  The date descriptor in a php date() format,
 253      *   like for instance 'Y/m/d'
 254      * 
 255      * @todo Other types handling
 256      */
 257  	function strtodate(dateString,phpDateFormat)
 258      {
 259          var _this = this;
 260          var elements = new Object;
 261          this.tmpelm = elements;
 262          elements['d'] = { leng: 2, pos:-1};
 263          elements['m'] = { leng: 2, pos:-1};
 264          elements['Y'] = { leng: 4, pos:-1};
 265      
 266  
 267          //array to populate - sort order
 268          var indexes = new Array();
 269  
 270          for (var i in elements)
 271          {
 272              elements[i]['pos'] = phpDateFormat.indexOf(i);
 273  
 274              indexes.push(i);
 275          }
 276  
 277  		function sortingFunction(a,b) {
 278              return _this.tmpelm[a]['pos'] - _this.tmpelm[b]['pos'];
 279          };
 280          
 281          indexes.sort(sortingFunction);
 282  
 283          var offset = 0;
 284          for (var i in indexes)
 285          {
 286              var curr_index = indexes[i];
 287              elements[curr_index]['start_pos'] = elements[curr_index]['pos'] + offset;
 288              offset += elements[curr_index]['leng'] - 1;
 289          }
 290  
 291          for (var i in elements)
 292          {
 293              switch (i)
 294              {
 295                  case 'd':
 296                      var day = parseInt(dateString.slice(elements[i]['start_pos'],elements[i]['start_pos']+elements[i]['leng']));
 297                      break;
 298                  case 'm':
 299                      var month = parseInt(dateString.slice(elements[i]['start_pos'],elements[i]['start_pos']+elements[i]['leng']));
 300                      break;
 301                  case 'Y':
 302                      var year = parseInt(dateString.slice(elements[i]['start_pos'],elements[i]['start_pos']+elements[i]['leng']));
 303                      break;
 304              }
 305          }
 306          var ret = new Object();
 307          ret['year'] = year;
 308          ret['month'] = month - 1;
 309          ret['day'] = day;
 310          return ret;
 311      }
 312  
 313  
 314  /***********************************************\
 315  *               AUXILIAR FUNCTIONS              *
 316  \***********************************************/
 317  
 318  /* 
 319      function js2xmlrpc
 320      @param methodName  the name of the method, for instance appointmentcenter.uixmlresponder.test
 321      @param args        all args in sequence, passed to the xml-rpc method
 322      @return            xml-rpc string corresponding to js objects passed in args
 323  */
 324  function js2xmlrpc(methodName)
 325  {
 326      var msg = new XMLRPCMessage(methodName);
 327      for (var i = 1; i< arguments.length; i++)
 328      {
 329          if (i==1 && GLOBALS['extra_get_vars'] && typeof(arguments[i]) == 'object' 
 330              && typeof(GLOBALS['extra_get_vars']) == 'object')
 331          {
 332              arguments[i]['extra_get_vars'] = GLOBALS['extra_get_vars'];
 333          }
 334          msg.addParameter(arguments[i]);
 335      }
 336      return msg.xml();
 337  }
 338  
 339  
 340  /* 
 341      function xmlrpc2js
 342      @param responseText  The xml-rpc text of return of a xml-rpc function call
 343      @return                 Javascript object corresponding to the given xmlrpc 
 344  */
 345  
 346  var xmlrpcHandler = null;
 347  function xmlrpc2js(responseText)
 348  {
 349      if (!xmlrpcHandler || typeof(xmlrpcHandler) != 'object')
 350      {
 351          xmlrpcHandler = importModule("xmlrpc");
 352      }
 353      return xmlrpcHandler.unmarshall(responseText);
 354  }
 355  
 356  function resizeIcon(id, action)
 357  {
 358      var element = Element(id);
 359      
 360      if (action == 0)
 361      {
 362          CC_old_icon_w = element.style.width;
 363          CC_old_icon_h = element.style.height;
 364  
 365          element.style.zIndex = parseInt(element.style.zIndex) + 1;
 366          element.style.width = '36px';
 367          element.style.height = '36px';
 368          element.style.top = (parseInt(element.style.top) - parseInt(element.style.height)/2) + 'px';
 369          element.style.left = (parseInt(element.style.left) - parseInt(element.style.width)/2) + 'px';
 370      }
 371      else if (action == 1)
 372      {
 373          element.style.zIndex = parseInt(element.style.zIndex) - 1;
 374          element.style.top = (parseInt(element.style.top) + parseInt(element.style.height)/2) + 'px';
 375          element.style.left = (parseInt(element.style.left) + parseInt(element.style.width)/2) + 'px';
 376          element.style.width = CC_old_icon_w;
 377          element.style.height = CC_old_icon_h;
 378      }
 379  }
 380  
 381  function Element (element)
 382  {
 383      /* IE OBJECTS */
 384      if (document.all)
 385      {
 386          return document.all[element];
 387      }
 388      /* MOZILLA OBJECTS */
 389      else if (document.getElementById)
 390      {
 391          return document.getElementById(element);
 392      }
 393      /* NS4 OBJECTS */
 394      else if (document.layers)
 395      {
 396          return document.layers[element];
 397      }
 398  }
 399  
 400  function removeHTMLCode(id)
 401  {
 402      Element(id).parentNode.removeChild(Element(id));
 403  }
 404  
 405  function addHTMLCode(parent_id,child_id,child_code,surround_block_tag)
 406  {
 407      var obj = document.createElement(surround_block_tag);
 408      Element(parent_id).appendChild(obj);
 409      obj.id = child_id;
 410      obj.innerHTML = child_code;
 411      return obj;
 412  }
 413  
 414  function adjustString (str, max_chars)
 415  {
 416      if (str.length > max_chars)
 417      {
 418          return str.substr(0,max_chars) + '...';
 419      }
 420      else
 421      {
 422          return str;
 423      }
 424  }
 425  
 426  function addSlashes(code)
 427  {
 428      for (var i = 0; i < code.length; i++)
 429      {
 430          switch(code.charAt(i))
 431          {
 432              case "'":
 433              case '"':
 434              case "\\":
 435                  code = code.substr(0, i) + "\\" + code.charAt(i) + code.substr(i+1);
 436                  i++;
 437                  break;
 438          }
 439      }
 440  
 441      return code;
 442  }
 443  
 444  function htmlSpecialChars(str)
 445  {
 446      // TODO: Not implemented!!!
 447      var pos = 0;
 448      
 449      for (var i = 0; i < str.length; i++)
 450      {
 451          
 452      }
 453  }
 454  
 455  function replaceComAnd(str, replacer)
 456  {
 457      var oldPos = 0;
 458      var pos = 0;
 459      
 460      while ((pos = str.indexOf('&', pos)) != -1)
 461      {
 462          str = str.substring(oldPos, pos) + replacer + str.substring(pos+1);
 463      }
 464  
 465      return str;
 466  }
 467  
 468  function Timeout(control, code, maxCalls, actualCall, singleTimeout)
 469  {
 470      if (control())
 471      {
 472          if (typeof(code) == 'function')
 473          {
 474              code();
 475          }
 476          else
 477          {
 478              eval(code);
 479          }
 480          
 481          return true;
 482      }
 483  
 484      if (!actualCall)
 485      {
 486          actualCall = 1;
 487      }
 488  
 489      if (!maxCalls)
 490      {
 491          maxCalls = 100;
 492      }
 493  
 494      if (actualCall == maxCalls)
 495      {
 496          showMessage(Element('cc_msg_err_timeout').value);
 497          return false;
 498      }
 499  
 500      if (!singleTimeout)
 501      {
 502          singleTimeout = 100;
 503      }
 504  
 505      setTimeout(function(){Timeout(control,code,maxCalls,actualCall+1,singleTimeout);}, singleTimeout);
 506  }
 507  
 508  function showMessage(msg, type)
 509  {
 510      // TODO: Replace alert with 'loading' style div with Ok button
 511  
 512      switch(type)
 513      {
 514          case 'confirm':
 515              return confirm(msg);
 516  
 517          default:
 518              alert(msg);
 519              return;
 520      }
 521  }
 522  
 523  // works only correctly in Mozilla/FF and Konqueror
 524  function egw_openWindowCentered2(_url, _windowName, _width, _height, _status)
 525  {
 526      windowWidth = egw_getWindowOuterWidth();
 527      windowHeight = egw_getWindowOuterHeight();
 528  
 529      positionLeft = (windowWidth/2)-(_width/2)+egw_getWindowLeft();
 530      positionTop  = (windowHeight/2)-(_height/2)+egw_getWindowTop();
 531  
 532      windowID = window.open(_url, _windowName, "width=" + _width + ",height=" + _height + 
 533          ",screenX=" + positionLeft + ",left=" + positionLeft + ",screenY=" + positionTop + ",top=" + positionTop +
 534          ",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status="+_status);
 535      
 536      return windowID;
 537  }
 538  function egw_openWindowCentered(_url, _windowName, _width, _height)
 539  {
 540      return egw_openWindowCentered2(_url, _windowName, _width, _height, 'no');
 541  }
 542  
 543  // return the left position of the window
 544  function egw_getWindowLeft()
 545  {
 546      if(is_mozilla)
 547      {
 548          return window.screenX;
 549      }
 550      else
 551      {
 552          return window.screenLeft;
 553      }
 554  }
 555  
 556  // return the left position of the window
 557  function egw_getWindowTop()
 558  {
 559      if(is_mozilla)
 560      {
 561          return window.screenY;
 562      }
 563      else
 564      {
 565          //alert(window.screenTop);
 566          return window.screenTop-90;
 567      }
 568  }
 569  
 570  // get the outerWidth of the browser window. For IE we simply return the innerWidth
 571  function egw_getWindowInnerWidth()
 572  {
 573      if (is_mozilla)
 574      {
 575          return window.innerWidth;
 576      }
 577      else
 578      {
 579          // works only after the body has parsed
 580          //return document.body.offsetWidth;
 581          return document.body.clientWidth;
 582          //return document.documentElement.clientWidth;
 583      }
 584  }
 585  
 586  // get the outerHeight of the browser window. For IE we simply return the innerHeight
 587  function egw_getWindowInnerHeight()
 588  {
 589      if (is_mozilla)
 590      {
 591          return window.innerHeight;
 592      }
 593      else
 594      {
 595          // works only after the body has parsed
 596          //return document.body.offsetHeight;
 597          //return document.body.clientHeight;
 598          return document.documentElement.clientHeight;
 599      }
 600  }
 601  
 602  // get the outerWidth of the browser window. For IE we simply return the innerWidth
 603  function egw_getWindowOuterWidth()
 604  {
 605      if (is_mozilla)
 606      {
 607          return window.outerWidth;
 608      }
 609      else
 610      {
 611          return egw_getWindowInnerWidth();
 612      }
 613  }
 614  
 615  // get the outerHeight of the browser window. For IE we simply return the innerHeight
 616  function egw_getWindowOuterHeight()
 617  {
 618      if (is_mozilla)
 619      {
 620          return window.outerHeight;
 621      }
 622      else
 623      {
 624          return egw_getWindowInnerHeight();
 625      }
 626  }
 627  
 628  /***********************************************\
 629  *      HTML ELEMENTS AUXILIAR FUNCTIONS         *
 630  \***********************************************/
 631  
 632  //-------------------SELECT-------------------------
 633  
 634  /* Copy the selected values from one select box to another */
 635  function copyFromSelects(origSelectObj,destSelectObj)
 636  {
 637      var selectBox1 = origSelectObj;
 638      var selectBox2 = destSelectObj;
 639      var exists;
 640      
 641      if (selectBox1 == null || selectBox2 == null)
 642      {
 643          return false;
 644      }
 645      
 646      var max1 = selectBox1.options.length;
 647      var max2 = selectBox2.options.length;    
 648      
 649      for (var i=0 ; i < max1 ; i++)
 650      {
 651          if (selectBox1.options[i].selected)
 652          {
 653              exists = false;
 654              for (var j=0 ; j < max2 ; j++)
 655              {
 656                  if (selectBox1.options[i].value == selectBox2.options[j].value)
 657                  {
 658                      exists = true;
 659                  }
 660              }
 661  
 662              if (exists == false)
 663              {
 664                  selectBox2.options[selectBox2.length] = new Option(selectBox1.options[i].text,selectBox1.options[i].value);
 665                  selectBox1.options[i].selected = false;
 666              }
 667          }
 668      }
 669  }
 670  
 671  function removeSelectedOptions(selectId)
 672  {
 673      var selectBox1 = Element(selectId);
 674      
 675      if (selectBox1 == null)
 676      {
 677          return false;    
 678      }
 679      
 680      for (var i=0; i < selectBox1.options.length; )
 681      {
 682          if (selectBox1.options[i].selected)
 683          {
 684              selectBox1.removeChild(selectBox1.options[i]);    
 685          }
 686          else
 687          {
 688              i++;    
 689          }
 690      }
 691      
 692  }
 693  
 694  function clearSelectBox(obj, startIndex)
 695  {
 696      var nOptions = obj.options.length;
 697  
 698      for (var i = nOptions - 1; i >= startIndex; i--)
 699      {
 700          obj.removeChild(obj.options[i]);
 701      }
 702  }
 703  
 704  function fillSelectBox(obj,data)
 705  {
 706  
 707      if (typeof(data) != 'object')
 708      {
 709          return false;
 710      }
 711      
 712      var i;
 713          
 714      //include new options
 715      for (i in data)
 716      {
 717          if (typeof(data[i]) == 'function')
 718          {
 719              continue;
 720          }
 721  
 722          obj.options[obj.length] = new Option(data[i],i);
 723      }
 724  }
 725  
 726  //use for select-multiple. The values of opts will be selected.
 727  function selectOptions (obj,opts)
 728  {
 729      if (obj == false || obj.options == false)
 730      {
 731          throw('selectOptions: invalid object given as param');
 732          return false;    
 733      }
 734      if (opts == undefined || opts == null) //clean everything
 735      {
 736          var objtam  = obj.options.length;
 737          for (var i=0; i < objtam; i++)
 738          {
 739              obj.options[i].selected = false;    
 740          }
 741      }
 742      else
 743      {        
 744          if (typeof(opts) != 'object')
 745          {
 746              //throw('selectOptions: opts must be an element of type Array or Object');
 747              return false;
 748          }
 749  
 750          var objtam  = obj.options.length;
 751          var optstam = opts.length;
 752  
 753          for (var i=0; i < objtam; i++)
 754          {
 755              obj.options[i].selected = false;
 756              for (var j in opts)
 757              {
 758                  if (obj.options[i].value == opts[j])
 759                  {
 760                      obj.options[i].selected = true;
 761                  }
 762              }
 763          }
 764      }
 765  
 766  }
 767  
 768  //return selected options of a select in an array
 769  function getSelectedOptions(obj)
 770  {
 771      if (obj == null)
 772      {
 773          throw('getSelectedOptions: invalid object');
 774          return new Array();
 775      }
 776      
 777      var max = obj.options.length;
 778      var response = new Array();
 779      
 780      for (var i=0; i< max; i++)
 781      {
 782          if (obj.options[i].selected)
 783          {
 784              response.push(obj.options[i].value);    
 785          }
 786      }
 787      return response;
 788  }
 789  
 790  //return selected values of a select in an array
 791  function getSelectedValues(obj)
 792  {
 793      if (obj == null || typeof(obj) != 'object')
 794      {
 795          return new Object();
 796      }
 797  
 798      var max = obj.options.length;
 799      var response = new Object();
 800      
 801      for (var i=0; i< max; i++)
 802      {
 803          if (obj.options[i].selected)
 804          {
 805              response[obj.options[i].value] = obj.options[i].text;
 806          }
 807      }
 808      return response;
 809  }
 810  
 811  //return all options of a select in an array
 812  function getAllOptions(id)
 813  {
 814      var    obj = Element(id);
 815      
 816      if (obj == null)
 817      {
 818          throw('getSelectedOptions: invalid object');
 819          return new Array();
 820      }
 821      
 822      var max = obj.options.length;
 823      var response = new Array();
 824      
 825      for (var i=0; i< max; i++)
 826      {
 827          response.push(obj.options[i].value);    
 828      }
 829      return response;
 830  }
 831  
 832  
 833  //-------------------RADIO-------------------------
 834  
 835  function selectRadio (id, index)
 836  {
 837      var obj = Element(id);
 838      var max = obj.options.length;
 839      for (var i = 0; i < max; i++)
 840      {
 841          i == index ? obj.options[i].checked = true : obj.options[i].checked = false;
 842      }
 843  }
 844  
 845  function getSelectedRadio(obj)
 846  {
 847      if (obj.type == 'radio')
 848      {
 849          if (obj.checked)
 850          {
 851              return obj.value;
 852          }
 853      }
 854      else if (obj.length)
 855      {
 856          var max = obj.length;
 857          for (var i = 0; i < max; i++)
 858          {
 859              if (obj[i].checked)
 860              {
 861                  return obj[i].value;    
 862              }    
 863          }
 864      }
 865      return null;
 866  }
 867  
 868  
 869  /***********************************************\
 870  *                   JSLIB OBJECT                *
 871  \***********************************************/
 872  
 873  function cJsLib ()
 874  {
 875      this._functions = new Array();
 876      this._arguments = new Array();
 877      this._original_body_onload = null;
 878  
 879      this.loaded = false;
 880  }
 881  
 882  //postpone function to be executed after body had loaded
 883  cJsLib.prototype.postponeFunction = function(obj_function)
 884  {
 885      if (typeof(obj_function) != 'function')
 886      {
 887          throw ('JsLib.postponeFunction: parameter must be a function');    
 888      }
 889      
 890      this._functions.push(obj_function);
 891      
 892      // 'arguments' are all args passed to this function
 893      var args = new Array();
 894      for (var i = 1; i< arguments.length; i++)
 895      {
 896          args.push(arguments[i]);
 897      }
 898  
 899      if (args.length)
 900      {
 901          this._arguments.push(args);
 902      }
 903      this.init();
 904  }
 905  
 906  //exec postponed functions
 907  cJsLib.prototype.execPostponed = function(e)
 908  {
 909      if (this._original_body_onload != null)
 910      {
 911          this._original_body_onload();    
 912      }
 913      
 914      var code = '';
 915      var _this = this;
 916      
 917      for (var i in this._functions)
 918      {
 919          if (typeof(this._functions[i]) != 'function')
 920          {
 921              continue;
 922          }
 923          
 924          if (typeof(this._arguments[i]) == 'object')
 925          {
 926              code += 'this._functions['+i+'](';
 927              for (var j in _this._arguments[i])
 928              {
 929                  code += this._arguments[i][j]+',';
 930              }
 931  
 932              code = code.substr(code, code.length-1);
 933              code += ');';
 934  
 935              continue;
 936          }
 937  
 938          code += 'this._functions['+i+']();';
 939      }
 940  
 941      eval(code);
 942  
 943      for (var i in this._functions)
 944      {
 945          if (typeof(this._arguments[i]) == 'object')
 946          {
 947              delete this._arguments[i];
 948              this._arguments[i] = null;
 949          }
 950  
 951          delete this._functions[i];
 952          this._functions[i] = null;
 953      }
 954  }
 955  
 956  //put function on body onload
 957  cJsLib.prototype.init = function()
 958  {
 959  /*    if (this.initialized)
 960      {
 961          return;
 962      }
 963  */
 964      this.initialized = true;
 965  
 966      var _this = this;
 967      var init = function()
 968      {
 969          _this.execPostponed();
 970      };
 971  
 972      Timeout(function() { if (document.body) return true; else return false;}, init);
 973  }
 974  
 975  var JsLib = new cJsLib();
 976  
 977  // Insert Debug Holder
 978  function _createDebugDOM()
 979  {
 980      var dbg_holder = document.createElement('xmp');
 981      
 982      dbg_holder.id = 'jsapiDebug';
 983      dbg_holder.style.position = 'absolute';
 984      dbg_holder.style.left = '1500px';
 985      dbg_holder.style.top = '0px';
 986      dbg_holder.style.fontFamily = 'monospace';
 987      
 988      var func = function()
 989      {
 990          document.body.appendChild(dbg_holder);
 991      }
 992      
 993      JsLib.postponeFunction(func);
 994  }
 995  
 996  /***********************************************\
 997  *                   CONSTANTS                   *
 998  \***********************************************/
 999  
1000  /***********************************************\
1001  *               GLOBALS VARIABLES               *
1002  \***********************************************/
1003  
1004  /***********************************************\
1005  *                OTHER FUNCTIONS                *
1006  \***********************************************/
1007  
1008  //JsLib.postponeFunction(function ()
1009  //{
1010  //    dynapi.setPath(GLOBALS['serverRoot']+'/phpgwapi/js/dynapi');
1011  //});


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7