You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by bd...@apache.org on 2012/03/20 15:40:16 UTC
svn commit: r1302916 - in /incubator/devicemap/trunk/prototypes/logcapture:
index.html logcapture.js
Author: bdelacretaz
Date: Tue Mar 20 14:40:16 2012
New Revision: 1302916
URL: http://svn.apache.org/viewvc?rev=1302916&view=rev
Log:
use dmap object to compute values + nicer debug format
Modified:
incubator/devicemap/trunk/prototypes/logcapture/index.html
incubator/devicemap/trunk/prototypes/logcapture/logcapture.js
Modified: incubator/devicemap/trunk/prototypes/logcapture/index.html
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/prototypes/logcapture/index.html?rev=1302916&r1=1302915&r2=1302916&view=diff
==============================================================================
--- incubator/devicemap/trunk/prototypes/logcapture/index.html (original)
+++ incubator/devicemap/trunk/prototypes/logcapture/index.html Tue Mar 20 14:40:16 2012
@@ -64,7 +64,7 @@ h1 {
font-size:80%;
font-family: Courier New, Courier, monospace;
}
-.devicemapDebug .title {
+.devicemapDebug .valueKey {
font-weight:bold;
}
</style>
Modified: incubator/devicemap/trunk/prototypes/logcapture/logcapture.js
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/prototypes/logcapture/logcapture.js?rev=1302916&r1=1302915&r2=1302916&view=diff
==============================================================================
--- incubator/devicemap/trunk/prototypes/logcapture/logcapture.js (original)
+++ incubator/devicemap/trunk/prototypes/logcapture/logcapture.js Tue Mar 20 14:40:16 2012
@@ -26,34 +26,34 @@
// start devicemap code scope
(function() {
+var dmap = {};
+
// encode a name/value pair for us in our image URL
function encodeValue(name, value) {
return "&" + name + "=" + escape(value);
}
-// return expr, suitably formatted as an URL parameter,
-// invalid expr outputs NOVALUE.
-function getExpr(expr) {
- var result = "NOVALUE";
+// eval expr, return null if fails
+function safeEval(expr) {
+ var value = null;
try {
- result = eval(expr);
+ value = eval(expr);
} catch(e) {
}
- return encodeValue(expr, result);
+ return value;
}
-// return prefix.name.propertyName=true if creating an element
+// return { prefix.name.propertyName, true } if creating an element
// called "name" returns an object that has a "propertyName"
// property. Used to check for html5 audio/video support
// by checking for audio.play and video.play.
-function getElementSupport(prefix, name, propertyName) {
+function getElementSupport(data, prefix, name, propertyName) {
var e = document.createElement(name);
- var result = eval("e." + propertyName) ? "true" : "false";
- return "&" + prefix + "." + name + "." + propertyName + "=" + result;
+ var value = eval("e." + propertyName) ? "true" : "false";
+ data[prefix + "." + name + "." + propertyName] = value;
}
// build devicemap image URL with cache killer, adding useful device values
-var img="devicemap.png?dmap=" + new Date(). getTime();
var expr = [
"screen.width",
"screen.height",
@@ -66,13 +66,13 @@ var expr = [
"this.gives.NOVALUE"
];
for(i in expr) {
- img += getExpr(expr[i]);
+ dmap[expr[i]] = safeEval(expr[i]);
}
// detect some HTML5 features
-img += getElementSupport("html5","audio", "play");
-img += getElementSupport("html5","video", "play");
-img += getElementSupport("dummy","video", "foo");
+getElementSupport(dmap, "html5","audio", "play");
+getElementSupport(dmap, "html5","video", "play");
+getElementSupport(dmap, "dummy","video", "foo");
// call plugins
if(window._DMAP_ && window._DMAP_.plugins) {
@@ -80,11 +80,17 @@ if(window._DMAP_ && window._DMAP_.plugin
var f = window._DMAP_.plugins[i];
var data = f.call();
for(d in data) {
- img += encodeValue(d, data[d]);
+ dmap[d] = data[d];
}
}
}
+// compute img URL
+var img="devicemap.png?dmap=" + new Date(). getTime();
+for(i in dmap) {
+ img += encodeValue(i, dmap[i]);
+}
+
// add img element with computed path + parameters, so
// that server log provides device information
function writeDeviceMapInfo(container) {
@@ -93,7 +99,13 @@ function writeDeviceMapInfo(container) {
container.appendChild(e);
e = document.createElement("div");
e.setAttribute("class", "devicemapDebug");
- e.innerHTML = "<span class='title'>Image URL: </span>" + img
+
+ var html = "<h1>DeviceMap values:</h1>";
+ for(i in dmap) {
+ html += "<span class='valueKey'>" + i + "</span> = " + dmap[i] + "<br/>";
+ }
+ e.innerHTML = html;
+
container.appendChild(e);
}