- md5
- 2b0707565b3496488c3f12557a4075cf
- sha1
- bd41284050894ef1435e3debb20a48418af9a254
- sha256
- c3605d4397cf6172e5b2f22fcc0ce24a846c818cd2556d3a0645747273628046
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/
/**
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* JavaScript behavior to allow shift select in administrator grids
*/
(Joomla => {
'use strict';
class JMultiSelect {
constructor(formElement) {
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(row => {
row.addEventListener('click', this.onRowClick);
});
}
}
} // Changes the background-color on every cell inside a <tr>
// eslint-disable-next-line class-methods-use-this
changeBg(row, isChecked) {
// Check if it should add or remove the background colour
if (isChecked) {
[].slice.call(row.querySelectorAll('td, th')).forEach(elementToMark => {
elementToMark.classList.add('row-selected');
});
} else {
[].slice.call(row.querySelectorAll('td, th')).forEach(elementToMark => {
elementToMark.classList.remove('row-selected');
});
}
}
onCheckallToggleClick(event) {
const isChecked = event.target.checked;
this.rows.forEach(row => {
this.changeBg(row, isChecked);
});
}
onRowClick(event) {
// Do not interfere with links or buttons
if (event.target.tagName && (event.target.tagName.toLowerCase() === 'a' || event.target.tagName.toLowerCase() === 'button')) {
return;
}
if (!this.boxes.length) {
return;
}
const currentRowNum = this.rows.indexOf(event.target.closest('tr'));
const currentCheckBox = this.checkallToggle ? currentRowNum + 1 : currentRowNum;
let isChecked = this.boxes[currentCheckBox].checked;
if (currentCheckBox >= 0) {
if (!(event.target.id === this.boxes[currentCheckBox].id)) {
// We will prevent selecting text to prevent artifacts
if (event.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 (event.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';
}
}
}
}
const 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);
No other release has this exact content. See every version of this file.