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

📄 combobox.js

📁 对java中如何使用Ajax技术
💻 JS
📖 第 1 页 / 共 3 页
字号:
		//		the <input> field		autoComplete: true,		// searchDelay: Integer		//		Delay in milliseconds between when user types something and we start		//		searching based on that value		searchDelay: 100,		// dataUrl: String		//		URL argument passed to data provider object (class name specified in "dataProviderClass")		//		An example of the URL format for the default data provider is		//		"remoteComboBoxData.js?search=%{searchString}"		dataUrl: "",		// fadeTime: Integer		//		Milliseconds duration of fadeout for drop down box		fadeTime: 200,		// maxListLength: Integer		//		 Limits list to X visible rows, scroll on rest		maxListLength: 8,		// mode: String		//		Mode must be specified unless dataProviderClass is specified.		//		"local" to inline search string, "remote" for JSON-returning live search		//		or "html" for dumber live search.		mode: "local",		// selectedResult: Array		//		(Read only) array specifying the value/label that the user selected		selectedResult: null,		// dataProviderClass: String		//		Name of data provider class (code that maps a search string to a list of values)		//		The class must match the interface demonstrated by dojo.widget.incrementalComboBoxDataProvider		dataProviderClass: "",		// buttonSrc: URI		//		URI for the down arrow icon to the right of the input box.		buttonSrc: dojo.uri.dojoUri("src/widget/templates/images/combo_box_arrow.png"),		// dropdownToggle: String		//		Animation effect for showing/displaying drop down box		dropdownToggle: "fade",		templatePath: dojo.uri.dojoUri("src/widget/templates/ComboBox.html"),		templateCssPath: dojo.uri.dojoUri("src/widget/templates/ComboBox.css"),		setValue: function(/*String*/ value){			// summary: Sets the value of the combobox			this.comboBoxValue.value = value;			if (this.textInputNode.value != value){ // prevent mucking up of selection				this.textInputNode.value = value;				// only change state and value if a new value is set				dojo.widget.html.stabile.setState(this.widgetId, this.getState(), true);				this.onValueChanged(value);			}		},		onValueChanged: function(/*String*/ value){			// summary: callback when value changes, for user to attach to		},		getValue: function(){			// summary: Rerturns combo box value			return this.comboBoxValue.value;		},		getState: function(){			// summary:			//	Used for saving state of ComboBox when navigates to a new			//	page, in case they then hit the browser's "Back" button.			return {value: this.getValue()};		},		setState: function(/*Object*/ state){			// summary:			//	Used for restoring state of ComboBox when has navigated to a new			//	page but then hits browser's "Back" button.			this.setValue(state.value);		},		enable:function(){			this.disabled=false;			this.textInputNode.removeAttribute("disabled");		},		disable: function(){			this.disabled = true;			this.textInputNode.setAttribute("disabled",true);		},		_getCaretPos: function(/*DomNode*/ element){			// khtml 3.5.2 has selection* methods as does webkit nightlies from 2005-06-22			if(dojo.lang.isNumber(element.selectionStart)){				// FIXME: this is totally borked on Moz < 1.3. Any recourse?				return element.selectionStart;			}else if(dojo.render.html.ie){				// in the case of a mouse click in a popup being handled,				// then the document.selection is not the textarea, but the popup				// var r = document.selection.createRange();				// hack to get IE 6 to play nice. What a POS browser.				var tr = document.selection.createRange().duplicate();				var ntr = element.createTextRange();				tr.move("character",0);				ntr.move("character",0);				try {					// If control doesnt have focus, you get an exception.					// Seems to happen on reverse-tab, but can also happen on tab (seems to be a race condition - only happens sometimes).					// There appears to be no workaround for this - googled for quite a while.					ntr.setEndPoint("EndToEnd", tr);					return String(ntr.text).replace(/\r/g,"").length;				} catch (e){					return 0; // If focus has shifted, 0 is fine for caret pos.				}			}		},		_setCaretPos: function(/*DomNode*/ element, /*Number*/ location){			location = parseInt(location);			this._setSelectedRange(element, location, location);		},		_setSelectedRange: function(/*DomNode*/ element, /*Number*/ start, /*Number*/ end){			if(!end){ end = element.value.length; }  // NOTE: Strange - should be able to put caret at start of text?			// Mozilla			// parts borrowed from http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130			if(element.setSelectionRange){				element.focus();				element.setSelectionRange(start, end);			}else if(element.createTextRange){ // IE				var range = element.createTextRange();				with(range){					collapse(true);					moveEnd('character', end);					moveStart('character', start);					select();				}			}else{ //otherwise try the event-creation hack (our own invention)				// do we need these?				element.value = element.value;				element.blur();				element.focus();				// figure out how far back to go				var dist = parseInt(element.value.length)-end;				var tchar = String.fromCharCode(37);				var tcc = tchar.charCodeAt(0);				for(var x = 0; x < dist; x++){					var te = document.createEvent("KeyEvents");					te.initKeyEvent("keypress", true, true, null, false, false, false, false, tcc, tcc);					element.dispatchEvent(te);				}			}		},		_handleKeyEvents: function(/*Event*/ evt){			// summary: handles keyboard events			if(evt.ctrlKey || evt.altKey || !evt.key){ return; }			// reset these			this._prev_key_backspace = false;			this._prev_key_esc = false;			var k = dojo.event.browser.keys;			var doSearch = true;			switch(evt.key){	 			case k.KEY_DOWN_ARROW:					if(!this.popupWidget.isShowingNow){						this._startSearchFromInput();					}					this._highlightNextOption();					dojo.event.browser.stopEvent(evt);					return;				case k.KEY_UP_ARROW:					this._highlightPrevOption();					dojo.event.browser.stopEvent(evt);					return;				case k.KEY_TAB:					// using linux alike tab for autocomplete					if(!this.autoComplete && this.popupWidget.isShowingNow && this._highlighted_option){						dojo.event.browser.stopEvent(evt);						this._selectOption({ 'target': this._highlighted_option, 'noHide': false});						// put caret last						this._setSelectedRange(this.textInputNode, this.textInputNode.value.length, null);					}else{						this._selectOption();						return;					}					break;				case k.KEY_ENTER:					// prevent submitting form if we press enter with list open					if(this.popupWidget.isShowingNow){						dojo.event.browser.stopEvent(evt);					}					if(this.autoComplete){						this._selectOption();						return;					}					// fallthrough				case " ":					if(this.popupWidget.isShowingNow && this._highlighted_option){						dojo.event.browser.stopEvent(evt);						this._selectOption();						this._hideResultList();						return;					}					break;				case k.KEY_ESCAPE:					this._hideResultList();					this._prev_key_esc = true;					return;				case k.KEY_BACKSPACE:					this._prev_key_backspace = true;					if(!this.textInputNode.value.length){						this.setAllValues("", "");						this._hideResultList();						doSearch = false;					}					break;				case k.KEY_RIGHT_ARROW: // fall through				case k.KEY_LEFT_ARROW: // fall through					doSearch = false;					break;				default:// non char keys (F1-F12 etc..)  shouldn't open list					if(evt.charCode==0){						doSearch = false;					}			}			if(this.searchTimer){				clearTimeout(this.searchTimer);			}			if(doSearch){				// if we have gotten this far we dont want to keep our highlight				this._blurOptionNode();				// need to wait a tad before start search so that the event bubbles through DOM and we have value visible				this.searchTimer = setTimeout(dojo.lang.hitch(this, this._startSearchFromInput), this.searchDelay);			}		},		compositionEnd: function(/*Event*/ evt){			// summary: When inputting characters using an input method, such as Asian			// languages, it will generate this event instead of onKeyDown event			evt.key = evt.keyCode;			this._handleKeyEvents(evt);		},		onKeyUp: function(/*Event*/ evt){			// summary: callback on key up event			this.setValue(this.textInputNode.value);		},		setSelectedValue: function(/*String*/ value){			// summary:			//		This sets a hidden value associated w/the displayed value.			//		The hidden value (and this function) shouldn't be used; if			//		you need a hidden value then use Select widget instead of ComboBox.			// TODO: remove?			// FIXME, not sure what to do here!			this.comboBoxSelectionValue.value = value;		},		setAllValues: function(/*String*/ value1, /*String*/ value2){			// summary:			//		This sets the displayed value and hidden value.			//		The hidden value (and this function) shouldn't be used; if			//		you need a hidden value then use Select widget instead of ComboBox.			this.setSelectedValue(value2);			this.setValue(value1);		},		_focusOptionNode: function(/*DomNode*/ node){			// summary: does the actual highlight			if(this._highlighted_option != node){				this._blurOptionNode();				this._highlighted_option = node;				dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");			}		},		_blurOptionNode: function(){			// sumary: removes highlight on highlighted			if(this._highlighted_option){				dojo.html.removeClass(this._highlighted_option, "dojoComboBoxItemHighlight");				this._highlighted_option = null;			}		},		_highlightNextOption: function(){			if((!this._highlighted_option) || !this._highlighted_option.parentNode){				this._focusOptionNode(this.optionsListNode.firstChild);			}else if(this._highlighted_option.nextSibling){				this._focusOptionNode(this._highlighted_option.nextSibling);			}			dojo.html.scrollIntoView(this._highlighted_option);		},		_highlightPrevOption: function(){			if(this._highlighted_option && this._highlighted_option.previousSibling){				this._focusOptionNode(this._highlighted_option.previousSibling);			}else{				this._highlighted_option = null;				this._hideResultList();				return;			}			dojo.html.scrollIntoView(this._highlighted_option);		},		_itemMouseOver: function(/*Event*/ evt){			if (evt.target === this.optionsListNode){ return; }			this._focusOptionNode(evt.target);			dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");		},

⌨️ 快捷键说明

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