[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/ -> multiselect-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  
   9    /**
  10     * JavaScript behavior to allow shift select in administrator grids
  11     */
  12    (function (Joomla) {
  13      var JMultiSelect = /*#__PURE__*/function () {
  14        function JMultiSelect(formElement) {
  15          var _this = this;
  16  
  17          this.tableEl = document.querySelector(formElement);
  18  
  19          if (this.tableEl) {
  20            this.boxes = [].slice.call(this.tableEl.querySelectorAll('td input[type=checkbox]'));
  21            this.rows = [].slice.call(document.querySelectorAll('tr[class^="row"]'));
  22            this.checkallToggle = document.querySelector('[name="checkall-toggle"]');
  23            this.onCheckallToggleClick = this.onCheckallToggleClick.bind(this);
  24            this.onRowClick = this.onRowClick.bind(this);
  25  
  26            if (this.checkallToggle) {
  27              this.checkallToggle.addEventListener('click', this.onCheckallToggleClick);
  28            }
  29  
  30            if (this.rows.length) {
  31              this.rows.forEach(function (row) {
  32                row.addEventListener('click', _this.onRowClick);
  33              });
  34            }
  35          }
  36        } // Changes the background-color on every cell inside a <tr>
  37        // eslint-disable-next-line class-methods-use-this
  38  
  39  
  40        var _proto = JMultiSelect.prototype;
  41  
  42        _proto.changeBg = function changeBg(row, isChecked) {
  43          // Check if it should add or remove the background colour
  44          if (isChecked) {
  45            [].slice.call(row.querySelectorAll('td, th')).forEach(function (elementToMark) {
  46              elementToMark.classList.add('row-selected');
  47            });
  48          } else {
  49            [].slice.call(row.querySelectorAll('td, th')).forEach(function (elementToMark) {
  50              elementToMark.classList.remove('row-selected');
  51            });
  52          }
  53        };
  54  
  55        _proto.onCheckallToggleClick = function onCheckallToggleClick(_ref) {
  56          var _this2 = this;
  57  
  58          var target = _ref.target;
  59          var isChecked = target.checked;
  60          this.rows.forEach(function (row) {
  61            _this2.changeBg(row, isChecked);
  62          });
  63        };
  64  
  65        _proto.onRowClick = function onRowClick(_ref2) {
  66          var target = _ref2.target,
  67              shiftKey = _ref2.shiftKey;
  68  
  69          // Do not interfere with links or buttons
  70          if (target.tagName && (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'button')) {
  71            return;
  72          }
  73  
  74          if (!this.boxes.length) {
  75            return;
  76          }
  77  
  78          var closestRow = target.closest('tr');
  79          var currentRowNum = this.rows.indexOf(closestRow);
  80          var currentCheckBox = closestRow.querySelector('td input[type=checkbox]');
  81  
  82          if (currentCheckBox) {
  83            var isChecked = currentCheckBox.checked;
  84  
  85            if (!(target.id === currentCheckBox.id)) {
  86              // We will prevent selecting text to prevent artifacts
  87              if (shiftKey) {
  88                document.body.style['-webkit-user-select'] = 'none';
  89                document.body.style['-moz-user-select'] = 'none';
  90                document.body.style['-ms-user-select'] = 'none';
  91                document.body.style['user-select'] = 'none';
  92              }
  93  
  94              currentCheckBox.checked = !currentCheckBox.checked;
  95              isChecked = currentCheckBox.checked;
  96              Joomla.isChecked(isChecked, this.tableEl.id);
  97            }
  98  
  99            this.changeBg(this.rows[currentRowNum], isChecked); // Restore normality
 100  
 101            if (shiftKey) {
 102              document.body.style['-webkit-user-select'] = 'none';
 103              document.body.style['-moz-user-select'] = 'none';
 104              document.body.style['-ms-user-select'] = 'none';
 105              document.body.style['user-select'] = 'none';
 106            }
 107          }
 108        };
 109  
 110        return JMultiSelect;
 111      }();
 112  
 113      var onBoot = function onBoot() {
 114        var formId = '#adminForm';
 115  
 116        if (Joomla && Joomla.getOptions('js-multiselect', {}).formName) {
 117          formId = "#" + Joomla.getOptions('js-multiselect', {}).formName;
 118        } // eslint-disable-next-line no-new
 119  
 120  
 121        new JMultiSelect(formId);
 122      };
 123  
 124      document.addEventListener('DOMContentLoaded', onBoot);
 125    })(Joomla);
 126  
 127  })();


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