Skip to content

Commit

Permalink
Allow multiple selection of checkboxes holding shift key
Browse files Browse the repository at this point in the history
Improved usability of the checkboxes in ticket bulk update form, as
well as in many administration pages, by allowing to select range of
checkboxes by holding shift key.
  • Loading branch information
richieri-bps committed Sep 12, 2023
1 parent 25b2123 commit 68247b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions share/static/css/elevator-light/misc.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ ul.ui-autocomplete {
.modal.search-results-filter .modal-dialog {
margin: 0;
}

/* Enable checkboxes to be selected holding shift key */
input[type="checkbox"] {
z-index: 1;
}
24 changes: 24 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ function checkboxesToInput(target,checkboxes) {
tar.val(emails.join(', ')).change();
}

// Enable multiple checkbox selection holding shift key
jQuery(function () {
var lastCheckedByName = {};
jQuery('input[type=checkbox]').click(function (event) {
var name = jQuery(this).attr('name');
if (name) {
// Remove text after "-" from name for better compatibility
name = name.replace(/-.*/, '');
var lastChecked = lastCheckedByName[name];
if (event.shiftKey && name) {
if (lastChecked) {
var checkboxes = jQuery('input[type=checkbox][name^=' + name + ']');
var start = checkboxes.index(this);
var end = checkboxes.index(lastChecked);
checkboxes.slice(Math.min(start, end),
Math.max(start, end) + 1).prop('checked',
this.checked);
}
}
lastCheckedByName[name] = this;
}
});
});

// ahah for back compatibility as plugins may still use it
function ahah( url, id ) {
jQuery('#'+id).load(url);
Expand Down

0 comments on commit 68247b8

Please sign in to comment.