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:
+2
-31
@@ -1,36 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
Adds the plovr generated script to the document. The following default
|
Adds the plovr generated script to the document.
|
||||||
values may be overridden with query string parameters:
|
|
||||||
|
|
||||||
* hostname - localhost
|
|
||||||
* port - 9810
|
|
||||||
* mode - SIMPLE
|
|
||||||
* id - ol
|
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
var search = window.location.search.substring(1);
|
var url = "http://" + window.location.hostname + ":9810/compile?id=ol";
|
||||||
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("&");
|
|
||||||
document.write("<script type='text/javascript' src='" + url + "'></script>");
|
document.write("<script type='text/javascript' src='" + url + "'></script>");
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user