forked from yuku/textcomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
127 lines (118 loc) · 4.08 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
<!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"/>
<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>
</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>Basic Usage</h3>
<div><textarea id="textarea1" rows="4" style="display: block; width: 100%;">:a</textarea></div>
<pre class="brush: js; script">
var words = ['apple', 'google', 'facebook', 'github'];
$('#textarea1').textcomplete({
// emoji strategy
emoji: {
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
},
techCompanies: {
match: /(\s|\n)(\w{2,})$/,
search: function (term, callback) {
callback($.map(words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
replace: function (word) {
return '$1' + word + ' ';
}
}
});
</pre>
<h3>Insert Cursor After Autocomplete</h3>
<div><textarea id="textarea2" rows="4" style="display: block; width: 100%;">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>Use with <a href="http://yuku-t.com/jquery-overlay/" target="_blank">jQuery.overlay</a></h3>
<div><textarea id="textarea3" rows="4" style="display: block; width: 100%;">Hey @guys,
All words start with @ are emphasized like @this.</textarea></div>
<pre class="brush: js; script">
var mentions = ['yuku_t'];
$('#textarea3').textcomplete({
html: {
match: /\B@(\w*)$/,
search: function (term, callback) {
callback($.map(mentions, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
index: 1,
replace: function (mention) {
return '@' + mention + ' ';
}
}
}).overlay([
{
match: /\B@\w+/g,
css: {
'background-color': '#d8dfea'
}
}
]);
</pre>
<h2>License</h2>
<p>
MIT
</p>
</div>
</body>
</html>