From 1466f38f0bd71980e1079cf6fcc642dc36034214 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 17 Feb 2022 08:48:57 -0500 Subject: Don't show references header if there are no references. --- js/garden.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/js/garden.js b/js/garden.js index fe3b952..046943a 100644 --- a/js/garden.js +++ b/js/garden.js @@ -569,22 +569,24 @@ function viewCropDetails(crop) { } function addReferences() { - const div = document.createElement("div"); - const title = document.createElement("span"); - const list = document.createElement("ul"); - title.appendChild(document.createTextNode("References")); - div.appendChild(title); - crop.references.forEach(ref => { - const li = document.createElement("li"); - const link = document.createElement("a"); - link.appendChild(document.createTextNode(ref.title)); - link.href = ref.url; - link.target = "_blank"; // open in new tab. - li.appendChild(link); - list.appendChild(li); - }); - div.appendChild(list); - modal.appendChild(div); + if(crop.references.length > 0) { + const div = document.createElement("div"); + const title = document.createElement("span"); + const list = document.createElement("ul"); + title.appendChild(document.createTextNode("References")); + div.appendChild(title); + crop.references.forEach(ref => { + const li = document.createElement("li"); + const link = document.createElement("a"); + link.appendChild(document.createTextNode(ref.title)); + link.href = ref.url; + link.target = "_blank"; // open in new tab. + li.appendChild(link); + list.appendChild(li); + }); + div.appendChild(list); + modal.appendChild(div); + } } const container = document.getElementById("container"); -- cgit v1.2.3