Skip to content

Commit 6fa1f56

Browse files
author
Friedrich W. H. Kossebau
committed
Move HTML rendering of logging out of normal BrowserRuntime
1 parent 2d536ac commit 6fa1f56

4 files changed

Lines changed: 77 additions & 31 deletions

File tree

webodf/lib/runtime.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,8 @@ Runtime.assert = function (condition, message) {
340340
* @constructor
341341
* @augments Runtime
342342
* @implements {Runtime}
343-
* @param {Element} logoutput
344343
*/
345-
function BrowserRuntime(logoutput) {
344+
function BrowserRuntime() {
346345
"use strict";
347346
var self = this;
348347

@@ -490,32 +489,13 @@ function BrowserRuntime(logoutput) {
490489
* @return {undefined}
491490
*/
492491
function log(msgOrCategory, msg) {
493-
var node, doc, category;
492+
var category;
494493
if (msg !== undefined) {
495494
category = msgOrCategory;
496495
} else {
497496
msg = msgOrCategory;
498497
}
499-
if (logoutput) {
500-
doc = logoutput.ownerDocument;
501-
if (category) {
502-
node = doc.createElement("span");
503-
node.className = category;
504-
node.appendChild(doc.createTextNode(category));
505-
logoutput.appendChild(node);
506-
logoutput.appendChild(doc.createTextNode(" "));
507-
}
508-
node = doc.createElement("span");
509-
if (msg.length > 0 && msg[0] === "<") {
510-
node.innerHTML = msg;
511-
} else {
512-
node.appendChild(doc.createTextNode(msg));
513-
}
514-
logoutput.appendChild(node);
515-
logoutput.appendChild(doc.createElement("br"));
516-
} else if (console) {
517-
console.log(msg);
518-
}
498+
console.log(msg);
519499
if (self.enableAlerts && category === "alert") {
520500
alert(msg);
521501
}
@@ -1492,7 +1472,7 @@ Runtime.create = function create() {
14921472
var /**@type{!Runtime}*/
14931473
result;
14941474
if (String(typeof window) !== "undefined") {
1495-
result = new BrowserRuntime(window.document.getElementById("logoutput"));
1475+
result = new BrowserRuntime();
14961476
} else if (String(typeof require) !== "undefined") {
14971477
result = new NodeJSRuntime();
14981478
} else {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright (C) 2012-2015 KO GmbH <copyright@kogmbh.com>
3+
*
4+
* @licstart
5+
* This file is part of WebODF.
6+
*
7+
* WebODF is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License (GNU AGPL)
9+
* as published by the Free Software Foundation, either version 3 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* WebODF is distributed in the hope that it will be useful, but
13+
* WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
19+
* @licend
20+
*
21+
* @source: http://www.webodf.org/
22+
* @source: https://github.com/kogmbh/WebODF/
23+
*/
24+
25+
/*global window, runtime*/
26+
27+
runtime.libraryPaths = (function () {
28+
"use strict";
29+
30+
return function () {
31+
return ["../lib", "."];
32+
};
33+
}());
34+
35+
runtime.log = (function () {
36+
"use strict";
37+
38+
var normalLog = runtime.log,
39+
logoutput = window.document.getElementById("logoutput");
40+
41+
return function (msgOrCategory, msg) {
42+
var node, doc, category;
43+
44+
// do normal log first
45+
normalLog(msgOrCategory, msg);
46+
47+
// now output also
48+
if (msg !== undefined) {
49+
category = msgOrCategory;
50+
} else {
51+
msg = msgOrCategory;
52+
}
53+
54+
doc = logoutput.ownerDocument;
55+
if (category) {
56+
node = doc.createElement("span");
57+
node.className = category;
58+
node.appendChild(doc.createTextNode(category));
59+
logoutput.appendChild(node);
60+
logoutput.appendChild(doc.createTextNode(" "));
61+
}
62+
node = doc.createElement("span");
63+
if (msg.length > 0 && msg[0] === "<") {
64+
node.innerHTML = msg;
65+
} else {
66+
node.appendChild(doc.createTextNode(msg));
67+
}
68+
logoutput.appendChild(node);
69+
logoutput.appendChild(doc.createElement("br"));
70+
};
71+
}());

webodf/tests/tests.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
<div id="console"></div>
1111
<div id="logoutput"></div>
1212
<script src="../lib/runtime.js"></script>
13-
<script type="text/javascript">
14-
runtime.libraryPaths = (function () {
15-
return function () {
16-
return ["../lib", "."];
17-
};
18-
}());
19-
</script>
13+
<script src="testruntimeadaption.js"></script>
2014
<script src="tests.js"></script>
2115
</body>
2216
</html>

webodf/tools/updateJS.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ function main(f) {
650650
delete contents[pathModule.normalize("lib/runtime.js")];
651651
delete contents[pathModule.normalize("lib/core/JSLint.js")];
652652
delete contents[pathModule.normalize("tests/tests.js")];
653+
delete contents[pathModule.normalize("tests/testruntimeadaption.js")];
653654
Object.keys(contents).forEach(function (name) {
654655
if (typeof contents[name] === "string") {
655656
files[name] = contents[name];

0 commit comments

Comments
 (0)