CoreFiles by mySites.guru
stats-message.es6.js93 lines, 2,660 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
a43bbc8ef6c92ae299e68991634e0b62
sha1
8c8e699fe817ecbeb2b7a5f1757e51d36016c4ae
sha256
79fc5d1363aee5cda26cc457fb353bb4ab294fff2f21bd7502bbfb2d7a3a11da
/**
 * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @since      3.5.0
 */

Joomla = window.Joomla || {};

((Joomla, document) => {
  'use strict';

  const initStatsEvents = (callback) => {
    const messageContainer = document.getElementById('system-message-container');
    const joomlaAlert = messageContainer.querySelector('.js-pstats-alert');
    const detailsContainer = messageContainer.querySelector('.js-pstats-data-details');

    // Show details about the information being sent
    document.addEventListener('click', (event) => {
      if (event.target.classList.contains('js-pstats-btn-details')) {
        event.preventDefault();
        detailsContainer.classList.toggle('d-none');
      }
    });

    // Always allow
    document.addEventListener('click', (event) => {
      if (event.target.classList.contains('js-pstats-btn-allow-always')) {
        event.preventDefault();

        // Remove message
        joomlaAlert.close();

        callback({ plugin: 'sendAlways' });
      }
    });

    // Allow once
    document.addEventListener('click', (event) => {
      if (event.target.classList.contains('js-pstats-btn-allow-once')) {
        event.preventDefault();

        // Remove message
        joomlaAlert.close();

        callback({ plugin: 'sendOnce' });
      }
    });

    // Never allow
    document.addEventListener('click', (event) => {
      if (event.target.classList.contains('js-pstats-btn-allow-never')) {
        event.preventDefault();

        // Remove message
        joomlaAlert.close();

        callback({ plugin: 'sendNever' });
      }
    });
  };

  const getJson = ({ plugin = 'sendStats' } = {}) => {
    const url = `index.php?option=com_ajax&group=system&plugin=${plugin}&format=raw`;
    const messageContainer = document.getElementById('system-message-container');
    Joomla.request({
      url,
      headers: {
        'Content-Type': 'application/json',
      },
      onSuccess: (response) => {
        try {
          const json = JSON.parse(response);
          if (json && json.html) {
            messageContainer.innerHTML = json.html;
            messageContainer.querySelector('.js-pstats-alert').style.display = 'block';
            initStatsEvents(getJson);
          }
        } catch (e) {
          throw new Error(e);
        }
      },
      onError: (xhr) => {
        Joomla.renderMessages({
          error: [xhr.response],
        });
      },
    });
  };

  document.addEventListener('DOMContentLoaded', () => {
    getJson();
  });
})(Joomla, 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.