From: Mike Taylor Date: Fri, 28 Jun 2013 09:00:46 +0000 (+0200) Subject: Simplify renderDetails(), eliminating repetition of HTML boilerplate. X-Git-Tag: 0.9.1~425 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=f19fe8fd7a7ec7405272654995aeb07cfdb70c2e Simplify renderDetails(), eliminating repetition of HTML boilerplate. --- diff --git a/experiments/spclient/mkws.js b/experiments/spclient/mkws.js index 6bc3a30..c97464d 100644 --- a/experiments/spclient/mkws.js +++ b/experiments/spclient/mkws.js @@ -442,30 +442,39 @@ function renderDetails(data, marker) { var details = '
'; if (marker) details += ''; - if (data["md-title"] != undefined) { - details += ''; - } - if (data["md-date"] != undefined) - details += ''; - if (data["md-author"] != undefined) - details += ''; - if (data["md-electronic-url"] != undefined) - details += ''; - if (data["location"][0]["md-subject"] != undefined) - details += ''; - if (data["location"][0]["@name"] != undefined) - details += ''; + + details += renderField("Title", data["md-title"], data["md-title-remainder"], data["md-title-responsibility"]); + details += renderField("Date", data["md-date"]); + details += renderField("Author", data["md-author"]); + details += renderField("URL", data["md-electronic-url"]); + details += renderField("Subject", data["location"][0]["md-subject"]); + details += renderField("Location", data["location"][0]["@name"], data["location"][0]["@id"]); details += '
'+ marker + '
' + M('Title') + ': '+data["md-title"]; - if (data["md-title-remainder"] !== undefined) { - details += ' : ' + data["md-title-remainder"] + ' '; - } - if (data["md-title-responsibility"] !== undefined) { - details += ' '+ data["md-title-responsibility"] +''; - } - details += '
' + M('Date') + ': ' + data["md-date"] + '
' + M('Author') + ': ' + data["md-author"] + '
URL: ' + data["md-electronic-url"] + '' + '
' + M('Subject') + ': ' + data["location"][0]["md-subject"] + '
' + M('Location') + ': ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + '
'; + return details; } +function renderField(caption, data, data2, data3) { + if (data === undefined) { + return ""; + } + + if (caption == "URL") { + data = '' + data + ''; + } + + if (data2 != undefined) { + data = data + " (" + data2 + ")"; + } + + if (data3 != undefined) { + data = data + " " + data3 + ""; + } + + return '' + M(caption) + ': ' + data + ''; +} + + /* * All the HTML stuff to render the search forms and * result pages.