📄 autocomplete.js
字号:
};YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function (v, oSelf) {oSelf._bOverContainer = false;if (oSelf._oCurItem) {oSelf._toggleHighlight(oSelf._oCurItem, "to");}};YAHOO.widget.AutoComplete.prototype._onContainerScroll = function (v, oSelf) {oSelf._oTextbox.focus();};YAHOO.widget.AutoComplete.prototype._onContainerResize = function (v, oSelf) {oSelf._toggleContainerHelpers(oSelf._bContainerOpen);};YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function (v, oSelf) {var nKeyCode = v.keyCode;switch (nKeyCode) {case 9:if (oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) {if (oSelf._bContainerOpen) {YAHOO.util.Event.stopEvent(v);}}if (oSelf._oCurItem) {oSelf._selectItem(oSelf._oCurItem);} else {oSelf._clearList();}break;case 13:if (oSelf._nKeyCode != nKeyCode) {if (oSelf._bContainerOpen) {YAHOO.util.Event.stopEvent(v);}}if (oSelf._oCurItem) {oSelf._selectItem(oSelf._oCurItem);} else {oSelf._clearList();}break;case 27:oSelf._clearList();return;case 39:oSelf._jumpSelection();break;case 38:YAHOO.util.Event.stopEvent(v);oSelf._moveSelection(nKeyCode);break;case 40:YAHOO.util.Event.stopEvent(v);oSelf._moveSelection(nKeyCode);break;default:break;}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function (v, oSelf) {var nKeyCode = v.keyCode;switch (nKeyCode) {case 9:case 13:if ((oSelf._nKeyCode != nKeyCode)) {YAHOO.util.Event.stopEvent(v);}break;case 38:case 40:YAHOO.util.Event.stopEvent(v);break;default:break;}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function (v, oSelf) {oSelf._initProps();var nKeyCode = v.keyCode;oSelf._nKeyCode = nKeyCode;var sChar = String.fromCharCode(nKeyCode);var sText = this.value;if (oSelf._isIgnoreKey(nKeyCode) || (sText.toLowerCase() == oSelf._sCurQuery)) {return;} else {oSelf.textboxKeyEvent.fire(oSelf, nKeyCode);}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 {oSelf._sendQuery(sText);}};YAHOO.widget.AutoComplete.prototype._isIgnoreKey = function (nKeyCode) {if ((nKeyCode == 9) || (nKeyCode == 13) || (nKeyCode == 16) || (nKeyCode == 17) || (nKeyCode >= 18 && nKeyCode <= 20) || (nKeyCode == 27) || (nKeyCode >= 33 && nKeyCode <= 35) || (nKeyCode >= 36 && nKeyCode <= 38) || (nKeyCode == 40) || (nKeyCode >= 44 && nKeyCode <= 45)) {return true;}return false;};YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v, oSelf) {oSelf._oTextbox.setAttribute("autocomplete", "off");oSelf._bFocused = true;oSelf.textboxFocusEvent.fire(oSelf);};YAHOO.widget.AutoComplete.prototype._onTextboxBlur = function (v, oSelf) {if (!oSelf._bOverContainer || (oSelf._nKeyCode == 9)) {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._clearList();}oSelf._bFocused = false;oSelf.textboxBlurEvent.fire(oSelf);}};YAHOO.widget.AutoComplete.prototype._onFormSubmit = function (v, oSelf) {if (oSelf.allowBrowserAutocomplete) {oSelf._oTextbox.setAttribute("autocomplete", "on");} else {oSelf._oTextbox.setAttribute("autocomplete", "off");}};YAHOO.widget.AutoComplete.prototype._sendQuery = function (sQuery) {var aDelimChar = (this.delimChar) ? this.delimChar : null;if (aDelimChar) {var nDelimIndex = -1;for (var i = aDelimChar.length - 1; i >= 0; i--) {var nNewIndex = sQuery.lastIndexOf(aDelimChar[i]);if (nNewIndex > nDelimIndex) {nDelimIndex = nNewIndex;}}if (aDelimChar[i] == " ") {for (var j = aDelimChar.length - 1; j >= 0; j--) {if (sQuery[nDelimIndex - 1] == aDelimChar[j]) {nDelimIndex--;break;}}}if (nDelimIndex > -1) {var nQueryStart = nDelimIndex + 1;while (sQuery.charAt(nQueryStart) == " ") {nQueryStart += 1;}this._sSavedQuery = sQuery.substring(0, nQueryStart);sQuery = sQuery.substr(nQueryStart);} else {if (sQuery.indexOf(this._sSavedQuery) < 0) {this._sSavedQuery = null;}}}if (sQuery.length < this.minQueryLength) {if (this._nDelayID != -1) {clearTimeout(this._nDelayID);}this._clearList();return;}sQuery = encodeURIComponent(sQuery);this._nDelayID = -1;this.dataRequestEvent.fire(this, sQuery);this.dataSource.getResults(this._populateList, sQuery, this);};YAHOO.widget.AutoComplete.prototype._clearList = function () {this._oContainer._oContent.scrollTop = 0;var aItems = this._aListItems;if (aItems && (aItems.length > 0)) {for (var i = aItems.length - 1; i >= 0; i--) {aItems[i].style.display = "none";}}if (this._oCurItem) {this._toggleHighlight(this._oCurItem, "from");}this._oCurItem = null;this._nDisplayedItems = 0;this._sCurQuery = null;this._toggleContainer(false);};YAHOO.widget.AutoComplete.prototype._populateList = function (sQuery, aResults, oSelf) {if (aResults === null) {oSelf.dataErrorEvent.fire(oSelf, sQuery);}if (!oSelf._bFocused || !aResults) {return;}var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);var contentStyle = oSelf._oContainer._oContent.style;contentStyle.width = (!isOpera) ? null : "";contentStyle.height = (!isOpera) ? null : "";var sCurQuery = decodeURIComponent(sQuery);oSelf._sCurQuery = sCurQuery;oSelf._bItemSelected = false;if (oSelf._maxResultsDisplayed != oSelf.maxResultsDisplayed) {oSelf._initList();}var nItems = Math.min(aResults.length, oSelf.maxResultsDisplayed);oSelf._nDisplayedItems = nItems;if (nItems > 0) {oSelf._initContainerHelpers();var aItems = oSelf._aListItems;for (var i = nItems - 1; i >= 0; i--) {var oItemi = aItems[i];var oResultItemi = aResults[i];oItemi.innerHTML = oSelf.formatResult(oResultItemi, sCurQuery);oItemi.style.display = "list-item";oItemi._sResultKey = oResultItemi[0];oItemi._oResultData = oResultItemi;}for (var j = aItems.length - 1; j >= nItems; j--) {var oItemj = aItems[j];oItemj.innerHTML = null;oItemj.style.display = "none";oItemj._sResultKey = null;oItemj._oResultData = null;}if (oSelf.autoHighlight) {var oFirstItem = aItems[0];oSelf._toggleHighlight(oFirstItem, "to");oSelf.itemArrowToEvent.fire(oSelf, oFirstItem);oSelf._typeAhead(oFirstItem, sQuery);} else {oSelf._oCurItem = null;}oSelf._toggleContainer(true);} else {oSelf._clearList();}oSelf.dataReturnEvent.fire(oSelf, sQuery, aResults);};YAHOO.widget.AutoComplete.prototype._clearSelection = function () {var sValue = this._oTextbox.value;var sChar = (this.delimChar) ? this.delimChar[0] : null;var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length - 2) : -1;if (nIndex > -1) {this._oTextbox.value = sValue.substring(0, nIndex);} else {this._oTextbox.value = "";}this._sSavedQuery = this._oTextbox.value;this.selectionEnforceEvent.fire(this);};YAHOO.widget.AutoComplete.prototype._textMatchesOption = function () {var foundMatch = false;for (var i = this._nDisplayedItems - 1; i >= 0; i--) {var oItem = this._aListItems[i];var sMatch = oItem._sResultKey.toLowerCase();if (sMatch == this._sCurQuery.toLowerCase()) {foundMatch = true;break;}}return (foundMatch);};YAHOO.widget.AutoComplete.prototype._typeAhead = function (oItem, sQuery) {if (!this.typeAhead) {return;}var oTextbox = this._oTextbox;var sValue = this._oTextbox.value;if (!oTextbox.setSelectionRange && !oTextbox.createTextRange) {return;}var nStart = sValue.length;this._updateValue(oItem);var nEnd = oTextbox.value.length;this._selectText(oTextbox, nStart, nEnd);var sPrefill = oTextbox.value.substr(nStart, nEnd);this.typeAheadEvent.fire(this, sQuery, sPrefill);};YAHOO.widget.AutoComplete.prototype._selectText = function (oTextbox, nStart, nEnd) {if (oTextbox.setSelectionRange) {oTextbox.setSelectionRange(nStart, nEnd);} else {if (oTextbox.createTextRange) {var oTextRange = oTextbox.createTextRange();oTextRange.moveStart("character", nStart);oTextRange.moveEnd("character", nEnd - oTextbox.value.length);oTextRange.select();} else {oTextbox.select();}}};YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers = function (bShow) {var bFireEvent = false;var width = this._oContainer._oContent.offsetWidth + "px";var height = this._oContainer._oContent.offsetHeight + "px";if (this.useIFrame && this._oContainer._oIFrame) {bFireEvent = true;if (this.alwaysShowContainer || bShow) {this._oContainer._oIFrame.style.width = width;this._oContainer._oIFrame.style.height = height;} else {this._oContainer._oIFrame.style.width = 0;this._oContainer._oIFrame.style.height = 0;}}if (this.useShadow && this._oContainer._oShadow) {bFireEvent = true;if (this.alwaysShowContainer || bShow) {this._oContainer._oShadow.style.width = width;this._oContainer._oShadow.style.height = height;} else {this._oContainer._oShadow.style.width = 0;this._oContainer._oShadow.style.height = 0;}}};YAHOO.widget.AutoComplete.prototype._toggleContainer = function (bShow) {if (this.alwaysShowContainer) {if (bShow) {this.containerExpandEvent.fire(this);} else {this.containerCollapseEvent.fire(this);}this._bContainerOpen = bShow;return;}var oContainer = this._oContainer;if (!bShow && !this._bContainerOpen) {oContainer._oContent.style.display = "none";return;}var oAnim = this._oAnim;if (oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) {if (!bShow) {this._toggleContainerHelpers(bShow);}if (oAnim.isAnimated()) {oAnim.stop();}var oClone = oContainer._oContent.cloneNode(true);oContainer.appendChild(oClone);oClone.style.top = "-9000px";oClone.style.display = "block";var wExp = oClone.offsetWidth;var hExp = oClone.offsetHeight;var wColl = (this.animHoriz) ? 0 : wExp;var hColl = (this.animVert) ? 0 : hExp;oAnim.attributes = (bShow) ? {width:{to:wExp}, height:{to:hExp}} : {width:{to:wColl}, height:{to:hColl}};if (bShow && !this._bContainerOpen) {oContainer._oContent.style.width = wColl + "px";oContainer._oContent.style.height = hColl + "px";} else {oContainer._oContent.style.width = wExp + "px";oContainer._oContent.style.height = hExp + "px";}oContainer.removeChild(oClone);oClone = null;var oSelf = this;var onAnimComplete = function () {oAnim.onComplete.unsubscribeAll();if (bShow) {oSelf.containerExpandEvent.fire(oSelf);} else {oContainer._oContent.style.display = "none";oSelf.containerCollapseEvent.fire(oSelf);}oSelf._toggleContainerHelpers(bShow);};oContainer._oContent.style.display = "block";oAnim.onComplete.subscribe(onAnimComplete);oAnim.animate();this._bContainerOpen = bShow;} else {if (bShow) {oContainer._oContent.style.display = "block";this.containerExpandEvent.fire(this);} else {oContainer._oContent.style.display = "none";this.containerCollapseEvent.fire(this);}this._toggleContainerHelpers(bShow);this._bContainerOpen = bShow;}};YAHOO.widget.AutoComplete.prototype._toggleHighlight = function (oNewItem, sType) {var sHighlight = this.highlightClassName;if (this._oCurItem) {YAHOO.util.Dom.removeClass(this._oCurItem, sHighlight);}if ((sType == "to") && sHighlight) {YAHOO.util.Dom.addClass(oNewItem, sHighlight);this._oCurItem = oNewItem;}};YAHOO.widget.AutoComplete.prototype._togglePrehighlight = function (oNewItem, sType) {if (oNewItem == this._oCurItem) {return;}var sPrehighlight = this.prehighlightClassName;if ((sType == "mouseover") && sPrehighlight) {YAHOO.util.Dom.addClass(oNewItem, sPrehighlight);} else {YAHOO.util.Dom.removeClass(oNewItem, sPrehighlight);}};YAHOO.widget.AutoComplete.prototype._updateValue = function (oItem) {var oTextbox = this._oTextbox;var sDelimChar = (this.delimChar) ? this.delimChar[0] : null;var sSavedQuery = this._sSavedQuery;var sResultKey = oItem._sResultKey;oTextbox.focus();oTextbox.value = "";if (sDelimChar) {if (sSavedQuery) {oTextbox.value = sSavedQuery;}oTextbox.value += sResultKey + sDelimChar;if (sDelimChar != " ") {oTextbox.value += " ";}} else {oTextbox.value = sResultKey;}if (oTextbox.type == "textarea") {oTextbox.scrollTop = oTextbox.scrollHeight;}var end = oTextbox.value.length;this._selectText(oTextbox, end, end);this._oCurItem = oItem;};YAHOO.widget.AutoComplete.prototype._selectItem = function (oItem) {this._bItemSelected = true;this._updateValue(oItem);this.itemSelectEvent.fire(this, oItem, oItem._oResultData);this._clearList();};YAHOO.widget.AutoComplete.prototype._jumpSelection = function () {if (!this.typeAhead) {return;} else {this._clearList();}};YAHOO.widget.AutoComplete.prototype._moveSelection = function (nKeyCode) {if (this._bContainerOpen) {var oCurItem = this._oCurItem;var nCurItemIndex = -1;if (oCurItem) {nCurItemIndex = oCurItem._nItemIndex;}var nNewItemIndex = (nKeyCode == 40) ? (nCurItemIndex + 1) : (nCurItemIndex - 1);if (nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) {return;}if (oCurItem) {this._toggleHighlight(oCurItem, "from");this.itemArrowFromEvent.fire(this, oCurItem);}if (nNewItemIndex == -1) {if (this.delimChar && this._sSavedQuery) {if (!this._textMatchesOption()) {this._oTextbox.value = this._sSavedQuery;} else {this._oTextbox.value = this._sSavedQuery + this._sCurQuery;}} else {this._oTextbox.value = this._sCurQuery;}this._oCurItem = null;return;}if (nNewItemIndex == -2) {this._clearList();return;}var oNewItem = this._aListItems[nNewItemIndex];if ((YAHOO.util.Dom.getStyle(this._oContainer._oContent, "overflow") == "auto") && (nNewItemIndex > -1) && (nNewItemIndex < this._nDisplayedItems)) {if (nKeyCode == 40) {if ((oNewItem.offsetTop + oNewItem.offsetHeight) > (this._oContainer._oContent.scrollTop + this._oContainer._oContent.offsetHeight)) {this._oContainer._oContent.scrollTop = (oNewItem.offsetTop + oNewItem.offsetHeight) - this._oContainer._oContent.offsetHeight;} else {if ((oNewItem.offsetTop + oNewItem.offsetHeight) < this._oContainer._oContent.scrollTop) {this._oContainer._oContent.scrollTop = oNewItem.offsetTop;}}} else {if (oNewItem.offsetTop < this._oContainer._oContent.scrollTop) {this._oContainer._oContent.scrollTop = oNewItem.offsetTop;} else {if (oNewItem.offsetTop > (this._oContainer._oContent.scrollTop + this._oContainer._oContent.offsetHeight)) {this._oContainer._oContent.scrollTop = (oNewItem.offsetTop + oNewItem.offsetHeight) - this._oContainer._oContent.offsetHeight;}}}}this._toggleHighlight(oNewItem, "to");this.itemArrowToEvent.fire(this, oNewItem);if (this.typeAhead) {this._updateValue(oNewItem);}}};YAHOO.widget.DataSource = function () {};YAHOO.widget.DataSource.prototype.ERROR_DATANULL = "Response data was null";YAHOO.widget.DataSource.prototype.ERROR_DATAPARSE = "Response data could not be parsed";YAHOO.widget.DataSource.prototype.maxCacheEntries = 15;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -