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

📄 combobox.js

📁 对java中如何使用Ajax技术
💻 JS
📖 第 1 页 / 共 3 页
字号:
		_itemMouseOut: function(/*Event*/ evt){			if (evt.target === this.optionsListNode){ return; }			this._blurOptionNode();		},		onResize: function(){			// summary: this function is called when the input area has changed size			var inputSize = dojo.html.getContentBox(this.textInputNode);			if( inputSize.height <= 0 ){				// need more time to calculate size				dojo.lang.setTimeout(this, "onResize", 100);				return;			}			var buttonSize = { width: inputSize.height, height: inputSize.height};			dojo.html.setContentBox(this.downArrowNode, buttonSize);		},		fillInTemplate: function(/*Object*/ args, /*Object*/ frag){			// there's some browser specific CSS in ComboBox.css			dojo.html.applyBrowserClass(this.domNode);			var source = this.getFragNodeRef(frag);			if (! this.name && source.name){ this.name = source.name; }			this.comboBoxValue.name = this.name;			this.comboBoxSelectionValue.name = this.name+"_selected";			/* different nodes get different parts of the style */			dojo.html.copyStyle(this.domNode, source);			dojo.html.copyStyle(this.textInputNode, source);			dojo.html.copyStyle(this.downArrowNode, source);			with (this.downArrowNode.style){ // calculate these later				width = "0px";				height = "0px";			}			// Use specified data provider class; if no class is specified			// then use comboboxDataProvider or incrmentalComboBoxDataProvider			// depending on setting of mode			var dpClass;			if(this.dataProviderClass){				if(typeof this.dataProviderClass == "string"){					dpClass = dojo.evalObjPath(this.dataProviderClass)				}else{					dpClass = this.dataProviderClass;				}			}else{				if(this.mode == "remote"){					dpClass = dojo.widget.incrementalComboBoxDataProvider;				}else{					dpClass = dojo.widget.basicComboBoxDataProvider;				}			}			this.dataProvider = new dpClass(this, this.getFragNodeRef(frag));			this.popupWidget = new dojo.widget.createWidget("PopupContainer",				{toggle: this.dropdownToggle, toggleDuration: this.toggleDuration});			dojo.event.connect(this, 'destroy', this.popupWidget, 'destroy');			this.optionsListNode = this.popupWidget.domNode;			this.domNode.appendChild(this.optionsListNode);			dojo.html.addClass(this.optionsListNode, 'dojoComboBoxOptions');			dojo.event.connect(this.optionsListNode, 'onclick', this, '_selectOption');			dojo.event.connect(this.optionsListNode, 'onmouseover', this, '_onMouseOver');			dojo.event.connect(this.optionsListNode, 'onmouseout', this, '_onMouseOut');			// TODO: why does onmouseover and onmouseout connect to two separate handlers???			dojo.event.connect(this.optionsListNode, "onmouseover", this, "_itemMouseOver");			dojo.event.connect(this.optionsListNode, "onmouseout", this, "_itemMouseOut");		},		_openResultList: function(/*Array*/ results){			if (this.disabled){				return;			}			this._clearResultList();			if(!results.length){				this._hideResultList();			}			if(	(this.autoComplete)&&				(results.length)&&				(!this._prev_key_backspace)&&				(this.textInputNode.value.length > 0)){				var cpos = this._getCaretPos(this.textInputNode);				// only try to extend if we added the last character at the end of the input				if((cpos+1) > this.textInputNode.value.length){					// only add to input node as we would overwrite Capitalisation of chars					this.textInputNode.value += results[0][0].substr(cpos);					// build a new range that has the distance from the earlier					// caret position to the end of the first string selected					this._setSelectedRange(this.textInputNode, cpos, this.textInputNode.value.length);				}			}			var even = true;			while(results.length){				var tr = results.shift();				if(tr){					var td = document.createElement("div");					td.appendChild(document.createTextNode(tr[0]));					td.setAttribute("resultName", tr[0]);					td.setAttribute("resultValue", tr[1]);					td.className = "dojoComboBoxItem "+((even) ? "dojoComboBoxItemEven" : "dojoComboBoxItemOdd");					even = (!even);					this.optionsListNode.appendChild(td);				}			}			// show our list (only if we have content, else nothing)			this._showResultList();		},		_onFocusInput: function(){			this._hasFocus = true;		},		_onBlurInput: function(){			this._hasFocus = false;			this._handleBlurTimer(true, 500);		},		_handleBlurTimer: function(/*Boolean*/clear, /*Number*/ millisec){			// summary: collect all blur timers issues here			if(this.blurTimer && (clear || millisec)){				clearTimeout(this.blurTimer);			}			if(millisec){ // we ignore that zero is false and never sets as that never happens in this widget				this.blurTimer = dojo.lang.setTimeout(this, "_checkBlurred", millisec);			}		},		_onMouseOver: function(/*Event*/ evt){			// summary: needed in IE and Safari as inputTextNode loses focus when scrolling optionslist			if(!this._mouseover_list){				this._handleBlurTimer(true, 0);				this._mouseover_list = true;			}		},		_onMouseOut:function(/*Event*/ evt){			// summary: needed in IE and Safari as inputTextNode loses focus when scrolling optionslist			var relTarget = evt.relatedTarget;			try { // fixes #1807				if(!relTarget || relTarget.parentNode != this.optionsListNode){					this._mouseover_list = false;					this._handleBlurTimer(true, 100);					this._tryFocus();				}			}catch(e){}		},		_isInputEqualToResult: function(/*String*/ result){			var input = this.textInputNode.value;			if(!this.dataProvider.caseSensitive){				input = input.toLowerCase();				result = result.toLowerCase();			}			return (input == result);		},		_isValidOption: function(){			var tgt = dojo.html.firstElement(this.optionsListNode);			var isValidOption = false;			while(!isValidOption && tgt){				if(this._isInputEqualToResult(tgt.getAttribute("resultName"))){					isValidOption = true;				}else{					tgt = dojo.html.nextElement(tgt);				}			}			return isValidOption;		},		_checkBlurred: function(){			if(!this._hasFocus && !this._mouseover_list){				this._hideResultList();				// clear the list if the user empties field and moves away.				if(!this.textInputNode.value.length){					this.setAllValues("", "");					return;				}				var isValidOption = this._isValidOption();				// enforce selection from option list				if(this.forceValidOption && !isValidOption){					this.setAllValues("", "");					return;				}				if(!isValidOption){// clear					this.setSelectedValue("");				}			}		},		_selectOption: function(/*Event*/ evt){			var tgt = null;			if(!evt){				evt = { target: this._highlighted_option };			}			if(!dojo.html.isDescendantOf(evt.target, this.optionsListNode)){				// handle autocompletion where the the user has hit ENTER or TAB				// if the input is empty do nothing				if(!this.textInputNode.value.length){					return;				}				tgt = dojo.html.firstElement(this.optionsListNode);				// user has input value not in option list				if(!tgt || !this._isInputEqualToResult(tgt.getAttribute("resultName"))){					return;				}				// otherwise the user has accepted the autocompleted value			}else{				tgt = evt.target;			}			while((tgt.nodeType!=1)||(!tgt.getAttribute("resultName"))){				tgt = tgt.parentNode;				if(tgt === dojo.body()){					return false;				}			}			this.selectedResult = [tgt.getAttribute("resultName"), tgt.getAttribute("resultValue")];			this.setAllValues(tgt.getAttribute("resultName"), tgt.getAttribute("resultValue"));			if(!evt.noHide){				this._hideResultList();				this._setSelectedRange(this.textInputNode, 0, null);			}			this._tryFocus();		},		_clearResultList: function(){			if(this.optionsListNode.innerHTML){				this.optionsListNode.innerHTML = "";  // browser natively knows how to collect this memory			}		},		_hideResultList: function(){			this.popupWidget.close();		},		_showResultList: function(){			// Our dear friend IE doesnt take max-height so we need to calculate that on our own every time			var childs = this.optionsListNode.childNodes;			if(childs.length){				var visibleCount = Math.min(childs.length,this.maxListLength);				with(this.optionsListNode.style)				{					display = "";					if(visibleCount == childs.length){						//no scrollbar is required, so unset height to let browser calcuate it,						//as in css, overflow is already set to auto						height = "";					}else{						//show it first to get the correct dojo.style.getOuterHeight(childs[0])						//FIXME: shall we cache the height of the item?						height = visibleCount * dojo.html.getMarginBox(childs[0]).height +"px";					}					width = (dojo.html.getMarginBox(this.domNode).width-2)+"px";				}				this.popupWidget.open(this.domNode, this, this.downArrowNode);			}else{				this._hideResultList();			}		},		handleArrowClick: function(){			// summary: callback when arrow is clicked			this._handleBlurTimer(true, 0);			this._tryFocus();			if(this.popupWidget.isShowingNow){				this._hideResultList();			}else{				// forces full population of results, if they click				// on the arrow it means they want to see more options				this._startSearch("");			}		},		_tryFocus: function(){			try {				this.textInputNode.focus();			} catch (e){				// element isn't focusable if disabled, or not visible etc - not easy to test for.	 		};		},		_startSearchFromInput: function(){			this._startSearch(this.textInputNode.value);		},		_startSearch: function(/*String*/ key){			this.dataProvider.startSearch(key, dojo.lang.hitch(this, "_openResultList"));		},		postCreate: function(){			this.onResize();			// TODO: add these attach events to template			dojo.event.connect(this.textInputNode, "onblur", this, "_onBlurInput");			dojo.event.connect(this.textInputNode, "onfocus", this, "_onFocusInput");			if (this.disabled){				this.disable();			}			var s = dojo.widget.html.stabile.getState(this.widgetId);			if (s){				this.setState(s);			}		}	});

⌨️ 快捷键说明

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