CoreFiles by mySites.guru
jupdatecheck.es6.js91 lines, 3,304 bytes, from Joomla_4.0.0-alpha6-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha5
md5
0058bc57286350186327db631f89e2e1
sha1
0c70983b224c546f3df2c9f88b27ee854cf5ef09
sha256
d4db7d3ed42e0c582df0c151312a2d181da7d3758770d9da06edd9e98ecbe054
/**
 * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
/**
 * Ajax call to get the update status of Joomla
 */
((window, document, Joomla) => {
  'use strict';

  const checkForJoomlaUpdates = () => {
    const options = Joomla.getOptions('js-joomla-update');
    const link = document.getElementById('plg_quickicon_joomlaupdate');
    const linkSpans = [].slice.call(link.querySelectorAll('span.j-links-link'));

    Joomla.request({
      url: `${options.ajaxUrl}&eid=700&cache_timeout=3600`,
      method: 'GET',
      data: '',
      perform: true,
      onSuccess: (response) => {
        const updateInfoList = JSON.parse(response);

        if (updateInfoList instanceof Array) {
          if (updateInfoList.length === 0) {
            // No updates
            link.classList.add('success');
            linkSpans.forEach((span) => {
              span.innerHTML = Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_UPTODATE');
            });
          } else {
            const updateInfo = updateInfoList.shift();

            if (updateInfo.version !== options.version) {
              const messages = {
                warning: [
                  `<div class="message-alert">` + `${Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_UPDATEFOUND_MESSAGE').replace('%s', `<span class="badge badge-danger"> \u200E ${updateInfo.version}</span>`)}`
                  + `<button class="btn btn-sm btn-primary" onclick="document.location='${options.url}'">`
                  + `${Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_UPDATEFOUND_BUTTON')}</button>`,
                ],
              };

              // Render the message
              Joomla.renderMessages(messages);

              // Scroll to page top
              window.scrollTo(0, 0);

              link.classList.add('warning');
              linkSpans.forEach((span) => {
                span.innerHTML = Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_UPDATEFOUND').replace('%s', `<span class="badge badge-light"> \u200E ${updateInfo.version}</span>`);
              });
            } else {
              link.classList.add('success');
              linkSpans.forEach((span) => {
                span.innerHTML = Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_UPTODATE');
              });
            }
          }
        } else {
          // An error occurred
          link.classList.add('danger');
          linkSpans.forEach((span) => {
            span.innerHTML = Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_ERROR');
          });
        }
      },
      onError: () => {
        // An error occurred
        link.classList.add('danger');
        linkSpans.forEach((span) => {
          span.innerHTML = Joomla.JText._('PLG_QUICKICON_JOOMLAUPDATE_ERROR');
        });
      },
    });
  };

  const onBoot = () => {
    if (!Joomla || typeof Joomla.getOptions !== 'function' || !Joomla.getOptions('js-joomla-update')) {
      throw new Error('Script is not properly initialised');
    }

    setTimeout(checkForJoomlaUpdates, 2000);

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

  // Initialize
  document.addEventListener('DOMContentLoaded', onBoot);
})(window, document, Joomla);

No other release has this exact content. See every version of this file.