Ignore:
Timestamp:
Aug 6, 2009, 11:21:29 PM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

adjust hierarchy

Location:
ruby/branches/0.5
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/public/javascripts/controls.js

    r164 r169  
    11// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    2 //           (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
    3 //           (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
     2//           (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
     3//           (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
    44// Contributors:
    55//  Richard Livsey
    66//  Rahul Bhargava
    77//  Rob Wills
    8 // 
     8//
    99// script.aculo.us is freely distributable under the terms of an MIT-style license.
    1010// For details, see the script.aculo.us web site: http://script.aculo.us/
    1111
    12 // Autocompleter.Base handles all the autocompletion functionality 
     12// Autocompleter.Base handles all the autocompletion functionality
    1313// that's independent of the data source for autocompletion. This
    1414// includes drawing the autocompletion menu, observing keyboard
    1515// and mouse events, and similar.
    1616//
    17 // Specific autocompleters need to provide, at the very least, 
     17// Specific autocompleters need to provide, at the very least,
    1818// a getUpdatedChoices function that will be invoked every time
    19 // the text inside the monitored textbox changes. This method 
     19// the text inside the monitored textbox changes. This method
    2020// should get the text for which to provide autocompletion by
    2121// invoking this.getToken(), NOT by directly accessing
     
    3131// Additionally, ',' in the above example can be replaced with
    3232// a token array, e.g. { tokens: [',', '\n'] } which
    33 // enables autocompletion on multiple tokens. This is most 
    34 // useful when one of the tokens is \n (a newline), as it 
     33// enables autocompletion on multiple tokens. This is most
     34// useful when one of the tokens is \n (a newline), as it
    3535// allows smart autocompletion after linebreaks.
    3636
     
    3838  throw("controls.js requires including script.aculo.us' effects.js library");
    3939
    40 var Autocompleter = { }
     40var Autocompleter = { };
    4141Autocompleter.Base = Class.create({
    4242  baseInitialize: function(element, update, options) {
    43     element          = $(element)
    44     this.element     = element; 
    45     this.update      = $(update); 
    46     this.hasFocus    = false; 
    47     this.changed     = false; 
    48     this.active      = false; 
    49     this.index       = 0;     
     43    element          = $(element);
     44    this.element     = element;
     45    this.update      = $(update);
     46    this.hasFocus    = false;
     47    this.changed     = false;
     48    this.active      = false;
     49    this.index       = 0;
    5050    this.entryCount  = 0;
    5151    this.oldElementValue = this.element.value;
     
    6060    this.options.frequency    = this.options.frequency || 0.4;
    6161    this.options.minChars     = this.options.minChars || 1;
    62     this.options.onShow       = this.options.onShow || 
    63       function(element, update){ 
     62    this.options.onShow       = this.options.onShow ||
     63      function(element, update){
    6464        if(!update.style.position || update.style.position=='absolute') {
    6565          update.style.position = 'absolute';
    6666          Position.clone(element, update, {
    67             setHeight: false, 
     67            setHeight: false,
    6868            offsetTop: element.offsetHeight
    6969          });
     
    7171        Effect.Appear(update,{duration:0.15});
    7272      };
    73     this.options.onHide = this.options.onHide || 
     73    this.options.onHide = this.options.onHide ||
    7474      function(element, update){ new Effect.Fade(update,{duration:0.15}) };
    7575
    76     if(typeof(this.options.tokens) == 'string') 
     76    if(typeof(this.options.tokens) == 'string')
    7777      this.options.tokens = new Array(this.options.tokens);
    7878    // Force carriage returns as token delimiters anyway
     
    8181
    8282    this.observer = null;
    83    
     83
    8484    this.element.setAttribute('autocomplete','off');
    8585
     
    9292  show: function() {
    9393    if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
    94     if(!this.iefix && 
     94    if(!this.iefix &&
    9595      (Prototype.Browser.IE) &&
    9696      (Element.getStyle(this.update, 'position')=='absolute')) {
    97       new Insertion.After(this.update, 
     97      new Insertion.After(this.update,
    9898       '<iframe id="' + this.update.id + '_iefix" '+
    9999       'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
     
    103103    if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
    104104  },
    105  
     105
    106106  fixIEOverlapping: function() {
    107107    Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
     
    151151         return;
    152152      }
    153      else 
    154        if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 
     153     else
     154       if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
    155155         (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
    156156
     
    159159
    160160    if(this.observer) clearTimeout(this.observer);
    161       this.observer = 
     161      this.observer =
    162162        setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
    163163  },
     
    171171  onHover: function(event) {
    172172    var element = Event.findElement(event, 'LI');
    173     if(this.index != element.autocompleteIndex) 
     173    if(this.index != element.autocompleteIndex)
    174174    {
    175175        this.index = element.autocompleteIndex;
     
    178178    Event.stop(event);
    179179  },
    180  
     180
    181181  onClick: function(event) {
    182182    var element = Event.findElement(event, 'LI');
     
    185185    this.hide();
    186186  },
    187  
     187
    188188  onBlur: function(event) {
    189189    // needed to make click events working
    190190    setTimeout(this.hide.bind(this), 250);
    191191    this.hasFocus = false;
    192     this.active = false;     
    193   }, 
    194  
     192    this.active = false;
     193  },
     194
    195195  render: function() {
    196196    if(this.entryCount > 0) {
    197197      for (var i = 0; i < this.entryCount; i++)
    198         this.index==i ? 
    199           Element.addClassName(this.getEntry(i),"selected") : 
     198        this.index==i ?
     199          Element.addClassName(this.getEntry(i),"selected") :
    200200          Element.removeClassName(this.getEntry(i),"selected");
    201       if(this.hasFocus) { 
     201      if(this.hasFocus) {
    202202        this.show();
    203203        this.active = true;
     
    208208    }
    209209  },
    210  
     210
    211211  markPrevious: function() {
    212     if(this.index > 0) this.index--
     212    if(this.index > 0) this.index--;
    213213      else this.index = this.entryCount-1;
    214214    this.getEntry(this.index).scrollIntoView(true);
    215215  },
    216  
     216
    217217  markNext: function() {
    218     if(this.index < this.entryCount-1) this.index++
     218    if(this.index < this.entryCount-1) this.index++;
    219219      else this.index = 0;
    220220    this.getEntry(this.index).scrollIntoView(false);
    221221  },
    222  
     222
    223223  getEntry: function(index) {
    224224    return this.update.firstChild.childNodes[index];
    225225  },
    226  
     226
    227227  getCurrentEntry: function() {
    228228    return this.getEntry(this.index);
    229229  },
    230  
     230
    231231  selectEntry: function() {
    232232    this.active = false;
     
    245245    } else
    246246      value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
    247    
     247
    248248    var bounds = this.getTokenBounds();
    249249    if (bounds[0] != -1) {
     
    258258    this.oldElementValue = this.element.value;
    259259    this.element.focus();
    260    
     260
    261261    if (this.options.afterUpdateElement)
    262262      this.options.afterUpdateElement(this.element, selectedElement);
     
    270270
    271271      if(this.update.firstChild && this.update.down().childNodes) {
    272         this.entryCount = 
     272        this.entryCount =
    273273          this.update.down().childNodes.length;
    274274        for (var i = 0; i < this.entryCount; i++) {
     
    277277          this.addObservers(entry);
    278278        }
    279       } else { 
     279      } else {
    280280        this.entryCount = 0;
    281281      }
     
    283283      this.stopIndicator();
    284284      this.index = 0;
    285      
     285
    286286      if(this.entryCount==1 && this.options.autoSelect) {
    287287        this.selectEntry();
     
    299299
    300300  onObserverEvent: function() {
    301     this.changed = false;   
     301    this.changed = false;
    302302    this.tokenBounds = null;
    303303    if(this.getToken().length>=this.options.minChars) {
     
    352352  getUpdatedChoices: function() {
    353353    this.startIndicator();
    354    
    355     var entry = encodeURIComponent(this.options.paramName) + '=' + 
     354
     355    var entry = encodeURIComponent(this.options.paramName) + '=' +
    356356      encodeURIComponent(this.getToken());
    357357
     
    359359      this.options.callback(this.element, entry) : entry;
    360360
    361     if(this.options.defaultParams) 
     361    if(this.options.defaultParams)
    362362      this.options.parameters += '&' + this.options.defaultParams;
    363    
     363
    364364    new Ajax.Request(this.url, this.options);
    365365  },
     
    383383//
    384384// - partialSearch - If false, the autocompleter will match entered
    385 //                    text only at the beginning of strings in the 
     385//                    text only at the beginning of strings in the
    386386//                    autocomplete array. Defaults to true, which will
    387387//                    match text at the beginning of any *word* in the
     
    400400//                 Defaults to true.
    401401//
    402 // It's possible to pass in a custom function as the 'selector' 
     402// It's possible to pass in a custom function as the 'selector'
    403403// option, if you prefer to write your own autocompletion logic.
    404404// In that case, the other options above will not apply unless
     
    428428        var count     = 0;
    429429
    430         for (var i = 0; i < instance.options.array.length && 
    431           ret.length < instance.options.choices ; i++) { 
     430        for (var i = 0; i < instance.options.array.length &&
     431          ret.length < instance.options.choices ; i++) {
    432432
    433433          var elem = instance.options.array[i];
    434           var foundPos = instance.options.ignoreCase ? 
    435             elem.toLowerCase().indexOf(entry.toLowerCase()) : 
     434          var foundPos = instance.options.ignoreCase ?
     435            elem.toLowerCase().indexOf(entry.toLowerCase()) :
    436436            elem.indexOf(entry);
    437437
    438438          while (foundPos != -1) {
    439             if (foundPos == 0 && elem.length != entry.length) { 
    440               ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" + 
     439            if (foundPos == 0 && elem.length != entry.length) {
     440              ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
    441441                elem.substr(entry.length) + "</li>");
    442442              break;
    443             } else if (entry.length >= instance.options.partialChars && 
     443            } else if (entry.length >= instance.options.partialChars &&
    444444              instance.options.partialSearch && foundPos != -1) {
    445445              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
     
    451451            }
    452452
    453             foundPos = instance.options.ignoreCase ? 
    454               elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 
     453            foundPos = instance.options.ignoreCase ?
     454              elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
    455455              elem.indexOf(entry, foundPos + 1);
    456456
     
    458458        }
    459459        if (partial.length)
    460           ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
     460          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
    461461        return "<ul>" + ret.join('') + "</ul>";
    462462      }
     
    475475    Field.activate(field);
    476476  }, 1);
    477 }
     477};
    478478
    479479Ajax.InPlaceEditor = Class.create({
     
    605605  },
    606606  getText: function() {
    607     return this.element.innerHTML;
     607    return this.element.innerHTML.unescapeHTML();
    608608  },
    609609  handleAJAXFailure: function(transport) {
     
    781781        var js = transport.responseText.strip();
    782782        if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
    783           throw 'Server returned an invalid collection representation.';
     783          throw('Server returned an invalid collection representation.');
    784784        this._collection = eval(js);
    785785        this.checkForExternalText();
     
    938938};
    939939
    940 // Delayed observer, like Form.Element.Observer, 
     940// Delayed observer, like Form.Element.Observer,
    941941// but waits for delay after last key input
    942942// Ideal for live-search fields
     
    948948    this.callback  = callback;
    949949    this.timer     = null;
    950     this.lastValue = $F(this.element); 
     950    this.lastValue = $F(this.element);
    951951    Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
    952952  },
Note: See TracChangeset for help on using the changeset viewer.