CoreFiles by mySites.guru
select-colour.js47 lines, 1,613 bytes, from Joomla_4.0.0-alpha11-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha10
md5
a63c481926a34e52bb6df5be20f31e09
sha1
1556fdd226c1d65bcdbcbb5c2427402be5022b5a
sha256
f36f490410f5932fe77f3f2125b5726ea5b068e09ab436eea5efe8b0e14110b2
/**
* 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 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
(function () {
  'use strict';

  var onChange = function onChange(event) {
    var self = event.target;
    var 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');
    }
  };

  var updateSelectboxColour = function updateSelectboxColour() {
    var colourSelects = [].slice.call(document.querySelectorAll('.custom-select-color-state'));
    colourSelects.forEach(function (colourSelect) {
      var 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 6 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha12. See them all, or every version of this file.