@@ -10,18 +10,22 @@ This jQuery plugin is for easily finding the starting and ending positions of se
1010
1111Include the file directly using ` <script> ` tags:
1212
13- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
14- <script src="jquery-plugins/jquery-textrange.js"></script>
13+ ``` html
14+ <script src =" http://code.jquery.com/jquery-latest.min.js" ></script >
15+ <script src =" jquery-plugins/jquery-textrange.js" ></script >
16+ ```
1517
1618Or, with RequireJS (** note** : jquery-textrange can be loaded through any [ UMD] ( https://github.com/umdjs/umd/blob/master/README.md ) -compatible Javascript Module Loader):
1719
18- requirejs.config({
19- "baseUrl": "lib",
20- "paths": {
21- "jquery": "//code.jquery.com/jquery-latest.min.js",
22- "jquery-textrange": "jquery-plugins/jquery-textrange"
23- }
24- });
20+ ``` javascript
21+ requirejs .config ({
22+ " baseUrl" : " lib" ,
23+ " paths" : {
24+ " jquery" : " //code.jquery.com/jquery-latest.min.js" ,
25+ " jquery-textrange" : " jquery-plugins/jquery-textrange"
26+ }
27+ });
28+ ```
2529
2630## Methods
2731
@@ -31,29 +35,37 @@ You can use this method to get all the information on the selected text of an el
3135
3236##### Get everything
3337
34- $('input[name="example"]').textrange('get');
38+ ``` javascript
39+ $ (' input[name="example"]' ).textrange (' get' );
40+ ```
3541
3642or for short:
3743
38- $('input[name="example"]').textrange();
44+ ``` javascript
45+ $ (' input[name="example"]' ).textrange ();
46+ ```
3947
4048This will return a JSON object with the following information:
4149
42- {
43- position: (cursor location in the text field),
44- start: (starting position of the selected text in the text field),
45- end: (ending position of the selected text in the text field),
46- length: (the length of the selected text in the text field),
47- text: (the text that is selected)
48- }
50+ ``` javascript
51+ {
52+ " position" : // cursor location in the text field)
53+ " start" : // starting position of the selected text in the text field
54+ " end" : // ending position of the selected text in the text field
55+ " length" : // the length of the selected text in the text field
56+ " text" : // the text that is selected
57+ }
58+ ```
4959
5060##### Get a particular property
5161
5262This function can also be used to get a particular property of the object.
5363
5464For example, this will obtain the starting location of the selected text:
5565
56- var start = $('input[name="example"]').textrange('get', 'start');
66+ ``` javascript
67+ var start = $ (' input[name="example"]' ).textrange (' get' , ' start' );
68+ ```
5769
5870### 'set'
5971
@@ -63,13 +75,15 @@ It works much like [PHP's substr()](http://php.net/manual/en/function.substr.php
6375
6476For the following examples, let's say ` input[name="example"] ` contains the text ` abcdef ` .
6577
66- $('input[name="example"]').textrange('set'); // selects "abcdef" (select all)
67- $('input[name="example"]').textrange('set', 2); // selects "cdef"
68- $('input[name="example"]').textrange('set', 2, 3); // selects "cde"
69- $('input[name="example"]').textrange('set', 2, -2); // selects "cd"
70- $('input[name="example"]').textrange('set', -3); // selects "def"
71- $('input[name="example"]').textrange('set', -2, 1); // selects "e"
72- $('input[name="example"]').textrange('set', -4, -1); // selects "cde"
78+ ``` javascript
79+ $ (' input[name="example"]' ).textrange (' set' ); // selects "abcdef" (select all)
80+ $ (' input[name="example"]' ).textrange (' set' , 2 ); // selects "cdef"
81+ $ (' input[name="example"]' ).textrange (' set' , 2 , 3 ); // selects "cde"
82+ $ (' input[name="example"]' ).textrange (' set' , 2 , - 2 ); // selects "cd"
83+ $ (' input[name="example"]' ).textrange (' set' , - 3 ); // selects "def"
84+ $ (' input[name="example"]' ).textrange (' set' , - 2 , 1 ); // selects "e"
85+ $ (' input[name="example"]' ).textrange (' set' , - 4 , - 1 ); // selects "cde"
86+ ```
7387
7488If you're looking to set the cursor at one specific location, you can use ` 0 ` for length, or you can use ` $().textrange('setcursor') ` (see below).
7589
@@ -79,20 +93,26 @@ You can use this method to set the location of the cursor in your text field.
7993
8094To set the cursor at the fifth character position:
8195
82- $('input[name="example"]').textrange('setcursor', 5);
96+ ``` javascript
97+ $ (' input[name="example"]' ).textrange (' setcursor' , 5 );
98+ ```
8399
84100### 'replace'
85101
86102You can use this method to replace the selection with given text.
87103
88- $('input[name="example"]').textrange('replace', 'some text');
104+ ``` javascript
105+ $ (' input[name="example"]' ).textrange (' replace' , ' some text' );
106+ ```
89107
90108There is also an ` insert ` alias for ` replace ` if you're using this method to insert text at the cursor location. They work the same way.
91109
92110## Minified Version
93111A minified version of this plugin can be generated using Google's Closure Compiler (preferred).
94112
95- wget http://closure-compiler.googlecode.com/files/compiler-latest.tar.gz
96- tar -zvxf compiler-latest.tar.gz compiler.jar
97- wget https://raw.github.com/dwieeb/jquery-textrange/master/jquery-textrange.js
98- java -jar compiler.jar --js jquery-textrange.js --js_output_file jquery-textrange.min.js
113+ ``` bash
114+ wget http://closure-compiler.googlecode.com/files/compiler-latest.tar.gz
115+ tar -zvxf compiler-latest.tar.gz compiler.jar
116+ wget https://raw.github.com/dwieeb/jquery-textrange/master/jquery-textrange.js
117+ java -jar compiler.jar --js jquery-textrange.js --js_output_file jquery-textrange.min.js
118+ ```
0 commit comments