Пример #1
0
		public static void InputKeypressHandler(jQueryEvent evt, InputElement el, TransformCharDelegate transformChar) {
			if (evt.AltKey || evt.CtrlKey)
				return; // don't ever change Alt+key or Ctrl+key

			if (jQuery.Browser.MSIE) {
				if (evt.Which == 13)
					return; // Enter seems to be the only non-printable key we catch in IE.
				char newc = transformChar((char)evt.Which);
				if (newc == 0) {
					evt.PreventDefault();
				}
				else if (newc != evt.Which) {
					((dynamic)evt).originalEvent.keyCode = newc;
				}
			}
			else {
				if (evt.Which == 0)
					return; // Firefox, and likely other non-IE browsers, lets us trap non-characters, but we don't want that.

				char newc = transformChar((char)evt.Which);
				if (newc == 0) {
					evt.PreventDefault();
				}
				else if (newc != evt.Which) {
					int startPos = ((dynamic)el).selectionStart,
					    endPos   = ((dynamic)el).selectionEnd;
					string oldVal = el.Value;
					el.Value = oldVal.Substr(0, startPos) + String.FromCharCode(newc) + oldVal.Substr(endPos);
					((dynamic)el).setSelectionRange(startPos + 1, startPos + 1);
					evt.PreventDefault();
				}
			}
		}
Пример #2
0
 public static void InputKeypressHandler(jQueryEvent evt, InputElement el, TransformCharDelegate transformChar)
 {
     if (evt.AltKey || evt.CtrlKey)
     {
         return;                 // don't ever change Alt+key or Ctrl+key
     }
     if (jQuery.Browser.MSIE)
     {
         if (evt.Which == 13)
         {
             return;                     // Enter seems to be the only non-printable key we catch in IE.
         }
         char newc = transformChar((char)evt.Which);
         if (newc == 0)
         {
             evt.PreventDefault();
         }
         else if (newc != evt.Which)
         {
             ((dynamic)evt).originalEvent.keyCode = newc;
         }
     }
     else
     {
         if (evt.Which == 0)
         {
             return;                     // Firefox, and likely other non-IE browsers, lets us trap non-characters, but we don't want that.
         }
         char newc = transformChar((char)evt.Which);
         if (newc == 0)
         {
             evt.PreventDefault();
         }
         else if (newc != evt.Which)
         {
             int startPos  = ((dynamic)el).selectionStart,
                 endPos    = ((dynamic)el).selectionEnd;
             string oldVal = el.Value;
             el.Value = oldVal.Substr(0, startPos) + String.FromCharCode(newc) + oldVal.Substr(endPos);
             ((dynamic)el).setSelectionRange(startPos + 1, startPos + 1);
             evt.PreventDefault();
         }
     }
 }