Chromium Code Reviews| Index: remoting/webapp/me2mom/debug_log.js |
| =================================================================== |
| --- remoting/webapp/me2mom/debug_log.js (revision 0) |
| +++ remoting/webapp/me2mom/debug_log.js (revision 0) |
| @@ -0,0 +1,42 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Maximum numer of lines to record in the debug log. |
| +// Only the most recent <n> lines are displayed. |
| +var MAX_DEBUG_LOG_SIZE = 1000; |
| + |
| +function toggleDebugLog() { |
| + debugLog = document.getElementById('debug-log'); |
| + toggleButton = document.getElementById('debug-log-toggle'); |
| + |
| + if (!debugLog.style.display || debugLog.style.display == 'none') { |
|
Jamie
2011/06/07 18:58:32
I've used class='hidden' elsewhere to avoid changi
garykac
2011/06/07 20:44:32
Good point. However, it doesn't seem worth entangl
|
| + debugLog.style.display = 'block'; |
| + toggleButton.value = 'Hide Debug Log'; |
|
Jamie
2011/06/07 18:58:32
Is this the only place we have display strings in
garykac
2011/06/07 20:44:32
Changed to simply "Debug log" so that the button i
|
| + } else { |
| + debugLog.style.display = 'none'; |
| + toggleButton.value = 'Show Debug Log'; |
| + } |
| +} |
| + |
| +/** |
| + * Add the given message to the debug log. |
| + * |
| + * @param {string} message The debug info to add to the log. |
| + */ |
| +function addToDebugLog(message) { |
| + var debugLog = document.getElementById('debug-log'); |
| + |
| + // Remove lines from top if we've hit our max log size. |
| + if (debugLog.childNodes.length == MAX_DEBUG_LOG_SIZE) { |
| + debugLog.removeChild(debugLog.firstChild); |
| + } |
| + |
| + // Add the new <p> to the end of the debug log. |
| + var p = document.createElement('p'); |
| + p.appendChild(document.createTextNode(message)); |
| + debugLog.appendChild(p); |
| + |
| + // Scroll to bottom of div |
| + debugLog.scrollTop = debugLog.scrollHeight; |
| +} |