Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions public/campfire-commerce/script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// Fetch product data from JSON source
// blocked by https://github.com/lightpanda-io/browsercore/issues/187
// window.addEventListener("load", () => {

window.addEventListener("load", () => {
// use XHR to retrieve the product's infos.
const detailsXHR = new XMLHttpRequest();
// blocked by https://github.com/lightpanda-io/browsercore/issues/186
// detailsXHR.open('GET', 'json/product.json');
detailsXHR.open('GET', document.URL + 'json/product.json');
detailsXHR.open('GET', 'json/product.json');
detailsXHR.responseType = 'json';
detailsXHR.onload = function() {
if (this.status === 200) {
Expand All @@ -29,18 +25,16 @@ detailsXHR.open('GET', document.URL + 'json/product.json');
}
}());

// blocked by https://github.com/lightpanda-io/browsercore/issues/185
//
// var MenuItems = document.getElementById('MenuItems');
// MenuItems.style.maxHeight = '0px';
//
// function menutoggle() {
// if (MenuItems.style.maxHeight == '0px') {
// MenuItems.style.maxHeight = '200px';
// } else {
// MenuItems.style.maxHeight = '0px';
// }
// }
var MenuItems = document.getElementById('MenuItems');
MenuItems.style.maxHeight = '0px';

function menutoggle() {
if (MenuItems.style.maxHeight == '0px') {
MenuItems.style.maxHeight = '200px';
} else {
MenuItems.style.maxHeight = '0px';
}
}

var ProductImg = document.getElementById('product-image');
document.getElementById('small-product-image-1').onclick = function() {
Expand All @@ -49,16 +43,17 @@ detailsXHR.open('GET', document.URL + 'json/product.json');
document.getElementById('small-product-image-2').onclick = function() {
ProductImg.src = this.src;
};
// });
});



// Update product information in HTML elements
function updateProductInfo(product) {
// blocked by https://github.com/lightpanda-io/browsercore/issues/20
// document.getElementById('product-image').src = product.image;
// document.getElementById('small-product-image-1').src = product.image;
// document.getElementById('small-product-image-2').src = product.images[0];

document.getElementById('product-image').src = product.image;
document.getElementById('small-product-image-1').src = product.image;
document.getElementById('small-product-image-2').src = product.images[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix doesn't really works.
If you remove the 3 following lines (which use the setAttribute) the images are not correctly updated.

expected

    <div class="col-2">
      <img id="product-image" src="images/nomad_000.jpg" alt="" width="100%">

      <div class="small-img-row">
        <div class="small-img-col">
          <img id="small-product-image-1" src="images/nomad_000.jpg" alt="" width="100%" class="small-img">
        </div>
        <div class="small-img-col">
          <img id="small-product-image-2" src="images/nomad_001.jpg" alt="" width="100%" class="small-img">
        </div>
      </div>

current

    <div class="col-2">
      <img id="product-image" src="" alt="" width="100%">

      <div class="small-img-row">
        <div class="small-img-col">
          <img id="small-product-image-1" src="" alt="" width="100%" class="small-img">
        </div>
        <div class="small-img-col">
          <img id="small-product-image-2" src="" alt="" width="100%" class="small-img">
        </div>
      </div>
    </div>


document.getElementById('product-image').setAttribute('src', product.image);
document.getElementById('small-product-image-1').setAttribute('src', product.image);
document.getElementById('small-product-image-2').setAttribute('src', product.images[0]);
Expand Down