summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2022-02-15 08:01:27 -0500
committerDavid Thompson <dthompson@vistahigherlearning.com>2022-02-15 08:01:27 -0500
commitf9770873e92ccc5d8fff322165dcb77d75f9ef08 (patch)
tree68640d8f7b5e0cbc947b41608db565f096dcf198
parent8e6601165fe2c2e657cd872b061aa049a0a9fff2 (diff)
Add references field to Crop class.
-rw-r--r--js/garden.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/js/garden.js b/js/garden.js
index 1551ff5..8e5c991 100644
--- a/js/garden.js
+++ b/js/garden.js
@@ -44,7 +44,7 @@ class Season {
class Crop {
constructor(name, {depth, fallCrop, family, headStart, interval, maturity, multisow,
- overwinterPlant, pause, spacing, springPlant, resume,
+ overwinterPlant, pause, references, spacing, springPlant, resume,
species, transplant, trellis}) {
// Seed planting depth in inches.
this.depth = depth || .25;
@@ -70,6 +70,8 @@ class Crop {
this.overwinterPlant = overwinterPlant;
// When to pause succession planting (weeks after last frost)
this.pause = pause || 99;
+ // External links to helpful information about the crop.
+ this.references = references || [];
// When to resume succession planting (weeks before first frost)
this.resume = resume || 99;
// Plants per square foot, or, in the case of multisowing, clumps
@@ -551,6 +553,25 @@ function viewCropDetails(crop) {
modal.appendChild(p);
}
+ 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);
+ }
+
const container = document.getElementById("container");
const overlay = document.createElement("div");
const modal = document.createElement("div");
@@ -608,6 +629,7 @@ function viewCropDetails(crop) {
}
addDetail("Seed planting depth", `${crop.depth}"`);
addDetail("Needs a trellis", crop.trellis ? "Yes" : "No");
+ addReferences();
overlay.classList.add("overlay");
overlay.appendChild(modal);
container.appendChild(overlay);