[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/jscripts/ -> peeker.js (source)

   1  /**
   2   * Peeker is a simple class which controls the visibility of something based on a value of a select form
   3   *
   4   * Usage:
   5   * var peeker = new Peeker( <id of the controlling select menu>, <id of the thing to show/hide>, <matching regexp to show the thing>);
   6   */
   7  
   8  var Peeker = Class.create();
   9  Peeker.prototype = {
  10      
  11      controller: null,
  12      domain: null,
  13      match: null,
  14      is_nodelist: null,
  15      
  16      /**
  17       * Checks the controller and shows/hide
  18       */
  19      check: function()
  20      {
  21          // Array
  22          if(this.is_nodelist)
  23          {
  24              // Find a match (if found show domain)
  25              for(i = 0; i < this.controller.length; i++)
  26              {
  27                  if(this.controller[i].checked && this.controller[i].value.match(this.match))
  28                  {
  29                      Element.show(this.domain);
  30                      return;
  31                  }
  32              }
  33              // Nothing found
  34              Element.hide(this.domain);
  35          }
  36          else
  37          {
  38              type = this.controller.value;
  39              this.domain.style.display = (type.match(this.match)) ? '' : 'none';
  40          }
  41      },
  42      
  43      /**
  44       * Constructor
  45       * @param string ID of the controlling select menu
  46       * @param string ID of the thing to show/hide
  47       * @param regexp If this regexp matches value of the select menu, then the 'thing' will be shown
  48       * @param boolean Should be set to true for radio/checkboxes
  49       */
  50      initialize: function(controller, domain, match, is_nodelist)
  51      {
  52          // Ugly code to differentiate initialization between nodelist and element
  53          if(is_nodelist)
  54          {
  55              if(controller.length > 0 && domain)
  56              {
  57                  this.controller = controller;
  58                  this.domain = domain;
  59                  this.match = match;
  60                  this.is_nodelist = is_nodelist;
  61                  
  62                  for(i = 0; i < controller.length; i++)
  63                  {
  64                         if(controller[i].getAttribute("id") != null)
  65                         {
  66                             Event.observe(controller[i], "change", this.check.bindAsEventListener(this));
  67                            Event.observe(controller[i], "click", this.check.bindAsEventListener(this));
  68                         }
  69                  }
  70                  this.check();
  71              }
  72          }
  73          else if(controller && domain)
  74          {
  75              this.controller = controller;
  76              this.domain = domain;
  77              this.match = match;
  78              this.is_nodelist = is_nodelist;
  79              
  80              Event.observe(controller, "change", this.check.bindAsEventListener(this));
  81              this.check();
  82          }
  83      }
  84  };
  85  
  86  /**
  87   * Add a "required" asterisk to a FormContainer row
  88   * @param string ID of the row
  89   */
  90  var add_star = function(id)
  91  {
  92      if($(id))
  93      {
  94          cell = $(id).getElementsByTagName("td")[0];
  95          label = cell.getElementsByTagName("label")[0];
  96          star = document.createElement("em");
  97          starText = document.createTextNode(" *");
  98          star.appendChild(starText);
  99          label.appendChild(star);
 100      }
 101  }


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1