simplify togglebutton using all the latest sugar

This commit is contained in:
frankiefu
2012-10-23 10:41:51 -07:00
parent 9f72878c71
commit 8947d48888

View File

@@ -5,7 +5,7 @@
* license that can be found in the LICENSE file.
*/
-->
<element name="g-togglebutton" attributes="value" handlers="click: clickHandler">
<element name="g-togglebutton" attributes="value" handlers="click: toggle">
<link rel="components" href="g-component.html">
<link rel="stylesheet" href="css/g-togglebutton.css" />
<template>
@@ -17,19 +17,12 @@
</template>
<script>
this.component({
created: function() {
this.valueAttributeChanged();
},
prototype: {
valueAttributeChanged: function() {
this.$.toggle.classList.enable('on', this.trueValue());
valueChanged: function() {
this.$.toggle.classList.enable('on', this.value);
},
clickHandler: function() {
this.value = !this.trueValue();
},
// TODO(ffu): remove this when base component handles auto-converting string value to boolean
trueValue: function() {
return this.value != 'false' && Boolean(this.value);
toggle: function() {
this.value = !this.value;
}
// TODO(ffu): need to add dragging support
}