-
Notifications
You must be signed in to change notification settings - Fork 4
/
scratch-card.html
99 lines (92 loc) · 2.31 KB
/
scratch-card.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
<script src="js/scratch.js" type="text/javascript"></script>
<link rel="import" href="bower_components/polymer/polymer-element.html">
<dom-module id="scratch-card">
<template>
<style>
:host {
display: block;
}
</style>
<h2>[[title]]!</h2>
<div id="container">
</div>
</template>
<script>
/**
* `scratch-card`
* scratch card using to images
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class ScratchCard extends Polymer.Element {
static get is() { return 'scratch-card'; }
static get properties() {
return {
title: {
type: String,
value: "scratch card"
},
background: {
type: String,
},
foreground: {
type: String,
},
percent: {
type: Number,
value: 85
},
thickness: {
type: Number,
value: 30
},
coin: {
type: String,
},
load: {
type: Boolean,
value: false,
notify: true,
observer: '_doLoad'
},
};
}
_doLoad() {
if (this.load) {
this._clear();
this._loadScratch();
}
}
_loadScratch() {
createScratchCard({
"container": this.$.container,
"background": this.background,
"foreground": this.foreground,
"percent": this.percent,
"thickness": this.thickness,
"coin": this.coin,
});
this.load = false;
}
_clear() {
if (typeof(this.$.container.clean) === typeof(Function)) {
this.$.container.clean();
}
}
_callback(event) {
this.dispatchEvent(new CustomEvent('scratch-finished', { detail: event.detail, bubbles: true, composed: true }));
}
connectedCallback() {
super.connectedCallback();
this.$.container.addEventListener('scratch-end', this._callback);
}
disconnectedCallback() {
super.disconnectedCallback();
this.$.container.removeEventListener('scratch-end', this._callback);
}
}
window.customElements.define(ScratchCard.is, ScratchCard);
</script>
</dom-module>