From: Mike Taylor Date: Thu, 3 Apr 2014 16:26:06 +0000 (+0100) Subject: All of the functionality of the autosearch function now happens on X-Git-Tag: 1.0.0~1049 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=2e98f6b0b8c985dadb49d9658f22df6911b43eee All of the functionality of the autosearch function now happens on the "ready" event. Previously, the initial checks of the query were done when the widget was created, but that doesn't allow us to set the query by default in a subclass promotion-function (as in fact we now do with the Lolcat subclass). --- diff --git a/src/mkws-widgets.js b/src/mkws-widgets.js index 551527c..98a48bd 100644 --- a/src/mkws-widgets.js +++ b/src/mkws-widgets.js @@ -61,26 +61,26 @@ function widget($, team, type, node) { // Utility function for use by all widgets that can invoke autosearch. widget.autosearch = function(widget) { - var query = widget.config.autosearch; - if (query) { - if (query.match(/^!param!/)) { - var param = query.replace(/^!param!/, ''); - query = mkws.getParameterByName(param); - widget.log("obtained query '" + query + "' from param '" + param + "'"); - if (!query) { - alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); - } - } else if (query.match(/^!path!/)) { - var index = query.replace(/^!path!/, ''); - var path = window.location.pathname.split('/'); - query = path[path.length - index]; - widget.log("obtained query '" + query + "' from path-component '" + index + "'"); - if (!query) { - alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); + widget.team.queue("ready").subscribe(function() { + var query = widget.config.autosearch; + if (query) { + if (query.match(/^!param!/)) { + var param = query.replace(/^!param!/, ''); + query = mkws.getParameterByName(param); + widget.log("obtained query '" + query + "' from param '" + param + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); + } + } else if (query.match(/^!path!/)) { + var index = query.replace(/^!path!/, ''); + var path = window.location.pathname.split('/'); + query = path[path.length - index]; + widget.log("obtained query '" + query + "' from path-component '" + index + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); + } } - } - widget.team.queue("ready").subscribe(function() { var sortOrder = widget.config.sort; var maxrecs = widget.config.maxrecs; var perpage = widget.config.perpage; @@ -100,8 +100,8 @@ widget.autosearch = function(widget) { widget.log(s); widget.team.newSearch(query, sortOrder, maxrecs, perpage, limit, targets, targetfilter); - }); - } + } + }); };