mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
simplify togglebutton using all the latest sugar
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user