CoreFiles by mySites.guru
admin-compare-compare.js37 lines, 1,271 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
6412bf876b9c53c53aaa21ff1e18bef5
sha1
4c87d753e35dab16d2fed06f80935c650af3f580
sha256
d6a309b707fa05752b05a27ba0d89605fbbbc12d2ff036cbc206b132f00c05ef
/**
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
(() => {

  // This method is used to decode HTML entities
  const decodeHtml = html => {
    const textarea = document.createElement('textarea');
    textarea.innerHTML = Joomla.sanitizeHtml(html);
    return textarea.value;
  };
  const compare = (original, changed) => {
    const display = changed.nextElementSibling;
    const diff = window.Diff.diffWords(original.innerHTML, changed.innerHTML);
    const fragment = document.createDocumentFragment();
    diff.forEach(part => {
      let tag = 'span';
      if (part.added) {
        tag = 'ins';
      } else if (part.removed) {
        tag = 'del';
      }
      const element = document.createElement(tag);
      element.appendChild(document.createTextNode(decodeHtml(part.value)));
      fragment.appendChild(element);
    });
    display.appendChild(fragment);
  };
  const onBoot = () => {
    document.querySelectorAll('.original').forEach(fragment => compare(fragment, fragment.nextElementSibling));

    // Cleanup
    document.removeEventListener('DOMContentLoaded', onBoot);
  };
  document.addEventListener('DOMContentLoaded', onBoot);
})();

The same content is in 3 releases, Joomla 6.2.1-rc1 to 6.3.0-alpha1. See them all, or every version of this file.