From: Mike Taylor Date: Mon, 29 Jun 2015 19:04:11 +0000 (+0100) Subject: Main part of ACREP-32. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=fcd300157c2acf190002c1808b97139eda16b6c9;p=mkws-moved-to-github.git Main part of ACREP-32. The 'records' handler now adds two new fields to the data objects that it renders: * bestLink -- a single URL, is there is a good electronic-url. * otherLinks -- all other electronic-urls, whether well-formed or not. --- diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 62d7076..367ec46 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -138,7 +138,29 @@ mkws.registerWidgetType('records', function() { hit.renderedDetails = team.renderDetails(team.currentRecordData()); } } + + 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?:)?\/\//)) { + mkws.debug("'" + url + "' *is* a URL"); + bestLink = url; + } else if (bestLink) { + mkws.debug("'" + url + "' not tested"); + otherLinks.push(url); + } else { + mkws.debug("'" + url + "' is not a URL"); + otherLinks.push(url); + } + } + hit.bestLink = bestLink; + hit.otherLinks = otherLinks; } + var template = team.loadTemplate(that.config.template || "records"); var summaryPartial = team.loadTemplate(that.config['summary-template'] || "summary"); var tdata = $.extend({}, {"hits": m_dataToRedraw.hits}, that.config.template_vars);