Why is only 1 record's link functional instead of each record's link?

This JavaScript object code populates an accordion drawer and reveals the contents as part listing rows, some with thumbnails, some without. Clicking/tapping on the thumbnail opens a modal to show a larger view of the image and caption underneath. Clicking/tapping on the upper right X will close the modal. All of this works.

The problem: if there is more than one thumbnail in the parts listing, only the lower thumbnail will open up a modal, even though each thumb has its own id assigned, and each id is separately targeted in the CSS.

A sample of the JavaScript object (a TaffyDB code) looks like this:
(A screenshot of working app: http://www.reedyrace.com/ae/history/screenshot.jpg )

 {
 yearHistory: 1989, // ******************** 1989
 heading:"year1989",
 partNo:"6025",
 partName:"RC10 Graphite, less electrics and bearings",
 popupId:"b1989", // add to index.html for :target
 popupContent:"#6025 RC10 Graphite",
 imageThumb:"rc10-6025"
 },
 {
 yearHistory: 1989, 
 heading:"year1989",
 partNo:"6030",
 partName:"RC10 Graphite, less electrics, with bearings",
 imageThumb:"blank"
 },
 {
 yearHistory: 1989,
 heading:"year1989",
 breakpoint:"---", // Add breakpoint between vehicle types if a series
 partNo:"unknown",
 partName:"TQ10 Graphite",
 popupId:"a1989", // add to index.html for :target
 popupContent:"Released exclusively for Horizon Hobby Distributors Inc. Substantially the same as the RC10 Graphite, but the chassis is not woven, and is a slightly different shape. Features TQ wheels and tires, limited-slip VariLok ball differential allows the outside rear wheel to turn slightly faster than the inside on the corner, unpainted driver, wing, and body (from TQ10 Graphite Instruction Manual, no date).",
 imageThumb:"tq10"
 },

The code to cycle through the above looks like this:

// REPEATING ELEMENTS -- part listing of rows
 db({heading:show}).each(function (name){ // 'show' and 'heading' = yearxxxx; "name" is an alias
    var partNo       = name.partNo; // part no in listing row
    var partName     = name.partName; // part name in listing row
    var imageThumb   = name.imageThumb; // thumbnail in listing row; 'blank' if no thumbnail
    var yearHistory  = name.yearHistory; // like 1999
    var breakpoint   = name.breakpoint; // only if adding a solid line above this record

    // construct and target the unique outputxxxx innerHTML div id
    var output = "output" + yearHistory;
        output = document.getElementById(output);
        
        if(breakpoint === "---"){output.innerHTML+="<span class='breakhr'></span";} // create a solid line above this record

    // show full size image and caption in modal  
    var popupId       = name.popupId; // identify the modal for this record
    var popupContent  = name.popupContent; // the modal caption
    // if imageThumb is other than 'blank', construct the code to write out the parts listing and make the modal when thumbnail is clicked
    var imageThumbSrc = "<span style='width:7em'>#" + partNo + "</span><span style='width:100px'><a href='#" + popupId  + "'><img style='width:60px;' src='images/" + imageThumb + ".jpg'></a></span><span>" + partName + "</span><br><div id='" + popupId + "' class='popup'><div class='popup__block'><img class='image_thumb' style='width:100%; border:1px black solid;' src='images/" + imageThumb + ".jpg'><p>" + popupContent + "</p><a href='#' class='popup__close'>Close</a>";

    // don't display thumbnail if imageThumb = "blank", otherwise a "image broken" icon will show
    if(imageThumb === "blank"){imageThumbSrc = "<span style='width:7em'>#" + partNo + "</span><span style='width:100px'><img class='image_thumb' src='images/" + imageThumb + ".jpg' style='height:4px;'></span><span>" + partName + "</span><br>";} 
    output.innerHTML+="" + imageThumbSrc; 
    });
 }

I appears that the cycling through is not really working. It is only allowing the last thumbnail to be clickable. Where did I go wrong?

Well lets start with low hanging fruit:

if(breakpoint === "---"){output.innerHTML+="<span class='breakhr'></span";} // create a solid line above this record

I spy with my little eye, something missing from the end of that string.

