⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autocomplete.js

📁 SugarCRM5.1 开源PHP客户关系管理系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
            }            // User is keying up            else {                // Top of selected item is above scroll area                if(oNewItem.offsetTop < oContent.scrollTop) {                    // Set top of scroll area to top of selected item                    this._oContainer._oContent.scrollTop = oNewItem.offsetTop;                }                // Top of selected item is below scroll area                else if(oNewItem.offsetTop > (oContent.scrollTop + oContent.offsetHeight)) {                    // Set bottom of selected item to bottom of scroll area                    this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight;                }            }        }        this._toggleHighlight(oNewItem, "to");        this.itemArrowToEvent.fire(this, oNewItem);        if(this.typeAhead) {            this._updateValue(oNewItem);        }    }};///////////////////////////////////////////////////////////////////////////////// Private event handlers////////////////////////////////////////////////////////////////////////////////** * Handles &lt;li&gt; element mouseover events in the container. * * @method _onItemMouseover * @param v {HTMLEvent} The mouseover event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onItemMouseover = function(v,oSelf) {    if(oSelf.prehighlightClassName) {        oSelf._togglePrehighlight(this,"mouseover");    }    else {        oSelf._toggleHighlight(this,"to");    }    oSelf.itemMouseOverEvent.fire(oSelf, this);};/** * Handles &lt;li&gt; element mouseout events in the container. * * @method _onItemMouseout * @param v {HTMLEvent} The mouseout event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onItemMouseout = function(v,oSelf) {    if(oSelf.prehighlightClassName) {        oSelf._togglePrehighlight(this,"mouseout");    }    else {        oSelf._toggleHighlight(this,"from");    }    oSelf.itemMouseOutEvent.fire(oSelf, this);};/** * Handles &lt;li&gt; element click events in the container. * * @method _onItemMouseclick * @param v {HTMLEvent} The click event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onItemMouseclick = function(v,oSelf) {    // In case item has not been moused over    oSelf._toggleHighlight(this,"to");    oSelf._selectItem(this);};/** * Handles container mouseover events. * * @method _onContainerMouseover * @param v {HTMLEvent} The mouseover event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function(v,oSelf) {    oSelf._bOverContainer = true;};/** * Handles container mouseout events. * * @method _onContainerMouseout * @param v {HTMLEvent} The mouseout event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function(v,oSelf) {    oSelf._bOverContainer = false;    // If container is still active    if(oSelf._oCurItem) {        oSelf._toggleHighlight(oSelf._oCurItem,"to");    }};/** * Handles container scroll events. * * @method _onContainerScroll * @param v {HTMLEvent} The scroll event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onContainerScroll = function(v,oSelf) {    oSelf._oTextbox.focus();};/** * Handles container resize events. * * @method _onContainerResize * @param v {HTMLEvent} The resize event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onContainerResize = function(v,oSelf) {    oSelf._toggleContainerHelpers(oSelf._bContainerOpen);};/** * Handles textbox keydown events of functional keys, mainly for UI behavior. * * @method _onTextboxKeyDown * @param v {HTMLEvent} The keydown event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function(v,oSelf) {    var nKeyCode = v.keyCode;    switch (nKeyCode) {        case 9: // tab            if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) {                if(oSelf._bContainerOpen) {                    YAHOO.util.Event.stopEvent(v);                }            }            // select an item or clear out            if(oSelf._oCurItem) {                oSelf._selectItem(oSelf._oCurItem);            }            else {                oSelf._toggleContainer(false);            }            break;        case 13: // enter            if(oSelf._nKeyCode != nKeyCode) {                if(oSelf._bContainerOpen) {                    YAHOO.util.Event.stopEvent(v);                }            }            if(oSelf._oCurItem) {                oSelf._selectItem(oSelf._oCurItem);            }            else {                oSelf._toggleContainer(false);            }            break;        case 27: // esc            oSelf._toggleContainer(false);            return;        case 39: // right            oSelf._jumpSelection();            break;        case 38: // up            YAHOO.util.Event.stopEvent(v);            oSelf._moveSelection(nKeyCode);            break;        case 40: // down            YAHOO.util.Event.stopEvent(v);            oSelf._moveSelection(nKeyCode);            break;        default:            break;    }};/** * Handles textbox keypress events. * @method _onTextboxKeyPress * @param v {HTMLEvent} The keypress event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function(v,oSelf) {    var nKeyCode = v.keyCode;        //Expose only to Mac browsers, where stopEvent is ineffective on keydown events (bug 790337)        var isMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1);        if(isMac) {            switch (nKeyCode) {            case 9: // tab                if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) {                    YAHOO.util.Event.stopEvent(v);                }                break;            case 13: // enter                if(oSelf._nKeyCode != nKeyCode) {                    YAHOO.util.Event.stopEvent(v);                }                break;            case 38: // up            case 40: // down                YAHOO.util.Event.stopEvent(v);                break;            default:                break;            }        }        //TODO: (?) limit only to non-IE, non-Mac-FF for Korean IME support (bug 811948)        // Korean IME detected        else if(nKeyCode == 229) {            oSelf._queryInterval = setInterval(function() { oSelf._onIMEDetected(oSelf); },500);        }};/** * Handles textbox keyup events that trigger queries. * * @method _onTextboxKeyUp * @param v {HTMLEvent} The keyup event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function(v,oSelf) {    // Check to see if any of the public properties have been updated    oSelf._initProps();    var nKeyCode = v.keyCode;    oSelf._nKeyCode = nKeyCode;    var sText = this.value; //string in textbox    // Filter out chars that don't trigger queries    if(oSelf._isIgnoreKey(nKeyCode) || (sText.toLowerCase() == oSelf._sCurQuery)) {        return;    }    else {        oSelf.textboxKeyEvent.fire(oSelf, nKeyCode);    }    // Set timeout on the request    if(oSelf.queryDelay > 0) {        var nDelayID =            setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay * 1000));        if(oSelf._nDelayID != -1) {            clearTimeout(oSelf._nDelayID);        }        oSelf._nDelayID = nDelayID;    }    else {        // No delay so send request immediately        oSelf._sendQuery(sText);    }};/** * Handles text input box receiving focus. * * @method _onTextboxFocus * @param v {HTMLEvent} The focus event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) {    oSelf._oTextbox.setAttribute("autocomplete","off");    oSelf._bFocused = true;    if(!oSelf._bItemSelected) {        oSelf.textboxFocusEvent.fire(oSelf);    }};/** * Handles text input box losing focus. * * @method _onTextboxBlur * @param v {HTMLEvent} The focus event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onTextboxBlur = function (v,oSelf) {    // Don't treat as a blur if it was a selection via mouse click    if(!oSelf._bOverContainer || (oSelf._nKeyCode == 9)) {        // Current query needs to be validated        if(!oSelf._bItemSelected) {            if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && !oSelf._textMatchesOption())) {                if(oSelf.forceSelection) {                    oSelf._clearSelection();                }                else {                    oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery);                }            }        }        if(oSelf._bContainerOpen) {            oSelf._toggleContainer(false);        }        oSelf._cancelIntervalDetection(oSelf);        oSelf._bFocused = false;        oSelf.textboxBlurEvent.fire(oSelf);    }};/** * Handles form submission event. * * @method _onFormSubmit * @param v {HTMLEvent} The submit event. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @private */YAHOO.widget.AutoComplete.prototype._onFormSubmit = function(v,oSelf) {    if(oSelf.allowBrowserAutocomplete) {        oSelf._oTextbox.setAttribute("autocomplete","on");    }    else {        oSelf._oTextbox.setAttribute("autocomplete","off");    }};/****************************************************************************//****************************************************************************//****************************************************************************//** * The DataSource classes manages sending a request and returning response from a live * database. Supported data include local JavaScript arrays and objects and databases * accessible via XHR connections. Supported response formats include JavaScript arrays, * JSON, XML, and flat-file textual data. *   * @class DataSource * @constructor */YAHOO.widget.DataSource = function() {     /* abstract class */};///////////////////////////////////////////////////////////////////////////////// Public constants////////////////////////////////////////////////////////////////////////////////** * Error message for null data responses. * * @property ERROR_DATANULL * @type String * @static * @final */YAHOO.widget.DataSource.ERROR_DATANULL = "Response data was null";/** * Error message for data responses with parsing errors. * * @property ERROR_DATAPARSE * @type String * @static * @final */YAHOO.widget.DataSource.ERROR_DATAPARSE = "Response data could not be parsed";///////////////////////////////////////////////////////////////////////////////// Public member variables////////////////////////////////////////////////////////////////////////////////** * Max size of the local cache.  Set to 0 to turn off caching.  Caching is * useful to reduce the number of server connections.  Recommended only for data * sources that return comprehensive results for queries or when stale data is * not an issue. * * @property maxCacheEntries * @type Number * @default 15 */YAHOO.widget.DataSource.prototype.maxCacheEntries = 15;/** * Use this to equate cache matching with the type of matching done by your live * data source. If caching is on and queryMatchContains is true, the cache * returns results that "contain" the query string. By default, * queryMatchContains is set to false, meaning the cache only returns results * that "start with" the query string. * * @property queryMatchContains * @type Boolean * @default false */YAHOO.widget.DataSou

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -