-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathwa-led.html
More file actions
116 lines (100 loc) · 2.4 KB
/
Copy pathwa-led.html
File metadata and controls
116 lines (100 loc) · 2.4 KB
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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Led.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
pin: {
get: function() {
return this.getAttribute('pin');
},
set: function(val) {
this.setAttribute('pin', val);
}
},
intensity: {
get: function() {
return this.getAttribute('intensity');
},
set: function(val) {
this.setAttribute('intensity', val);
}
},
gnd: {
get: function() {
return this.getAttribute('gnd');
},
set: function(val) {
this.setAttribute('gnd', val);
}
},
state: {
get: function() {
return this.getAttribute('state');
},
set: function(val) {
this.setAttribute('state', val);
}
}
});
proto.init_ = function(board) {
var observer, config,
Led = webduino.module.Led;
this.led = new Led(board, board.getDigitalPin(this.pin));
if (this.state === 'on') {
this.on();
}
};
proto.createGnd_ = function() {
var gndLed;
if (this.gnd) {
if (this.gndLed) {
this.gndLed.parentNode.removeChild(this.gndLed);
}
gndLed = document.createElement('wa-led');
gndLed.setAttribute('pin', this.gnd);
this.parentNode.appendChild(gndLed);
this.gndLed = gndLed;
}
};
proto.on = function() {
this.led.on();
};
proto.off = function() {
this.led.off();
};
proto.toggle = function() {
this.led.toggle();
};
proto.attributeChangedCallback = function(attrName, oldVal, newVal) {
if (this.led) {
switch (attrName) {
case 'state':
newVal === "on" ? this.on() : this.off();
break;
case 'gnd':
this.createGnd_();
break;
case 'intensity':
this.led.intensity = newVal;
break;
}
}
};
proto.createdCallback = function() {
this.createGnd_();
};
proto.detachedCallback = function() {
if (this.gndLed) {
this.gndLed.parentNode.removeChild(this.gndLed);
}
};
document.registerElement('wa-led', {
prototype: proto
});
})();
</script>
</body>
</html>