From: Mike Taylor Date: Thu, 13 Feb 2014 14:39:08 +0000 (+0000) Subject: Add support for auto-running widgets that take their query from a X-Git-Tag: 1.0.0~1446 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=e7b275636165405283e6e25ebcc4ef3d63c85cba 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" --- 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();