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

Side by Side Diff: sky/examples/radio.sky

Issue 692563003: Docs: Update radio.sky to use the specced API for shadow roots (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 SKY MODULE - radio button and radio button group 1 SKY MODULE - radio button and radio button group
2 <!-- accessibility handling not implemented yet, pending mojo service --> 2 <!-- accessibility handling not implemented yet, pending mojo service -->
3 <import src="sky:core" as="sky"/> 3 <import src="sky:core" as="sky"/>
4 4
5 <!-- <radio> --> 5 <!-- <radio> -->
6 <template id="radio-shadow"> 6 <template id="radio-shadow">
7 <style> 7 <style>
8 :host { width: 1em; height: 1em; border: solid; background: white; } 8 :host { width: 1em; height: 1em; border: solid; background: white; }
9 :host[checked] { background: black; } 9 :host[checked] { background: black; }
10 </style> 10 </style>
11 </template> 11 </template>
12 <script> 12 <script>
13 module.exports = {}; 13 module.exports = {};
14 module.exports.RadioElement = sky.registerElement('radio', class extends Elemen t { 14 module.exports.RadioElement = sky.registerElement('radio', class extends Elemen t {
15 constructor () { 15 constructor () {
16 this.addEventListener('click', (event) => this.checked = true); 16 this.addEventListener('click', (event) => this.checked = true);
17 this.createShadowTree().appendChild(module.document.findId('radio-shadow'). content.cloneNode(true)); 17 this.addShadowRoot(new sky.ShadowRoot(module.document.findId('radio-shadow' ).content.cloneNode(true)));
18 } 18 }
19 get checked () { 19 get checked () {
20 return this.hasAttribute('checked'); 20 return this.hasAttribute('checked');
21 } 21 }
22 set checked (value) { 22 set checked (value) {
23 if (value) 23 if (value)
24 this.setAttribute('checked', ''); 24 this.setAttribute('checked', '');
25 else 25 else
26 this.removeAttribute('checked'); 26 this.removeAttribute('checked');
27 } 27 }
(...skipping 13 matching lines...) Expand all
41 41
42 <!-- <radiogroup> --> 42 <!-- <radiogroup> -->
43 <template id="radiogroup-shadow"> 43 <template id="radiogroup-shadow">
44 <style> 44 <style>
45 :host { padding: 1em; border: thin solid; } 45 :host { padding: 1em; border: thin solid; }
46 </style> 46 </style>
47 </template> 47 </template>
48 <script> 48 <script>
49 module.exports.RadioGroupElement = sky.registerElement('radiogroup', class exte nds Element { 49 module.exports.RadioGroupElement = sky.registerElement('radiogroup', class exte nds Element {
50 constructor () { 50 constructor () {
51 this.createShadowTree().appendChild(module.document.findId('radiogroup-shad ow').cloneNode(true)); 51 this.addShadowRoot(new sky.ShadowRoot(module.document.findId('radiogroup-sh adow').content.cloneNode(true)));
52 } 52 }
53 get value () { 53 get value () {
54 let children = this.getChildNodes(); 54 let children = this.getChildNodes();
55 for (let child of children) 55 for (let child of children)
56 if (child instanceof module.exports.RadioElement) 56 if (child instanceof module.exports.RadioElement)
57 if (child.checked) 57 if (child.checked)
58 return child.name; 58 return child.name;
59 return ''; 59 return '';
60 } 60 }
61 set value (name) { 61 set value (name) {
62 let children = this.getChildNodes(); 62 let children = this.getChildNodes();
63 for (let child of children) 63 for (let child of children)
64 if (child instanceof module.exports.RadioElement) 64 if (child instanceof module.exports.RadioElement)
65 if (child.value == name) 65 if (child.value == name)
66 child.checked = true; 66 child.checked = true;
67 } 67 }
68 setChecked(radio) { 68 setChecked(radio) {
69 if (!((radio instanceof module.exports.Radio) && radio.parentNode == this)) 69 if (!((radio instanceof module.exports.Radio) && radio.parentNode == this))
70 throw; 70 throw;
71 let children = this.getChildNodes(); 71 let children = this.getChildNodes();
72 for (let child of children) 72 for (let child of children)
73 if (child instanceof module.exports.RadioElement) 73 if (child instanceof module.exports.RadioElement)
74 if (child != radio) 74 if (child != radio)
75 child.checked = false; 75 child.checked = false;
76 } 76 }
77 }); 77 });
78 </script> 78 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698