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

[js] r289: LJSUP-6515: Custom Userheads.

Committer: pkornilov
LJSUP-6515: Custom Userheads.
U   trunk/inputcomplete.js
Modified: trunk/inputcomplete.js
===================================================================
--- trunk/inputcomplete.js	2010-06-01 07:49:52 UTC (rev 288)
+++ trunk/inputcomplete.js	2010-08-24 10:04:06 UTC (rev 289)
@@ -205,10 +205,9 @@
 
     // returns the word currently being typed, or null
     wordInProgress: function () {
-        var sel = this.getSelectedRange();
-        if (!sel) return null;
+        var sel = DOM.getSelectedRange(this.ele);
 
-        var cidx = sel.selectionStart; // current indx
+        var cidx = sel.start; // current indx
         var sidx = cidx;  // start of word index
         while (sidx > 0 && this.ele.value.charAt(sidx) != ',') {
             sidx--;
@@ -224,73 +223,22 @@
 
     // appends some selected text after the care
     addSelectedText: function (chars) {
-        var sel = this.getSelectedRange();
+        var sel = DOM.getSelectedRange(this.ele);
         this.ele.value = this.ele.value + chars;
-        this.setSelectedRange(sel.selectionStart, this.ele.value.length);
+        DOM.setSelectedRange(this.ele, sel.start, this.ele.value.length);
     },
 
     moveCaretToEnd: function () {
         var len = this.ele.value.length;
-        this.setSelectedRange(len, len);
+        DOM.setSelectedRange(this.ele, len, len);
     },
 
-    getSelectedRange: function () {
-        var ret = {};
-        var ele = this.ele;
-
-        if ("selectionStart" in ele) {
-            ret.selectionStart = ele.selectionStart;
-            ret.selectionEnd   = ele.selectionEnd;
-            return ret;
-        }
-
-        if (document.selection && document.selection.createRange) {
-            var range = document.selection.createRange();
-            ret.selectionStart = InputComplete.IEOffset(range, "StartToStart");
-            ret.selectionEnd   = InputComplete.IEOffset(range, "EndToEnd");
-            return ret;
-        }
-
-        return null;
-    },
-
-    setSelectedRange: function (sidx, eidx) {
-        var ele = this.ele;
-
-        // preferred to setting selectionStart and end
-        if (ele.setSelectionRange) {
-            ele.focus();
-            ele.setSelectionRange(sidx, eidx);
-            return true;
-        }
-
-        // IE
-        if (document.selection && document.selection.createRange) {
-            ele.focus();
-            var sel = document.selection.createRange ();
-            sel.moveStart('character', -ele.value.length);
-            sel.moveStart('character', sidx);
-            sel.moveEnd('character', eidx - sidx);
-            sel.select();
-            return true;
-        }
-
-        // mozilla
-        if ("selectionStart" in ele) {
-            ele.selectionStart = sidx;
-            ele.selectionEnd   = eidx;
-            return true;
-        }
-
-        return false;
-    },
-
     // returns true if caret is at end of line, or everything to the right
     // of us is selected
     caretAtEndOfNotSelected: function (sel) {
-        sel = sel || this.getSelectedRange();
+        sel = sel || DOM.getSelectedRange(this.ele);
         var len = this.ele.value.length;
-        return sel.selectionEnd == len;
+        return sel.end == len;
     },
 
     disable: function () {
@@ -330,10 +278,10 @@
     if (code == 9 || code == 8 || code == 37 || code == 39 || code == 46 || code == 13)
        return false;
 
-    var sel = this.getSelectedRange();
+    var sel = DOM.getSelectedRange(this.ele);
 
-    var ss = sel.selectionStart;
-    var se = sel.selectionEnd;
+    var ss = sel.start;
+    var se = sel.end;
 
     this.dbg("keyUp, got ss="+ss +  ", se="+se+", val.length="+val.length);
 
@@ -391,36 +339,3 @@
 InputComplete.onFocus = function (e) {
     if (this.disabled) return;
 };
-
-
-InputComplete.IEOffset = function ( range, compareType ) {
-    if (this.disabled) return;
-
-    var range2 = range.duplicate();
-    range2.collapse( true );
-    var parent = range2.parentElement();
-    var length = range2.text.length;
-    range2.move("character", -parent.value.length);
-
-    var delta = max( 1, finiteInt( length * 0.5 ) );
-    range2.collapse( true );
-    var offset = 0;
-    var steps = 0;
-
-    // bail after 10k iterations in case of borkage
-    while( (test = range2.compareEndPoints( compareType, range )) != 0 ) {
-        if( test < 0 ) {
-            range2.move( "character", delta );
-            offset += delta;
-        } else {
-            range2.move( "character", -delta );
-            offset -= delta;
-        }
-        delta = max( 1, finiteInt( delta * 0.5 ) );
-        steps++;
-        if( steps > 1000 )
-            throw "unable to find textrange endpoint in " + steps + " steps";
-    }
-
-    return offset;
-};

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