Палсеич— (lusever) wrote in changelog,
Палсеич—
lusever
changelog

[js] r291: LJSV-1426: Incorrect behavior when sendi...

Committer: pkornilov
LJSV-1426: Incorrect behavior when sending private message
U   trunk/inputcomplete.js
Modified: trunk/inputcomplete.js
===================================================================
--- trunk/inputcomplete.js	2011-03-11 04:08:10 UTC (rev 290)
+++ trunk/inputcomplete.js	2011-04-06 04:32:50 UTC (rev 291)
@@ -193,10 +193,8 @@
         DOM.addEventListener(ele, "focus",   InputComplete.onFocus.bindEventListener(this));
         DOM.addEventListener(ele, "keydown", InputComplete.onKeyDown.bindEventListener(this));
         DOM.addEventListener(ele, "keyup",   InputComplete.onKeyUp.bindEventListener(this));
+        DOM.addEventListener(ele, "keypress",InputComplete.onKeyPress.bindEventListener(this));
         DOM.addEventListener(ele, "blur",    InputComplete.onBlur.bindEventListener(this));
-        if (ele.form) {
-            DOM.addEventListener(ele.form, "submit", InputComplete.formSubmit.bindEventListener(this));
-        }
     },
 
     // returns the word currently being typed, or null
@@ -303,6 +301,18 @@
     }
 };
 
+InputComplete.onKeyPress = function (e) {
+    e = jQuery.event.fix(e);
+    // 10 is IE with ctrlKey
+    if ((e.which === 13 || e.which === 10) && !e.ctrlKey) {
+        var sel = DOM.getSelectedRange(this.ele);
+        if (sel.start !== sel.end) {
+            e.preventDefault();
+            DOM.setSelectedRange(this.ele, sel.end, sel.end);
+        }
+    }
+};
+
 InputComplete.onBlur = function (e) {
     if (this.disabled) return;
 
@@ -326,11 +336,3 @@
 InputComplete.onFocus = function (e) {
     if (this.disabled) return;
 };
-
-InputComplete.formSubmit = function (e) {
-    var sel = DOM.getSelectedRange(this.ele);
-    if (sel.start !== sel.end) {
-        jQuery.event.fix(e).preventDefault();
-        DOM.setSelectedRange(this.ele, sel.end, sel.end);
-    }
-};

Tags: js, lusever
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments