/[drupal]/contributions/modules/activeselect/activeselect.js
ViewVC logotype

Diff of /contributions/modules/activeselect/activeselect.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.15, Wed Mar 29 12:51:48 2006 UTC revision 1.16, Sun Apr 9 05:11:52 2006 UTC
# Line 1  Line 1 
1  // $Id: activeselect.js,v 1.13 2006/03/28 13:23:35 jaza Exp $  // $Id: activeselect.js,v 1.15 2006/03/29 12:51:48 jaza Exp $
2    
3  // Global Killswitch  // Global Killswitch
4  if (isJsEnabled()) {  if (isJsEnabled()) {
# Line 120  jsAS.prototype.populateTargets = functio Line 120  jsAS.prototype.populateTargets = functio
120   * Fills the target select boxes with any matches received   * Fills the target select boxes with any matches received
121   */   */
122  jsAS.prototype.populate = function (matches) {  jsAS.prototype.populate = function (matches) {
123    if (matches.length > 0) {    for (targetIndex in this.targets) {
124      for (targetIndex in this.targets) {      var target = this.targets[targetIndex];
125        var target = this.targets[targetIndex];      var matchesTarget = 0;
126        var matchesTarget = 0;      for (targetElement in matches) {
127        for (targetElement in matches) {        if ('edit-'+targetElement == target.id) {
128          if ('edit-'+ matches[targetElement][0] == target.id) {          matchesTarget = targetElement;
129            matchesTarget = targetElement;          continue;
           continue;  
         }  
130        }        }
131        if (matchesTarget) {      }
132          this.targets[targetIndex].multiple = matches[matchesTarget][2];      if (matchesTarget) {
133          if (matches[matchesTarget][2]) {        this.targets[targetIndex].multiple = matches[matchesTarget]['multiple'];
134            if (target.name.indexOf('[]') == -1) {        if (matches[matchesTarget]['multiple']) {
135              this.targets[targetIndex].name += '[]';          if (target.name.indexOf('[]') == -1) {
136            }            this.targets[targetIndex].name += '[]';
137          }          }
138          else {        }
139            var bracketIndex = target.name.indexOf('[]');        else {
140            if (bracketIndex != -1) {          var bracketIndex = target.name.indexOf('[]');
141              this.targets[targetIndex].name = target.name.substr(0, target.name.length-2);          if (bracketIndex != -1) {
142            }            this.targets[targetIndex].name = target.name.substr(0, target.name.length-2);
143          }          }
144          }
145    
146          while (target.hasChildNodes()) {
147            target.removeChild(target.childNodes[0]);
148          }
149          var targetMatches = matches[matchesTarget]['options'];
150          var maxWidth = 0;
151          for (currMatch in targetMatches) {
152            var value = currMatch;
153            var text = targetMatches[currMatch]['value'];
154            var selected = targetMatches[currMatch]['selected'];
155    
156          while (target.hasChildNodes()) {          if (text.length > maxWidth) {
157            target.removeChild(target.childNodes[0]);            maxWidth = text.length;
         }  
         var targetMatches = matches[matchesTarget][1];  
         var maxWidth = 0;  
         for (var i = 0; i < targetMatches.length; i++) {  
           var value = targetMatches[i][0];  
           var text = targetMatches[i][1];  
           var selected = targetMatches[i][2];  
   
           if (text.length > maxWidth) {  
             maxWidth = text.length;  
           }  
           // 'new Option()' used instead of appendChild(), because IE6 refuses to  
           // display option text if the latter method is used (otherwise they seem  
           // to behave the same).  
           this.targets[targetIndex].options[this.targets[targetIndex].options.length] = new Option(text, value, false, selected);  
         }  
         if (this.targets[targetIndex].selectedIndex == -1) {  
           this.targets[targetIndex].selectedIndex = 0;  
         }  
   
         if (hasClass(this.targets[targetIndex], 'form-activeselect')) {  
           // Since IE does not support the DOM 2 methods for manually firing an  
           // event, we must cater especially to its needs.  
           // Reference: http://www.howtocreate.co.uk/tutorials/javascript/domevents  
           if (document.createEvent) {  
             // DOM 2 compliant method (Firefox / Opera / Safari / etc)  
             var e = document.createEvent('HTMLEvents');  
             e.initEvent('change', true, false);  
             this.targets[targetIndex].dispatchEvent(e);  
           }  
           else if (document.createEventObject) {  
             // IE special weird method  
             var e = document.createEventObject();  
             e.bubbles = true;  
             e.cancelable = false;  
             this.targets[targetIndex].fireEvent('onchange', e);  
           }  
158          }          }
159          else {          // 'new Option()' used instead of appendChild(), because IE6 refuses to
160            this.setTargetWidth(targetIndex, maxWidth);          // display option text if the latter method is used (otherwise they seem
161            // to behave the same).
162            this.targets[targetIndex].options[this.targets[targetIndex].options.length] = new Option(text, value, false, selected);
163          }
164          if (this.targets[targetIndex].selectedIndex == -1) {
165            this.targets[targetIndex].selectedIndex = 0;
166          }
167    
168          if (hasClass(this.targets[targetIndex], 'form-activeselect')) {
169            // Since IE does not support the DOM 2 methods for manually firing an
170            // event, we must cater especially to its needs.
171            // Reference: http://www.howtocreate.co.uk/tutorials/javascript/domevents
172            if (document.createEvent) {
173              // DOM 2 compliant method (Firefox / Opera / Safari / etc)
174              var e = document.createEvent('HTMLEvents');
175              e.initEvent('change', true, false);
176              this.targets[targetIndex].dispatchEvent(e);
177            }
178            else if (document.createEventObject) {
179              // IE special weird method
180              var e = document.createEventObject();
181              e.bubbles = true;
182              e.cancelable = false;
183              this.targets[targetIndex].fireEvent('onchange', e);
184          }          }
185        }        }
186          else {
187            this.setTargetWidth(targetIndex, maxWidth);
188          }
189      }      }
     this.setSelectWidth(null);  
190    }    }
191      this.setSelectWidth(null);
192  }  }
193    
194  /**  /**
# Line 241  ASDB.prototype.receive = function(string Line 239  ASDB.prototype.receive = function(string
239      return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ asdb.uri);      return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ asdb.uri);
240    }    }
241    // Split into array of key->value pairs    // Split into array of key->value pairs
242    var targets = string.length > 0 ? string.split('||||') : [];    if (string.length > 0) {
243    for (var targetIndex = 0; targetIndex < targets.length; targetIndex++) {      var targets = parseJson(string);
244      if (targets[targetIndex].length > 0) {      if (typeof targets['status'] == 'undefined' || targets['status'] != 0) {
245        targets[targetIndex] = targets[targetIndex].split('|||');        asdb.cache[asdb.searchString] = targets;
246        var targetInfo = targets[targetIndex][0].split('|');        asdb.owner.populate(targets);
       targets[targetIndex][0] = eregReplace('&#124;', '|', targetInfo[0]);  
       targets[targetIndex][1] = targets[targetIndex][1].split('||');  
       if (targetInfo.length > 1 && targetInfo[1] == 'multiple') {  
         targets[targetIndex][2] = true;  
       }  
       else {  
         targets[targetIndex][2] = false;  
       }  
       for (var matchesIndex = 0; matchesIndex < targets[targetIndex][1].length; matchesIndex++) {  
         var match = targets[targetIndex][1][matchesIndex];  
         if (match.length > 0) {  
           targets[targetIndex][1][matchesIndex] = match = match.split('|');  
           // Decode textfield pipes back to plain-text  
           targets[targetIndex][1][matchesIndex][1] = eregReplace('&#124;', '|', match[1]);  
           if (match.length > 2 && match[2] == 'selected') {  
             targets[targetIndex][1][matchesIndex][2] = true;  
           }  
           else {  
             targets[targetIndex][1][matchesIndex][2] = false;  
           }  
         }  
         else {  
           targets[targetIndex][1][matchesIndex] = [];  
         }  
       }  
     }  
     else {  
       targets[targetIndex] = [];  
247      }      }
248    }    }
   asdb.cache[asdb.searchString] = targets;  
   asdb.owner.populate(targets);  
249  }  }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.2