Exemplo n.º 1
0
		public void AddItem(KeyValuePair pair)
		{

			DivElement div = (DivElement)Document.CreateElement("DIV");
			Dictionary<object, object> divAsArray = (Dictionary<object, object>)(object)div;
			divAsArray["value"] = pair.Value;
			if (pair.Key.IndexOf("<") > -1)
				div.InnerHTML = pair.Key;
			else
				div.InnerHTML = "<div class=\"DefaultPopupMenuItem\">" + pair.Key + "</div>";
			container.AppendChild(div);
			jQuery.FromElement(div).Click(ItemClickHandler);
			jQuery.FromElement(div).MouseOver(ItemMouseEnterHandler);
			
		}
		void HandleKeyDown(jQueryEvent e)
		{
			if (e.Which == 38 /*Key.Up*/)
			{
				if (popupMenu != null) popupMenu.IndexOfCurrentlyHighlightedItem -= 1;
			}
			else if (e.Which == 40 /*Key.Down*/)
			{
				if (popupMenu != null) popupMenu.IndexOfCurrentlyHighlightedItem += 1;
			}
			else if (e.Which == 27 /*Key.Esc*/)
			{
				if (this.popupMenu.CurrentlyHighlightedItem != null)
				{
					Clear();
					e.PreventDefault();
				}
				else
				{
					Cancel();
				}
			} 
			else if ((e.Which == 9 /*Key.Tab*/ && !e.ShiftKey) || e.Which == 13 /*Key.Enter*/)
			{
				if (mode == HtmlAutoCompleteMode.Suggest)
				{
					if (SuggestionIsHighlighted)
					{
						e.PreventDefault();
						ItemSelected(this.popupMenu.CurrentlyHighlightedItem);
						popupMenu.Clear();
						return;
					}
					else
					{
						if (ValidSelectionHasBeenMade)
						{
							KeyValuePair pair = new KeyValuePair();
							pair.Key = this.input.Value;
							pair.Value = this.input.Value;
							ItemSelected(pair);
							return;
						}
					}
				}
				else if (mode == HtmlAutoCompleteMode.Complete)
				{
					if (SuggestionIsHighlighted && !ValidSelectionHasBeenMade)
					{
						if (e.Which == 13 /*Key.Enter*/) e.PreventDefault();
						ItemSelected(this.popupMenu.CurrentlyHighlightedItem);

						return;
					}
				}
			}
			else if (e.Which == 8 /*Key.Backspace*/ && mode == HtmlAutoCompleteMode.Complete)
			{
				Suggestions.Clear();
				if (this.ValidSelectionHasBeenMade)
				{
					this.hiddenInput.Value = ""; this.input.Value = ""; 
				}
				else
				{
					this.hiddenInput.Value = ""; RequestSuggestions(); ; 
				}
			}
			else if (e.Which == 46 /*Key.Del*/ && mode == HtmlAutoCompleteMode.Complete)
			{
				this.hiddenInput.Value = "";
				RequestSuggestions();
			}
		}
		public void DisplaySuggestionsInPopupMenu()
		{
			Trace.Write("DisplaySuggestionsInPopupMenu"); 
			popupMenu.Clear();
			for (int i = 0; i < Suggestions.Count; i++)
			{
				Suggestion suggestion = (Suggestion)Suggestions[i];
				KeyValuePair pair = new KeyValuePair();
				pair.Key = suggestion.html;
				KeyValuePair value = new KeyValuePair();
				value.Key = suggestion.text;
				value.Value = mode == HtmlAutoCompleteMode.Complete ? suggestion.value : suggestion.text;
				pair.Value = value;
				popupMenu.AddItem(pair);
			}
			HighlightFirstSuggestion();
			
			
			popupMenu.Show(anchor, minWidth, maxWidth, popupTopOffset, popupLeftOffset, rightAlign);
		}