Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: ui/webui/resources/js/i18n_template_no_process.js

Issue 1076093002: Minimize flicker by adding a   to nodes that will have (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ::after -> ::before Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // not have native shadow DOM support. If shadow DOM is supported (or 115 // not have native shadow DOM support. If shadow DOM is supported (or
116 // polyfilled), search for i18n attributes using the /deep/ selector; 116 // polyfilled), search for i18n attributes using the /deep/ selector;
117 // otherwise, do not attempt to search within the shadow DOM. 117 // otherwise, do not attempt to search within the shadow DOM.
118 var selector = 118 var selector =
119 (window.document.body && window.document.body.createShadowRoot) ? 119 (window.document.body && window.document.body.createShadowRoot) ?
120 'html /deep/ [' + attributeNames.join('],[') + ']' : 120 'html /deep/ [' + attributeNames.join('],[') + ']' :
121 '[' + attributeNames.join('],[') + ']'; 121 '[' + attributeNames.join('],[') + ']';
122 122
123 /** 123 /**
124 * Processes a DOM tree with the {@code dictionary} map. 124 * Processes a DOM tree with the {@code dictionary} map.
125 * @param {HTMLElement} node The root of the DOM tree to process. 125 * @param {Document|Element} root The root of the DOM tree to process.
126 * @param {LoadTimeData} dictionary The dictionary to draw from. 126 * @param {LoadTimeData} dictionary The dictionary to draw from.
127 */ 127 */
128 function process(node, dictionary) { 128 function process(root, dictionary) {
129 var elements = node.querySelectorAll(selector); 129 var elements = root.querySelectorAll(selector);
130 for (var element, i = 0; element = elements[i]; i++) { 130 for (var element, i = 0; element = elements[i]; i++) {
131 for (var j = 0; j < attributeNames.length; j++) { 131 for (var j = 0; j < attributeNames.length; j++) {
132 var name = attributeNames[j]; 132 var name = attributeNames[j];
133 var attribute = element.getAttribute(name); 133 var attribute = element.getAttribute(name);
134 if (attribute != null) 134 if (attribute != null)
135 handlers[name](element, attribute, dictionary); 135 handlers[name](element, attribute, dictionary);
136 } 136 }
137 } 137 }
138 var doc = root instanceof Document ? root : root.ownerDocument;
139 if (doc)
140 doc.documentElement.classList.add('i18n-processed');
138 } 141 }
139 142
140 return { 143 return {
141 process: process 144 process: process
142 }; 145 };
143 }()); 146 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698