You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by ed...@apache.org on 2015/11/29 06:56:00 UTC
[3/3] incubator-freemarker-docgen git commit: populate the search
field with the search term, if applicable
populate the search field with the search term, if applicable
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-docgen/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-docgen/commit/bab5de6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-docgen/tree/bab5de6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-docgen/diff/bab5de6d
Branch: refs/heads/master
Commit: bab5de6d8293621ca4e2fa69287b81a15e23fdc7
Parents: ce1336b
Author: ratherblue <ra...@gmail.com>
Authored: Sat Nov 28 21:55:33 2015 -0800
Committer: ratherblue <ra...@gmail.com>
Committed: Sat Nov 28 21:55:33 2015 -0800
----------------------------------------------------------------------
src/main/org/freemarker/docgen/js/search.js | 44 ++++++++++++++++++++++++
1 file changed, 44 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker-docgen/blob/bab5de6d/src/main/org/freemarker/docgen/js/search.js
----------------------------------------------------------------------
diff --git a/src/main/org/freemarker/docgen/js/search.js b/src/main/org/freemarker/docgen/js/search.js
new file mode 100644
index 0000000..e03a24a
--- /dev/null
+++ b/src/main/org/freemarker/docgen/js/search.js
@@ -0,0 +1,44 @@
+// fix search population
+(function() {
+
+ var SEARCH_VARIABLE = 'q'; // this must be the same as google analytics
+ var searchField;
+
+ function populationSearchField(query) {
+ // replace '+' signs with spaces
+ query = query.replace(/\+/g, ' ');
+ query = decodeURIComponent(query); // decode so value stays as expected
+
+ searchField.value = query;
+ }
+
+ function checkForSearchQuery() {
+ var query = window.location.search;
+
+ if (query !== '') {
+ var params = query.split('&'); // note: if the user's search term
+ // includes & then this won't work as
+ // expected for them
+
+ // extract the search query
+ for (var x = 0; x < params.length; x++) {
+ var param = params[x];
+ var parts = param.split('=');
+
+ if (parts[0] === '?' + SEARCH_VARIABLE) {
+ populationSearchField(parts[1]); // second part is the query
+ }
+ }
+ }
+ }
+
+ function init() {
+ searchField = document.getElementById('search-field');
+
+ if (searchField !== null) {
+ checkForSearchQuery();
+ }
+ }
+
+ init();
+})();