-
Notifications
You must be signed in to change notification settings - Fork 14
/
wa-button.html
63 lines (49 loc) · 1.36 KB
/
wa-button.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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Button.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
pin: {
get: function() {
return this.getAttribute('pin');
}
}
});
proto.init_ = function(board) {
var events, button,
self = this,
Button = webduino.module.Button,
ButtonEvent = webduino.module.ButtonEvent;
events = new webduino.Events();
button = new Button(board, board.getDigitalPin(self.pin), Button.PULL_DOWN);
self.events_ = events;
self.button = button;
button.on(ButtonEvent.PRESS, function(event) {
events.emit('pressed');
});
button.on(ButtonEvent.RELEASE, function(event) {
events.emit('released');
});
button.on(ButtonEvent.SUSTAINED_PRESS, function(event) {
events.emit('sustainedPress');
});
button.on(ButtonEvent.LONG_PRESS, function(event) {
events.emit('longPress');
});
};
proto.on = function(eventType, handler) {
this.events_.on(eventType, handler);
};
proto.off = function(eventType, handler) {
this.events_.off(eventType, handler);
};
document.registerElement('wa-button', {
prototype: proto
});
})();
</script>
</body>
</html>