var imageThumbSrc = "<span style='width:7em'>#" + partNo + "</span><span style='width:100px'><a href='#" + popupId  + "'><img style='width:60px;' src='images/" + imageThumb + ".jpg'></a></span><span>" + partName + "</span><br><div id='" + popupId + "' class='popup'><div class='popup__block'><img class='image_thumb' style='width:100%; border:1px black solid;' src='images/" + imageThumb + ".jpg'><p>" + popupContent + "</p><a href='#' class='popup__close'>Close</a>";

I spy with my little eye some dangling <div> tags…
Close your closures, and you might find the problems sort themselves out.

Thanks! </span;} is now </span>;}
Added the two </div>s

But the images are still not consistently clickable.

[I tried to update my earlier post with the above changes, but I keep getting a note saying I am not authorized to see them. Now the Edit this Post icon is gone from the opening post. ]

Well at least now we have some well formed HTML :wink:

In my demo ( https://codepen.io/EtoileLion/pen/GGXBbm ), the two images seem to be clickable just fine… so the question now becomes “What’re you using to make the popups…popup?”

Off Topic:

There is a five-hour window for edits. After this time, you can always flag the post and ask a moderator to edit it for you. (Often it’s better not to make edits once the discussion has moved on, as changing earlier posts can be confusing, and edits can be missed by folk who have already read those posts.)

1 Like

Here’s the popup code I’m using:

/* popup code modified from https://codepen.io/melnik909/pen/QModrM */

.popup{
  width: 100%;
  height: 100vh;
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  background-color: #aaa;
  background-image: url(images/RC10.COM-gray.jpg);
}
/* for thumbnail modals */
#a1975:target, #a1979:target, #a1989:target, #a1990:target, #a1999:target
{
  display: flex;
}

.popup:before{
  content: "";
  box-sizing: border-box;
  width: 100%;
  position: fixed;
  left: 0;
  top: 50%;
}

.popup:after{
  content: "";
  width: 0;
  height: 2px;
}

.popup__block{
  height: calc(100vh - 40px);
  padding: 5% 5%;
  box-sizing: border-box;
  position: relative;
  margin: auto;
  overflow: auto;
  animation: fade .3s ease-out .3s both;
  background-color: #ccc;
  border-radius: 4px;
}

@keyframes fade{
  0%{
    opacity: 0;
  }
  100%{
    opacity: 1;
  }
}

.popup__title{
  font-size: 2.5rem;
  margin: 0 0 1em;
}

.popup__close{
  width: 3.2rem;
  height: 3.2rem;
  text-indent: -9999px;
  position: fixed;
  top: 20px;
  right: 20px;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gICAgPHBhdGggZD0iTTE5IDYuNDFMMTcuNTkgNSAxMiAxMC41OSA2LjQxIDUgNSA2LjQxIDEwLjU5IDEyIDUgMTcuNTkgNi40MSAxOSAxMiAxMy40MSAxNy41OSAxOSAxOSAxNy41OSAxMy40MSAxMnoiLz4gICAgPHBhdGggZD0iTTAgMGgyNHYyNEgweiIgZmlsbD0ibm9uZSIvPjwvc3ZnPg==);
  background-color: red;
  border-radius: 4px;
}

The popup HTML is found in this line:

`




" + popupContent + "


Close

`

Hard to think it’s the popup code, because it works standalone. I think the problem has to do with the fact that only the last popup works in the section of rows called in the function. However, using the Inspector shows all the popup code for each of the thumbnails is available, each with its own id. That’s what confuses me.

Thanks TechnoBear, I’ll leave it as is, then.

1 Like
 #a1975:target, #a1979:target, #a1989:target, #a1990:target, #a1999:target
{
  display: flex;
}
popupId:"b1989", // add to index.html for :target

One of these things is missing in the other…(perhaps you’d do better to make this a class definition, rather than a list of ID’s?)

This answer resolves the whole issue. I have been overlooking this line in CSS. If I make it a class name, wouldn’t the same image pop up over and over? Will have to try this out. Thanks!

1 Like

All the CSS does is set the display type.

What’s the difference between

 #a1975:target, #a1979:target, #a1989:target, #a1990:target, #a1999:target
{

and

.popup:target
{

?
(The only difference is that the class definition may find additional elements… which is what you want it to do…)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.