-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (35 loc) · 1.18 KB
/
index.js
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
$("#inpt_search").on('focus', function() {
$(this).parent('label').addClass('active');
});
function search(data, keyword) {
var wanted = [];
for (var name in data) {
//console.log(list[name].keywords)
if (data[name].keywords.indexOf(keyword) !== -1) {
wanted.push(name);
}
}
//console.log(wanted);
return wanted;
}
$("#inpt_search").on('change', function() {
$("div.cntr-innr img, div.cntr-innr p.not-found").remove();
$.getJSON("search.json", function(result) {
//console.log(search(result, $("#inpt_search").val()));
var html = "";
var emojis = search(result, $("#inpt_search").val());
if (emojis.length > 0) {
for (var image in emojis) {
html += "<img src='http://grimacing.karmies.com/emojis/" + emojis[image] + ".png'/>";
}
$("div.cntr-innr").append(html);
} else {
$("div.cntr-innr").append("<p class='not-found'> Keyword not found, try another</p>");
}
});
});
$("#inpt_search").on('blur', function() {
if ($(this).val().length === 0) {
$(this).parent('label').removeClass('active');
}
});