Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 111 lines (96 sloc) 4.117 kB
d3ea1ca @drpheltright
authored
1 <!doctype html>
2 <html>
3 <head>
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
4 <title>$.fn.caret() Examples</title>
d3ea1ca @drpheltright
authored
5 <meta charset="utf-8" />
6 </head>
7 <body>
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
8 <h1>$.fn.caret() Examples</h1>
d3ea1ca @drpheltright
authored
9
10 <h2>&lt;input /&gt; Example</h2>
11 <p>
12 <input id="input-ex" value="A test string..." />
267fa4d @drpheltright Update whitespace.
authored
13 </p>
6ae4ced @drpheltright Update example to report caret position.
authored
14 <div id="input-buttons">
d3ea1ca @drpheltright
authored
15 <button id="input-start">Jump to start</button>
16 <button id="input-end">Jump to end</button>
267fa4d @drpheltright Update whitespace.
authored
17 <br />
18 Index: <input id="input-index" value="5" />
19 <button id="input-ex-index">Jump to index</button>
d64e28f @drpheltright Add more coverage to example.
authored
20 <br />
21 toString: <input id="input-string" value="string" />
593ca7b @drpheltright Whitespace, again.
authored
22 after: <input type="checkbox" id="input-string-after" />
d64e28f @drpheltright Add more coverage to example.
authored
23 <button id="input-ex-string">Jump to string</button>
6ae4ced @drpheltright Update example to report caret position.
authored
24 </div>
d3ea1ca @drpheltright
authored
25
26 <h2>&lt;textarea&gt; Example</h2>
27 <p>
28 <textarea id="textarea-ex">A test string...</textarea>
267fa4d @drpheltright Update whitespace.
authored
29 </p>
6ae4ced @drpheltright Update example to report caret position.
authored
30 <div id="textarea-buttons">
d3ea1ca @drpheltright
authored
31 <button id="textarea-start">Jump to start</button>
32 <button id="textarea-end">Jump to end</button>
267fa4d @drpheltright Update whitespace.
authored
33 <br />
34 Index: <input id="textarea-index" value="5" />
35 <button id="textarea-ex-index">Jump to index</button>
d64e28f @drpheltright Add more coverage to example.
authored
36 <br />
37 toString: <input id="textarea-string" value="string" />
593ca7b @drpheltright Whitespace, again.
authored
38 after: <input type="checkbox" id="textarea-string-after" />
d64e28f @drpheltright Add more coverage to example.
authored
39 <button id="textarea-ex-string">Jump to string</button>
6ae4ced @drpheltright Update example to report caret position.
authored
40 </div>
20803a7 @drpheltright Add onFocus example to example.html.
authored
41
42 <h2>onFocus Example</h2>
43 <p>
44 <input type="text" id="onfocus-ex" value="Hello world!" />
45 </p>
d3ea1ca @drpheltright
authored
46
6ae4ced @drpheltright Update example to report caret position.
authored
47 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
d3ea1ca @drpheltright
authored
48 <script src="jquery.caret.js"></script>
49 <script>
50 jQuery(function ($) {
51 var $inputExample = $('#input-ex'),
20803a7 @drpheltright Add onFocus example to example.html.
authored
52 $textareaExample = $('#textarea-ex'),
53 $onFocusExample = $('#onfocus-ex');
d3ea1ca @drpheltright
authored
54
55 $('#input-start').click(function () {
56 $inputExample.caretToStart();
57 });
58
59 $('#input-end').click(function () {
60 $inputExample.caretToEnd();
61 });
267fa4d @drpheltright Update whitespace.
authored
62
d56a039 @drpheltright Update example.
authored
63 $('#input-ex-index').click(function () {
6ae4ced @drpheltright Update example to report caret position.
authored
64 // Turn to number by multiplication
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
65 $inputExample.caret($('#input-index').val() * 1);
d56a039 @drpheltright Update example.
authored
66 });
d3ea1ca @drpheltright
authored
67
d64e28f @drpheltright Add more coverage to example.
authored
68 $('#input-ex-string').click(function () {
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
69 $inputExample.caret(
593ca7b @drpheltright Whitespace, again.
authored
70 $('#input-string').val(),
71 $('#input-string-after').is(':checked')
72 );
d64e28f @drpheltright Add more coverage to example.
authored
73 });
74
6ae4ced @drpheltright Update example to report caret position.
authored
75 $('#input-buttons').click(function () {
76 if (console.log) console.log($inputExample.caret());
77 });
78
d56a039 @drpheltright Update example.
authored
79 $('#textarea-start').click(function () {
d3ea1ca @drpheltright
authored
80 $textareaExample.caretToStart();
81 });
82
d56a039 @drpheltright Update example.
authored
83 $('#textarea-end').click(function () {
d3ea1ca @drpheltright
authored
84 $textareaExample.caretToEnd();
85 });
267fa4d @drpheltright Update whitespace.
authored
86
d56a039 @drpheltright Update example.
authored
87 $('#textarea-ex-index').click(function () {
6ae4ced @drpheltright Update example to report caret position.
authored
88 // Turn to number by multiplication
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
89 $textareaExample.caret($('#textarea-index').val() * 1);
d56a039 @drpheltright Update example.
authored
90 });
593ca7b @drpheltright Whitespace, again.
authored
91
d64e28f @drpheltright Add more coverage to example.
authored
92 $('#textarea-ex-string').click(function () {
bc3ee2f @drpheltright Rename .caretTo to .caret and add getter functionality.
authored
93 $textareaExample.caret(
593ca7b @drpheltright Whitespace, again.
authored
94 $('#textarea-string').val(),
95 $('#textarea-string-after').is(':checked')
96 );
d64e28f @drpheltright Add more coverage to example.
authored
97 });
6ae4ced @drpheltright Update example to report caret position.
authored
98
99 $('#textarea-buttons').click(function () {
100 if (console.log) console.log($textareaExample.caret());
101 });
20803a7 @drpheltright Add onFocus example to example.html.
authored
102
103 $onFocusExample.focus(function () {
104 // Delay needed to escape focus since
105 // native focus cannot be suppressed
106 $(this).delay(13).caretToEnd();
107 });
d3ea1ca @drpheltright
authored
108 });
109 </script>
110 </body>
111 </html>
Something went wrong with that request. Please try again.