-
Notifications
You must be signed in to change notification settings - Fork 144
/
index.html
219 lines (215 loc) · 6.02 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
<html>
<head>
<title>emoji-translate</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="icon" type="image/png" href="extension/logo.png">
<link rel="apple-touch-icon" sizes="128x128" href="extension/logo.png" />
<link href='https://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
<script src="public/bundle.js"></script>
</head>
<style>
body {
font-family: 'Helvetica';
font-weight: 300;
background: #fff;
color: #535353;
margin: 0px;
padding: 50px;
overflow: auto;
font-size: 16px;
}
.container {
max-width: 600px;
margin: 0 auto;
overflow: auto;
z-index: 10;
}
@media (max-width: 500px) {
body {
padding: 20px;
}
button {
margin: 20px 0 !important;
}
}
h1 {
font-family: 'Lato', 'Helvetica', Arial, sans-serif;
font-weight: 300;
margin-bottom: 0;
}
textarea {
width: 100%;
font-family: 'Helvetica';
font-weight: 300;
font-size: 16px;
height: 150px;
line-height: 24px;
}
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
display: inline-block;
border: 0;
outline: 0;
background: transparent;
cursor: pointer;
font-size: 16px;
padding: 0 4px;
line-height: 1.5;
background-color: #eee;
border-radius: 3px;
margin: 0 4px 4px 4px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14),
0 1px 5px 0 rgba(0, 0, 0, 0.12),
0 3px 1px -2px rgba(0, 0, 0, 0.2);
}
select:focus {
background-color: #7bd6cf;
}
button {
border: none;
outline: none;
cursor: pointer;
text-align: center;
background: #E91E63;
color: white;
font-weight: normal;
transition: all .4s;
height: 30px;
border-radius: 2px;
text-transform: uppercase;
vertical-align: middle;
font-size: 14px;
margin: 20px;
width: 180px;
}
#footer {
margin-top: 100px;
padding-top: 20px;
border-top: 2px solid #E91E63;
text-align: center;
text-transform: uppercase;
}
#footer > p {
text-transform: uppercase;
font-size: 10px;
letter-spacing: .2em;
padding-right: 6px;
}
.note {
margin-top: 0;
margin-bottom: 20px;
font-size: 12px;
}
.red {
color: #E91E63;
}
a:link, a:visited {
color: #E91E63;
text-decoration: none;
}
a:hover {
color: #2196F3;
}
/* Hide this somewhere */
#clipboardContents {
opacity: 0;
position: absolute;
bottom: 0;
left: 0;
z-index: 0;
}
</style>
<body>
<div class="container">
<h1>From 🇬🇧</h1>
<p class="note">(just start typing!)</p>
<textarea id="input">OMG!!! The house is on fire and the cat is eating all the donuts!</textarea>
<br><br>
<h1>To ✨emoji✨ <button onclick="copy()" id="copyButton">Copy to clipboard</button></h1>
<div id="output"></div>
<div id="footer">
<p>made with <span class="red">❤︎</span> by <a href="https://twitter.com/notwaldorf">monica</a>.
find this on <a href="https://github.com/notwaldorf/emoji-translate">github</a></p>
</div>
</div>
<!-- Gigantor hack to get the copy-to-clipboard working. I don't think it
works with hidden divs, so uhhhh just hide this one real well -->
<div id="clipboardContents"></div>
<script type="text/javascript">
console.log(EmojiTranslate.translate('the cat is on fire'));
</script>
<script>
updateOutput();
document.getElementById('input').addEventListener('input', function() {
updateOutput();
});
function updateOutput() {
// Rather than calling EmojiTranslate.translate, we want all the
// possible options.
document.getElementById('output').innerHTML = '';
var text = document.getElementById('input').value;
var container = document.getElementById('output');
var allLines = text.split('\n');
for (var line = 0; line < allLines.length; line++ ){
if (allLines[line] == '')
continue
var words = allLines[line].split(' ');
// Re-add the translated words.
for (var i = 0; i < words.length; i++ ) {
var node = EmojiTranslate.translateForDisplay(words[i]);
if (node)
container.appendChild(node);
}
var newLine = document.createElement('br');
container.appendChild(newLine);
}
return container;
}
function copy() {
var value = getActualOutput();
clipboardContents.textContent = value;
// From https://github.com/google/material-design-lite/blob/master/docs/_assets/snippets.js
var snipRange = document.createRange();
snipRange.selectNodeContents(clipboardContents);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(snipRange);
var result = false;
try {
result = document.execCommand('copy');
copyButton.innerHTML = 'Done!';
} catch (err) {
// Copy command is not available
console.error(err);
copyButton.innerHTML = 'Oops, error copying :(';
}
// Return to the copy button after a second.
setTimeout(function() {
copyButton.innerHTML = 'Copy to clipboard';
}.bind(this), 1000);
selection.removeAllRanges();
return result;
}
function getActualOutput() {
var value = '';
var nodes = output.children;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].tagName === 'SELECT') {
// Do this instead of .value because we want to maintain whitespace.
value += nodes[i].options[nodes[i].selectedIndex].textContent;
} else if (nodes[i].tagName === 'BR') {
value += '\n';
} else if (nodes[i].tagName != 'OPTION') {
value += nodes[i].textContent;
}
}
return value;
}
</script>
</body>
</html>