From e7b275636165405283e6e25ebcc4ef3d63c85cba Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 13 Feb 2014 14:39:08 +0000 Subject: [PATCH] Add support for auto-running widgets that take their query from a nominated URL parameter. The syntax is
to search for the term specified in the URL as "?q=TERM" --- tools/htdocs/mkws.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index a886bcf..eba4b27 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -1310,6 +1310,14 @@ function team($, teamName) { // ### should check mkwsTermlist as well, for facet-only teams var node = $('.mkwsRecords.mkwsTeam_' + teamName); var query = node.attr('autosearch'); + if (query.match(/^!param!/)) { + var param = query.replace(/^!param!/, ''); + query = getParameterByName(param); + debug("obtained query '" + query + "' from param '" + param + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); + } + } debug("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query); if (query) { @@ -1328,6 +1336,16 @@ function team($, teamName) { } + // This function is taken from a StackOverflow answer + // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144 + function getParameterByName(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + $(document).ready(function() { debug("on load ready"); default_mkws_config(); -- 1.7.10.4