CoreFiles by mySites.guru
select-colour.es6.js49 lines, 1,575 bytes, from Joomla_4.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 3.9.0-beta4
md5
0abe2f3bb57ae6cc6a936bb5f3594658
sha1
b36dd34c2dd56060a37900931de3e957ab7de23e
sha256
cbfca22e2ab83092fb18f71009e1ec26ea789acbda37e499f23d4a9e3b99a0cf
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
(() => {
  'use strict';

  const onChange = ({
    target
  }) => {
    const self = 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 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.