Generalizing query string parsing in the loader.
This commit is contained in:
+36
-36
@@ -1,36 +1,36 @@
|
|||||||
// the following code includes the sourc-files of OpenLayers as they are
|
/**
|
||||||
// defined in ol.js.
|
Adds the plovr generated script to the document. The following default
|
||||||
//
|
values may be overridden with query string parameters:
|
||||||
// You can control in which form the source will be loaded by passing
|
|
||||||
// URL-parameters:
|
* hostname - localhost
|
||||||
//
|
* port - 9810
|
||||||
// - host
|
* mode - SIMPLE
|
||||||
// where the plovr compiler is running, if not passed this defaults to the
|
* id - ol
|
||||||
// current host on port 9810
|
*/
|
||||||
//
|
(function() {
|
||||||
// - mode
|
var search = window.location.search.substring(1);
|
||||||
// which mode of compilation should be applied. Common values for this are
|
var params = {
|
||||||
// RAW, SIMPLE or ADVANCED. If not provided, SIMPLE is used.
|
hostname: "localhost",
|
||||||
(function(doc, l){
|
port: "9810",
|
||||||
var hostRegex = /[\\?&]host=([^&#]*)/,
|
mode: "SIMPLE",
|
||||||
modeRegex = /[\\?&]mode=([^&#]*)/,
|
id: "ol"
|
||||||
idRegex = /[\\?&]id=([^&#]*)/,
|
};
|
||||||
hostResult = hostRegex.exec(l.href),
|
var chunks = search.split("&");
|
||||||
modeResult = modeRegex.exec(l.href),
|
var pair;
|
||||||
idResult = idRegex.exec(l.href),
|
for (var i=chunks.length-1; i>=0; --i) {
|
||||||
host = (hostResult && hostResult[1])
|
pair = chunks[i].split("=");
|
||||||
? hostResult[1]
|
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
||||||
: (l.host)
|
}
|
||||||
? l.host + ':9810'
|
|
||||||
: 'localhost:9810',
|
var host = params.hostname + ":" + params.port;
|
||||||
mode = (modeResult && modeResult[1])
|
delete params.hostname;
|
||||||
? modeResult[1]
|
delete params.port;
|
||||||
: 'SIMPLE',
|
|
||||||
id = (idResult && idResult[1])
|
var pairs = [];
|
||||||
? idResult[1]
|
for (var key in params) {
|
||||||
: 'ol',
|
pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
|
||||||
script = '<sc' + 'ript type="text/javascript" '
|
}
|
||||||
+ 'src="http://' + host + '/compile?id=' + id + '&mode=' + mode + '">'
|
|
||||||
+ '</scr' + 'ipt>';
|
var url = "http://" + host + "/compile?" + pairs.join("&");
|
||||||
doc.write(script);
|
document.write("<script type='text/javascript' src='" + url + "'></script>");
|
||||||
})(document, location);
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user