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

📄 autocomplete-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
    }    YAHOO.log("Did not find subset match for query subset \"" + sQuery + "\"" , "info", this.toString());    return null;};/** * Executed by DataSource (within DataSource scope via doBeforeParseData()) to * handle responseStripAfter cleanup. * * @method preparseRawResponse * @param sQuery {String} Query string. * @return {Object} oParsedResponse or null.  */YAHOO.widget.AutoComplete.prototype.preparseRawResponse = function(oRequest, oFullResponse, oCallback) {    var nEnd = ((this.responseStripAfter !== "") && (oFullResponse.indexOf)) ?        oFullResponse.indexOf(this.responseStripAfter) : -1;    if(nEnd != -1) {        oFullResponse = oFullResponse.substring(0,nEnd);    }    return oFullResponse;};/** * Executed by DataSource (within DataSource scope via doBeforeCallback()) to * filter results through a simple client-side matching algorithm.  * * @method filterResults * @param sQuery {String} Original request. * @param oFullResponse {Object} Full response object. * @param oParsedResponse {Object} Parsed response object. * @param oCallback {Object} Callback object.  * @return {Object} Filtered response object. */YAHOO.widget.AutoComplete.prototype.filterResults = function(sQuery, oFullResponse, oParsedResponse, oCallback) {    // Only if a query string is available to match against    if(sQuery && sQuery !== "") {        // First make a copy of the oParseResponse        oParsedResponse = YAHOO.widget.AutoComplete._cloneObject(oParsedResponse);                var oAC = oCallback.scope,            oDS = this,            allResults = oParsedResponse.results, // the array of results            filteredResults = [], // container for filtered results            bMatchFound = false,            bMatchCase = (oDS.queryMatchCase || oAC.queryMatchCase), // backward compat            bMatchContains = (oDS.queryMatchContains || oAC.queryMatchContains); // backward compat                    // Loop through each result object...        for(var i = allResults.length-1; i >= 0; i--) {            var oResult = allResults[i];            // Grab the data to match against from the result object...            var sResult = null;                        // Result object is a simple string already            if(YAHOO.lang.isString(oResult)) {                sResult = oResult;            }            // Result object is an array of strings            else if(YAHOO.lang.isArray(oResult)) {                sResult = oResult[0];                        }            // Result object is an object literal of strings            else if(this.responseSchema.fields) {                var key = this.responseSchema.fields[0].key || this.responseSchema.fields[0];                sResult = oResult[key];            }            // Backwards compatibility            else if(this.key) {                sResult = oResult[this.key];            }                        if(YAHOO.lang.isString(sResult)) {                                var sKeyIndex = (bMatchCase) ?                sResult.indexOf(decodeURIComponent(sQuery)) :                sResult.toLowerCase().indexOf(decodeURIComponent(sQuery).toLowerCase());                // A STARTSWITH match is when the query is found at the beginning of the key string...                if((!bMatchContains && (sKeyIndex === 0)) ||                // A CONTAINS match is when the query is found anywhere within the key string...                (bMatchContains && (sKeyIndex > -1))) {                    // Stash the match                    filteredResults.unshift(oResult);                }            }        }        oParsedResponse.results = filteredResults;        YAHOO.log("Filtered " + filteredResults.length + " results against query \""  + sQuery + "\": " + YAHOO.lang.dump(filteredResults), "info", this.toString());    }    else {        YAHOO.log("Did not filter results against query", "info", this.toString());    }        return oParsedResponse;};/** * Handles response for display. This is the callback function method passed to * YAHOO.util.DataSourceBase#sendRequest so results from the DataSource are * returned to the AutoComplete instance. * * @method handleResponse * @param sQuery {String} Original request. * @param oResponse {Object} Response object. * @param oPayload {MIXED} (optional) Additional argument(s) */YAHOO.widget.AutoComplete.prototype.handleResponse = function(sQuery, oResponse, oPayload) {    if((this instanceof YAHOO.widget.AutoComplete) && this._sName) {        this._populateList(sQuery, oResponse, oPayload);    }};/** * Overridable method called before container is loaded with result data. * * @method doBeforeLoadData * @param sQuery {String} Original request. * @param oResponse {Object} Response object. * @param oPayload {MIXED} (optional) Additional argument(s) * @return {Boolean} Return true to continue loading data, false to cancel. */YAHOO.widget.AutoComplete.prototype.doBeforeLoadData = function(sQuery, oResponse, oPayload) {    return true;};/** * Overridable method that returns HTML markup for one result to be populated * as innerHTML of an <LI> element.  * * @method formatResult * @param oResultData {Object} Result data object. * @param sQuery {String} The corresponding query string. * @param sResultMatch {HTMLElement} The current query string.  * @return {String} HTML markup of formatted result data. */YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultData, sQuery, sResultMatch) {    var sMarkup = (sResultMatch) ? sResultMatch : "";    return sMarkup;};/** * Overridable method called before container expands allows implementers to access data * and DOM elements. * * @method doBeforeExpandContainer * @param elTextbox {HTMLElement} The text input box. * @param elContainer {HTMLElement} The container element. * @param sQuery {String} The query string. * @param aResults {Object[]}  An array of query results. * @return {Boolean} Return true to continue expanding container, false to cancel the expand. */YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(elTextbox, elContainer, sQuery, aResults) {    return true;};/** * Nulls out the entire AutoComplete instance and related objects, removes attached * event listeners, and clears out DOM elements inside the container. After * calling this method, the instance reference should be expliclitly nulled by * implementer, as in myDataTable = null. Use with caution! * * @method destroy */YAHOO.widget.AutoComplete.prototype.destroy = function() {    var instanceName = this.toString();    var elInput = this._elTextbox;    var elContainer = this._elContainer;    // Unhook custom events    this.textboxFocusEvent.unsubscribeAll();    this.textboxKeyEvent.unsubscribeAll();    this.dataRequestEvent.unsubscribeAll();    this.dataReturnEvent.unsubscribeAll();    this.dataErrorEvent.unsubscribeAll();    this.containerPopulateEvent.unsubscribeAll();    this.containerExpandEvent.unsubscribeAll();    this.typeAheadEvent.unsubscribeAll();    this.itemMouseOverEvent.unsubscribeAll();    this.itemMouseOutEvent.unsubscribeAll();    this.itemArrowToEvent.unsubscribeAll();    this.itemArrowFromEvent.unsubscribeAll();    this.itemSelectEvent.unsubscribeAll();    this.unmatchedItemSelectEvent.unsubscribeAll();    this.selectionEnforceEvent.unsubscribeAll();    this.containerCollapseEvent.unsubscribeAll();    this.textboxBlurEvent.unsubscribeAll();    this.textboxChangeEvent.unsubscribeAll();    // Unhook DOM events    YAHOO.util.Event.purgeElement(elInput, true);    YAHOO.util.Event.purgeElement(elContainer, true);    // Remove DOM elements    elContainer.innerHTML = "";    // Null out objects    for(var key in this) {        if(YAHOO.lang.hasOwnProperty(this, key)) {            this[key] = null;        }    }    YAHOO.log("AutoComplete instance destroyed: " + instanceName);};///////////////////////////////////////////////////////////////////////////////// Public events////////////////////////////////////////////////////////////////////////////////** * Fired when the input field receives focus. * * @event textboxFocusEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null;/** * Fired when the input field receives key input. * * @event textboxKeyEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param nKeycode {Number} The keycode number. */YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null;/** * Fired when the AutoComplete instance makes a request to the DataSource. *  * @event dataRequestEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sQuery {String} The query string.  * @param oRequest {Object} The request. */YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null;/** * Fired when the AutoComplete instance receives query results from the data * source. * * @event dataReturnEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sQuery {String} The query string. * @param aResults {Object[]} Results array. */YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null;/** * Fired when the AutoComplete instance does not receive query results from the * DataSource due to an error. * * @event dataErrorEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sQuery {String} The query string. */YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null;/** * Fired when the results container is populated. * * @event containerPopulateEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.containerPopulateEvent = null;/** * Fired when the results container is expanded. * * @event containerExpandEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sQuery {String} The query string. * @param aResults {Object[]} Results array. */YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null;/** * Fired when the input field has been prefilled by the type-ahead * feature.  * * @event typeAheadEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sQuery {String} The query string. * @param sPrefill {String} The prefill string. */YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null;/** * Fired when result item has been moused over. * * @event itemMouseOverEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param elItem {HTMLElement} The <li&gt element item moused to. */YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null;/** * Fired when result item has been moused out. * * @event itemMouseOutEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param elItem {HTMLElement} The <li> element item moused from. */YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null;/** * Fired when result item has been arrowed to.  * * @event itemArrowToEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param elItem {HTMLElement} The <li> element item arrowed to. */YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null;/** * Fired when result item has been arrowed away from. * * @event itemArrowFromEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param elItem {HTMLElement} The <li> element item arrowed from. */YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null;/** * Fired when an item is selected via mouse click, ENTER key, or TAB key. * * @event itemSelectEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param elItem {HTMLElement} The selected <li> element item. * @param oData {Object} The data returned for the item, either as an object, * or mapped from the schema into an array. */YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null;/** * Fired when a user selection does not match any of the displayed result items. * * @event unmatchedItemSelectEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. * @param sSelection {String} The selected string.   */YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null;/** * Fired if forceSelection is enabled and the user's input has been cleared * because it did not match one of the returned query results. * * @event selectionEnforceEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null;/** * Fired when the results container is collapsed. * * @event containerCollapseEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null;/** * Fired when the input field loses focus. * * @event textboxBlurEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null;/** * Fired when the input field value has changed when it loses focus. * * @event textboxChangeEvent * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. */YAHOO.widget.AutoComplete.prototype.textboxChangeEvent = null;///////////////////////////////////////////////////////////////////////////////// Private member variables//

⌨️ 快捷键说明

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