From f4b20175cc9a9de7dfbebedb5476749f603060c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 16 Oct 2012 21:51:48 +0200 Subject: [PATCH] Add a specific loader for hosted examples This loader is responsible for adding ol.js, ol.css and the example-specific js script to the document. This is the loader used in examples when hosted. --- build/loader_hosted_examples.js | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 build/loader_hosted_examples.js diff --git a/build/loader_hosted_examples.js b/build/loader_hosted_examples.js new file mode 100644 index 0000000000..3ec22aa5e2 --- /dev/null +++ b/build/loader_hosted_examples.js @@ -0,0 +1,46 @@ +/** + * + * Loader to add ol.css, ol.js and the example-specific js file to the + * documents. + * + * This loader is used for the hosted examples. It is used in place of the + * development loader (examples/loader.js). + * + * ol.css and ol.js are built with Plovr/Closure, based build/ol.json. + * (`make build` should build them). They are located in the ../build/ + * directory, relatively to this script. + * + * The script should be named loader.js. So it needs to be renamed to + * loader.js from loader_hosted_examples.js. + * + * Usage: + * + * + */ + +(function() { + var scripts = document.getElementsByTagName('script'); + + var i, src, index, search, chunks, pair, params = {}; + for (i = scripts.length - 1; i >= 0; --i) { + src = scripts[i].getAttribute('src'); + if (~(index = src.indexOf('loader.js?'))) { + 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; + } + } + + document.write(''); + document.write('' + + ''); + document.write('' + + ''); +}());