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 /** @typedef {Document|DocumentFragment|Element} */ | 5 /** @typedef {Document|DocumentFragment|Element} */ |
6 var ProcessingRoot; | 6 var ProcessingRoot; |
7 | 7 |
8 /** | 8 /** |
9 * @fileoverview This is a simple template engine inspired by JsTemplates | 9 * @fileoverview This is a simple template engine inspired by JsTemplates |
10 * optimized for i18n. | 10 * optimized for i18n. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 return prefix + '[' + attributeNames.join('], ' + prefix + '[') + ']'; | 131 return prefix + '[' + attributeNames.join('], ' + prefix + '[') + ']'; |
132 }).join(', '); | 132 }).join(', '); |
133 | 133 |
134 /** | 134 /** |
135 * Processes a DOM tree using a |data| source to populate template values. | 135 * Processes a DOM tree using a |data| source to populate template values. |
136 * @param {!ProcessingRoot} root The root of the DOM tree to process. | 136 * @param {!ProcessingRoot} root The root of the DOM tree to process. |
137 * @param {!LoadTimeData} data The data to draw from. | 137 * @param {!LoadTimeData} data The data to draw from. |
138 */ | 138 */ |
139 function process(root, data) { | 139 function process(root, data) { |
140 processWithoutCycles(root, data, new Set(), true); | 140 processWithoutCycles(root, data, new Set(), true); |
141 | |
142 root.dispatchEvent(new Event('i18n-processed', { | |
Dan Beam
2016/02/17 04:47:34
i can't use cr.dispatchSimpleEvent() because this
| |
143 bubbles: true, | |
144 cancelable: false, | |
145 })); | |
141 } | 146 } |
142 | 147 |
143 /** | 148 /** |
144 * Internal process() method that stops cycles while processing. | 149 * Internal process() method that stops cycles while processing. |
145 * @param {!ProcessingRoot} root | 150 * @param {!ProcessingRoot} root |
146 * @param {!LoadTimeData} data | 151 * @param {!LoadTimeData} data |
147 * @param {!Set<ProcessingRoot>} visited Already visited roots. | 152 * @param {!Set<ProcessingRoot>} visited Already visited roots. |
148 * @param {boolean} mark Whether nodes should be marked processed. | 153 * @param {boolean} mark Whether nodes should be marked processed. |
149 */ | 154 */ |
150 function processWithoutCycles(root, data, visited, mark) { | 155 function processWithoutCycles(root, data, visited, mark) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 var attribute = element.getAttribute(name); | 211 var attribute = element.getAttribute(name); |
207 if (attribute != null) | 212 if (attribute != null) |
208 handlers[name](element, attribute, data, visited); | 213 handlers[name](element, attribute, data, visited); |
209 } | 214 } |
210 } | 215 } |
211 | 216 |
212 return { | 217 return { |
213 process: process | 218 process: process |
214 }; | 219 }; |
215 }()); | 220 }()); |
OLD | NEW |