CoreFiles by mySites.guru
select-colour.es6.js47 lines, 1,464 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
51dc0e11481b6d74c88141371b41df80
sha1
66348ac7cf8fb4a71a9e941891dc101d67f67a91
sha256
7b3fe1ab2bd0941249a8bf69f3d406ce120cc1de60ba6a7f0337aab29bafff65
/**
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
(() => {
  'use strict';

  const onChange = (event) => {
    const self = event.target;
    const value = parseInt(self.value, 10);

    self.classList.remove('custom-select-success', 'custom-select-danger');

    if (value === 1) {
      self.classList.add('custom-select-success');
    } else if (value === 0 || value === -2) {
      self.classList.add('custom-select-danger');
    }
  };

  const updateSelectboxColour = () => {
    const colourSelects = [].slice.call(document.querySelectorAll('.custom-select-color-state'));

    colourSelects.forEach((colourSelect) => {
      const value = parseInt(colourSelect.value, 10);

      // Add class on page load
      if (value === 1) {
        colourSelect.classList.add('custom-select-success');
      } else if (value === 0 || value === -2) {
        colourSelect.classList.add('custom-select-danger');
      }

      // Add class when value is changed
      colourSelect.addEventListener('change', onChange);
    });

    // Cleanup
    document.removeEventListener('DOMContentLoaded', updateSelectboxColour, true);
  };

  // On docunment loaded
  document.addEventListener('DOMContentLoaded', updateSelectboxColour, true);

  // On Joomla updated
  document.addEventListener('joomla:updated', updateSelectboxColour, true);
})();

The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.