From 72c6d3bccb232398552aa5ff6f66f016b2bf69a5 Mon Sep 17 00:00:00 2001 From: Dave Gaeddert Date: Thu, 18 Jan 2024 16:58:00 -0600 Subject: [PATCH] Add shift clicking to list checkboxes --- bolt-staff/bolt/admin/assets/admin/list.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bolt-staff/bolt/admin/assets/admin/list.js b/bolt-staff/bolt/admin/assets/admin/list.js index 80db46d14e..1e2296a33a 100644 --- a/bolt-staff/bolt/admin/assets/admin/list.js +++ b/bolt-staff/bolt/admin/assets/admin/list.js @@ -3,6 +3,7 @@ jQuery(function ($) { var $actionPks = $('[name="action_pks"]'); var $actionSelect = $('[name="action_name"]'); var $actionSubmit = $('[data-actions-form] [type="submit"]'); + var $lastActionCheckboxChecked = null; $actionCheckbox.on("change", function () { var pks = []; @@ -29,5 +30,18 @@ jQuery(function ($) { } } - // TODO Enable shift-clicking to select a range of checkboxes + // Enable shift-clicking to select a range of checkboxes + $actionCheckbox.on("click", function (e) { + if (e.shiftKey) { + var $this = $(this); + var thisIndex = $actionCheckbox.index($this); + var lastIndex = $actionCheckbox.index($lastActionCheckboxChecked); + var minIndex = Math.min(thisIndex, lastIndex); + var maxIndex = Math.max(thisIndex, lastIndex); + var $checkboxes = $actionCheckbox.slice(minIndex, maxIndex + 1); + $checkboxes.prop("checked", $this.is(":checked")); + } else { + $lastActionCheckboxChecked = $(this); + } + }); });