X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=a21fd42a9632b61339900fbe35bc591d89d3c215;hb=ce1503ff9f918a52ded3643ba8595d49c71e1277;hp=e539e6d1145758d0c814b3620584bb1025bd52db;hpb=f7732bc6fe4ee86d260b8b581281ceae09a6e49b;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index e539e6d..a21fd42 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -140,19 +140,22 @@ mkws.registerWidgetType('records', function() { } var urls = hit['md-electronic-url']; - that.warn("urls = " + mkws.$.toJSON(urls)); - var bestLink = null; - var otherLinks = []; - for (var j = 0; j < urls.length; j++) { - var url = urls[j]; - if (!bestLink && url.match(/^(https?:)?\/\//)) { - bestLink = url; - } else { - otherLinks.push(url); + if (urls) { + var bestLink = null; + var otherLinks = []; + for (var j = 0; j < urls.length; j++) { + var url = urls[j]; + if (!url.match(/^(https?:)?\/\//)) { + that.warn("link '" + url + "' is not a valid URL"); + } else if (!bestLink) { + bestLink = url; + } else { + otherLinks.push(url); + } } + hit.bestLink = bestLink; + hit.otherLinks = otherLinks; } - hit.bestLink = bestLink; - hit.otherLinks = otherLinks; } var template = team.loadTemplate(that.config.template || "records"); @@ -283,9 +286,10 @@ mkws.registerWidgetType('search', function() { mkws.registerWidgetType('search-form', function() { var team = this.team; + var that = this; this.node.submit(function() { var val = team.widget('query').value(); - team.newSearch(val); + team.newSearch(that, val); return false; }); });