Simplifying the loader.

Plovr checks the referrer for query string parameters (like mode), so we don't need any of this query string parsing (thanks @elemoine for the tip).

The reason we still dynamically generate the script tag is to work on other domains (e.g. testing on a VM or mobile device).  In this case, we make use of the `window.location.hostname`.
This commit is contained in:
tschaub
2012-07-05 13:55:24 -06:00
parent d8e8e55b44
commit d435f6b4fd

View File

@@ -1,36 +1,7 @@
/**
Adds the plovr generated script to the document. The following default
values may be overridden with query string parameters:
* hostname - localhost
* port - 9810
* mode - SIMPLE
* id - ol
Adds the plovr generated script to the document.
*/
(function() {
var search = window.location.search.substring(1);
var params = {
hostname: "localhost",
port: "9810",
mode: "SIMPLE",
id: "ol"
};
var chunks = search.split("&");
var pair;
for (var i=chunks.length-1; i>=0; --i) {
pair = chunks[i].split("=");
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
var host = params.hostname + ":" + params.port;
delete params.hostname;
delete params.port;
var pairs = [];
for (var key in params) {
pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
}
var url = "http://" + host + "/compile?" + pairs.join("&");
var url = "http://" + window.location.hostname + ":9810/compile?id=ol";
document.write("<script type='text/javascript' src='" + url + "'></script>");
})();