X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmisc%2Ftableselect.es6.js;h=475efa6945e8d7bf67c4e88a5569d347d6537018;hb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2;hp=a92fdd5f17c8416c4165e77ad4a5f5fa2c0e8e71;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website
diff --git a/web/core/misc/tableselect.es6.js b/web/core/misc/tableselect.es6.js
index a92fdd5f1..475efa694 100644
--- a/web/core/misc/tableselect.es6.js
+++ b/web/core/misc/tableselect.es6.js
@@ -3,7 +3,7 @@
* Table select functionality.
*/
-(function ($, Drupal) {
+(function($, Drupal) {
/**
* Initialize tableSelects.
*
@@ -15,14 +15,18 @@
Drupal.behaviors.tableSelect = {
attach(context, settings) {
// Select the inner-most table in case of nested tables.
- $(context).find('th.select-all').closest('table').once('table-select').each(Drupal.tableSelect);
+ $(context)
+ .find('th.select-all')
+ .closest('table')
+ .once('table-select')
+ .each(Drupal.tableSelect);
},
};
/**
* Callback used in {@link Drupal.behaviors.tableSelect}.
*/
- Drupal.tableSelect = function () {
+ Drupal.tableSelect = function() {
// Do not add a "Select all" checkbox if there are no rows with checkboxes
// in the table.
if ($(this).find('td input[type="checkbox"]').length === 0) {
@@ -39,80 +43,106 @@
selectAll: Drupal.t('Select all rows in this table'),
selectNone: Drupal.t('Deselect all rows in this table'),
};
- const updateSelectAll = function (state) {
+ const updateSelectAll = function(state) {
// Update table's select-all checkbox (and sticky header's if available).
- $table.prev('table.sticky-header').addBack().find('th.select-all input[type="checkbox"]').each(function () {
- const $checkbox = $(this);
- const stateChanged = $checkbox.prop('checked') !== state;
-
- $checkbox.attr('title', state ? strings.selectNone : strings.selectAll);
-
- /**
- * @checkbox {HTMLElement}
- */
- if (stateChanged) {
- $checkbox.prop('checked', state).trigger('change');
- }
- });
- };
-
- // Find all
with class select-all, and insert the check all checkbox.
- $table.find('th.select-all').prepend($('').attr('title', strings.selectAll)).on('click', (event) => {
- if ($(event.target).is('input[type="checkbox"]')) {
- // Loop through all checkboxes and set their state to the select all
- // checkbox' state.
- checkboxes.each(function () {
+ $table
+ .prev('table.sticky-header')
+ .addBack()
+ .find('th.select-all input[type="checkbox"]')
+ .each(function() {
const $checkbox = $(this);
- const stateChanged = $checkbox.prop('checked') !== event.target.checked;
+ const stateChanged = $checkbox.prop('checked') !== state;
+
+ $checkbox.attr(
+ 'title',
+ state ? strings.selectNone : strings.selectAll,
+ );
/**
* @checkbox {HTMLElement}
*/
if (stateChanged) {
- $checkbox.prop('checked', event.target.checked).trigger('change');
+ $checkbox.prop('checked', state).trigger('change');
}
- // Either add or remove the selected class based on the state of the
- // check all checkbox.
-
- /**
- * @checkbox {HTMLElement}
- */
- $checkbox.closest('tr').toggleClass('selected', this.checked);
});
- // Update the title and the state of the check all box.
- updateSelectAll(event.target.checked);
- }
- });
+ };
+
+ // Find all
with class select-all, and insert the check all checkbox.
+ $table
+ .find('th.select-all')
+ .prepend(
+ $('').attr(
+ 'title',
+ strings.selectAll,
+ ),
+ )
+ .on('click', event => {
+ if ($(event.target).is('input[type="checkbox"]')) {
+ // Loop through all checkboxes and set their state to the select all
+ // checkbox' state.
+ checkboxes.each(function() {
+ const $checkbox = $(this);
+ const stateChanged =
+ $checkbox.prop('checked') !== event.target.checked;
+
+ /**
+ * @checkbox {HTMLElement}
+ */
+ if (stateChanged) {
+ $checkbox.prop('checked', event.target.checked).trigger('change');
+ }
+ // Either add or remove the selected class based on the state of the
+ // check all checkbox.
+
+ /**
+ * @checkbox {HTMLElement}
+ */
+ $checkbox.closest('tr').toggleClass('selected', this.checked);
+ });
+ // Update the title and the state of the check all box.
+ updateSelectAll(event.target.checked);
+ }
+ });
// For each of the checkboxes within the table that are not disabled.
- checkboxes = $table.find('td input[type="checkbox"]:enabled').on('click', function (e) {
- // Either add or remove the selected class based on the state of the
- // check all checkbox.
-
- /**
- * @this {HTMLElement}
- */
- $(this).closest('tr').toggleClass('selected', this.checked);
-
- // If this is a shift click, we need to highlight everything in the
- // range. Also make sure that we are actually checking checkboxes
- // over a range and that a checkbox has been checked or unchecked before.
- if (e.shiftKey && lastChecked && lastChecked !== e.target) {
- // We use the checkbox's parent
to do our range searching.
- Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
- }
+ checkboxes = $table
+ .find('td input[type="checkbox"]:enabled')
+ .on('click', function(e) {
+ // Either add or remove the selected class based on the state of the
+ // check all checkbox.
+
+ /**
+ * @this {HTMLElement}
+ */
+ $(this)
+ .closest('tr')
+ .toggleClass('selected', this.checked);
+
+ // If this is a shift click, we need to highlight everything in the
+ // range. Also make sure that we are actually checking checkboxes
+ // over a range and that a checkbox has been checked or unchecked before.
+ if (e.shiftKey && lastChecked && lastChecked !== e.target) {
+ // We use the checkbox's parent
to do our range searching.
+ Drupal.tableSelectRange(
+ $(e.target).closest('tr')[0],
+ $(lastChecked).closest('tr')[0],
+ e.target.checked,
+ );
+ }
- // If all checkboxes are checked, make sure the select-all one is checked
- // too, otherwise keep unchecked.
- updateSelectAll((checkboxes.length === checkboxes.filter(':checked').length));
+ // If all checkboxes are checked, make sure the select-all one is checked
+ // too, otherwise keep unchecked.
+ updateSelectAll(
+ checkboxes.length === checkboxes.filter(':checked').length,
+ );
- // Keep track of the last checked checkbox.
- lastChecked = e.target;
- });
+ // Keep track of the last checked checkbox.
+ lastChecked = e.target;
+ });
// If all checkboxes are checked on page load, make sure the select-all one
// is checked too, otherwise keep unchecked.
- updateSelectAll((checkboxes.length === checkboxes.filter(':checked').length));
+ updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length);
};
/**
@@ -123,18 +153,18 @@
* @param {bool} state
* The state to set on the range.
*/
- Drupal.tableSelectRange = function (from, to, state) {
+ Drupal.tableSelectRange = function(from, to, state) {
// We determine the looping mode based on the order of from and to.
- const mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
+ const mode =
+ from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
// Traverse through the sibling nodes.
for (let i = from[mode]; i; i = i[mode]) {
- var $i;
+ const $i = $(i);
// Make sure that we're only dealing with elements.
if (i.nodeType !== 1) {
continue;
}
- $i = $(i);
// Either add or remove the selected class based on the state of the
// target checkbox.
$i.toggleClass('selected', state);
@@ -152,4 +182,4 @@
}
}
};
-}(jQuery, Drupal));
+})(jQuery, Drupal);