| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Part of the template compilation that concerns with simplifying HTML trees to | 6 * Part of the template compilation that concerns with simplifying HTML trees to |
| 7 * emit trimmed simple HTML code. | 7 * emit trimmed simple HTML code. |
| 8 */ | 8 */ |
| 9 library html_cleaner; | 9 library html_cleaner; |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 _component = info; | 28 _component = info; |
| 29 super.visitComponentInfo(info); | 29 super.visitComponentInfo(info); |
| 30 _component = oldComponent; | 30 _component = oldComponent; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void visitElementInfo(ElementInfo info) { | 33 void visitElementInfo(ElementInfo info) { |
| 34 var node = info.node; | 34 var node = info.node; |
| 35 info.removeAttributes.forEach(node.attributes.remove); | 35 info.removeAttributes.forEach(node.attributes.remove); |
| 36 info.removeAttributes.clear(); | 36 info.removeAttributes.clear(); |
| 37 | 37 |
| 38 // Hide all template elements. At the very least, we must do this for | 38 |
| 39 // template attributes, such as `<td template if="cond">`. | 39 // Normally, <template> nodes hang around in the DOM as placeholders, and |
| 40 if (info.hasIfCondition && !info.isTemplateElement) { | 40 // the user-agent style specifies that they are hidden. For browsers without |
| 41 node.attributes['style'] = 'display:none'; | 41 // native template, we inject the style later. |
| 42 // |
| 43 // However, template *attributes* are used for things like this: |
| 44 // * <td template if="condition"> |
| 45 // * <td template repeat="x in list"> |
| 46 // |
| 47 // In this case, we'll leave the TD as a placeholder. So hide it. |
| 48 // |
| 49 // For now, we also support this: |
| 50 // * <tr template iterate="x in list"> |
| 51 // |
| 52 // We don't need to hide this node, because its children are expanded as |
| 53 // child nodes. |
| 54 if (info is TemplateInfo) { |
| 55 TemplateInfo t = info; |
| 56 if (!t.isTemplateElement && (t.hasCondition || t.isRepeat)) { |
| 57 node.attributes['style'] = 'display:none'; |
| 58 } |
| 42 } | 59 } |
| 43 | 60 |
| 44 if (info.childrenCreatedInCode) { | 61 if (info.childrenCreatedInCode) { |
| 45 node.nodes.clear(); | 62 node.nodes.clear(); |
| 46 } | 63 } |
| 47 | 64 |
| 48 if (node.tagName == 'style' && node.attributes.containsKey("scoped") && | 65 if (node.tagName == 'style' && node.attributes.containsKey("scoped") && |
| 49 _component != null) { | 66 _component != null) { |
| 50 // Remove the style tag we've parsed the CSS. | 67 // Remove the style tag we've parsed the CSS. |
| 51 node.remove(); | 68 node.remove(); |
| 52 } | 69 } |
| 53 | 70 |
| 54 super.visitElementInfo(info); | 71 super.visitElementInfo(info); |
| 55 } | 72 } |
| 56 } | 73 } |
| OLD | NEW |