1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/tests/MochiKit-1.4.2/MochiKit/LoggingPane.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,353 @@ 1.4 +/*** 1.5 + 1.6 +MochiKit.LoggingPane 1.4.2 1.7 + 1.8 +See <http://mochikit.com/> for documentation, downloads, license, etc. 1.9 + 1.10 +(c) 2005 Bob Ippolito. All rights Reserved. 1.11 + 1.12 +***/ 1.13 + 1.14 +MochiKit.Base._deps('LoggingPane', ['Base', 'Logging']); 1.15 + 1.16 +MochiKit.LoggingPane.NAME = "MochiKit.LoggingPane"; 1.17 +MochiKit.LoggingPane.VERSION = "1.4.2"; 1.18 +MochiKit.LoggingPane.__repr__ = function () { 1.19 + return "[" + this.NAME + " " + this.VERSION + "]"; 1.20 +}; 1.21 + 1.22 +MochiKit.LoggingPane.toString = function () { 1.23 + return this.__repr__(); 1.24 +}; 1.25 + 1.26 +/** @id MochiKit.LoggingPane.createLoggingPane */ 1.27 +MochiKit.LoggingPane.createLoggingPane = function (inline/* = false */) { 1.28 + var m = MochiKit.LoggingPane; 1.29 + inline = !(!inline); 1.30 + if (m._loggingPane && m._loggingPane.inline != inline) { 1.31 + m._loggingPane.closePane(); 1.32 + m._loggingPane = null; 1.33 + } 1.34 + if (!m._loggingPane || m._loggingPane.closed) { 1.35 + m._loggingPane = new m.LoggingPane(inline, MochiKit.Logging.logger); 1.36 + } 1.37 + return m._loggingPane; 1.38 +}; 1.39 + 1.40 +/** @id MochiKit.LoggingPane.LoggingPane */ 1.41 +MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = MochiKit.Logging.logger */) { 1.42 + 1.43 + /* Use a div if inline, pop up a window if not */ 1.44 + /* Create the elements */ 1.45 + if (typeof(logger) == "undefined" || logger === null) { 1.46 + logger = MochiKit.Logging.logger; 1.47 + } 1.48 + this.logger = logger; 1.49 + var update = MochiKit.Base.update; 1.50 + var updatetree = MochiKit.Base.updatetree; 1.51 + var bind = MochiKit.Base.bind; 1.52 + var clone = MochiKit.Base.clone; 1.53 + var win = window; 1.54 + var uid = "_MochiKit_LoggingPane"; 1.55 + if (typeof(MochiKit.DOM) != "undefined") { 1.56 + win = MochiKit.DOM.currentWindow(); 1.57 + } 1.58 + if (!inline) { 1.59 + // name the popup with the base URL for uniqueness 1.60 + var url = win.location.href.split("?")[0].replace(/[#:\/.><&%-]/g, "_"); 1.61 + var name = uid + "_" + url; 1.62 + var nwin = win.open("", name, "dependent,resizable,height=200"); 1.63 + if (!nwin) { 1.64 + alert("Not able to open debugging window due to pop-up blocking."); 1.65 + return undefined; 1.66 + } 1.67 + nwin.document.write( 1.68 + '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ' 1.69 + + '"http://www.w3.org/TR/html4/loose.dtd">' 1.70 + + '<html><head><title>[MochiKit.LoggingPane]</title></head>' 1.71 + + '<body></body></html>' 1.72 + ); 1.73 + nwin.document.close(); 1.74 + nwin.document.title += ' ' + win.document.title; 1.75 + win = nwin; 1.76 + } 1.77 + var doc = win.document; 1.78 + this.doc = doc; 1.79 + 1.80 + // Connect to the debug pane if it already exists (i.e. in a window orphaned by the page being refreshed) 1.81 + var debugPane = doc.getElementById(uid); 1.82 + var existing_pane = !!debugPane; 1.83 + if (debugPane && typeof(debugPane.loggingPane) != "undefined") { 1.84 + debugPane.loggingPane.logger = this.logger; 1.85 + debugPane.loggingPane.buildAndApplyFilter(); 1.86 + return debugPane.loggingPane; 1.87 + } 1.88 + 1.89 + if (existing_pane) { 1.90 + // clear any existing contents 1.91 + var child; 1.92 + while ((child = debugPane.firstChild)) { 1.93 + debugPane.removeChild(child); 1.94 + } 1.95 + } else { 1.96 + debugPane = doc.createElement("div"); 1.97 + debugPane.id = uid; 1.98 + } 1.99 + debugPane.loggingPane = this; 1.100 + var levelFilterField = doc.createElement("input"); 1.101 + var infoFilterField = doc.createElement("input"); 1.102 + var filterButton = doc.createElement("button"); 1.103 + var loadButton = doc.createElement("button"); 1.104 + var clearButton = doc.createElement("button"); 1.105 + var closeButton = doc.createElement("button"); 1.106 + var logPaneArea = doc.createElement("div"); 1.107 + var logPane = doc.createElement("div"); 1.108 + 1.109 + /* Set up the functions */ 1.110 + var listenerId = uid + "_Listener"; 1.111 + this.colorTable = clone(this.colorTable); 1.112 + var messages = []; 1.113 + var messageFilter = null; 1.114 + 1.115 + /** @id MochiKit.LoggingPane.messageLevel */ 1.116 + var messageLevel = function (msg) { 1.117 + var level = msg.level; 1.118 + if (typeof(level) == "number") { 1.119 + level = MochiKit.Logging.LogLevel[level]; 1.120 + } 1.121 + return level; 1.122 + }; 1.123 + 1.124 + /** @id MochiKit.LoggingPane.messageText */ 1.125 + var messageText = function (msg) { 1.126 + return msg.info.join(" "); 1.127 + }; 1.128 + 1.129 + /** @id MochiKit.LoggingPane.addMessageText */ 1.130 + var addMessageText = bind(function (msg) { 1.131 + var level = messageLevel(msg); 1.132 + var text = messageText(msg); 1.133 + var c = this.colorTable[level]; 1.134 + var p = doc.createElement("span"); 1.135 + p.className = "MochiKit-LogMessage MochiKit-LogLevel-" + level; 1.136 + p.style.cssText = "margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: " + c; 1.137 + p.appendChild(doc.createTextNode(level + ": " + text)); 1.138 + logPane.appendChild(p); 1.139 + logPane.appendChild(doc.createElement("br")); 1.140 + if (logPaneArea.offsetHeight > logPaneArea.scrollHeight) { 1.141 + logPaneArea.scrollTop = 0; 1.142 + } else { 1.143 + logPaneArea.scrollTop = logPaneArea.scrollHeight; 1.144 + } 1.145 + }, this); 1.146 + 1.147 + /** @id MochiKit.LoggingPane.addMessage */ 1.148 + var addMessage = function (msg) { 1.149 + messages[messages.length] = msg; 1.150 + addMessageText(msg); 1.151 + }; 1.152 + 1.153 + /** @id MochiKit.LoggingPane.buildMessageFilter */ 1.154 + var buildMessageFilter = function () { 1.155 + var levelre, infore; 1.156 + try { 1.157 + /* Catch any exceptions that might arise due to invalid regexes */ 1.158 + levelre = new RegExp(levelFilterField.value); 1.159 + infore = new RegExp(infoFilterField.value); 1.160 + } catch(e) { 1.161 + /* If there was an error with the regexes, do no filtering */ 1.162 + logDebug("Error in filter regex: " + e.message); 1.163 + return null; 1.164 + } 1.165 + 1.166 + return function (msg) { 1.167 + return ( 1.168 + levelre.test(messageLevel(msg)) && 1.169 + infore.test(messageText(msg)) 1.170 + ); 1.171 + }; 1.172 + }; 1.173 + 1.174 + /** @id MochiKit.LoggingPane.clearMessagePane */ 1.175 + var clearMessagePane = function () { 1.176 + while (logPane.firstChild) { 1.177 + logPane.removeChild(logPane.firstChild); 1.178 + } 1.179 + }; 1.180 + 1.181 + /** @id MochiKit.LoggingPane.clearMessages */ 1.182 + var clearMessages = function () { 1.183 + messages = []; 1.184 + clearMessagePane(); 1.185 + }; 1.186 + 1.187 + /** @id MochiKit.LoggingPane.closePane */ 1.188 + var closePane = bind(function () { 1.189 + if (this.closed) { 1.190 + return; 1.191 + } 1.192 + this.closed = true; 1.193 + if (MochiKit.LoggingPane._loggingPane == this) { 1.194 + MochiKit.LoggingPane._loggingPane = null; 1.195 + } 1.196 + this.logger.removeListener(listenerId); 1.197 + try { 1.198 + try { 1.199 + debugPane.loggingPane = null; 1.200 + } catch(e) { logFatal("Bookmarklet was closed incorrectly."); } 1.201 + if (inline) { 1.202 + debugPane.parentNode.removeChild(debugPane); 1.203 + } else { 1.204 + this.win.close(); 1.205 + } 1.206 + } catch(e) {} 1.207 + }, this); 1.208 + 1.209 + /** @id MochiKit.LoggingPane.filterMessages */ 1.210 + var filterMessages = function () { 1.211 + clearMessagePane(); 1.212 + 1.213 + for (var i = 0; i < messages.length; i++) { 1.214 + var msg = messages[i]; 1.215 + if (messageFilter === null || messageFilter(msg)) { 1.216 + addMessageText(msg); 1.217 + } 1.218 + } 1.219 + }; 1.220 + 1.221 + this.buildAndApplyFilter = function () { 1.222 + messageFilter = buildMessageFilter(); 1.223 + 1.224 + filterMessages(); 1.225 + 1.226 + this.logger.removeListener(listenerId); 1.227 + this.logger.addListener(listenerId, messageFilter, addMessage); 1.228 + }; 1.229 + 1.230 + 1.231 + /** @id MochiKit.LoggingPane.loadMessages */ 1.232 + var loadMessages = bind(function () { 1.233 + messages = this.logger.getMessages(); 1.234 + filterMessages(); 1.235 + }, this); 1.236 + 1.237 + /** @id MochiKit.LoggingPane.filterOnEnter */ 1.238 + var filterOnEnter = bind(function (event) { 1.239 + event = event || window.event; 1.240 + key = event.which || event.keyCode; 1.241 + if (key == 13) { 1.242 + this.buildAndApplyFilter(); 1.243 + } 1.244 + }, this); 1.245 + 1.246 + /* Create the debug pane */ 1.247 + var style = "display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: " + this.logFont; 1.248 + if (inline) { 1.249 + style += "; height: 10em; border-top: 2px solid black"; 1.250 + } else { 1.251 + style += "; height: 100%;"; 1.252 + } 1.253 + debugPane.style.cssText = style; 1.254 + 1.255 + if (!existing_pane) { 1.256 + doc.body.appendChild(debugPane); 1.257 + } 1.258 + 1.259 + /* Create the filter fields */ 1.260 + style = {"cssText": "width: 33%; display: inline; font: " + this.logFont}; 1.261 + 1.262 + updatetree(levelFilterField, { 1.263 + "value": "FATAL|ERROR|WARNING|INFO|DEBUG", 1.264 + "onkeypress": filterOnEnter, 1.265 + "style": style 1.266 + }); 1.267 + debugPane.appendChild(levelFilterField); 1.268 + 1.269 + updatetree(infoFilterField, { 1.270 + "value": ".*", 1.271 + "onkeypress": filterOnEnter, 1.272 + "style": style 1.273 + }); 1.274 + debugPane.appendChild(infoFilterField); 1.275 + 1.276 + /* Create the buttons */ 1.277 + style = "width: 8%; display:inline; font: " + this.logFont; 1.278 + 1.279 + filterButton.appendChild(doc.createTextNode("Filter")); 1.280 + filterButton.onclick = bind("buildAndApplyFilter", this); 1.281 + filterButton.style.cssText = style; 1.282 + debugPane.appendChild(filterButton); 1.283 + 1.284 + loadButton.appendChild(doc.createTextNode("Load")); 1.285 + loadButton.onclick = loadMessages; 1.286 + loadButton.style.cssText = style; 1.287 + debugPane.appendChild(loadButton); 1.288 + 1.289 + clearButton.appendChild(doc.createTextNode("Clear")); 1.290 + clearButton.onclick = clearMessages; 1.291 + clearButton.style.cssText = style; 1.292 + debugPane.appendChild(clearButton); 1.293 + 1.294 + closeButton.appendChild(doc.createTextNode("Close")); 1.295 + closeButton.onclick = closePane; 1.296 + closeButton.style.cssText = style; 1.297 + debugPane.appendChild(closeButton); 1.298 + 1.299 + /* Create the logging pane */ 1.300 + logPaneArea.style.cssText = "overflow: auto; width: 100%"; 1.301 + logPane.style.cssText = "width: 100%; height: " + (inline ? "8em" : "100%"); 1.302 + 1.303 + logPaneArea.appendChild(logPane); 1.304 + debugPane.appendChild(logPaneArea); 1.305 + 1.306 + this.buildAndApplyFilter(); 1.307 + loadMessages(); 1.308 + 1.309 + if (inline) { 1.310 + this.win = undefined; 1.311 + } else { 1.312 + this.win = win; 1.313 + } 1.314 + this.inline = inline; 1.315 + this.closePane = closePane; 1.316 + this.closed = false; 1.317 + 1.318 + 1.319 + return this; 1.320 +}; 1.321 + 1.322 +MochiKit.LoggingPane.LoggingPane.prototype = { 1.323 + "logFont": "8pt Verdana,sans-serif", 1.324 + "colorTable": { 1.325 + "ERROR": "red", 1.326 + "FATAL": "darkred", 1.327 + "WARNING": "blue", 1.328 + "INFO": "black", 1.329 + "DEBUG": "green" 1.330 + } 1.331 +}; 1.332 + 1.333 + 1.334 +MochiKit.LoggingPane.EXPORT_OK = [ 1.335 + "LoggingPane" 1.336 +]; 1.337 + 1.338 +MochiKit.LoggingPane.EXPORT = [ 1.339 + "createLoggingPane" 1.340 +]; 1.341 + 1.342 +MochiKit.LoggingPane.__new__ = function () { 1.343 + this.EXPORT_TAGS = { 1.344 + ":common": this.EXPORT, 1.345 + ":all": MochiKit.Base.concat(this.EXPORT, this.EXPORT_OK) 1.346 + }; 1.347 + 1.348 + MochiKit.Base.nameFunctions(this); 1.349 + 1.350 + MochiKit.LoggingPane._loggingPane = null; 1.351 + 1.352 +}; 1.353 + 1.354 +MochiKit.LoggingPane.__new__(); 1.355 + 1.356 +MochiKit.Base._exportSymbols(this, MochiKit.LoggingPane);