- md5
- 9567c6edf048f7bf7663282388dab887
- sha1
- 8e06854ea990f9c5447ba5b613f1da0dfe97b9f3
- sha256
- b91f929d6cffd49f26391b2e3087f2a8331d31757d71273758465a17a6e3d8a1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* JavaScript behavior to allow shift select in administrator grids
*/
(function (Joomla) {
'use strict';
var JMultiSelect = /*#__PURE__*/function () {
function JMultiSelect(formElement) {
var _this = this;
_classCallCheck(this, JMultiSelect);
this.tableEl = document.querySelector(formElement);
if (this.tableEl) {
this.boxes = [].slice.call(this.tableEl.querySelectorAll('input[type=checkbox]'));
this.rows = [].slice.call(document.querySelectorAll('tr[class^="row"]'));
this.checkallToggle = document.querySelector('[name="checkall-toggle"]');
this.onCheckallToggleClick = this.onCheckallToggleClick.bind(this);
this.onRowClick = this.onRowClick.bind(this);
if (this.checkallToggle) {
this.checkallToggle.addEventListener('click', this.onCheckallToggleClick);
}
if (this.rows.length) {
this.rows.forEach(function (row) {
row.addEventListener('click', _this.onRowClick);
});
}
}
} // Changes the background-color on every cell inside a <tr>
// eslint-disable-next-line class-methods-use-this
_createClass(JMultiSelect, [{
key: "changeBg",
value: function changeBg(row, isChecked) {
// Check if it should add or remove the background colour
if (isChecked) {
[].slice.call(row.querySelectorAll('td, th')).forEach(function (elementToMark) {
elementToMark.classList.add('row-selected');
});
} else {
[].slice.call(row.querySelectorAll('td, th')).forEach(function (elementToMark) {
elementToMark.classList.remove('row-selected');
});
}
}
}, {
key: "onCheckallToggleClick",
value: function onCheckallToggleClick(_ref) {
var _this2 = this;
var target = _ref.target;
var isChecked = target.checked;
this.rows.forEach(function (row) {
_this2.changeBg(row, isChecked);
});
}
}, {
key: "onRowClick",
value: function onRowClick(_ref2) {
var target = _ref2.target,
shiftKey = _ref2.shiftKey;
// Do not interfere with links or buttons
if (target.tagName && (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'button')) {
return;
}
if (!this.boxes.length) {
return;
}
var currentRowNum = this.rows.indexOf(target.closest('tr'));
var currentCheckBox = this.checkallToggle ? currentRowNum + 1 : currentRowNum;
var isChecked = this.boxes[currentCheckBox].checked;
if (currentCheckBox >= 0) {
if (!(target.id === this.boxes[currentCheckBox].id)) {
// We will prevent selecting text to prevent artifacts
if (shiftKey) {
document.body.style['-webkit-user-select'] = 'none';
document.body.style['-moz-user-select'] = 'none';
document.body.style['-ms-user-select'] = 'none';
document.body.style['user-select'] = 'none';
}
this.boxes[currentCheckBox].checked = !this.boxes[currentCheckBox].checked;
isChecked = this.boxes[currentCheckBox].checked;
Joomla.isChecked(this.boxes[currentCheckBox].checked, this.tableEl.id);
}
this.changeBg(this.rows[currentCheckBox - 1], isChecked); // Restore normality
if (shiftKey) {
document.body.style['-webkit-user-select'] = 'none';
document.body.style['-moz-user-select'] = 'none';
document.body.style['-ms-user-select'] = 'none';
document.body.style['user-select'] = 'none';
}
}
}
}]);
return JMultiSelect;
}();
var onBoot = function onBoot() {
if (!Joomla) {
// eslint-disable-next-line no-new
new JMultiSelect('#adminForm');
} else if (Joomla.getOptions && typeof Joomla.getOptions === 'function' && Joomla.getOptions('js-multiselect')) {
if (Joomla.getOptions('js-multiselect').formName) {
// eslint-disable-next-line no-new
new JMultiSelect("#".concat(Joomla.getOptions('js-multiselect').formName));
} else {
// eslint-disable-next-line no-new
new JMultiSelect('#adminForm');
}
}
};
document.addEventListener('DOMContentLoaded', onBoot);
})(Joomla);
The same content is in 2 releases, Joomla 4.0.0-beta6 to 4.0.0-beta7. See them all, or every version of this file.