Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1030311 // hjs_focusEnd - helper to move caret to end of text area

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2698L/17K).

1  
sS hjs_focusEnd() {
2  
  ret hjs([[
3  
    $.fn.setCursorPosition = function(position, noFocus) {
4  
        if(this.length == 0) return this;
5  
        return $(this).setSelection(position, position, noFocus);
6  
    }
7  
    
8  
    $.fn.setSelection = function(selectionStart, selectionEnd, noFocus) {
9  
        if(this.length == 0) return this;
10  
        var input = this[0];
11  
    
12  
        if (input.createTextRange) {
13  
            var range = input.createTextRange();
14  
            range.collapse(true);
15  
            range.moveEnd('character', selectionEnd);
16  
            range.moveStart('character', selectionStart);
17  
            range.select();
18  
        } else if (input.setSelectionRange) {
19  
            if (!noFocus) input.focus();
20  
            input.setSelectionRange(selectionStart, selectionEnd);
21  
        }
22  
    
23  
        return this;
24  
    }
25  
    
26  
    $.fn.focusEnd = function(noFocus) {
27  
        this.setCursorPosition(this.val().length, noFocus);
28  
        return this;
29  
    }
30  
  ]]);
31  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030311
Snippet name: hjs_focusEnd - helper to move caret to end of text area
Eternal ID of this version: #1030311/2
Text MD5: 1ec098b8a374d16a2333ca0fb4d7c086
Transpilation MD5: f7218098eb482abb28a9503ad1b03b14
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-30 15:14:24
Source code size: 987 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 103 / 151
Version history: 1 change(s)
Referenced in: [show references]