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

[js] r290: 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	2010-08-24 10:04:06 UTC (rev 289)
+++ trunk/inputcomplete.js	2011-03-11 04:08:10 UTC (rev 290)
@@ -1,7 +1,6 @@
 /* input completion library */
 
 /* TODO:
-    -- test on non-US keyboard layouts (too much use of KeyCode)
     -- lazy data model (xmlhttprequest, or generic callbacks)
     -- drop-down menu?
     -- option to disable comma-separated mode (or explicitly ask for it)
@@ -195,11 +194,8 @@
         DOM.addEventListener(ele, "keydown", InputComplete.onKeyDown.bindEventListener(this));
         DOM.addEventListener(ele, "keyup",   InputComplete.onKeyUp.bindEventListener(this));
         DOM.addEventListener(ele, "blur",    InputComplete.onBlur.bindEventListener(this));
-    },
-
-    dbg: function (msg) {
-        if (this.debug) {
-            this.debug(msg);
+        if (ele.form) {
+            DOM.addEventListener(ele.form, "submit", InputComplete.formSubmit.bindEventListener(this));
         }
     },
 
@@ -253,8 +249,6 @@
 
     var code = e.keyCode || e.which;
 
-    this.dbg("onKeyDown, code="+code+", shift="+e.shiftKey);
-    
     // if comma, but not with a shift which would be "<".  (FIXME: what about other keyboards layouts?)
     //FIXME: may be there is a stable cross-browser way to detect so-called other keyboard layouts - but i don't know anything easier than ... (see onKeyUp changes in tis revision)
     /*if ((code == 188 || code == 44) && ! e.shiftKey && this.caretAtEndOfNotSelected()) {
@@ -271,9 +265,7 @@
     var val = this.ele.value;
 
     var code = e.keyCode || e.which;
-    this.dbg("keyUp = " + code);
-    
-    
+
     // ignore tab, backspace, left, right, delete, and enter
     if (code == 9 || code == 8 || code == 37 || code == 39 || code == 46 || code == 13)
        return false;
@@ -283,22 +275,17 @@
     var ss = sel.start;
     var se = sel.end;
 
-    this.dbg("keyUp, got ss="+ss +  ", se="+se+", val.length="+val.length);
-
     // only auto-complete if we're at the end of the line
     if (se != val.length) return false;
 
     var chr = String.fromCharCode(code);
 
-    this.dbg("keyUp, got chr="+chr);
     //if (code == 188 || chr == ",") {
     if(/,$/.test(val)){	
         if (! this.caretAtEndOfNotSelected(sel)) {
             return false;
         }
 
-        this.dbg("hit comma! .. value = " + this.ele.value);
-
         this.ele.value = this.ele.value.replace(/[\s,]+$/, "") + ", ";
         this.moveCaretToEnd();
 
@@ -339,3 +326,11 @@
 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