Changeset 5265 in subversion


Ignore:
Timestamp:
Sep 22, 2011 3:26:28 AM (20 months ago)
Author:
alec
Message:
  • Abort pending autocomplete requests when max entries found, small code improvements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/js/app.js

    r5264 r5265  
    36203620      return; 
    36213621 
     3622    this.ksearch_destroy(); 
     3623 
    36223624    if (q.length && q.length < min) { 
    36233625      if (!this.ksearch_info) { 
     
    36303632    var old_value = this.ksearch_value; 
    36313633    this.ksearch_value = q; 
    3632     this.ksearch_destroy(); 
    36333634 
    36343635    // ...string is empty 
     
    36723673 
    36733674    // display search results 
    3674     var p, ul, li, text, init, s_val = this.ksearch_value, 
     3675    var ul, li, text, init, 
     3676      value = this.ksearch_value, 
     3677      data = this.ksearch_data, 
    36753678      maxlen = this.env.autocomplete_max ? this.env.autocomplete_max : 15; 
    36763679 
     
    37053708        text = typeof results[i] === 'object' ? results[i].name : results[i]; 
    37063709        li = document.createElement('LI'); 
    3707         li.innerHTML = text.replace(new RegExp('('+RegExp.escape(s_val)+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>'); 
     3710        li.innerHTML = text.replace(new RegExp('('+RegExp.escape(value)+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>'); 
    37083711        li.onmouseover = function(){ ref.ksearch_select(this); }; 
    37093712        li.onmouseup = function(){ ref.ksearch_click(this) }; 
     
    37273730 
    37283731    // run next parallel search 
    3729     if (this.ksearch_data.id == reqid) { 
    3730       if (maxlen > 0 && this.ksearch_data.sources.length) { 
    3731         var lock, xhr, props = this.ksearch_data, source = props.sources.shift(); 
     3732    if (data.id == reqid) { 
     3733      if (maxlen > 0 && data.sources.length) { 
     3734        var lock, xhr, source = data.sources.shift(); 
    37323735        if (source) { 
    37333736          lock = this.display_message(this.get_label('searching'), 'loading'); 
    3734           xhr = this.http_post(props.action, '_search='+urlencode(s_val)+'&_id='+reqid 
     3737          xhr = this.http_post(data.action, '_search='+urlencode(value)+'&_id='+reqid 
    37353738            +'&_source='+urlencode(source), lock); 
    37363739 
     
    37393742        } 
    37403743      } 
    3741       else if (!maxlen && !this.ksearch_msg) 
    3742         this.ksearch_msg = this.display_message(this.get_label('autocompletemore')); 
     3744      else if (!maxlen) { 
     3745        if (!this.ksearch_msg) 
     3746          this.ksearch_msg = this.display_message(this.get_label('autocompletemore')); 
     3747        // abort pending searches 
     3748        this.ksearch_abort(); 
     3749      } 
    37433750    } 
    37443751  }; 
     
    37733780  }; 
    37743781 
    3775   // Aborts pending autocomplete requests 
     3782  // Clears autocomplete data/requests 
    37763783  this.ksearch_destroy = function() 
    37773784  { 
    3778     var i, len, ac = this.ksearch_data; 
    3779  
    3780     if (!ac) 
    3781       return; 
    3782  
    3783     for (i=0, len=ac.locks.length; i<len; i++) 
    3784       this.abort_request({request: ac.requests[i], lock: ac.locks[i]}); 
     3785    this.ksearch_abort(); 
    37853786 
    37863787    if (this.ksearch_info) 
     
    37943795    this.ksearch_msg = null; 
    37953796  } 
     3797 
     3798  // Aborts pending autocomplete requests 
     3799  this.ksearch_abort = function() 
     3800  { 
     3801    var i, len, ac = this.ksearch_data; 
     3802 
     3803    if (!ac) 
     3804      return; 
     3805 
     3806    for (i=0, len=ac.locks.length; i<len; i++) 
     3807      this.abort_request({request: ac.requests[i], lock: ac.locks[i]}); 
     3808  }; 
     3809 
    37963810 
    37973811  /*********************************************************/ 
Note: See TracChangeset for help on using the changeset viewer.