-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.html
213 lines (180 loc) · 7.11 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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Responsive Sketchpad</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="assets/normalize.css">
<link rel="stylesheet" href="assets/skeleton.css">
<link rel="stylesheet" href="assets/custom.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
<!-- Google Analytics
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-33670860-4', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<section class="text-center">
<h2>Responsive Sketchpad</h2>
<h5>A completely responsive, HTML5 canvas sketchpad for use on desktop and mobile browsers</h5>
</section>
<section>
<div class="row">
<div class="two-thirds column">
<div id="sketchpad"></div>
<em>Try resizing the window!</em>
</div>
<div class="toolbox one-third column">
<label for="line-color-input">Set Line Color</label>
<input class="u-full-width" type="text" value="#000000" id="line-color-input">
<label for="line-size-input">Set Line Size</label>
<input class="u-full-width" type="number" value="5" id="line-size-input">
<div class="row">
<div class="one-half column">
<button class="u-full-width" id="undo">Undo</button>
</div>
<div class="one-half column">
<button class="u-full-width" id="redo">Redo</button>
</div>
<button class="u-full-width no-margin" id="clear">Clear</button>
<div class="docs-section text-center">
<p>Read and write sketchpad data</p>
<div class="row">
<div class="one-half column">
<a class="button u-full-width" id="uploadJson" download="image.png">Upload JSON</a>
<input type="file" id="uploadJsonInput" style="position: fixed; top: -100em" accept="application/json" />
</div>
<div class="one-half column">
<a class="button u-full-width" id="downloadJson" download="data.json">Download JSON</a>
</div>
<a class="button u-full-width" id="downloadPng" download="image.png">Download PNG</a>
</div>
</div>
</div>
</div>
</section>
<section>
<h3>Basic Usage</h3>
<pre><code>var Sketchpad = require('responsive-sketchpad');
// Initialize Sketchpad
var el = document.getElementById('sketchpad');
var pad = new Sketchpad(el, {
line: {
color: '#f44335',
size: 5
}
});
// Set line color
pad.setLineColor('#f44336');
// Set line size
pad.setLineSize(10);
// Undo
pad.undo();
// Redo
pad.redo();
// Clear canvas
pad.clear();
// Resize canvas
pad.resize(100);
// Make read only
pad.setReadOnly(true);
</code></pre>
</section>
</div>
<!-- Scripts
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script src="./dist/sketchpad.js"></script>
<script>
var el = document.getElementById('sketchpad');
var pad = new Sketchpad(el);
// setLineColor
function setLineColor(e) {
var color = e.target.value;
if (!color.startsWith('#')) {
color = '#' + color;
}
pad.setLineColor(color);
}
document.getElementById('line-color-input').oninput = setLineColor;
// setLineSize
function setLineSize(e) {
var size = e.target.value;
pad.setLineSize(size);
}
document.getElementById('line-size-input').oninput = setLineSize;
// undo
function undo() {
pad.undo();
}
document.getElementById('undo').onclick = undo;
// redo
function redo() {
pad.redo();
}
document.getElementById('redo').onclick = redo;
// clear
function clear() {
pad.clear();
}
document.getElementById('clear').onclick = clear;
function uploadJson() {
document.getElementById('uploadJsonInput').click();
}
document.getElementById('uploadJson').addEventListener('click', uploadJson, false);
function changeJson(e, a) {
const files = e.target.files;
if (files.length == 0) return;
const reader = new FileReader();
reader.addEventListener('load', (event) => {
try {
var data = JSON.parse(event.target.result);
} catch (e) {
alert("Unable to read JSON file");
throw e;
}
pad.loadJSON(data);
});
reader.readAsText(files[0]);
}
document.getElementById('uploadJsonInput').addEventListener('change', changeJson, false);
function downloadJson() {
var data = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(pad.toJSON()));
this.href = data;
}
document.getElementById('downloadJson').addEventListener('click', downloadJson, false);
function downloadPng() {
var data = pad.canvas.toDataURL("image/png");
this.href = data;
}
document.getElementById('downloadPng').addEventListener('click', downloadPng, false);
// resize
window.onresize = function (e) {
pad.resize(el.offsetWidth);
}
</script>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>