[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/com_cpanel/js/ -> admin-cpanel-default-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    /**
   5     * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   6     * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7     */
   8  
   9    /**
  10     * Debounce
  11     * https://gist.github.com/nmsdvid/8807205
  12     *
  13     * @param { function } callback  The callback function to be executed
  14     * @param { int }  time      The time to wait before firing the callback
  15     * @param { int }  interval  The interval
  16     */
  17    // eslint-disable-next-line no-param-reassign, no-return-assign, default-param-last
  18    var debounce = function debounce(callback, time, interval) {
  19      if (time === void 0) {
  20        time = 250;
  21      }
  22  
  23      return function () {
  24        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  25          args[_key] = arguments[_key];
  26        }
  27  
  28        return clearTimeout(interval, interval = setTimeout.apply(void 0, [callback, time].concat(args)));
  29      };
  30    };
  31  
  32    (function (window, document, Joomla) {
  33      Joomla.unpublishModule = function (element) {
  34        // Get variables
  35        var baseUrl = 'index.php?option=com_modules&task=modules.unpublish&format=json';
  36        var id = element.getAttribute('data-module-id');
  37        Joomla.request({
  38          url: baseUrl + "&cid=" + id,
  39          method: 'POST',
  40          headers: {
  41            'Content-Type': 'application/json'
  42          },
  43          onSuccess: function onSuccess() {
  44            var wrapper = element.closest('.module-wrapper');
  45            wrapper.parentNode.removeChild(wrapper);
  46            Joomla.renderMessages({
  47              message: [Joomla.Text._('COM_CPANEL_UNPUBLISH_MODULE_SUCCESS')]
  48            });
  49          },
  50          onError: function onError() {
  51            Joomla.renderMessages({
  52              error: [Joomla.Text._('COM_CPANEL_UNPUBLISH_MODULE_ERROR')]
  53            });
  54          }
  55        });
  56      };
  57  
  58      var onBoot = function onBoot() {
  59        var cpanelModules = document.getElementById('content');
  60  
  61        if (cpanelModules) {
  62          var links = [].slice.call(cpanelModules.querySelectorAll('.unpublish-module'));
  63          links.forEach(function (link) {
  64            link.addEventListener('click', function (_ref) {
  65              var target = _ref.target;
  66              return Joomla.unpublishModule(target);
  67            });
  68          });
  69        } // Cleanup
  70  
  71  
  72        document.removeEventListener('DOMContentLoaded', onBoot);
  73      }; // Initialise
  74  
  75  
  76      document.addEventListener('DOMContentLoaded', onBoot); // Masonry layout for cpanel cards
  77  
  78      var MasonryLayout = {
  79        $gridBox: null,
  80        gridAutoRows: 0,
  81        gridRowGap: 10,
  82        // Calculate "grid-row-end" property
  83        resizeGridItem: function resizeGridItem($cell, rowHeight, rowGap) {
  84          var $content = $cell.querySelector('.card');
  85  
  86          if ($content) {
  87            var contentHeight = $content.getBoundingClientRect().height + rowGap;
  88            var rowSpan = Math.ceil(contentHeight / (rowHeight + rowGap));
  89            $cell.style.gridRowEnd = "span " + rowSpan;
  90          }
  91        },
  92        // Check a size of every cell in the grid
  93        resizeAllGridItems: function resizeAllGridItems() {
  94          var _this = this;
  95  
  96          var $gridCells = [].slice.call(this.$gridBox.children);
  97          $gridCells.forEach(function ($cell) {
  98            _this.resizeGridItem($cell, _this.gridAutoRows, _this.gridRowGap);
  99          });
 100        },
 101        initialise: function initialise() {
 102          var _this2 = this;
 103  
 104          this.$gridBox = document.querySelector('#cpanel-modules .card-columns');
 105          var gridStyle = window.getComputedStyle(this.$gridBox);
 106          this.gridAutoRows = parseInt(gridStyle.getPropertyValue('grid-auto-rows'), 10) || this.gridAutoRows;
 107          this.gridRowGap = parseInt(gridStyle.getPropertyValue('grid-row-gap'), 10) || this.gridRowGap;
 108          this.resizeAllGridItems(); // Recheck the layout after all content (fonts and images) is loaded.
 109  
 110          window.addEventListener('load', function () {
 111            return _this2.resizeAllGridItems();
 112          }); // Recheck the layout when the menu is toggled
 113  
 114          window.addEventListener('joomla:menu-toggle', function () {
 115            // 300ms is animation time, need to wait for the animation to end
 116            setTimeout(function () {
 117              return _this2.resizeAllGridItems();
 118            }, 330);
 119          }); // Watch on window resize
 120  
 121          window.addEventListener('resize', debounce(function () {
 122            return _this2.resizeAllGridItems();
 123          }, 50));
 124        }
 125      }; // Initialise Masonry layout at the very beginning, to avoid jumping.
 126      // We can do this because the script is deferred.
 127  
 128      MasonryLayout.initialise();
 129    })(window, document, window.Joomla);
 130  
 131  })();


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