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

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

Issue 1062813007: If shadow DOM is not supported, search for i18n attributes without using the /deep/ selector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add existence check for window.document.body before window.document.body.createShadowRoot. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698