[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/js/ -> joomla.javascript.js (source)

   1  // <?php !! This fools phpdocumentor into parsing this file
   2  /**
   3  * @version $Id: joomla.javascript.js 5691 2006-11-09 00:55:42Z Saka $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
   7  * Joomla! is Free Software
   8  */
   9  
  10  // general utility for browsing a named array or object
  11  function xshow(o) {
  12      s = '';
  13      for(e in o) {s += e+'='+o[e]+'\n';}
  14      alert( s );
  15  }
  16  
  17  /**
  18  * Writes a dynamically generated list
  19  * @param string The parameters to insert into the <select> tag
  20  * @param array A javascript array of list options in the form [key,value,text]
  21  * @param string The key to display for the initial state of the list
  22  * @param string The original key that was selected
  23  * @param string The original item value that was selected
  24  */
  25  function writeDynaList( selectParams, source, key, orig_key, orig_val ) {
  26      var html = '\n    <select ' + selectParams + '>';
  27      var i = 0;
  28      for (x in source) {
  29          if (source[x][0] == key) {
  30              var selected = '';
  31              if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
  32                  selected = 'selected="selected"';
  33              }
  34              html += '\n        <option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
  35          }
  36          i++;
  37      }
  38      html += '\n    </select>';
  39  
  40      document.writeln( html );
  41  }
  42  
  43  /**
  44  * Changes a dynamically generated list
  45  * @param string The name of the list to change
  46  * @param array A javascript array of list options in the form [key,value,text]
  47  * @param string The key to display
  48  * @param string The original key that was selected
  49  * @param string The original item value that was selected
  50  */
  51  function changeDynaList( listname, source, key, orig_key, orig_val ) {
  52      var list = eval( 'document.adminForm.' + listname );
  53  
  54      // empty the list
  55      for (i in list.options.length) {
  56          list.options[i] = null;
  57      }
  58      i = 0;
  59      for (x in source) {
  60          if (source[x][0] == key) {
  61              opt = new Option();
  62              opt.value = source[x][1];
  63              opt.text = source[x][2];
  64  
  65              if ((orig_key == key && orig_val == opt.value) || i == 0) {
  66                  opt.selected = true;
  67              }
  68              list.options[i++] = opt;
  69          }
  70      }
  71      list.length = i;
  72  }
  73  
  74  /**
  75  * Adds a select item(s) from one list to another
  76  */
  77  function addSelectedToList( frmName, srcListName, tgtListName ) {
  78      var form = eval( 'document.' + frmName );
  79      var srcList = eval( 'form.' + srcListName );
  80      var tgtList = eval( 'form.' + tgtListName );
  81  
  82      var srcLen = srcList.length;
  83      var tgtLen = tgtList.length;
  84      var tgt = "x";
  85  
  86      //build array of target items
  87      for (var i=tgtLen-1; i > -1; i--) {
  88          tgt += "," + tgtList.options[i].value + ","
  89      }
  90  
  91      //Pull selected resources and add them to list
  92      //for (var i=srcLen-1; i > -1; i--) {
  93      for (var i=0; i < srcLen; i++) {
  94          if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
  95              opt = new Option( srcList.options[i].text, srcList.options[i].value );
  96              tgtList.options[tgtList.length] = opt;
  97          }
  98      }
  99  }
 100  
 101  function delSelectedFromList( frmName, srcListName ) {
 102      var form = eval( 'document.' + frmName );
 103      var srcList = eval( 'form.' + srcListName );
 104  
 105      var srcLen = srcList.length;
 106  
 107      for (var i=srcLen-1; i > -1; i--) {
 108          if (srcList.options[i].selected) {
 109              srcList.options[i] = null;
 110          }
 111      }
 112  }
 113  
 114  function moveInList( frmName, srcListName, index, to) {
 115      var form = eval( 'document.' + frmName );
 116      var srcList = eval( 'form.' + srcListName );
 117      var total = srcList.options.length-1;
 118  
 119      if (index == -1) {
 120          return false;
 121      }
 122      if (to == +1 && index == total) {
 123          return false;
 124      }
 125      if (to == -1 && index == 0) {
 126          return false;
 127      }
 128  
 129      var items = new Array;
 130      var values = new Array;
 131  
 132      for (i=total; i >= 0; i--) {
 133          items[i] = srcList.options[i].text;
 134          values[i] = srcList.options[i].value;
 135      }
 136      for (i = total; i >= 0; i--) {
 137          if (index == i) {
 138              srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
 139              srcList.options[i] = new Option(items[i+to], values[i+to]);
 140              i--;
 141          } else {
 142              srcList.options[i] = new Option(items[i], values[i]);
 143         }
 144      }
 145      srcList.focus();
 146  }
 147  
 148  function getSelectedOption( frmName, srcListName ) {
 149      var form = eval( 'document.' + frmName );
 150      var srcList = eval( 'form.' + srcListName );
 151  
 152      i = srcList.selectedIndex;
 153      if (i != null && i > -1) {
 154          return srcList.options[i];
 155      } else {
 156          return null;
 157      }
 158  }
 159  
 160  function setSelectedValue( frmName, srcListName, value ) {
 161      var form = eval( 'document.' + frmName );
 162      var srcList = eval( 'form.' + srcListName );
 163  
 164      var srcLen = srcList.length;
 165  
 166      for (var i=0; i < srcLen; i++) {
 167          srcList.options[i].selected = false;
 168          if (srcList.options[i].value == value) {
 169              srcList.options[i].selected = true;
 170          }
 171      }
 172  }
 173  
 174  function getSelectedRadio( frmName, srcGroupName ) {
 175      var form = eval( 'document.' + frmName );
 176      var srcGroup = eval( 'form.' + srcGroupName );
 177  
 178      if (srcGroup[0]) {
 179          for (var i=0, n=srcGroup.length; i < n; i++) {
 180              if (srcGroup[i].checked) {
 181                  return srcGroup[i].value;
 182              }
 183          }
 184      } else {
 185          if (srcGroup.checked) {
 186              return srcGroup.value;
 187          } // if the one button is checked, return zero
 188      }
 189     // if we get to this point, no radio button is selected
 190     return null;
 191  }
 192  
 193  function getSelectedValue( frmName, srcListName ) {
 194      var form = eval( 'document.' + frmName );
 195      var srcList = eval( 'form.' + srcListName );
 196  
 197      i = srcList.selectedIndex;
 198      if (i != null && i > -1) {
 199          return srcList.options[i].value;
 200      } else {
 201          return null;
 202      }
 203  }
 204  
 205  function getSelectedText( frmName, srcListName ) {
 206      var form = eval( 'document.' + frmName );
 207      var srcList = eval( 'form.' + srcListName );
 208  
 209      i = srcList.selectedIndex;
 210      if (i != null && i > -1) {
 211          return srcList.options[i].text;
 212      } else {
 213          return null;
 214      }
 215  }
 216  
 217  function chgSelectedValue( frmName, srcListName, value ) {
 218      var form = eval( 'document.' + frmName );
 219      var srcList = eval( 'form.' + srcListName );
 220  
 221      i = srcList.selectedIndex;
 222      if (i != null && i > -1) {
 223          srcList.options[i].value = value;
 224          return true;
 225      } else {
 226          return false;
 227      }
 228  }
 229  
 230  // Form specific functions for editting content images
 231  
 232  function showImageProps(base_path) {
 233      form = document.adminForm;
 234      value = getSelectedValue( 'adminForm', 'imagelist' );
 235      parts = value.split( '|' );
 236      form._source.value = parts[0];
 237      setSelectedValue( 'adminForm', '_align', parts[1] || '' );
 238      form._alt.value = parts[2] || '';
 239      form._border.value = parts[3] || '0';
 240      form._caption.value = parts[4] || '';
 241      setSelectedValue( 'adminForm', '_caption_position', parts[5] || '' );
 242      setSelectedValue( 'adminForm', '_caption_align', parts[6] || '' );
 243      form._width.value = parts[7] || '';
 244  
 245      //previewImage( 'imagelist', 'view_imagelist', base_path );
 246      srcImage = eval( "document." + 'view_imagelist' );
 247      srcImage.src = base_path + parts[0];
 248  }
 249  
 250  function applyImageProps() {
 251      form = document.adminForm;
 252      if (!getSelectedValue( 'adminForm', 'imagelist' )) {
 253          alert( "Select and image from the list" );
 254          return;
 255      }
 256      value = form._source.value + '|'
 257      + getSelectedValue( 'adminForm', '_align' ) + '|'
 258      + form._alt.value + '|'
 259      + parseInt( form._border.value ) + '|'
 260      + form._caption.value + '|'
 261      + getSelectedValue( 'adminForm', '_caption_position' ) + '|'
 262      + getSelectedValue( 'adminForm', '_caption_align' ) + '|'
 263      + form._width.value;
 264      chgSelectedValue( 'adminForm', 'imagelist', value );
 265  }
 266  
 267  function previewImage( list, image, base_path ) {
 268      form = document.adminForm;
 269      srcList = eval( "form." + list );
 270      srcImage = eval( "document." + image );
 271      var srcOption = srcList.options[(srcList.selectedIndex < 0) ? 0 : srcList.selectedIndex];
 272      var fileName = srcOption.text;
 273      var fileName2 = srcOption.value;
 274      if (fileName.length == 0 || fileName2.length == 0) {
 275          srcImage.src = 'images/blank.gif';
 276      } else {
 277          srcImage.src = base_path + fileName2;
 278      }
 279  }
 280  
 281  /**
 282  * Toggles the check state of a group of boxes
 283  *
 284  * Checkboxes must have an id attribute in the form cb0, cb1...
 285  * @param The number of box to 'check'
 286  * @param An alternative field name
 287  */
 288  function checkAll( n, fldName ) {
 289    if (!fldName) {
 290       fldName = 'cb';
 291    }
 292      var f = document.adminForm;
 293      var c = f.toggle.checked;
 294      var n2 = 0;
 295      for (i=0; i < n; i++) {
 296          cb = eval( 'f.' + fldName + '' + i );
 297          if (cb) {
 298              cb.checked = c;
 299              n2++;
 300          }
 301      }
 302      if (c) {
 303          document.adminForm.boxchecked.value = n2;
 304      } else {
 305          document.adminForm.boxchecked.value = 0;
 306      }
 307  }
 308  
 309  function listItemTask( id, task ) {
 310      var f = document.adminForm;
 311      cb = eval( 'f.' + id );
 312      if (cb) {
 313          for (i = 0; true; i++) {
 314              cbx = eval('f.cb'+i);
 315              if (!cbx) break;
 316              cbx.checked = false;
 317          } // for
 318          cb.checked = true;
 319          f.boxchecked.value = 1;
 320          submitbutton(task);
 321      }
 322      return false;
 323  }
 324  
 325  function hideMainMenu()
 326  {
 327      document.adminForm.hidemainmenu.value=1;
 328  }
 329  
 330  function isChecked(isitchecked){
 331      if (isitchecked == true){
 332          document.adminForm.boxchecked.value++;
 333      }
 334      else {
 335          document.adminForm.boxchecked.value--;
 336      }
 337  }
 338  
 339  /**
 340  * Default function.  Usually would be overriden by the component
 341  */
 342  function submitbutton(pressbutton) {
 343      submitform(pressbutton);
 344  }
 345  
 346  /**
 347  * Submit the admin form
 348  */
 349  function submitform(pressbutton){
 350      document.adminForm.task.value=pressbutton;
 351      try {
 352          document.adminForm.onsubmit();
 353          }
 354      catch(e){}
 355      document.adminForm.submit();
 356  }
 357  
 358  /**
 359  * Submit the control panel admin form
 360  */
 361  function submitcpform(sectionid, id){
 362      document.adminForm.sectionid.value=sectionid;
 363      document.adminForm.id.value=id;
 364      submitbutton("edit");
 365  }
 366  
 367  /**
 368  * Getting radio button that is selected.
 369  */
 370  function getSelected(allbuttons){
 371      for (i=0;i<allbuttons.length;i++) {
 372          if (allbuttons[i].checked) {
 373              return allbuttons[i].value
 374          }
 375      }
 376  }
 377  
 378  // JS Calendar
 379  var calendar = null; // remember the calendar object so that we reuse
 380  // it and avoid creating another
 381  
 382  // This function gets called when an end-user clicks on some date
 383  function selected(cal, date) {
 384      cal.sel.value = date; // just update the value of the input field
 385  }
 386  
 387  // And this gets called when the end-user clicks on the _selected_ date,
 388  // or clicks the "Close" (X) button.  It just hides the calendar without
 389  // destroying it.
 390  function closeHandler(cal) {
 391      cal.hide();            // hide the calendar
 392  
 393      // don't check mousedown on document anymore (used to be able to hide the
 394      // calendar when someone clicks outside it, see the showCalendar function).
 395      Calendar.removeEvent(document, "mousedown", checkCalendar);
 396  }
 397  
 398  // This gets called when the user presses a mouse button anywhere in the
 399  // document, if the calendar is shown.  If the click was outside the open
 400  // calendar this function closes it.
 401  function checkCalendar(ev) {
 402      var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
 403      for (; el != null; el = el.parentNode)
 404      // FIXME: allow end-user to click some link without closing the
 405      // calendar.  Good to see real-time stylesheet change :)
 406      if (el == calendar.element || el.tagName == "A") break;
 407      if (el == null) {
 408          // calls closeHandler which should hide the calendar.
 409          calendar.callCloseHandler(); Calendar.stopEvent(ev);
 410      }
 411  }
 412  
 413  // This function shows the calendar under the element having the given id.
 414  // It takes care of catching "mousedown" signals on document and hiding the
 415  // calendar if the click was outside.
 416  function showCalendar(id) {
 417      var el = document.getElementById(id);
 418      if (calendar != null) {
 419          // we already have one created, so just update it.
 420          calendar.hide();        // hide the existing calendar
 421          calendar.parseDate(el.value); // set it to a new date
 422      } else {
 423          // first-time call, create the calendar
 424          var cal = new Calendar(true, null, selected, closeHandler);
 425          calendar = cal;        // remember the calendar in the global
 426          cal.setRange(1900, 2070);    // min/max year allowed
 427          calendar.create();        // create a popup calendar
 428          calendar.parseDate(el.value); // set it to a new date
 429      }
 430      calendar.sel = el;        // inform it about the input field in use
 431      calendar.showAtElement(el);    // show the calendar next to the input field
 432  
 433      // catch mousedown on the document
 434      Calendar.addEvent(document, "mousedown", checkCalendar);
 435      return false;
 436  }
 437  
 438  /**
 439  * Pops up a new window in the middle of the screen
 440  */
 441  function popupWindow(mypage, myname, w, h, scroll) {
 442      var winl = (screen.width - w) / 2;
 443      var wint = (screen.height - h) / 2;
 444      winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
 445      win = window.open(mypage, myname, winprops)
 446      if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
 447  }
 448  
 449  // LTrim(string) : Returns a copy of a string without leading spaces.
 450  function ltrim(str)
 451  {
 452     var whitespace = new String(" \t\n\r");
 453     var s = new String(str);
 454     if (whitespace.indexOf(s.charAt(0)) != -1) {
 455        var j=0, i = s.length;
 456        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
 457           j++;
 458        s = s.substring(j, i);
 459     }
 460     return s;
 461  }
 462  
 463  //RTrim(string) : Returns a copy of a string without trailing spaces.
 464  function rtrim(str)
 465  {
 466     var whitespace = new String(" \t\n\r");
 467     var s = new String(str);
 468     if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
 469        var i = s.length - 1;       // Get length of string
 470        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
 471           i--;
 472        s = s.substring(0, i+1);
 473     }
 474     return s;
 475  }
 476  
 477  // Trim(string) : Returns a copy of a string without leading or trailing spaces
 478  function trim(str) {
 479     return rtrim(ltrim(str));
 480  }
 481  
 482  function mosDHTML(){
 483      this.ver=navigator.appVersion
 484      this.agent=navigator.userAgent
 485      this.dom=document.getElementById?1:0
 486      this.opera5=this.agent.indexOf("Opera 5")<-1
 487      this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0;
 488      this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0;
 489      this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
 490      this.ie=this.ie4||this.ie5||this.ie6
 491      this.mac=this.agent.indexOf("Mac")<-1
 492      this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0;
 493      this.ns4=(document.layers && !this.dom)?1:0;
 494      this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
 495  
 496      this.activeTab = '';
 497      this.onTabStyle = 'ontab';
 498      this.offTabStyle = 'offtab';
 499  
 500      this.setElemStyle = function(elem,style) {
 501          document.getElementById(elem).className = style;
 502      }
 503      this.showElem = function(id) {
 504          if (elem = document.getElementById(id)) {
 505              elem.style.visibility = 'visible';
 506              elem.style.display = 'block';
 507          }
 508      }
 509      this.hideElem = function(id) {
 510          if (elem = document.getElementById(id)) {
 511              elem.style.visibility = 'hidden';
 512              elem.style.display = 'none';
 513          }
 514      }
 515      this.cycleTab = function(name) {
 516          if (this.activeTab) {
 517              this.setElemStyle( this.activeTab, this.offTabStyle );
 518              page = this.activeTab.replace( 'tab', 'page' );
 519              this.hideElem(page);
 520          }
 521          this.setElemStyle( name, this.onTabStyle );
 522          this.activeTab = name;
 523          page = this.activeTab.replace( 'tab', 'page' );
 524          this.showElem(page);
 525      }
 526      return this;
 527  }
 528  var dhtml = new mosDHTML();
 529  
 530  function MM_findObj(n, d) { //v4.01
 531      var p,i,x;
 532      if(!d) d=document;
 533      if((p=n.indexOf("?"))>0&&parent.frames.length) {
 534          d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
 535      }
 536      if(!(x=d[n])&&d.all) x=d.all[n];
 537      for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 538      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
 539      if(!x && d.getElementById) x=d.getElementById(n);
 540      return x;
 541  }
 542  function MM_swapImage() { //v3.0
 543      var i,j=0,x,a=MM_swapImage.arguments;
 544      document.MM_sr=new Array;
 545      for(i=0;i<(a.length-2);i+=3)
 546      if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
 547      if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
 548  }
 549  function MM_swapImgRestore() { //v3.0
 550      var i,x,a=document.MM_sr;
 551      for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
 552  }
 553  
 554  function MM_preloadImages() { //v3.0
 555      var d=document;
 556      if(d.images){
 557      if(!d.MM_p) d.MM_p=new Array();
 558      var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
 559      for(i=0; i<a.length; i++)
 560      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
 561  }
 562  
 563  
 564  function saveorder( n ) {
 565      checkAll_button( n );
 566  }
 567  
 568  //needed by saveorder function
 569  function checkAll_button( n ) {
 570      for ( var j = 0; j <= n; j++ ) {
 571          box = eval( "document.adminForm.cb" + j );
 572          if ( box ) {
 573              if ( box.checked == false ) {
 574                  box.checked = true;
 575              }
 576          } else {
 577              alert("You cannot change the order of items, as an item in the list is `Checked Out`");
 578              return;
 579          }
 580      }
 581      submitform('saveorder');
 582  }
 583  /**
 584  * @param object A form element
 585  * @param string The name of the element to find
 586  */
 587  function getElementByName( f, name ) {
 588      if (f.elements) {
 589          for (i=0, n=f.elements.length; i < n; i++) {
 590              if (f.elements[i].name == name) {
 591                  return f.elements[i];
 592              }
 593          }
 594      }
 595      return null;
 596  }


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics