| OLD | NEW |
| 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-binder.sky" as="binder" /> | 6 <import src="sky-binder.sky" as="binder" /> |
| 7 <script> | 7 <script> |
| 8 // TODO(esprehn): It would be nice if these were exposed by the platform so | 8 // TODO(esprehn): It would be nice if these were exposed by the platform so |
| 9 // the framework didn't need to hard code a list. | 9 // the framework didn't need to hard code a list. |
| 10 var globalAttributesNames = new Set([ | 10 var globalAttributesNames = new Set([ |
| 11 'class', | 11 'class', |
| 12 'contenteditable', | 12 'contenteditable', |
| 13 'dir', | 13 'dir', |
| 14 'id', | 14 'id', |
| 15 'lang', | 15 'lang', |
| 16 'spellcheck', | 16 'spellcheck', |
| 17 'tabindex', | 17 'tabindex', |
| 18 'style', | 18 'style', |
| 19 ]); | 19 ]); |
| 20 | 20 |
| 21 function isExpandableAttribute(name) { |
| 22 return name.startsWith('data-') || name.startsWith('on-'); |
| 23 } |
| 24 |
| 25 function isGlobalAttribute(name) { |
| 26 if (isExpandableAttribute(name)) |
| 27 return true; |
| 28 return globalAttributesNames.has(name); |
| 29 } |
| 30 |
| 21 var attributeConverters = { | 31 var attributeConverters = { |
| 22 boolean: function(value) { | 32 boolean: function(value) { |
| 23 if (typeof value == 'string') | 33 if (typeof value == 'string') |
| 24 return value == 'true'; | 34 return value == 'true'; |
| 25 return !!value; | 35 return !!value; |
| 26 }, | 36 }, |
| 27 number: function(value) { | 37 number: function(value) { |
| 28 return Number(value); | 38 return Number(value); |
| 29 }, | 39 }, |
| 30 string: function(value) { | 40 string: function(value) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 class ElementRegistration { | 59 class ElementRegistration { |
| 50 constructor(tagName) { | 60 constructor(tagName) { |
| 51 this.tagName = tagName; | 61 this.tagName = tagName; |
| 52 this.attributes = new Map(); | 62 this.attributes = new Map(); |
| 53 this.eventHandlers = new Map(); | 63 this.eventHandlers = new Map(); |
| 54 this.template = null; | 64 this.template = null; |
| 55 Object.preventExtensions(this); | 65 Object.preventExtensions(this); |
| 56 } | 66 } |
| 57 | 67 |
| 58 allowsAttribute(name) { | 68 allowsAttribute(name) { |
| 59 if (name.startsWith('data-')) | 69 if (isGlobalAttribute(name)) |
| 60 return true; | |
| 61 if (globalAttributesNames.has(name)) | |
| 62 return true; | 70 return true; |
| 63 if (this.attributes.has(name)) | 71 if (this.attributes.has(name)) |
| 64 return true; | 72 return true; |
| 65 return false; | 73 return false; |
| 66 } | 74 } |
| 67 | 75 |
| 68 defineAttribute(name, type) { | 76 defineAttribute(name, type) { |
| 69 var converter = attributeConverters[type]; | 77 var converter = attributeConverters[type]; |
| 70 | 78 |
| 71 if (!converter) { | 79 if (!converter) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 121 } |
| 114 | 122 |
| 115 function getRegistration(tagName) { | 123 function getRegistration(tagName) { |
| 116 return registrations.get(tagName); | 124 return registrations.get(tagName); |
| 117 } | 125 } |
| 118 | 126 |
| 119 function checkAttribute(tagName, attrName) { | 127 function checkAttribute(tagName, attrName) { |
| 120 var registration = getRegistration(tagName); | 128 var registration = getRegistration(tagName); |
| 121 | 129 |
| 122 if (!registration) | 130 if (!registration) |
| 123 return globalAttributesNames.has(attrName); | 131 return isGlobalAttribute(attrName); |
| 124 | 132 |
| 125 return registration.allowsAttribute(attrName); | 133 return registration.allowsAttribute(attrName); |
| 126 } | 134 } |
| 127 | 135 |
| 128 registerElement('img', { | 136 registerElement('img', { |
| 129 'width': 'number', | 137 'width': 'number', |
| 130 'height': 'number', | 138 'height': 'number', |
| 131 // TODO(esprehn): Sky probably doesn't want the crossorign attr. | 139 // TODO(esprehn): Sky probably doesn't want the crossorign attr. |
| 132 'crossorigin': 'string', | 140 'crossorigin': 'string', |
| 133 'src': 'string', | 141 'src': 'string', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 154 | 162 |
| 155 registerElement('template', { | 163 registerElement('template', { |
| 156 'if': 'string', | 164 'if': 'string', |
| 157 'repeat': 'string', | 165 'repeat': 'string', |
| 158 }); | 166 }); |
| 159 | 167 |
| 160 module.exports = { | 168 module.exports = { |
| 161 registerElement: registerElement, | 169 registerElement: registerElement, |
| 162 getRegistration: getRegistration, | 170 getRegistration: getRegistration, |
| 163 checkAttribute: checkAttribute, | 171 checkAttribute: checkAttribute, |
| 172 isGlobalAttribute: isGlobalAttribute, |
| 173 isExpandableAttribute: isExpandableAttribute, |
| 164 }; | 174 }; |
| 165 </script> | 175 </script> |
| OLD | NEW |