OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview This is a simple template engine inspired by JsTemplates | 6 * @fileoverview This is a simple template engine inspired by JsTemplates |
7 * optimized for i18n. | 7 * optimized for i18n. |
8 * | 8 * |
9 * It currently supports three handlers: | 9 * It currently supports three handlers: |
10 * | 10 * |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 process(element, dictionary); | 104 process(element, dictionary); |
105 } | 105 } |
106 } else { | 106 } else { |
107 element.setAttribute(propName, /** @type {string} */(value)); | 107 element.setAttribute(propName, /** @type {string} */(value)); |
108 } | 108 } |
109 }); | 109 }); |
110 } | 110 } |
111 }; | 111 }; |
112 | 112 |
113 var attributeNames = Object.keys(handlers); | 113 var attributeNames = Object.keys(handlers); |
114 var selector = 'html /deep/ [' + attributeNames.join('],[') + ']'; | 114 // Chrome for iOS must use Apple's UIWebView, which (as of April 2015) does |
115 // not have native shadow DOM support. If shadow DOM is supported (or | |
116 // polyfilled), search for i18n attributes using the /deep/ selector; | |
117 // otherwise, do not attempt to search within the shadow DOM. | |
118 var selector = | |
119 (window.document.body && window.document.body.createShadowRoot) ? | |
120 'html /deep/ [' + attributeNames.join('],[') + ']' : | |
Dan Beam
2015/06/23 23:33:12
so this is whining in the console now about /deep/
| |
121 '[' + attributeNames.join('],[') + ']'; | |
115 | 122 |
116 /** | 123 /** |
117 * Processes a DOM tree with the {@code dictionary} map. | 124 * Processes a DOM tree with the {@code dictionary} map. |
118 * @param {HTMLElement} node The root of the DOM tree to process. | 125 * @param {HTMLElement} node The root of the DOM tree to process. |
119 * @param {LoadTimeData} dictionary The dictionary to draw from. | 126 * @param {LoadTimeData} dictionary The dictionary to draw from. |
120 */ | 127 */ |
121 function process(node, dictionary) { | 128 function process(node, dictionary) { |
122 var elements = node.querySelectorAll(selector); | 129 var elements = node.querySelectorAll(selector); |
123 for (var element, i = 0; element = elements[i]; i++) { | 130 for (var element, i = 0; element = elements[i]; i++) { |
124 for (var j = 0; j < attributeNames.length; j++) { | 131 for (var j = 0; j < attributeNames.length; j++) { |
125 var name = attributeNames[j]; | 132 var name = attributeNames[j]; |
126 var attribute = element.getAttribute(name); | 133 var attribute = element.getAttribute(name); |
127 if (attribute != null) | 134 if (attribute != null) |
128 handlers[name](element, attribute, dictionary); | 135 handlers[name](element, attribute, dictionary); |
129 } | 136 } |
130 } | 137 } |
131 } | 138 } |
132 | 139 |
133 return { | 140 return { |
134 process: process | 141 process: process |
135 }; | 142 }; |
136 }()); | 143 }()); |
OLD | NEW |