This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
forked from garysieling/jquery-highlighttextarea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.htm
197 lines (151 loc) · 9.91 KB
/
index.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Description" content="highlightTextarea is a jQuery plugin which allows you to highlight words and sentences into textareas.">
<meta http-equiv="Content-Language" content="en">
<meta name="verify-v1" content="5Ig62l7QOrkVI27LoehUOkGDt4zpPqsmy+1ryCRh1fo=">
<title>jQuery • highlightTextarea</title>
<link type="text/css" href="src/style.css" rel="stylesheet" />
<link type="text/css" href="src/highlight.css" rel="stylesheet" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<link type="text/css" href="jquery.highlighttextarea.css" rel="stylesheet" />
<script type="text/javascript" src="jquery.highlighttextarea.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#demo").highlightTextarea({
words: ["Lorem ipsum","vulputate"]
});
});
</script>
</head>
<body>
<div id="the_header">
jQuery • highlightTextarea
<div id="menu">
<a href="#top">Download</a> • <a href="#install">Installation</a> • <a href="#config">Configuration</a> • <a href="#api">API</a> • <a href="#structure">Structure</a> • <a href="#bugs">Bugs & requests</a> • <a href="#changelog">Changelog</a> • <a href="#license">License</a>
</div>
</div>
<div id="the_page">
<p><b>highlightTextarea</b> is a jQuery plugin which allows you to highlight words and sentences into textareas. Words are defined in a jQuery array and you can customize highlight color and case sensitivity. The highlighting updates itself when typing in the textarea and follows scroll and resizing (with jQuery-UI).</p>
<a name="top" class="anchor"></a>
<h2>Quick demo</h2>
Words <i>Lorem ipsum</i> and <i>vulputate</i> are highlighted.<br>
<div id="downloadContainer">
<a href="https://github.com/mistic100/jQuery-highlightTextarea/zipball/2.0" id="download" ><span>Download</span><br>version 2.0 (latest)</a>
</div>
<textarea id="demo" style="width:370px;height:100px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at massa non erat convallis vulputate molestie nec dui. Donec auctor blandit nibh quis luctus. Donec tincidunt auctor consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at massa non erat convallis vulputate molestie nec dui. Donec auctor blandit nibh quis luctus. Donec tincidunt auctor consequat.</textarea>
<br><a href="demo.htm">Other examples</a>
<a name="install" class="anchor"></a>
<h2>Installation</h2>
Include <b>jQuery</b> and <b>highlightTextarea</b> codes between <code class="kwa"><head></code> tags on your page.
<pre class="html"><span class="kwa"><script</span> <span class="kwb">type</span>=<span class="str">"text/javascript"</span> <span class="kwb">src</span>=<span class="str">"http://code.jquery.com/jquery-1.8.2.js"</span><span class="kwa">></script></span>
<span class="kwa"><link</span> <span class="kwb">type</span>=<span class="str">"text/css"</span> <span class="kwb">rel</span>=<span class="str">"stylesheet"</span> <span class="kwb">href</span>=<span class="str">"jquery.highlighttextarea.css"</span> <span class="kwa">/></span>
<span class="kwa"><script</span> <span class="kwb">type</span>=<span class="str">"text/javascript"</span> <span class="kwb">src</span>=<span class="str">"jquery.highlighttextarea.js"</span><span class="kwa">></script></span>
<span class="kwa"><script</span> <span class="kwb">type</span>=<span class="str">"text/javascript"</span><span class="kwa">></span>
$<span class="opt">(</span>document<span class="opt">).</span><span class="kwd">ready</span><span class="opt">(</span><span class="kwa">function</span><span class="opt">() {</span>
$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">({</span>
words<span class="opt">: [</span><span class="str">"first word"</span><span class="opt">,</span><span class="str">"an other word"</span><span class="opt">]</span>
<span class="opt">});</span>
<span class="opt">});</span>
<span class="kwa"></script></span></pre>
<b>Done !</b>
<br>
<span class="important">Important :</span> I recommend to use fixed width and height for textarea instead of number of rows and cols.
<a name="config" class="anchor"></a>
<h2>Configuration</h2>
<b>highlightTextarea</b> takes some additional parameters. The following are available :
<dl>
<dt>words</dt>
<dd>
An array with words and sentences which must be highlighted. You can use regular expressions. Default :
<pre>words<span class="opt">: []</span></pre>
</dd>
<dt>color</dt>
<dd>
The color used for highlight words. Default :
<pre>color<span class="opt">:</span> <span class="str">'#ffff00'</span></pre>
</dd>
<dt>caseSensitive</dt>
<dd>
If set to <code class="kwa">false</code> upper and lower case words will be identically highlighted. Default :
<pre>caseSensitive<span class="opt">:</span> <span class="kwa">true</span></pre>
</dd>
<dt>id</dt>
<dd>
You can add an id to the main highlight container, see section "Structure" bellow. Default :
<pre>id<span class="opt">:</span> <span class="kwa">null</span></pre>
</dd>
<dt>resizable</dt>
<dd>
If set to <code class="kwa">true</code> the textarea will be resizable. Default :
<pre>resizable<span class="opt">:</span> <span class="kwa">false</span></pre>
<span class="important">Warning :</span> you must include jQuery-UI with resizable option to your page in order to be able to resize textareas :
<pre class="html"><span class="kwa"><link</span> <span class="kwb">type</span>=<span class="str">"text/css"</span> <span class="kwb">rel</span>=<span class="str">"stylesheet"</span>
<span class="kwb">href</span>=<span class="str">"http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css"</span> <span class="kwa">/></span>
<span class="kwa"><script</span> <span class="kwb">type</span>=<span class="str">"text/javascript"</span> <span class="kwb">src</span>=<span class="str">"http://code.jquery.com/ui/1.9.0/jquery-ui.js"</span><span class="kwa">></script></span></pre>
</dd>
</dl>
<a name="api" class="anchor"></a>
<h2>API</h2>
Some methods can be called after instanciate the plugin :
<dl>
<dt>disable</dt>
<dd>
Remove the highlight and disable handlers.
<pre>$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">(</span></span><span class="str">'disable'</span><span class="opt">);</span></pre>
</dd>
<dt>enable</dt>
<dd>
Enable handlers and refresh the highlight.
<pre>$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">(</span></span><span class="str">'enable'</span><span class="opt">);</span></pre>
</dd>
<dt>highlight</dt>
<dd>
Force refresh the highlight. Returns <code class="kwa">false</code> if handlers are disabled, <code class="kwa">true</code> otherwise.
<pre>$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">(</span></span><span class="str">'highlight'</span><span class="opt">);</span></pre>
</dd>
<dt>setOptions</dt>
<dd>
Update highlight options (you cannot change 'resizable' value). Returns <code class="kwa">false</code> if handlers are disabled, <code class="kwa">true</code> otherwise.
<pre>$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">(</span><span class="str">'setOptions'</span>, <span class="opt">{</span> <span class="ppc">......</span> <span class="opt">});</span></pre>
</dd>
<dt>setWords</dt>
<dd>
Update words list. Returns <code class="kwa">false</code> if handlers are disabled, <code class="kwa">true</code> otherwise.
<pre>$<span class="opt">(</span><span class="str">"textarea"</span><span class="opt">).</span><span class="kwd">highlightTextarea</span><span class="opt">(</span><span class="str">'setWords'</span>, <span class="opt">[</span> <span class="ppc">......</span> <span class="opt">]);</span></pre>
</dd>
</dl>
<a name="structure" class="anchor"></a>
<h2>Structure</h2>
Here is the layout created by <b>highlightTextarea</b> arround each triggered textarea.
<img src="src/structure.png" style="display:block;width:620px;margin:0 auto;" />
<a name="bugs" class="anchor"></a>
<h2>Bugs report and features request</h2>
<a href="https://github.com/mistic100/jQuery-highlightTextarea/issues">On my github repo.</a>
<a name="changelog" class="anchor"></a>
<h2>Changelog</h2>
<dl class="changelog">
<dt>2.0 - 21/10/2012</dt>
<dd><ul>
<li>Add API methods</li>
<li>Correct mis-allignement</li>
<li>Escape HTML chars</li>
</ul></dd>
<dt>1.0 - 17/02/2012</dt>
<dd><ul>
<li>First version</li>
</ul></dd>
</dl>
<a name="license" class="anchor"></a>
<h2>License</h2>
<b>highlightTextarea</b> is released under a dual license. You can choose either the GPL or MIT license depending on the project you are using it in and how you wish to use it.
<br><br>
Part of the code was written by Julien L on Stack Overflow : <a href="http://stackoverflow.com/a/7599199">http://stackoverflow.com/a/7599199</a>.
<br>
Thanks to Pascal Wacker for the jQuery wrapper and API methods.
</div>
<div id="the_footer">© 2012 <a href="http://www.strangeplanet.fr">strangeplanet.fr</a> - Created by Damien "Mistic" Sorel</div>
</div>
</body>
</html>