forked from yuku/textcomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
225 lines (215 loc) · 7.61 KB
/
index.html
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html>
<head>
<title>jQuery.textcomplete</title>
<link href="media/stylesheets/bootstrap.css" rel="stylesheet"/>
<link href="media/stylesheets/font-awesome.css" rel="stylesheet"/>
<link href="media/stylesheets/main.css" rel="stylesheet"/>
<link href="media/stylesheets/shCoreDefault.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>
jQuery.textcomplete
<small>Autocomplete for Textarea</small>
</h1>
</div>
<a href="https://github.com/yuku-t/jquery-textcomplete" class="btn btn-default btn-large">
<i class="icon-github"></i>
Fork me on GitHub.
</a>
<h2>Demo</h2>
<h3 id="basic-usage">Basic Usage</h3>
<div class="textarea-wrapper">
<span class="label">#textarea1</span>
<textarea id="textarea1" rows="4">:a</textarea>
</div>
<pre class="brush: js; script">
$('#textarea1').textcomplete([
{ // emoji strategy
match: /\B:([\-+\w]*)$/,
search: function (term, callback) {
callback($.map(emojies, function (emoji) {
return emoji.indexOf(term) === 0 ? emoji : null;
}));
},
template: function (value) {
return '<img src="media/images/emoji/' + value + '.png"></img>' + value;
},
replace: function (value) {
return ':' + value + ': ';
},
index: 1,
maxCount: 5
}
]);
// You can append strategies to an already existing textcomplete object.
$('#textarea1').textcomplete([
{ // tech companies
words: ['apple', 'google', 'facebook', 'github'],
match: /\b(\w{2,})$/,
search: function (term, callback) {
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return word + ' ';
},
placement: 'top'
}
]);
</pre>
<h3 id="insert-cursor-after-autocomplete">Insert Cursor After Autocomplete</h3>
<div class="textarea-wrapper">
<span class="label">#textarea2</span>
<textarea id="textarea2" rows="4">Please input HTML element: </textarea>
</div>
<pre class="brush: js; script">
var elements = ['span', 'div', 'h1', 'h2', 'h3'];
$('#textarea2').textcomplete([
{ // html
match: /<(\w*)$/,
search: function (term, callback) {
callback($.map(elements, function (element) {
return element.indexOf(term) === 0 ? element : null;
}));
},
index: 1,
replace: function (element) {
return ['<' + element + '>', '</' + element + '>'];
}
}
]);
</pre>
<h3 id="use-with-jquery-overlay">Use with <a href="http://yuku-t.com/jquery-overlay/" target="_blank">jQuery.overlay</a></h3>
<div class="textarea-wrapper">
<span class="label">#textarea3</span>
<textarea id="textarea3" rows="4">Hey @guys,
All words start with @ are emphasized like @this.</textarea>
</div>
<pre class="brush: js; script">
$('#textarea3').textcomplete([
{ // html
mentions: ['yuku_t'],
match: /\B@(\w*)$/,
search: function (term, callback) {
callback($.map(this.mentions, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
index: 1,
replace: function (mention) {
return '@' + mention + ' ';
}
}
], { appendTo: 'body' }).overlay([
{
match: /\B@\w+/g,
css: {
'background-color': '#d8dfea'
}
}
]);
</pre>
<h3 id="apply-to-multiple-textareas">Apply to Multiple Textareas</h3>
<div class="textarea-wrapper">
<span class="label">.textarea4</span>
<textarea class="textarea4" rows="4"></textarea>
</div>
<div class="textarea-wrapper">
<span class="label">.textarea4</span>
<textarea class="textarea4" rows="4"></textarea>
</div>
<pre class="brush: js; script">
$('.textarea4').textcomplete([
{ // tech companies
words: ['apple', 'google', 'facebook', 'github'],
match: /\b(\w{2,})$/,
search: function (term, callback) {
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return word + ' ';
}
}
]);
</pre>
<h3 id="customizing-header-footer">Customizing header, footer</h3>
<div class="textarea-wrapper">
<span class="label">#textarea5</span>
<textarea id="textarea5" rows="4">:a</textarea>
</div>
<pre class="brush: js; script">
$('#textarea5').textcomplete([
{ // emoji strategy
match: /\B:([\-+\w]*)$/,
search: function (term, callback) {
callback($.map(emojies, function (emoji) {
return emoji.indexOf(term) === 0 ? emoji : null;
}));
},
template: function (value) {
return '<img src="media/images/emoji/' + value + '.png"></img>' + value;
},
replace: function (value) {
return ':' + value + ': ';
},
index: 1,
maxCount: 5,
header: function (data) {
return '<strong style="text-align: center; display: block;">' + data.length + '</strong>';
},
footer: '<strong style="text-align: center; display: block;">Footer</strong>'
}
]).on('focus', function () {
var textComplete = $(this).data('textComplete');
// Cursor has not set yet. And wait 100ms to skip global click event.
setTimeout(function () {
// Cursor is ready.
textComplete.trigger();
}, 100);
});
</pre>
<h3 id="apply-to-contenteditables">Apply to Contenteditables</h3>
<div class="textarea-wrapper">
<span class="label">.contenteditable1</span>
<div class="contenteditable1" contenteditable="true"><b>Look</b> at this <em>glorious</em> contenteditable.</div>
</div>
<pre class="brush: js; script">
$('.contenteditable1').textcomplete([
{ // tech companies
words: ['stunning', 'amazing', 'incredible', 'fantastic', 'fantabulous'],
match: /\b(\w{2,})$/,
search: function (term, callback) {
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return word + ' ';
}
}
]);
</pre>
<h2>License</h2>
<p>
MIT
</p>
</div>
<script src="media/javascripts/jquery-1.10.2.js"></script>
<!-- <script src="media/javascripts/zepto-1.0.js"></script> -->
<script src="http://yuku-t.com/jquery-overlay/jquery.overlay.js"></script>
<script src="jquery.textcomplete.js"></script>
<script src="media/javascripts/emoji.js"></script>
<script src="media/javascripts/shCore.js"></script>
<script src="media/javascripts/shBrushJScript.js"></script>
<script src="media/javascripts/main.js"></script>
</body>
</html>