diff --git a/mmturkey.js b/mmturkey.js index 5da7c24..c03d4aa 100644 --- a/mmturkey.js +++ b/mmturkey.js @@ -17,6 +17,26 @@ turk = turk || {}; }; } + // micro edsl for generating html + // takes as arguments either: + // - a single array of strings + // - an arbitrary number of strings + var lines = function() { + if (arguments.length == 1 && arguments[0] instanceof Array) { + return arguments[0].join("\n") + } else { + var args = Array.prototype.slice.call(arguments); + return args.join("\n"); + } + } + + // micro edsl for generating html + // tag("a href='foo'", "inner") returns inner + // tag("a href='foo'", "inner","peace") returns inner\npeace + var tag = function(name, content /*, ... */) { + var contents = Array.prototype.slice.call(arguments, 1); + return "<" + name + ">" + lines(contents) + "" + name.split(/ +/)[0] + ">"; + } var hopUndefined = !Object.prototype.hasOwnProperty, showPreviewWarning = true; @@ -90,46 +110,39 @@ turk = turk || {}; var htmlifyTable = function(array) { var getRow = function(obj) { - var str = ""; - str += "
" + k + " | " }).join("\n"); - str += "
---|
Debug mode
Here is the data that would have been submitted to Turk:turk.submit
testing mode"),
+ tag("p", "Here is the data that would have been submitted to Turk:"),
+ tag("div style='width: 700px'", htmlify(rawData))
+ );
+
+ popup.document.body.appendChild(div);
+ popup.document.head.innerHTML = lines(
+ tag("title", "mmturkey data"),
+ tag("style",
+ lines(
+ "body { font-family: 'Helvetica'; font-size: 12px}",
+ "table { border: 1px solid gray; border-collapse: collapse; box-shadow: 2px 2px 1px #aaa; }",
+ ".tabular { margin: 0 0.5em 0.5em 0 } ",
+ ".tabular td { background-color: #e0e0e0; font-size: 10px; }",
+ "th, td { font-family: 'Courier New'; padding: 0.55em; font-size: 12px}",
+ "th { background-color: #6699cc }",
+ "td.key { font-weight: bold; background-color: tan }"
+ )));
+
return;
}