-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.html
171 lines (153 loc) · 5.97 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
<html>
<head>
<title>emojillate</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" href="favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html">
<link rel="import" href="bower_components/iron-icon/iron-icon.html">
<link rel="import" href="bower_components/paper-slider/paper-slider.html">
<link rel="import" href="elements/emoji-llate.html">
<link rel="import" href="elements/icons.html">
<custom-style>
<style is="custom-style">
paper-slider {
--paper-slider-knob-color: #01beb4;
--paper-slider-active-color: #01beb4;
--paper-slider-pin-color: #01beb4;
width: 30%;
margin-right: 30px;
}
paper-checkbox {
--paper-checkbox-checked-color: #01beb4;
--paper-checkbox-checked-ink-color: #01beb4;
--paper-checkbox-unchecked-color: #01beb4;
--paper-checkbox-unchecked-ink-color: #01beb4;
--paper-checkbox-label-color: #01beb4;
font-family: 'Lato', 'Helvetica', sans-serif;
font-weight: 400;
}
paper-icon-button {
border-radius: 50%;
}
paper-icon-button:hover {
background: #bdf0f1;
}
</style>
</custom-style>
</head>
<body unresolved>
<div class="wrapper">
<h1 title="emoji + pixellate = emojillate">~~emojillate~~</h1>
<dom-bind id="t">
<template is="dom-bind">
<div class="file">
<label class="button">
<input type="file" accept="image/*" on-change="munge">
<iron-icon icon="icons:upload"></iron-icon> Load image
</label>
<span id="actions">
<button class="button" on-click="copyToClipboard" title="copy to clipboard">
<iron-icon icon="icons:copy" id="copyButton"></iron-icon> Copy
</button>
<button class="button" on-click="uploadGist" title="upload gist">
<iron-icon icon="custom:github" id="uploadButton"></iron-icon> Create gist
</button>
<div><span class="statusText"></span><a class="statusLink" href="" target="_blank"></a> </div>
</span>
</div>
<div>
<span class="slider-label">resolution</span>
<paper-slider value="{{_value}}" pin snaps step=5 min=5 max=80></paper-slider>
<paper-checkbox checked="{{_noBackground}}">hide background</paper-checkbox>
</div>
<br><br>
<emoji-llate id="emojillate" resolution="{{_value}}" no-background="{{_noBackground}}">
<div class="output"></div>
</emoji-llate>
</template>
<dom-bind>
<footer>
<p>made with 🧀 & 🍷 by <a href="https://twitter.com/notwaldorf" target="_blank">monica</a>.
find this on <a href="https://github.com/notwaldorf/emojillate" target="_blank">github</a></p>
</footer>
</div>
</body>
<script>
t._value = 60;
t._noBackground = false;
t.munge = function(e) {
actions.hidden = false;
emojillate.file = e.target.files[0];
clearStatus();
//filename.innerHTML = e.target.files[0].name;
return false;
}
t.copyToClipboard = function() {
// From https://github.com/google/material-design-lite/blob/master/docs/_assets/snippets.js
var snipRange = document.createRange();
snipRange.selectNodeContents(document.querySelector('.output'));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(snipRange);
var result = false;
try {
result = document.execCommand('copy');
console.log('done');
copyButton.icon = 'icons:done';
} catch (err) {
// Copy command is not available
console.error(err);
copyButton.icon = 'icons:error';
}
// Return to the copy button after a second.
setTimeout(function() {
copyButton.icon = 'icons:copy';
}, 1000);
selection.removeAllRanges();
return result;
}
t.uploadGist = function() {
clearStatus();
var result = document.querySelector('.statusText').textContent = 'Creating gist...';
var fileContents = document.querySelector('.output').innerText;
var fileName = document.querySelector('emoji-llate').tldr;
var request = {'description': 'Made with http://meowni.ca/emojillate',
'public': 'true',
'files': {}
};
request.files[fileName] = {'content': fileContents};
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.github.com/gists', true);
xhr.send(JSON.stringify(request));
xhr.addEventListener("readystatechange", function(e) {
if (this.readyState === 4 && this.status >= 200 && this.status < 300) {
var response = JSON.parse(xhr.responseText);
clearStatus();
document.querySelector('.statusText').textContent = fileName + ' ';
var link = document.querySelector('.statusLink');
link.textContent = link.href = response.html_url;
uploadButton.icon = 'icons:done';
// Return to the github icon after a second, and clear the result.
setTimeout(function() {
uploadButton.icon = 'custom:github';
}, 1000);
} else if (this.readyState === 4 && this.status >= 400) {
console.log('Oops', xhr.responseText);
uploadButton.icon = 'icons:error';
}
}, false);
}
function clearStatus() {
document.querySelector('.statusText').textContent = '';
var link = document.querySelector('.statusLink');
link.textContent = link.href = '';
}
</script>
</html>