CoreFiles by mySites.guru
admin-item-edit_container.es6.js47 lines, 1,352 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
c3799e9f11f931318f95c15a22df02cf
sha1
99445f280532d0c660b6413237b17bf307410842
sha256
0236aa6c532c1bdefa64a7e83681166c978c995c4c9525d52dc81004bbabd8df
/**
 * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

((document) => {
  const isChecked = element => element.checked;
  const getTreeElements = element => element.querySelectorAll('input[type="checkbox"]');
  const getTreeRoot = element => element.parentElement.nextElementSibling;

  const check = (element) => {
    element.checked = true;
  };

  const uncheck = (element) => {
    element.checked = false;
  };

  const disable = element => element.setAttribute('disabled', 'disabled');
  const enable = element => element.removeAttribute('disabled');

  const toggleState = (element, rootChecked) => {
    if (rootChecked === true) {
      disable(element);
      check(element);

      return;
    }

    enable(element);
    uncheck(element);
  };
  const switchState = ({ target }) => {
    const root = getTreeRoot(target);
    const selfChecked = isChecked(target);

    if (root) {
      getTreeElements(root).map(element => toggleState(element, selfChecked));
    }
  };

  document.addEventListener('DOMContentLoaded', () => {
    [].slice.call(document.querySelectorAll('.treeselect input[type="checkbox"]')).forEach((checkbox) => {
      checkbox.addEventListener('click', switchState);
    });
  });
})(document);

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.