Commit 1d25262f authored by Xiaowu Zhang's avatar Xiaowu Zhang

add show message gadget

parent dd7729ec
<!DOCTYPE html>
<html lang="en">
<head>
<title>show message</title>
<!-- renderjs -->
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<!-- custom script -->
<script src="./log.js" type="text/javascript"></script>
</head>
<body>
<div id = "log"> </div>
</body>
</html>
/*global window, rJS, RSVP, console, document, JSON */
/*jslint maxlen:80, nomen: true */
(function (window, rJS) {
"use strict";
var gk = rJS(window),
logColor = 0,
arrayColor = ["white", "cyan"];
function logGetColor() {
logColor = (logColor + 1) % arrayColor.length;
return arrayColor[logColor];
}
gk.declareMethod('showMessage', function (msg) {
var node = document.createElement("pre");
node.setAttribute(
"style",
"background-color:" + logGetColor() +
";margin:0;padding:0;"
);
if (typeof msg === "string") {
node.textContent += msg;
} else {
node.textContent += JSON.stringify(msg, null, " ");
}
this.log.appendChild(node);
})
.declareMethod('clear', function () {
this.log.innerHTML = "";
});
gk.ready(function (g) {
g.log = g.__element.getElementsByTagName('div')[0];
var node = document.createElement("pre");
node.setAttribute(
"style",
"background-color:" + logGetColor() +
";margin:0;padding:0;"
);
node.textContent = "use for show message";
g.log.appendChild(node);
});
}(window, rJS));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment