CoreFiles by mySites.guru
admin-template-toggle-switch.es6.js126 lines, 3,578 bytes, from Joomla_4.0.0-alpha6-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha5
md5
9141e8fa3dd7d6b438bac7213ce4bb19
sha1
f7d423c656649e1c7cd2c77ab329e3b3c3cd14ec
sha256
41302fbcf8542cb2a5e9d7db6b938596de94df450bf4cc06b76201e821b7ac86
/**
 * @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 showDiffChangedOff = () => {
    const diffMain = document.getElementById('diff-main');

    if (diffMain) {
      diffMain.classList.remove('active');

      if (typeof Storage !== 'undefined') {
        localStorage.removeItem('diffSwitchState');
      }
    }
  };

  const showDiffChangedOn = () => {
    const diffMain = document.getElementById('diff-main');

    if (diffMain) {
      diffMain.classList.add('active');

      if (typeof Storage !== 'undefined') {
        localStorage.setItem('diffSwitchState', 'checked');
      }
    }
  };

  const showCoreChangedOff = () => {
    const override = document.getElementById('override-pane');
    const corePane = document.getElementById('core-pane');

    if (corePane && override) {
      corePane.classList.remove('active');
      override.className = 'col-md-12';

      if (typeof Storage !== 'undefined') {
        localStorage.removeItem('coreSwitchState');
      }
    }
  };

  const showCoreChangedOn = () => {
    const override = document.getElementById('override-pane');
    const corePane = document.getElementById('core-pane');

    if (corePane && override) {
      corePane.classList.add('active');
      override.className = 'col-md-6';

      if (Joomla.editors.instances.jform_core) {
        Joomla.editors.instances.jform_core.refresh();
      }

      if (typeof Storage !== 'undefined') {
        localStorage.setItem('coreSwitchState', 'checked');
      }
    }
  };

  document.addEventListener('DOMContentLoaded', () => {
    const JformShowDiff = document.getElementById('jform_show_diff');
    const JformShowCore = document.getElementById('jform_show_core');

    if (JformShowDiff) {
      JformShowDiff.addEventListener('joomla.switcher.on', showDiffChangedOn);
      JformShowDiff.addEventListener('joomla.switcher.off', showDiffChangedOff);
    }

    if (JformShowCore) {
      JformShowCore.addEventListener('joomla.switcher.on', showCoreChangedOn);
      JformShowCore.addEventListener('joomla.switcher.off', showCoreChangedOff);
    }

    // Callback executed when JformShowCore was found
    function handleJformShowCore() {
      JformShowCore.newActive = 1;
      JformShowCore.switch();
    }

    if (typeof Storage !== 'undefined' && localStorage.getItem('coreSwitchState') && JformShowCore) {
      // Set up the mutation observer
      const observerJformShowCore = new MutationObserver(((mutations, me) => {
        if (JformShowDiff) {
          handleJformShowCore();
          me.disconnect();
        }
      }));

      // Start observing
      observerJformShowCore.observe(JformShowCore, {
        childList: true,
        subtree: true,
      });

      showCoreChangedOn();
    }

    // Callback executed when JformShowDiff was found
    function handleJformShowDiff() {
      JformShowDiff.newActive = 1;
      JformShowDiff.switch();
    }

    if (typeof Storage !== 'undefined' && localStorage.getItem('diffSwitchState') && JformShowDiff) {
      // Set up the mutation observer
      const observerJformShowDiff = new MutationObserver(((mutations, me) => {
        if (JformShowDiff) {
          handleJformShowDiff();
          me.disconnect();
        }
      }));

      // Start observing
      observerJformShowDiff.observe(JformShowDiff, {
        childList: true,
        subtree: true,
      });

      showDiffChangedOn();
    }
  });
})();

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.