Pass query string through example index

This is so that visiting

    /examples/index.html?mode=RAW&Debug=true

will automatically add ?mode=RAW&Debug=true to all links in the
generated index.
This commit is contained in:
Tom Payne
2012-10-17 11:30:21 +02:00
parent f120410d6d
commit e9dbb00039
2 changed files with 17 additions and 1 deletions

View File

@@ -66,7 +66,7 @@ build-examples: examples $(subst .html,.combined.js,$(EXAMPLES))
examples: examples/index.html $(subst .html,.json,$(EXAMPLES))
examples/index.html: bin/generate-examples-index $(EXAMPLES)
bin/generate-examples-index -o $@ $(EXAMPLES)
bin/generate-examples-index -o $@ -s examples/index.js $(EXAMPLES)
examples/%.json: Makefile base.json
echo "{\"id\": \"$(basename $(notdir $@))\", \"inherits\": \"../base.json\", \"inputs\": [\"$(subst .json,.js,$@)\", \"build/src/internal/src/types.js\"]}" > $@

16
examples/index.js Normal file
View File

@@ -0,0 +1,16 @@
/**
* Loader to append the query string to every A element in the document.
*
* This is so that (for example) visiting
* /examples/index.html?mode=RAW&Debug=true
* will cause all links to automatically include the ?mode=RAW&Debug=true.
*/
(function() {
var as = document.getElementsByTagName('a');
var i, n = as.length;
for (i = 0; i < n; ++i) {
as[i].href += window.location.search;
}
})();