From 2e98f6b0b8c985dadb49d9658f22df6911b43eee Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 3 Apr 2014 17:26:06 +0100 Subject: [PATCH] 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). --- src/mkws-widgets.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) 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); - }); - } + } + }); }; -- 1.7.10.4