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

Side by Side Diff: native_client_sdk/src/examples/common.js

Issue 13488007: [NaCl SDK] Make the SDK examples buildable as a packaged app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix license headers Created 7 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 | Annotate | Revision Log
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 // Javascript module pattern: 5 // Javascript module pattern:
6 // see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces 6 // see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces
7 // In essence, we define an anonymous function which is immediately called and 7 // In essence, we define an anonymous function which is immediately called and
8 // returns a new object. The new object contains only the exported definitions; 8 // returns a new object. The new object contains only the exported definitions;
9 // all other definitions in the anonymous function are inaccessible to external 9 // all other definitions in the anonymous function are inaccessible to external
10 // code. 10 // code.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 * 119 *
120 * @param {string} s The string to search. 120 * @param {string} s The string to search.
121 * @param {string} prefix The prefix to search for in |s|. 121 * @param {string} prefix The prefix to search for in |s|.
122 */ 122 */
123 function startsWith(s, prefix) { 123 function startsWith(s, prefix) {
124 // indexOf would search the entire string, lastIndexOf(p, 0) only checks at 124 // indexOf would search the entire string, lastIndexOf(p, 0) only checks at
125 // the first index. See: http://stackoverflow.com/a/4579228 125 // the first index. See: http://stackoverflow.com/a/4579228
126 return s.lastIndexOf(prefix, 0) === 0; 126 return s.lastIndexOf(prefix, 0) === 0;
127 } 127 }
128 128
129 /** Maximum length of logMessageArray. */
130 var kMaxLogMessageLength = 20;
131
132 /** An array of messages to display in the element with id "log". */
133 var logMessageArray = [];
134
129 /** 135 /**
130 * Add a message to an element with id "log", separated by a <br> element. 136 * Add a message to an element with id "log".
131 * 137 *
132 * This function is used by the default "log:" message handler. 138 * This function is used by the default "log:" message handler.
133 * 139 *
134 * @param {string} message The message to log. 140 * @param {string} message The message to log.
135 */ 141 */
136 function logMessage(message) { 142 function logMessage(message) {
137 var logEl = document.getElementById('log'); 143 logMessageArray.push(message);
138 logEl.innerHTML += message + '<br>'; 144 if (logMessageArray.length > kMaxLogMessageLength)
145 logMessageArray.shift();
146
147 document.getElementById('log').textContent = logMessageArray.join('');
139 console.log(message) 148 console.log(message)
140 } 149 }
141 150
142 /** 151 /**
143 */ 152 */
144 var defaultMessageTypes = { 153 var defaultMessageTypes = {
145 'alert': alert, 154 'alert': alert,
146 'log': logMessage 155 'log': logMessage
147 }; 156 };
148 157
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 238
230 // The symbols to export. 239 // The symbols to export.
231 return { 240 return {
232 /** A reference to the NaCl module, once it is loaded. */ 241 /** A reference to the NaCl module, once it is loaded. */
233 naclModule: null, 242 naclModule: null,
234 243
235 attachDefaultListeners: attachDefaultListeners, 244 attachDefaultListeners: attachDefaultListeners,
236 domContentLoaded: domContentLoaded, 245 domContentLoaded: domContentLoaded,
237 createNaClModule: createNaClModule, 246 createNaClModule: createNaClModule,
238 hideModule: hideModule, 247 hideModule: hideModule,
248 logMessage: logMessage,
239 updateStatus: updateStatus 249 updateStatus: updateStatus
240 }; 250 };
241 251
242 }()); 252 }());
243 253
244 // Listen for the DOM content to be loaded. This event is fired when parsing of 254 // Listen for the DOM content to be loaded. This event is fired when parsing of
245 // the page's document has finished. 255 // the page's document has finished.
246 document.addEventListener('DOMContentLoaded', function() { 256 document.addEventListener('DOMContentLoaded', function() {
247 var body = document.querySelector('body'); 257 var body = document.querySelector('body');
248 258
(...skipping 26 matching lines...) Expand all
275 var config = configs.indexOf(searchVars.config) !== -1 ? 285 var config = configs.indexOf(searchVars.config) !== -1 ?
276 searchVars.config : configs[0]; 286 searchVars.config : configs[0];
277 var pathFormat = body.dataset.path; 287 var pathFormat = body.dataset.path;
278 var path = pathFormat.replace('{tc}', tc).replace('{config}', config); 288 var path = pathFormat.replace('{tc}', tc).replace('{config}', config);
279 289
280 loadFunction(body.dataset.name, tc, path, body.dataset.width, 290 loadFunction(body.dataset.name, tc, path, body.dataset.width,
281 body.dataset.height); 291 body.dataset.height);
282 } 292 }
283 } 293 }
284 }); 294 });
OLDNEW
« no previous file with comments | « native_client_sdk/src/build_tools/template.mk ('k') | native_client_sdk/src/examples/debugging/example.dsc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698