[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/plg_installer_webinstaller/js/ -> client-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    /**
   5     * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   6     * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7     */
   8    if (!Joomla) {
   9      throw new Error('Joomla API is not properly initialised');
  10    }
  11  
  12    var allowList = {
  13      button: ['type'],
  14      input: ['type', 'name', 'placeholder', 'inputmode'],
  15      select: ['name'],
  16      option: ['value', 'selected']
  17    };
  18    var webInstallerOptions = {
  19      view: 'dashboard',
  20      id: 0,
  21      ordering: '',
  22      version: 'current',
  23      list: 0,
  24      options: Joomla.getOptions('plg_installer_webinstaller', {})
  25    };
  26    var instance;
  27  
  28    var WebInstaller = /*#__PURE__*/function () {
  29      function WebInstaller() {}
  30  
  31      var _proto = WebInstaller.prototype;
  32  
  33      _proto.initialise = function initialise() {
  34        var _this = this;
  35  
  36        webInstallerOptions.loaded = 1;
  37        var cancelButton = document.getElementById('uploadform-web-cancel');
  38        cancelButton.addEventListener('click', function () {
  39          document.getElementById('uploadform-web').classList.add('hidden');
  40  
  41          if (webInstallerOptions.list && document.querySelector('.list-view')) {
  42            document.querySelector('.list-view').click();
  43          }
  44        });
  45        var installButton = document.getElementById('uploadform-web-install');
  46        installButton.addEventListener('click', function () {
  47          if (webInstallerOptions.options.installFrom === 4) {
  48            _this.submitButtonUrl();
  49          } else {
  50            _this.submitButtonWeb();
  51          }
  52        });
  53        this.loadweb(webInstallerOptions.options.base_url + "index.php?format=json&option=com_apps&view=dashboard");
  54        this.clickforlinks();
  55      };
  56  
  57      _proto.loadweb = function loadweb(url) {
  58        var _this2 = this;
  59  
  60        if (!url) {
  61          return false;
  62        } // eslint-disable-next-line prefer-regex-literals
  63  
  64  
  65        var pattern1 = new RegExp(webInstallerOptions.options.base_url);
  66        var pattern2 = /^index\.php/;
  67  
  68        if (!(pattern1.test(url) || pattern2.test(url))) {
  69          window.open(url, '_blank');
  70          return false;
  71        }
  72  
  73        var requestUrl = url + "&product=" + webInstallerOptions.options.product + "&release=" + webInstallerOptions.options.release + "&dev_level=" + webInstallerOptions.options.dev_level + "&list=" + (webInstallerOptions.list ? 'list' : 'grid') + "&lang=" + webInstallerOptions.options.language;
  74        var orderingSelect = document.getElementById('com-apps-ordering');
  75        var versionSelect = document.getElementById('com-apps-filter-joomla-version');
  76  
  77        if (webInstallerOptions.ordering !== '' && orderingSelect && orderingSelect.value) {
  78          webInstallerOptions.ordering = orderingSelect.value;
  79          requestUrl += "&ordering=" + webInstallerOptions.ordering;
  80        }
  81  
  82        if (webInstallerOptions.version !== '' && versionSelect && versionSelect.value) {
  83          webInstallerOptions.version = versionSelect.value;
  84          requestUrl += "&filter_version=" + webInstallerOptions.version;
  85        }
  86  
  87        WebInstaller.showLoadingLayer();
  88        new Promise(function (resolve, reject) {
  89          Joomla.request({
  90            url: requestUrl,
  91            onSuccess: function onSuccess(resp) {
  92              var response;
  93  
  94              try {
  95                response = JSON.parse(resp);
  96              } catch (error) {
  97                throw new Error('Failed to parse JSON');
  98              }
  99  
 100              if (document.getElementById('web-loader')) {
 101                document.getElementById('web-loader').classList.add('hidden');
 102              }
 103  
 104              var jedContainer = document.getElementById('jed-container');
 105              jedContainer.innerHTML = Joomla.sanitizeHtml(response.data.html, allowList);
 106              document.getElementById('com-apps-searchbox').addEventListener('keypress', function (_ref) {
 107                var which = _ref.which;
 108  
 109                if (which === 13) {
 110                  _this2.initiateSearch();
 111                }
 112              });
 113              document.getElementById('search-extensions').addEventListener('click', function () {
 114                _this2.initiateSearch();
 115              });
 116              document.getElementById('search-reset').addEventListener('click', function () {
 117                var searchBox = document.getElementById('com-apps-searchbox');
 118                searchBox.value = '';
 119  
 120                _this2.initiateSearch();
 121  
 122                document.getElementById('search-reset').setAttribute('disabled', 'disabled');
 123              });
 124  
 125              if (document.getElementById('com-apps-searchbox').value === '') {
 126                document.getElementById('search-reset').setAttribute('disabled', 'disabled');
 127              }
 128  
 129              document.getElementById('search-reset').innerHTML = Joomla.sanitizeHtml(Joomla.Text._('JSEARCH_FILTER_CLEAR')); // eslint-disable-next-line no-shadow
 130  
 131              var orderingSelect = document.getElementById('com-apps-ordering'); // eslint-disable-next-line no-shadow
 132  
 133              var versionSelect = document.getElementById('com-apps-filter-joomla-version');
 134  
 135              if (orderingSelect) {
 136                orderingSelect.addEventListener('change', function () {
 137                  var index = orderingSelect.selectedIndex;
 138                  webInstallerOptions.ordering = orderingSelect.options[index].value;
 139  
 140                  _this2.installfromwebajaxsubmit();
 141                });
 142              }
 143  
 144              if (versionSelect) {
 145                versionSelect.addEventListener('change', function () {
 146                  var index = versionSelect.selectedIndex;
 147                  webInstallerOptions.version = versionSelect.options[index].value;
 148  
 149                  _this2.installfromwebajaxsubmit();
 150                });
 151              }
 152  
 153              if (webInstallerOptions.options.installfrom_url !== '') {
 154                WebInstaller.installfromweb(webInstallerOptions.options.installfrom_url);
 155              }
 156  
 157              resolve();
 158            },
 159            onError: function onError(request) {
 160              var errorContainer = document.getElementById('web-loader-error');
 161              var loaderContainer = document.getElementById('web-loader');
 162  
 163              if (request.responseText && errorContainer) {
 164                errorContainer.innerHTML = Joomla.sanitizeHtml(request.responseText);
 165              }
 166  
 167              if (loaderContainer) {
 168                loaderContainer.classList.add('hidden');
 169                errorContainer.classList.remove('hidden');
 170              }
 171  
 172              Joomla.renderMessages({
 173                danger: [Joomla.Text._('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_LOADING_ERROR')]
 174              }, '#web-loader-error');
 175              reject();
 176            }
 177          });
 178        }).finally(function () {
 179          // Promise has been settled.
 180          // Run the following whether or not it was a success.
 181          var installAtField = document.getElementById('joomlaapsinstallatinput');
 182  
 183          if (installAtField) {
 184            installAtField.value = webInstallerOptions.options.installat_url;
 185          }
 186  
 187          _this2.clickforlinks();
 188  
 189          WebInstaller.clicker();
 190  
 191          if (webInstallerOptions.view !== 'extension') {
 192            [].slice.call(document.querySelectorAll('div.load-extension')).forEach(function (element) {
 193              element.addEventListener('click', function (event) {
 194                event.preventDefault();
 195  
 196                _this2.processLinkClick(element.getAttribute('data-url'));
 197              });
 198              element.setAttribute('href', '#');
 199            });
 200          }
 201  
 202          if (webInstallerOptions.view === 'extension') {
 203            var installExtensionButton = document.getElementById('install-extension');
 204            var installExtensionFromExternalButton = document.getElementById('install-extension-from-external');
 205  
 206            if (installExtensionButton) {
 207              installExtensionButton.addEventListener('click', function () {
 208                WebInstaller.installfromweb(installExtensionButton.getAttribute('data-downloadurl'), installExtensionButton.getAttribute('data-name'));
 209                document.getElementById('uploadform-web-install').scrollIntoView({
 210                  behavior: 'smooth',
 211                  block: 'start'
 212                });
 213              });
 214            }
 215  
 216            if (installExtensionFromExternalButton) {
 217              installExtensionFromExternalButton.addEventListener('click', function () {
 218                var redirectUrl = installExtensionFromExternalButton.getAttribute('data-downloadurl');
 219                var redirectConfirm = window.confirm(Joomla.Text._('PLG_INSTALLER_WEBINSTALLER_REDIRECT_TO_EXTERNAL_SITE_TO_INSTALL').replace('[SITEURL]', redirectUrl));
 220  
 221                if (redirectConfirm !== true) {
 222                  return;
 223                }
 224  
 225                document.getElementById('adminForm').setAttribute('action', redirectUrl);
 226                document.querySelector('input[name=task]').setAttribute('disabled', true);
 227                document.querySelector('input[name=install_directory]').setAttribute('disabled', true);
 228                document.querySelector('input[name=install_url]').setAttribute('disabled', true);
 229                document.querySelector('input[name=installtype]').setAttribute('disabled', true);
 230                document.querySelector('input[name=filter_search]').setAttribute('disabled', true);
 231                document.getElementById('adminForm').submit();
 232              });
 233            }
 234          }
 235  
 236          if (webInstallerOptions.list && document.querySelector('.list-view')) {
 237            document.querySelector('.list-view').click();
 238          }
 239  
 240          WebInstaller.hideLoadingLayer();
 241        });
 242        return true;
 243      };
 244  
 245      _proto.clickforlinks = function clickforlinks() {
 246        var _this3 = this;
 247  
 248        [].slice.call(document.querySelectorAll('a.transcode')).forEach(function (element) {
 249          var ajaxurl = element.getAttribute('href');
 250          element.addEventListener('click', function (event) {
 251            event.preventDefault();
 252  
 253            _this3.processLinkClick(ajaxurl);
 254          });
 255          element.setAttribute('href', '#');
 256        });
 257      };
 258  
 259      _proto.initiateSearch = function initiateSearch() {
 260        document.getElementById('search-reset').removeAttribute('disabled');
 261        webInstallerOptions.view = 'dashboard';
 262        this.installfromwebajaxsubmit();
 263      };
 264  
 265      _proto.installfromwebajaxsubmit = function installfromwebajaxsubmit() {
 266        var tail = "&view=" + webInstallerOptions.view;
 267  
 268        if (webInstallerOptions.id) {
 269          tail += "&id=" + webInstallerOptions.id;
 270        }
 271  
 272        if (document.getElementById('com-apps-searchbox').value) {
 273          var value = encodeURI(document.getElementById('com-apps-searchbox').value.toLowerCase().replace(/ +/g, '_').replace(/[^a-z0-9-_]/g, '').trim());
 274          tail += "&filter_search=" + value;
 275        }
 276  
 277        var orderingSelect = document.getElementById('com-apps-ordering');
 278        var versionSelect = document.getElementById('com-apps-filter-joomla-version');
 279  
 280        if (webInstallerOptions.ordering !== '' && orderingSelect && orderingSelect.value) {
 281          webInstallerOptions.ordering = orderingSelect.value;
 282        }
 283  
 284        if (webInstallerOptions.ordering) {
 285          tail += "&ordering=" + webInstallerOptions.ordering;
 286        }
 287  
 288        if (webInstallerOptions.version !== '' && versionSelect && versionSelect.value) {
 289          webInstallerOptions.version = versionSelect.value;
 290        }
 291  
 292        if (webInstallerOptions.version) {
 293          tail += "&filter_version=" + webInstallerOptions.version;
 294        }
 295  
 296        this.loadweb(webInstallerOptions.options.base_url + "index.php?format=json&option=com_apps" + tail);
 297      };
 298  
 299      _proto.processLinkClick = function processLinkClick(url) {
 300        var pattern1 = new RegExp(webInstallerOptions.options.base_url);
 301        var pattern2 = /^index\.php/;
 302  
 303        if (pattern1.test(url) || pattern2.test(url)) {
 304          webInstallerOptions.view = url.replace(/^.+[&?]view=(\w+).*$/, '$1');
 305  
 306          if (webInstallerOptions.view === 'dashboard') {
 307            webInstallerOptions.id = 0;
 308          } else if (webInstallerOptions.view === 'category') {
 309            webInstallerOptions.id = url.replace(/^.+[&?]id=(\d+).*$/, '$1');
 310          }
 311  
 312          this.loadweb(webInstallerOptions.options.base_url + url);
 313        } else {
 314          this.loadweb(url);
 315        }
 316      };
 317  
 318      WebInstaller.showLoadingLayer = function showLoadingLayer() {
 319        document.getElementById('web').appendChild(document.createElement('joomla-core-loader'));
 320      };
 321  
 322      WebInstaller.hideLoadingLayer = function hideLoadingLayer() {
 323        var spinnerElement = document.querySelector('#web joomla-core-loader');
 324        spinnerElement.parentNode.removeChild(spinnerElement);
 325      };
 326  
 327      WebInstaller.clicker = function clicker() {
 328        if (document.querySelector('.grid-view')) {
 329          document.querySelector('.grid-view').addEventListener('click', function () {
 330            webInstallerOptions.list = 0;
 331            document.querySelector('.list-container').classList.add('hidden');
 332            document.querySelector('.grid-container').classList.remove('hidden');
 333            document.getElementById('btn-list-view').classList.remove('active');
 334            document.getElementById('btn-grid-view').classList.remove('active');
 335          });
 336        }
 337  
 338        if (document.querySelector('.list-view')) {
 339          document.querySelector('.list-view').addEventListener('click', function () {
 340            webInstallerOptions.list = 1;
 341            document.querySelector('.grid-container').classList.add('hidden');
 342            document.querySelector('.list-container').classList.remove('hidden');
 343            document.getElementById('btn-grid-view').classList.remove('active');
 344            document.getElementById('btn-list-view').classList.add('active');
 345          });
 346        }
 347      }
 348      /**
 349       * @param {string} installUrl
 350       * @param {string} name
 351       * @returns {boolean}
 352       */
 353      ;
 354  
 355      WebInstaller.installfromweb = function installfromweb(installUrl, name) {
 356        if (name === void 0) {
 357          name = null;
 358        }
 359  
 360        if (!installUrl) {
 361          Joomla.renderMessages({
 362            warning: [Joomla.Text._('PLG_INSTALLER_WEBINSTALLER_CANNOT_INSTALL_EXTENSION_IN_PLUGIN')]
 363          });
 364          return false;
 365        }
 366  
 367        document.getElementById('install_url').value = installUrl;
 368        document.getElementById('uploadform-web-url').innerText = installUrl;
 369  
 370        if (name) {
 371          document.getElementById('uploadform-web-name').innerText = name;
 372          document.getElementById('uploadform-web-name-label').classList.remove('hidden');
 373        } else {
 374          document.getElementById('uploadform-web-name-label').classList.add('hidden');
 375        }
 376  
 377        document.getElementById('uploadform-web').classList.remove('hidden');
 378        return true;
 379      } // eslint-disable-next-line class-methods-use-this
 380      ;
 381  
 382      _proto.submitButtonUrl = function submitButtonUrl() {
 383        var form = document.getElementById('adminForm'); // do field validation
 384  
 385        if (form.install_url.value === '' || form.install_url.value === 'http://' || form.install_url.value === 'https://') {
 386          Joomla.renderMessages({
 387            warning: [Joomla.Text._('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL')]
 388          });
 389        } else {
 390          var loading = document.getElementById('loading');
 391  
 392          if (loading) {
 393            loading.classList.remove('hidden');
 394          }
 395  
 396          form.installtype.value = 'url';
 397          form.submit();
 398        }
 399      };
 400  
 401      _proto.submitButtonWeb = function submitButtonWeb() {
 402        var form = document.getElementById('adminForm'); // do field validation
 403  
 404        if (form.install_url.value !== '' || form.install_url.value !== 'http://' || form.install_url.value !== 'https://') {
 405          this.submitButtonUrl();
 406        } else if (form.install_url.value === '') {
 407          Joomla.renderMessages({
 408            warning: [Joomla.apps.options.btntxt]
 409          });
 410        } else {
 411          document.querySelector('#appsloading').classList.remove('hidden');
 412          form.installtype.value = 'web';
 413          form.submit();
 414        }
 415      };
 416  
 417      return WebInstaller;
 418    }();
 419  
 420    customElements.whenDefined('joomla-tab').then(function () {
 421      var installerTabs = document.getElementById('myTab');
 422      var link = installerTabs.querySelector('button[aria-controls=web]'); // Abort if the IFW tab cannot be found
 423  
 424      if (!link) {
 425        return;
 426      }
 427  
 428      if (webInstallerOptions.options.installfromon) {
 429        link.click();
 430      }
 431  
 432      if (link.hasAttribute('aria-expanded') && link.getAttribute('aria-expanded') === 'true' && !instance) {
 433        instance = new WebInstaller();
 434        instance.initialise();
 435      }
 436  
 437      if (webInstallerOptions.options.installfrom_url !== '') {
 438        link.click();
 439      }
 440  
 441      link.addEventListener('joomla.tab.shown', function () {
 442        if (!instance) {
 443          instance = new WebInstaller();
 444          instance.initialise();
 445        }
 446      });
 447    });
 448  
 449  })();


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer