function imgSelect() {
  // Select the <img> and the two <select> elements
  const img = document.querySelector('img');
  let imgFormat = document.querySelector('#image-format').value;
  const imgSelect = document.querySelector('#image-select').value;
  // Allow SVGs to be selected if on the IWT logo
  if (imgSelect == 'iwt-logo') {
    document.querySelector('option[value="svg"]').removeAttribute('disabled');
    // Remove SVG as an option as well as select PNG as a default
  } else {
    document.querySelector('option[value="svg"]').setAttribute('disabled', '');
    if (imgFormat == 'svg') {
      document.querySelector('option[value="png"]').selected = 'selected';
      imgFormat = document.querySelector('#image-format').value;
    }
  }
  // If either are empty, return and don't continue.
  if (imgFormat == '' || imgSelect == '') return;
  img.setAttribute('hidden', '');
  // Selecting various needed elements
  const imgSelectMsg = document.querySelector('p.image-msg.select');
  const imgSelectLoad = document.querySelector('p.image-msg.loading');
  const imgSelectSupport = document.querySelector('p.image-msg.no-support');
  const figCaption = document.querySelector('figcaption');
  // Find the index of the selected <optino> so we can select that <option> element
  const index = document.querySelector('#image-select').selectedIndex;
  const selectedElem = document.querySelector('#image-select').children[index];

  // Construct the caption given the current picture & size
  figCaption.innerHTML = `${selectedElem.innerHTML} - ${imgData[imgSelect].sizes[imgFormat]} KB`;

  // Hide and show loading message, no image selected message, and unsupported file type message
  imgSelectMsg.setAttribute('hidden', '');
  imgSelectSupport.setAttribute('hidden', '');
  imgSelectLoad.removeAttribute('hidden');

  // Update the <img> element with the selection
  img.setAttribute('src', `images/${imgSelect}/${imgSelect}.${imgFormat}`);
  img.setAttribute('alt', imgData[imgSelect].alt);
}
// Change the image when the image dropdowns are modified
Change the image when the image dropdowns are modified
Change the image when the image dropdowns are modified
function imgSelect() {
  const img = document.querySelector('img');
  let imgFormat = document.querySelector('#image-format').value;
  const imgSelect = document.querySelector('#image-select').value;
  if (imgSelect == 'iwt-logo') {
    document.querySelector('option[value="svg"]').removeAttribute('disabled');
  } else {
    document.querySelector('option[value="svg"]').setAttribute('disabled', '');
    if (imgFormat == 'svg') {
      document.querySelector('option[value="png"]').selected = 'selected';
      imgFormat = document.querySelector('#image-format').value;
    }
  }
  if (imgFormat == '' || imgSelect == '') return;
  img.setAttribute('hidden', '');
  const imgSelectMsg = document.querySelector('p.image-msg.select');
  const imgSelectLoad = document.querySelector('p.image-msg.loading');
  const imgSelectSupport = document.querySelector('p.image-msg.no-support');
  const figCaption = document.querySelector('figcaption');
  const index = document.querySelector('#image-select').selectedIndex;
  const selectedElem = document.querySelector('#image-select').children[index];
  figCaption.innerHTML = `${selectedElem.innerHTML} - ${imgData[imgSelect].sizes[imgFormat]} KB`;
  imgSelectMsg.setAttribute('hidden', '');
  imgSelectSupport.setAttribute('hidden', '');
  imgSelectLoad.removeAttribute('hidden');
  img.setAttribute('src', `images/${imgSelect}/${imgSelect}.${imgFormat}`);
  img.setAttribute('alt', imgData[imgSelect].alt);
}
function imgSelect ( ) { const img = document . querySelector ( 'img' ) ; let imgFormat = document . querySelector ( '#image-format' ) . value ; const imgSelect = document . querySelector ( '#image-select' ) . value ; if ( imgSelect == 'iwt-logo' ) { document . querySelector ( 'option[value="svg"]' ) . removeAttribute ( 'disabled' ) ; } else { document . querySelector ( 'option[value="svg"]' ) . setAttribute ( 'disabled' , '' ) ; if ( imgFormat == 'svg' ) { document . querySelector ( 'option[value="png"]' ) . selected = 'selected' ; imgFormat = document . querySelector ( '#image-format' ) . value ; } } if ( imgFormat == '' || imgSelect == '' ) return ; img . setAttribute ( 'hidden' , '' ) ; const imgSelectMsg = document . querySelector ( 'p.image-msg.select' ) ; const imgSelectLoad = document . querySelector ( 'p.image-msg.loading' ) ; const imgSelectSupport = document . querySelector ( 'p.image-msg.no-support' ) ; const figCaption = document . querySelector ( 'figcaption' ) ; const index = document . querySelector ( '#image-select' ) . selectedIndex ; const selectedElem = document . querySelector ( '#image-select' ) . children [ index ] ; figCaption . innerHTML = ` ${ selectedElem . innerHTML } ${ imgData [ imgSelect ] . sizes [ imgFormat ] } ` ; imgSelectMsg . setAttribute ( 'hidden' , '' ) ; imgSelectSupport . setAttribute ( 'hidden' , '' ) ; imgSelectLoad . removeAttribute ( 'hidden' ) ; img . setAttribute ( 'src' , ` ${ imgSelect } ${ imgSelect } ${ imgFormat } ` ) ; img . setAttribute ( 'alt' , imgData [ imgSelect ] . alt ) ; }
Change the image when the image dropdowns are modified
Change the image when the image dropdowns are modified
// Select the <img> and the two <select> elements // Allow SVGs to be selected if on the IWT logo // Remove SVG as an option as well as select PNG as a default // If either are empty, return and don't continue. // Selecting various needed elements // Find the index of the selected <optino> so we can select that <option> element // Construct the caption given the current picture & size // Hide and show loading message, no image selected message, and unsupported file type message // Update the <img> element with the selection