X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=b218a958720e80a6a3060cdb304448dfa06e6d0e;hb=90a334c4502a6e1e6cc15732373acf2676b9c599;hp=e23ce9c8da453eae4bef08f0040d0e92637b2bf3;hpb=d19df9e59963d2819fae0af3d94a5a6c498c9165;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index e23ce9c..b218a95 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -140,20 +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]; - that.warn("url #" + (j+1) + " = " + url); - 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");