diff --git a/Makefile b/Makefile index 39c4901eea..2075c5096d 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ demos/full-screen/advanced-optimizations.js: $(PLOVR_JAR) $(SRC) base.json \ @echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes demos/full-screen/debug.html: demos/full-screen/index.html.in - sed -e 's|@SRC@|http://localhost:9810/compile?id=demo-full-screen|' $< > $@ + sed -e 's|@SRC@|../loader.js?id=demo-full-screen|' $< > $@ demos/full-screen/simple-optimizations.html: demos/full-screen/index.html.in sed -e 's|@SRC@|simple-optimizations.js|' $< > $@ @@ -88,7 +88,7 @@ demos/side-by-side/advanced-optimizations.js: $(PLOVR_JAR) $(SRC) base.json \ @echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes demos/side-by-side/debug.html: demos/side-by-side/index.html.in - sed -e 's|@SRC@|http://localhost:9810/compile?id=demo-side-by-side|' $< > $@ + sed -e 's|@SRC@|../loader.js?id=demo-side-by-side|' $< > $@ demos/side-by-side/simple-optimizations.html: demos/side-by-side/index.html.in sed -e 's|@SRC@|simple-optimizations.js|' $< > $@ @@ -118,7 +118,7 @@ demos/two-layers/advanced-optimizations.js: $(PLOVR_JAR) $(SRC) base.json \ @echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes demos/two-layers/debug.html: demos/two-layers/index.html.in - sed -e 's|@SRC@|http://localhost:9810/compile?id=demo-two-layers|' $< > $@ + sed -e 's|@SRC@|../loader.js?id=demo-two-layers|' $< > $@ demos/two-layers/simple-optimizations.html: demos/two-layers/index.html.in sed -e 's|@SRC@|simple-optimizations.js|' $< > $@ diff --git a/demos/full-screen/index.html.in b/demos/full-screen/template.html.in similarity index 100% rename from demos/full-screen/index.html.in rename to demos/full-screen/template.html.in diff --git a/demos/loader.js b/demos/loader.js new file mode 100644 index 0000000000..8cb30645b8 --- /dev/null +++ b/demos/loader.js @@ -0,0 +1,59 @@ + + +/** + * Loader to add the plovr generated script to the document. The following + * default values may be overridden with query string parameters: + * + * * hostname - the current hostname + * * port - 9810 + * * mode - ADVANCED + * * id - id param in loader.js query string; defaults to 'ol' if not set + * + * Usage: + * + * + */ +(function() { + var scripts = document.getElementsByTagName('script'); + var params = { + hostname: window.location.hostname, + port: '9810', + mode: 'ADVANCED', + id: 'ol' + }; + var chunks, search, pair; + + var src, index, id, i; + for (i = scripts.length - 1; i >= 0; --i) { + src = scripts[i].getAttribute('src'); + if (~(index = src.indexOf('loader.js?'))) { + // script params + search = src.substr(index + 10); + chunks = search ? search.split('&') : []; + for (i = chunks.length - 1; i >= 0; --i) { + pair = chunks[i].split('='); + params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); + } + break; + } + } + // url params + search = window.location.search.substring(1); + chunks = search ? search.split('&') : []; + for (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(''); +}()); diff --git a/demos/proj4js/index.html.in b/demos/proj4js/template.html.in similarity index 100% rename from demos/proj4js/index.html.in rename to demos/proj4js/template.html.in diff --git a/demos/side-by-side/index.html.in b/demos/side-by-side/template.html.in similarity index 100% rename from demos/side-by-side/index.html.in rename to demos/side-by-side/template.html.in diff --git a/demos/two-layers/index.html.in b/demos/two-layers/template.html.in similarity index 100% rename from demos/two-layers/index.html.in rename to demos/two-layers/template.html.in