[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/rsc/js/ -> form_extensions.js (source)

   1  /**

   2   * This file is part of the evoCore framework - {@link http://evocore.net/}

   3   * See also {@link http://sourceforge.net/projects/evocms/}.

   4   *

   5   * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}

   6   * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.

   7   *

   8   * {@internal License choice

   9   * - If you have received this file as part of a package, please find the license.txt file in

  10   *   the same folder or the closest folder above for complete license terms.

  11   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  12   *   then you must choose one of the following licenses before using the file:

  13   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  14   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  15   * }}

  16   *

  17   * {@internal Open Source relicensing agreement:

  18   * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license

  19   * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project

  20   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  21   * }}

  22   *

  23   * @package admin

  24   *

  25   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  26   * @author fplanque: Francois PLANQUE.

  27   * @author fsaya: Fabrice SAYA-GASNIER / PROGIDISTRI

  28   *

  29   * @version $Id: form_extensions.js,v 1.15 2006/11/26 01:42:10 fplanque Exp $

  30   */
  31  
  32  
  33  /**

  34   * Takes an object and returns the parent form

  35   *

  36   * @param object the child object

  37   * @return form the parent form of the child object

  38   */
  39  function get_form( object )
  40  {
  41       while( object.tagName != 'FORM' )
  42      {    // loop which goes from the checkbox to the form
  43          // alert( object.nodeName );

  44          if( typeof( object ) != 'undefined' ) // make sure that we have not gone too far
  45          {
  46              object = object.parentNode;
  47          }
  48          else
  49          {
  50              return false;
  51          }
  52      }
  53      // alert( 'ok:'+object.tagName );

  54      return object;
  55  }
  56  
  57  
  58  /**

  59   * Toggles all checkboxes of the current form

  60   *

  61   * @param form the form

  62   * @param integer force set/unset

  63   */
  64  function check( object, action )
  65  {
  66  
  67      form_obj = get_form( object );
  68  
  69      if( ! form_obj )
  70      {
  71          alert( 'Could not find form' );
  72          return false;
  73      }
  74  
  75      //checks or unchecks all checkboxes in the form

  76      i = 0;
  77      while( i < form_obj.length )
  78      {
  79          if( form_obj.elements[i].type == 'checkbox' )
  80          {
  81              form_obj.elements[i].checked = action;
  82          }
  83          i++;
  84      }
  85  
  86      // Cancel default action:

  87      return false;
  88  }
  89  
  90  
  91  /**

  92   * Event function

  93   * check all checkboxes of the current form

  94   */
  95  function check_all( e )
  96  {    // Get the event target element
  97      target =  findTarget(e);
  98      // Call check funtion to check all check boxes

  99      // Cancel the event click (href..)

 100      check( target, true );
 101      // For Firefox

 102      cancelClick( e );
 103      // For IE

 104      return false;
 105  }
 106  
 107  /**

 108   * Event function

 109   * uncheck all checkboxes of the current form

 110   */
 111  function uncheck_all( e )
 112  {    // Get the event target element
 113      target =  findTarget(e);
 114      // Call check funtion to uncheck all check boxes

 115      check( target, false );
 116      // Cancel the event click (href..)

 117      // For Firefox

 118      cancelClick( e );
 119      // For IE

 120      return false;
 121  }
 122  
 123  
 124  /*

 125   * Cancel a click event

 126   */
 127  function cancelClick( e )
 128  {
 129      if( window.event && window.event.returnValue )
 130      {    // Ie
 131          window.event.returnValue = false;
 132      }
 133      if( e && e.preventDefault )
 134      {    // Firefox
 135          e.preventDefault();
 136      }
 137      return false;
 138  }
 139  
 140  
 141  /**

 142   *    Surround or unsurrond all' surround_check' span restrict to check_val

 143   *    used to surround all check_all checkboxes

 144   */
 145  function surround_check( e, class_name, check_val )
 146  {    // Get the event target element
 147      var el = findTarget(e);
 148      // Get the parent form

 149      el_form = get_form( el );
 150      // Get all form inputs

 151      el_inputs = el_form.getElementsByTagName( 'INPUT' );
 152  
 153      // Loop on all inputs

 154      for( i = 0 ; i < el_inputs.length ; i++ )
 155      {
 156          el_input = el_inputs[i];
 157  
 158          if( el_input.type == 'checkbox' )
 159          {    // The input is a checkbox
 160              if( check_val == null || el_input.checked == check_val )
 161              {    // Change the parent (span) class
 162                  el_input.parentNode.className = class_name;
 163              }
 164          }
 165      }
 166  }
 167  
 168  /**

 169   *    Suround all not checked checkboxes

 170   */
 171  function surround_unchecked( e )
 172  {
 173      surround_check( e, 'checkbox_surround', false );
 174  }
 175  /**

 176   *    Suround all checked checkboxes

 177   */
 178  function surround_checked( e )
 179  {
 180      surround_check( e, 'checkbox_surround', true);
 181  }
 182  
 183  /**

 184   *    Unsuround all checkboxes

 185   */
 186  function unsurround_all( e )
 187  {
 188      surround_check( e, 'checkbox_surround_init', null);
 189  }
 190  
 191  /*

 192   *     Add links event on all check_all and un_chek_all links

 193   */
 194  function init_check_all()
 195  {    // Get all check_all elements
 196  
 197      //var exx = document.getElementsByName('surround_check');

 198      //alert(exx.length);

 199  
 200      var check_links = document.getElementsByName('check_all_nocheckchanges')
 201      // Add click event on all check_all links

 202      for( var i=0; i < check_links.length ; i++ )
 203      {
 204          var link = check_links[i];
 205          addEvent( link, 'click', check_all, false );
 206          addEvent( link, 'mouseover', surround_unchecked, false );
 207          addEvent( link, 'mouseout', unsurround_all, false );
 208      }
 209      // Add click event on all un_check_all links

 210      var uncheck_links = document.getElementsByName('uncheck_all_nocheckchanges')
 211      for( var i=0; i < uncheck_links.length ; i++ )
 212      {
 213          var link = uncheck_links[i];
 214          addEvent( link, 'click', uncheck_all, false );
 215          addEvent( link, 'mouseover', surround_checked, false );
 216          addEvent( link, 'mouseout', unsurround_all, false );
 217      }
 218  }
 219  
 220  /**

 221   * Clear the form the current object belongs to

 222   *

 223   * @param object the object whose form must be cleared

 224   */
 225  function clear_form( object )
 226  {
 227      object = check( object, false );
 228  
 229      // empties all the input fields of the form

 230      i = 0;
 231      while( i < object.length )
 232      {
 233          if( object.elements[i].type == 'text' )
 234          {
 235              object.elements[i].value = '';
 236          }
 237          i++;
 238      }
 239  
 240      return object;
 241  }
 242  
 243  
 244  /**

 245   * focus on the first form input text

 246   */
 247  function focus_on_first_input()
 248  {
 249      all_inputs = document.getElementsByTagName( 'input' );
 250  
 251      if( all_inputs.length )
 252      { // There is at least one input
 253          // Loop on all inputs to find the first input text

 254          for( i = 0 ; i < all_inputs.length ; i++ )
 255          {
 256        if( all_inputs[i].type == 'text'
 257                      && all_inputs[i].disabled != true
 258                      )
 259              {    // We found the first input text, so we focus on it
 260                  try
 261                  {    // Will fail in IE if element is not visible/displayed
 262                      all_inputs[i].focus();
 263                  }
 264                  catch( ex )
 265                  {
 266                  }
 267                  break;
 268              }
 269          }
 270      }
 271  }
 272  
 273  // This will be conditionnaly enabled by PHP:

 274  //addEvent( window, 'load', focus_on_first_input, false );

 275  
 276  /**

 277   * Handle Combo Boxes

 278   * Display the input text when value is 'new'

 279   * and hide the input text for all other values

 280   *

 281   * @param string ID of the select list

 282   * @param string value selected

 283   * @param string class name for the input text

 284   */
 285  function check_combo( el_ID, value, class_name )
 286  {
 287      if( value == 'new' )
 288      {    // Display the input text and focus on
 289  
 290          // Get the combo the input text

 291          input_text = document.getElementById(el_ID+'_combo' );
 292  
 293          // Display the input text

 294          input_text.style.display = "inline";
 295  
 296           // Focus on the new input text

 297          input_text.focus();
 298      }
 299      else
 300      { // Hide the input text
 301  
 302          // Get the combo the input text

 303          input_text = document.getElementById(el_ID+'_combo' );
 304  
 305          // Hide the input text

 306          input_text.style.display = "none";
 307      }
 308  }
 309  
 310  
 311  /**

 312   * Decorate an input field with a "help value", which gets

 313   * removed onfocus and re-added onblur (if the fields real

 314   * value is still unchanged).

 315   *

 316   * @param string ID of the input field

 317   * @param string "Help value"

 318   */
 319  function input_decorated_help( id, hvalue )
 320  {
 321      var elm = document.getElementById(id);
 322  
 323      var onblur = function() {
 324              if( elm.value == '' || elm.value == hvalue )
 325              {
 326                  elm.style.color = '#666';
 327                  elm.value = hvalue;
 328              }
 329          }
 330  
 331      addEvent( elm, 'blur', onblur, false );
 332  
 333      addEvent( elm, 'focus', function() {
 334              elm.style.color = '';
 335  
 336              if( elm.value == hvalue )
 337                  elm.value = '';
 338          }, false );
 339  
 340      /* on form's submit: set to empty, if help value */

 341      addEvent( elm.form, 'submit', function() {
 342              if( elm.value == hvalue )
 343              {
 344                  elm.value = '';
 345              }
 346          }, false );
 347  
 348      // init:

 349      onblur();
 350  }
 351  
 352  /*

 353   * $Log: form_extensions.js,v $

 354   * Revision 1.15  2006/11/26 01:42:10  fplanque

 355   * doc

 356   *

 357   */
 358  


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics