Skip to content
Newer
Older
100644 48 lines (35 sloc) 1.65 KB
207a303 @kir Add deprecation notice
authored
1 Deprecation notice
2 ------------------
3 This library is no longer maintained, you may want to take a look at this solution instead:
4 https://github.com/component/textarea-caret-position
5
6
0e9ce94 @dandv Improve README
dandv authored
7 JavaScript cursor position in a textarea or input
8 =================================================
85e0bff @kir Initial code commit. Docs pending.
authored
9
0e9ce94 @dandv Improve README
dandv authored
10 What
11 ----
12 To obtain the text cursor position in a `<textarea>` or an `<input>` text field.
13 Cursor position is provided either in characters, or in pixels relative to top-left corner of the text area.
85e0bff @kir Initial code commit. Docs pending.
authored
14
4ccd168 @kir A little bit more docs
authored
15 Why
16 ---
0e9ce94 @dandv Improve README
dandv authored
17 The library can be used for positioning of a completion popup window in a `<textarea>` or `<input>` text field right
18 near the caret. Given that long text is wrapped in `<textarea>`s, the task is not very trivial.
4ccd168 @kir A little bit more docs
authored
19
207a303 @kir Add deprecation notice
authored
20 Alternative solution
21 --------------------
22 There is another, more recent library which uses the same principle and may have less (or different) bugs:
23 https://github.com/component/textarea-caret-position
24
4ccd168 @kir A little bit more docs
authored
25 How
26 ---
27 The library tries to model text wrapping in the textarea and to find out relative cursor position.
0e9ce94 @dandv Improve README
dandv authored
28 The results are not 100% accurate, but really close to it. Tested against IE8+, Chrome, Opera, Firefox as of 2012.
4ccd168 @kir A little bit more docs
authored
29
0e9ce94 @dandv Improve README
dandv authored
30 ### Usage
4ccd168 @kir A little bit more docs
authored
31
0e9ce94 @dandv Improve README
dandv authored
32 ```js
33 var padding = 3;
34 var positioner = new maxkir.CursorPosition(textarea_element, padding);
35 alert(positioner.getCursorCoordinates()); // [x, y] position of cursor in textarea in characters
36 alert(positioner.getPixelCoordinates()); // [x, y] position of cursor in textarea in pixels
37 ```
4ccd168 @kir A little bit more docs
authored
38
0e9ce94 @dandv Improve README
dandv authored
39 See also the functional test under [test/cursor_position_test.html]<test/cursor_position_test.html>
4ccd168 @kir A little bit more docs
authored
40
41 Dependencies
42 ------------
0e9ce94 @dandv Improve README
dandv authored
43 None, plain JavaScript code.
85e0bff @kir Initial code commit. Docs pending.
authored
44
bc701aa @kir Add some docs, license file, and extract selection_range.js
authored
45
85e0bff @kir Initial code commit. Docs pending.
authored
46 --
a6f60e4 @kir Update copyright
authored
47 Copyright (c) 2010-2012 Kirill Maximov, released under the MIT license
Something went wrong with that request. Please try again.