forked from github/gemoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (104 loc) · 2.58 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
<!doctype html>
<title>Emoji preview</title>
<style type="text/css">
body {
font: 14px/18px Verdana, Arial, sans-serif;
padding: 2em;
}
ol {
list-style: none;
padding-left: 0;
}
li {
margin-left: 0;
margin-top: 5px;
clear: left;
}
li:first-child { display: none; }
li > span {
display: block;
}
.emoji {
font-size: 50px;
line-height: 50px;
float: left;
margin-right: 20px;
}
.description {
font-style: italic;
color: gray;
}
.aliases span:before, .aliases span:after {
content: ":";
color: gray;
}
.tags {
font-size: 11px;
}
.tags span {
display: inline-block;
padding: 1px 5px 2px;
border-radius: 3px;
background: #dadada;
line-height: 11px;
}
</style>
<p><input type=search placeholder="Search..."></p>
<ol>
<li>
<span class="emoji"></span>
<span class="description"></span>
<span class="aliases"></span>
<span class="tags"></span>
</li>
</ol>
<script>
function renderEmoji(emojis) {
var item, els, template = document.querySelector('li')
for (var emoji, i=0; i < emojis.length; i++) {
emoji = emojis[i]
item = template.cloneNode(true)
els = item.querySelectorAll('span')
if (emoji.emoji) els[0].textContent = emoji.emoji
else {
var img = document.createElement('img')
img.src = "../images/emoji/" + emoji.aliases[0] + ".png"
els[0].appendChild(img)
}
els[1].textContent = emoji.description || ''
els[2].innerHTML = emoji.aliases.map(function(n){ return '<span>'+n+'</span>' }).join(' ')
els[3].innerHTML = emoji.tags.map(function(n){ return '<span>'+n+'</span>' }).join(' ')
template.parentNode.appendChild(item)
item._emojiText = (els[2].textContent + ' ' + els[3].textContent).replace(/_/g, '-')
}
}
xhr = new XMLHttpRequest
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
json = JSON.parse(this.responseText)
renderEmoji(json)
}
}
xhr.open('GET', 'emoji.json', false)
xhr.send(null)
function searchEmoji(query) {
var el,
re = new RegExp('\\b' + query),
els = document.querySelectorAll('li')
for (var i=1; i < els.length; i++) {
el = els[i]
if ( !query || re.test(el._emojiText) ) {
el.style.display = 'list-item'
} else {
el.style.display = 'none'
}
}
}
var timeout, search = document.querySelector('input[type=search]')
search.addEventListener('input', function() {
var $this = this
if (timeout) clearTimeout(timeout)
timeout = setTimeout(function(){ searchEmoji($this.value) }, 200)
}, false)
search.focus()
</script>