-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.html
149 lines (136 loc) · 5.71 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Auto Suggest</title>
<meta name="description" content="AutoSuggest">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet">
<link href="dropdown.css" rel="stylesheet">
<style type="text/css">
html {
height: 100%;
}
body {
background: #f0f0f0;
color: #464646;
padding: 15px 10px;
height: 100%;
font-family: 'Source Sans Pro';
}
#root {
background: #fff;
box-shadow: 0 1px 1px #bababa;
padding: 10px 20px 30px;
width: 640px;
margin: auto;
}
.heading {
padding-bottom: 5px;
border-bottom: 1px solid #ddd;
margin-bottom: 40px;
}
.heading small {
float: right;
position: relative;
bottom: -20px;
font-size: 50%;
}
#input,
#textarea,
#contenteditable {
border-radius: 0;
line-height: 20px;
}
#contenteditable {
height: 200px;
}
</style>
</head>
<body>
<div id="root">
<h3 class="subheading">Input Demo</h3>
<input type="text" id="input" class="form-control" />
<h3 class="subheading">Textarea Demo</h3>
<textarea id="textarea" class="form-control" rows="4"></textarea>
<h3 class="subheading">Contenteditable Demo</h3>
<div contenteditable="true" id="contenteditable" class="form-control"></div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="./dist/AutoSuggest.js"></script>
<script type="text/javascript">
const instance = new AutoSuggest({
onChange: function (suggestion) {
const change = suggestion.insertHtml || suggestion.insertText;
console.log('"' + change + '" has been inserted into #' + this.id);
},
suggestions: [
{
trigger: '<',
values: [
{
value: 'script',
insertText: '<script type="text/javascript" src="path/to/jsfile"><\/script>',
focusText: [-25, -11],
insertHtml: '<<span style="color: red">script</span> <span style="color:green">type</span>=<span style="color:darksalmon">"text/javascript"</span> <span style="color:green">src</span>=<span style="color:darksalmon">"path/to/jsfile"</span>><\/<span style="color: red">script</span>>',
focusHtml: [-25, -11],
},
{
value: 'link',
insertText: '<link href="path/to/cssfile" rel="stylesheet" \/>',
focusText: [-36, -21],
insertHtml: '<<span style="color:red">link</span> <span style="color:green">href</span>=<span style="color:darksalmon">"path/to/cssfile"</span> <span style="color:green">rel</span>=<span style="color:darksalmon">"stylesheet"</span> \/>',
focusHtml: [-36, -21],
}
]
}, {
trigger: '@',
values: [
{
on: ['avcs', 'cham', 'chandu'],
show: 'Chandrasekhar Ambula V',
insertText: '@AmbulaV',
insertHtml: '<a href="/" target="_blank">@AmbulaV</a>'
},
{
on: ['pj'],
show: 'Peter John',
insertText: '@John',
insertHtml: '<a href="/" target="_blank">@John</a>'
}
]
}, {
trigger: 'w',
values: ['word', 'world', 'with:^sp[e]c<i>(a)l ch{a}rs?$']
}, {
trigger: '//',
caseSensitive: true,
values: ['hello', 'world', 'simillar1', 'simillar12', 'with:^sp[e]c<i>(a)l ch{a}rs?$']
}, ['hello', 'world', 'simillar1', 'simillar12', 'with:^sp[e]c<i>(a)l ch{a}rs?$'],
function(keyword, callback) {
keyword = keyword.toLowerCase();
var results = [];
var dataset = this.value || this.textContent;
dataset = dataset.toLowerCase().split(/[^a-zA-Z0-9_]+/);
dataset.forEach(function(word) {
if (
word.length >= 4 &&
!word.indexOf(keyword) &&
word !== keyword &&
results.indexOf(word) === -1
) {
results.push(word);
}
});
setTimeout(function () {
callback(results);
}, 1000);
}
]
}, $('#input'), $('#textarea'), $('#contenteditable')[0]);
</script>
</body>
</html>