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

📄 autocomplete.js

📁 原名JSPackager
💻 JS
📖 第 1 页 / 共 3 页
字号:
YAHOO.widget.AutoComplete = function (inputEl, containerEl, oDataSource, oConfigs) {if (inputEl && containerEl && oDataSource) {if (oDataSource && (oDataSource instanceof YAHOO.widget.DataSource)) {this.dataSource = oDataSource;} else {return;}if (YAHOO.util.Dom.inDocument(inputEl)) {if (typeof inputEl == "string") {this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + inputEl;this._oTextbox = document.getElementById(inputEl);} else {this._sName = (inputEl.id) ? "instance" + YAHOO.widget.AutoComplete._nIndex + " " + inputEl.id : "instance" + YAHOO.widget.AutoComplete._nIndex;this._oTextbox = inputEl;}} else {return;}if (YAHOO.util.Dom.inDocument(containerEl)) {if (typeof containerEl == "string") {this._oContainer = document.getElementById(containerEl);} else {this._oContainer = containerEl;}if (this._oContainer.style.display == "none") {}} else {return;}if (typeof oConfigs == "object") {for (var sConfig in oConfigs) {if (sConfig) {this[sConfig] = oConfigs[sConfig];}}}this._initContainer();this._initProps();this._initList();this._initContainerHelpers();var oSelf = this;var oTextbox = this._oTextbox;var oContent = this._oContainer._oContent;YAHOO.util.Event.addListener(oTextbox, "keyup", oSelf._onTextboxKeyUp, oSelf);YAHOO.util.Event.addListener(oTextbox, "keydown", oSelf._onTextboxKeyDown, oSelf);YAHOO.util.Event.addListener(oTextbox, "keypress", oSelf._onTextboxKeyPress, oSelf);YAHOO.util.Event.addListener(oTextbox, "focus", oSelf._onTextboxFocus, oSelf);YAHOO.util.Event.addListener(oTextbox, "blur", oSelf._onTextboxBlur, oSelf);YAHOO.util.Event.addListener(oContent, "mouseover", oSelf._onContainerMouseover, oSelf);YAHOO.util.Event.addListener(oContent, "mouseout", oSelf._onContainerMouseout, oSelf);YAHOO.util.Event.addListener(oContent, "scroll", oSelf._onContainerScroll, oSelf);YAHOO.util.Event.addListener(oContent, "resize", oSelf._onContainerResize, oSelf);if (oTextbox.form) {YAHOO.util.Event.addListener(oTextbox.form, "submit", oSelf._onFormSubmit, oSelf);}this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this);this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this);this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this);this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this);this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this);this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this);this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this);this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this);this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this);this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this);this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this);this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this);this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this);this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this);this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this);this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this);oTextbox.setAttribute("autocomplete", "off");YAHOO.widget.AutoComplete._nIndex++;} else {}};YAHOO.widget.AutoComplete.prototype.dataSource = null;YAHOO.widget.AutoComplete.prototype.minQueryLength = 1;YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10;YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5;YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight";YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null;YAHOO.widget.AutoComplete.prototype.delimChar = null;YAHOO.widget.AutoComplete.prototype.autoHighlight = true;YAHOO.widget.AutoComplete.prototype.typeAhead = false;YAHOO.widget.AutoComplete.prototype.animHoriz = false;YAHOO.widget.AutoComplete.prototype.animVert = true;YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3;YAHOO.widget.AutoComplete.prototype.forceSelection = false;YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true;YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false;YAHOO.widget.AutoComplete.prototype.useIFrame = false;YAHOO.widget.AutoComplete.prototype.iFrameSrc = "about:blank";YAHOO.widget.AutoComplete.prototype.useShadow = false;YAHOO.widget.AutoComplete.prototype.getName = function () {return this._sName;};YAHOO.widget.AutoComplete.prototype.toString = function () {return "AutoComplete " + this._sName;};YAHOO.widget.AutoComplete.prototype.getListItems = function () {return this._aListItems;};YAHOO.widget.AutoComplete.prototype.getListItemData = function (oListItem) {if (oListItem._oResultData) {return oListItem._oResultData;} else {return false;}};YAHOO.widget.AutoComplete.prototype.setHeader = function (sHeader) {if (sHeader) {if (this._oContainer._oContent._oHeader) {this._oContainer._oContent._oHeader.innerHTML = sHeader;this._oContainer._oContent._oHeader.style.display = "block";}} else {this._oContainer._oContent._oHeader.innerHTML = "";this._oContainer._oContent._oHeader.style.display = "none";}};YAHOO.widget.AutoComplete.prototype.setFooter = function (sFooter) {if (sFooter) {if (this._oContainer._oContent._oFooter) {this._oContainer._oContent._oFooter.innerHTML = sFooter;this._oContainer._oContent._oFooter.style.display = "block";}} else {this._oContainer._oContent._oFooter.innerHTML = "";this._oContainer._oContent._oFooter.style.display = "none";}};YAHOO.widget.AutoComplete.prototype.setBody = function (sBody) {if (sBody) {if (this._oContainer._oContent._oBody) {this._oContainer._oContent._oBody.innerHTML = sBody;this._oContainer._oContent._oBody.style.display = "block";this._oContainer._oContent.style.display = "block";}} else {this._oContainer._oContent._oBody.innerHTML = "";this._oContainer._oContent.style.display = "none";}this._maxResultsDisplayed = 0;};YAHOO.widget.AutoComplete.prototype.formatResult = function (oResultItem, sQuery) {var sResult = oResultItem[0];if (sResult) {return sResult;} else {return "";}};YAHOO.widget.AutoComplete.prototype.sendQuery = function (sQuery) {if (sQuery) {this._sendQuery(sQuery);} else {return;}};YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null;YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null;YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null;YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null;YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null;YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null;YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null;YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null;YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null;YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null;YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null;YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null;YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null;YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null;YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null;YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null;YAHOO.widget.AutoComplete._nIndex = 0;YAHOO.widget.AutoComplete.prototype._sName = null;YAHOO.widget.AutoComplete.prototype._oTextbox = null;YAHOO.widget.AutoComplete.prototype._bFocused = true;YAHOO.widget.AutoComplete.prototype._oAnim = null;YAHOO.widget.AutoComplete.prototype._oContainer = null;YAHOO.widget.AutoComplete.prototype._bContainerOpen = false;YAHOO.widget.AutoComplete.prototype._bOverContainer = false;YAHOO.widget.AutoComplete.prototype._aListItems = null;YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0;YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0;YAHOO.widget.AutoComplete.prototype._sCurQuery = null;YAHOO.widget.AutoComplete.prototype._sSavedQuery = null;YAHOO.widget.AutoComplete.prototype._oCurItem = null;YAHOO.widget.AutoComplete.prototype._bItemSelected = false;YAHOO.widget.AutoComplete.prototype._nKeyCode = null;YAHOO.widget.AutoComplete.prototype._nDelayID = -1;YAHOO.widget.AutoComplete.prototype._initProps = function () {var minQueryLength = this.minQueryLength;if (isNaN(minQueryLength) || (minQueryLength < 1)) {minQueryLength = 1;}var maxResultsDisplayed = this.maxResultsDisplayed;if (isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) {this.maxResultsDisplayed = 10;}var queryDelay = this.queryDelay;if (isNaN(this.queryDelay) || (this.queryDelay < 0)) {this.queryDelay = 0.5;}var aDelimChar = (this.delimChar) ? this.delimChar : null;if (aDelimChar) {if (typeof aDelimChar == "string") {this.delimChar = [aDelimChar];} else {if (aDelimChar.constructor != Array) {this.delimChar = null;}}}var animSpeed = this.animSpeed;if ((this.animHoriz || this.animVert) && YAHOO.util.Anim) {if (isNaN(animSpeed) || (animSpeed < 0)) {animSpeed = 0.3;}if (!this._oAnim) {oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed);this._oAnim = oAnim;} else {this._oAnim.duration = animSpeed;}}if (this.forceSelection && this.delimChar) {}if (this.alwaysShowContainer && (this.useShadow || this.useIFrame)) {}if (this.alwaysShowContainer) {this._bContainerOpen = true;}};YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function () {if (this.useShadow && !this._oContainer._oShadow) {var oShadow = document.createElement("div");oShadow.className = "yui-ac-shadow";this._oContainer._oShadow = this._oContainer.appendChild(oShadow);}if (this.useIFrame && !this._oContainer._oIFrame) {var oIFrame = document.createElement("iframe");oIFrame.src = this.iFrameSrc;oIFrame.frameBorder = 0;oIFrame.scrolling = "no";oIFrame.style.position = "absolute";oIFrame.style.width = "100%";oIFrame.style.height = "100%";this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame);}};YAHOO.widget.AutoComplete.prototype._initContainer = function () {if (!this._oContainer._oContent) {var oContent = document.createElement("div");oContent.className = "yui-ac-content";oContent.style.display = "none";this._oContainer._oContent = this._oContainer.appendChild(oContent);var oHeader = document.createElement("div");oHeader.className = "yui-ac-hd";oHeader.style.display = "none";this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader);var oBody = document.createElement("div");oBody.className = "yui-ac-bd";this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody);var oFooter = document.createElement("div");oFooter.className = "yui-ac-ft";oFooter.style.display = "none";this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter);} else {}};YAHOO.widget.AutoComplete.prototype._initList = function () {this._aListItems = [];while (this._oContainer._oContent._oBody.hasChildNodes()) {var oldListItems = this.getListItems();if (oldListItems) {for (var oldi = oldListItems.length - 1; oldi >= 0; i--) {oldListItems[oldi] = null;}}this._oContainer._oContent._oBody.innerHTML = "";}var oList = document.createElement("ul");oList = this._oContainer._oContent._oBody.appendChild(oList);for (var i = 0; i < this.maxResultsDisplayed; i++) {var oItem = document.createElement("li");oItem = oList.appendChild(oItem);this._aListItems[i] = oItem;this._initListItem(oItem, i);}this._maxResultsDisplayed = this.maxResultsDisplayed;};YAHOO.widget.AutoComplete.prototype._initListItem = function (oItem, nItemIndex) {var oSelf = this;oItem.style.display = "none";oItem._nItemIndex = nItemIndex;oItem.mouseover = oItem.mouseout = oItem.onclick = null;YAHOO.util.Event.addListener(oItem, "mouseover", oSelf._onItemMouseover, oSelf);YAHOO.util.Event.addListener(oItem, "mouseout", oSelf._onItemMouseout, oSelf);YAHOO.util.Event.addListener(oItem, "click", oSelf._onItemMouseclick, oSelf);};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);};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);};YAHOO.widget.AutoComplete.prototype._onItemMouseclick = function (v, oSelf) {oSelf._toggleHighlight(this, "to");oSelf._selectItem(this);};YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function (v, oSelf) {oSelf._bOverContainer = true;

⌨️ 快捷键说明

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