forked from webcomponents/polymer-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
42 lines (37 loc) · 1.29 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><a-painter></title>
<!-- Importing Web Component's Polyfill -->
<script src="//cdnjs.cloudflare.com/ajax/libs/polymer/0.0.20130711/polymer.min.js"></script>
<!-- Importing Custom Elements -->
<link rel="import" href="src/a-painter.html">
</head>
<body>
<!-- Using Custom Elements -->
<a-painter width="500" height="500" style="border: 1px solid black;"></a-painter>
<form>
<label>Tools</label>
<input type="radio" name="tool" id="Pen" checked/><label for="Pen">Pen</label>
<input type="radio" name="tool" id="Eraser"/><label for="Eraser">Eraser</label>
<a href="###" id="export" download="export.png">Export as image</a>
</form>
<script>
document.addEventListener('DOMContentLoaded', function() {
var painter = document.querySelector('a-painter');
var tools = document.querySelectorAll('input[name=tool]');
for(var i = 0; i < tools.length; i++) {
tools[i].addEventListener('change', function(e) {
console.log('tool changed: ' + e.srcElement.id);
painter.tool = new painter.Tools[e.srcElement.id]();
}, false);
}
var exportBtn = document.getElementById('export');
exportBtn.addEventListener('click', function() {
exportBtn.href = painter.export('image/png');
}, false);
});
</script>
</body>
</html>