From e9dbb00039001d74b76eaba2b98b17cdec3a62aa Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 17 Oct 2012 11:30:21 +0200 Subject: [PATCH] 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. --- Makefile | 2 +- examples/index.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 examples/index.js diff --git a/Makefile b/Makefile index 8053496884..0f1946f2df 100644 --- a/Makefile +++ b/Makefile @@ -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\"]}" > $@ diff --git a/examples/index.js b/examples/index.js new file mode 100644 index 0000000000..21bc8fa4f4 --- /dev/null +++ b/examples/index.js @@ -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; + } +})();