Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: sky/framework/sky-radio/sky-radio.sky

Issue 836923002: Automate reflected properties in SkyElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: moar single quotes Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/sky-element/sky-element.sky ('k') | sky/tests/framework/templates.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" /> 6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" />
7 7
8 <sky-element name="sky-radio"> 8 <sky-element name="sky-radio" attributes="selected:boolean, group:string">
9 <template> 9 <template>
10 <style> 10 <style>
11 :host { 11 :host {
12 display: inline-block; 12 display: inline-block;
13 -webkit-user-select: none; 13 -webkit-user-select: none;
14 width: 14px; 14 width: 14px;
15 height: 14px; 15 height: 14px;
16 border-radius: 7px; 16 border-radius: 7px;
17 border: 1px solid blue; 17 border: 1px solid blue;
18 margin: 0 5px; 18 margin: 0 5px;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 addRadio(radio) { 50 addRadio(radio) {
51 this.radios.add(radio); 51 this.radios.add(radio);
52 // If this new radio is default-selected, take selection from the group. 52 // If this new radio is default-selected, take selection from the group.
53 if (radio.selected) 53 if (radio.selected)
54 this.takeSelectionFromGroup(radio); 54 this.takeSelectionFromGroup(radio);
55 } 55 }
56 removeRadio(radio) { 56 removeRadio(radio) {
57 this.radios.remove(radio); 57 this.radios.remove(radio);
58 } 58 }
59 takeSelectionFromGroup(selectedRadio) { 59 takeSelectionFromGroup(selectedRadio) {
60 // Emtpy/null/undefined group means and isolated radio. 60 // Emtpy/null/undefined group means an isolated radio.
61 if (!selectedRadio.group) 61 if (!selectedRadio.group)
62 return; 62 return;
63 this.radios.forEach(function(radio) { 63 this.radios.forEach(function(radio) {
64 if (selectedRadio === radio) 64 if (selectedRadio === radio)
65 return; 65 return;
66 if (radio.group != selectedRadio.group) 66 if (radio.group != selectedRadio.group)
67 return; 67 return;
68 radio.setSelected(false); 68 radio.selected = false;
69 }) 69 });
70 } 70 }
71 }; 71 };
72 72
73 module.exports = class extends SkyButton { 73 module.exports = class extends SkyButton {
74 created() { 74 created() {
75 super.created(); 75 super.created();
76 this.setSelected(this.getAttribute('selected'));
77 this.group = this.getAttribute('group');
78 76
79 this.addEventListener("mouseup", function() { 77 this.controller = null;
80 this.setSelected(true); 78
79 this.addEventListener('mouseup', function() {
80 this.selected = true;
81 }); 81 });
82 this.cachedController = null;
83 } 82 }
84 attached() { 83 attached() {
85 super.attached(); 84 super.attached();
86 this.cachedController = RadioGroupController.forRadio(this); 85 this.controller = RadioGroupController.forRadio(this);
87 this.cachedController.addRadio(this); 86 this.controller.addRadio(this);
88 } 87 }
89 detached() { 88 detached() {
90 super.detached(); 89 super.detached();
91 this.cachedController.removeRadio(this); 90 this.controller.removeRadio(this);
91 this.controller = null;
92 } 92 }
93 setSelected(selected) { 93 selectedChanged(oldValue, newValue) {
94 if (selected == this.selected) 94 if (newValue && this.controller)
95 return; 95 this.controller.takeSelectionFromGroup(this);
96 this.setAttribute('selected', selected); 96 }
97 this.selected = selected; 97 groupChanged(oldValue, newValue) {
98 if (selected && this.cachedController) 98 if (this.selected && this.controller)
99 this.cachedController.takeSelectionFromGroup(this); 99 this.controller.takeSelectionFromGroup(this);
100 } 100 }
101 }.register(); 101 }.register();
102 </script> 102 </script>
103 </sky-element> 103 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/sky-element/sky-element.sky ('k') | sky/tests/framework/templates.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698