| OLD | NEW |
| 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 | 3 |
| 4 <!-- <radio> --> | 4 <!-- <radio> --> |
| 5 <template id="radio-shadow"> | 5 <template id="radio-shadow"> |
| 6 <style> | 6 <style> |
| 7 :host { width: 1em; height: 1em; border: solid; background: white; } | 7 :host { width: 1em; height: 1em; border: solid; background: white; } |
| 8 :host[checked] { background: black; } | 8 :host[checked] { background: black; } |
| 9 </style> | 9 </style> |
| 10 </template> | 10 </template> |
| 11 <script> | 11 <script> |
| 12 module.exports.RadioElement = module.registerElement({ | 12 module.exports.RadioElement = module.registerElement( |
| 13 tagName: 'radio', | 13 class extends Element { |
| 14 shadow: true, | 14 static get tagName() { return 'radio'; } |
| 15 constructor: class extends Element { | 15 static get shadow() { return true; } |
| 16 constructor (module) { | 16 constructor (module) { |
| 17 super(module); | 17 super(module); |
| 18 this.addEventListener('click', (event) => this.checked = true); | 18 this.addEventListener('click', (event) => this.checked = true); |
| 19 this.shadowRoot.append(module.document.findId('radio-shadow').content.clo
neNode(true)); | 19 this.shadowRoot.append(module.document.findId('radio-shadow').content.clo
neNode(true)); |
| 20 } | 20 } |
| 21 get checked () { | 21 get checked () { |
| 22 return this.hasAttribute('checked'); | 22 return this.hasAttribute('checked'); |
| 23 } | 23 } |
| 24 set checked (value) { | 24 set checked (value) { |
| 25 if (value) | 25 if (value) |
| 26 this.setAttribute('checked', ''); | 26 this.setAttribute('checked', ''); |
| 27 else | 27 else |
| 28 this.removeAttribute('checked'); | 28 this.removeAttribute('checked'); |
| 29 } | 29 } |
| 30 get value () { | 30 get value () { |
| 31 return this.getAttribute('name'); | 31 return this.getAttribute('name'); |
| 32 } | 32 } |
| 33 set value (value) { | 33 set value (value) { |
| 34 this.setAttribute('value', value); | 34 this.setAttribute('value', value); |
| 35 } | 35 } |
| 36 attributeChanged(name, oldValue, newValue) { | 36 attributeChanged(name, oldValue, newValue) { |
| 37 if ((name == 'checked') && (newValue != null)) | 37 if ((name == 'checked') && (newValue != null)) |
| 38 if (this.parentNode instanceof module.exports.RadioGroupElement) | 38 if (this.parentNode instanceof module.exports.RadioGroupElement) |
| 39 this.parentNode.setChecked(this); | 39 this.parentNode.setChecked(this); |
| 40 } | 40 } |
| 41 }, | 41 } |
| 42 }); | 42 ); |
| 43 </script> | 43 </script> |
| 44 | 44 |
| 45 <!-- <radiogroup> --> | 45 <!-- <radiogroup> --> |
| 46 <template id="radiogroup-shadow"> | 46 <template id="radiogroup-shadow"> |
| 47 <style> | 47 <style> |
| 48 :host { padding: 1em; border: thin solid; } | 48 :host { padding: 1em; border: thin solid; } |
| 49 </style> | 49 </style> |
| 50 </template> | 50 </template> |
| 51 <script> | 51 <script> |
| 52 module.exports.RadioGroupElement = module.registerElement{ | 52 module.exports.RadioGroupElement = module.registerElement( |
| 53 tagName: 'radiogroup', | 53 class extends Element { |
| 54 shadow: true, | 54 static get tagName() { return 'radiogroup'; } |
| 55 constructor: (class extends Element { | 55 static get shadow() { return true; } |
| 56 constructor (module) { | 56 constructor (module) { |
| 57 super(module); | 57 super(module); |
| 58 this.shadowRoot.append(module.document.findId('radiogroup-shadow').conten
t.cloneNode(true)); | 58 this.shadowRoot.append(module.document.findId('radiogroup-shadow').conten
t.cloneNode(true)); |
| 59 } | 59 } |
| 60 get value () { | 60 get value () { |
| 61 let children = this.getChildNodes(); | 61 let children = this.getChildNodes(); |
| 62 for (let child of children) | 62 for (let child of children) |
| 63 if (child instanceof module.exports.RadioElement) | 63 if (child instanceof module.exports.RadioElement) |
| 64 if (child.checked) | 64 if (child.checked) |
| 65 return child.name; | 65 return child.name; |
| 66 return ''; | 66 return ''; |
| 67 } | 67 } |
| 68 set value (name) { | 68 set value (name) { |
| 69 let children = this.getChildNodes(); | 69 let children = this.getChildNodes(); |
| 70 for (let child of children) | 70 for (let child of children) |
| 71 if (child instanceof module.exports.RadioElement) | 71 if (child instanceof module.exports.RadioElement) |
| 72 if (child.value == name) | 72 if (child.value == name) |
| 73 child.checked = true; | 73 child.checked = true; |
| 74 } | 74 } |
| 75 setChecked(radio) { | 75 setChecked(radio) { |
| 76 if (!((radio instanceof module.exports.Radio) && radio.parentNode == this
)) | 76 if (!((radio instanceof module.exports.Radio) && radio.parentNode == this
)) |
| 77 throw; | 77 throw; |
| 78 let children = this.getChildNodes(); | 78 let children = this.getChildNodes(); |
| 79 for (let child of children) | 79 for (let child of children) |
| 80 if (child instanceof module.exports.RadioElement) | 80 if (child instanceof module.exports.RadioElement) |
| 81 if (child != radio) | 81 if (child != radio) |
| 82 child.checked = false; | 82 child.checked = false; |
| 83 } | 83 } |
| 84 }, | 84 } |
| 85 }); | 85 ); |
| 86 </script> | 86 </script> |
| OLD | NEW |