Skip to content

Commit

Permalink
Merge branch 'master' into dgad-677-avoid-race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Boutell authored Mar 27, 2019
2 parents 2b8a4d3 + 66055b9 commit 2ef6406
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
27 changes: 27 additions & 0 deletions lib/modules/apostrophe-pages/public/js/reorganize.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,33 @@ apos.define('apostrophe-pages-reorganize', {
}
});

// Add ability to select multiple checkboxes (Using Left Shift)
var lastChecked;
self.$el.on('click', 'input[name="selected"][type="checkbox"]', function (e) {

// Store a variable called lastchecked to point to the last checked checkbox. If it is undefined it's the first checkbox that's selected.
if (!lastChecked) {
lastChecked = this;
return;
}

// If shift key is pressed and the checkbox is checked.
if (e.shiftKey && this.checked) {
// Get the siblings for the checkboxes that are being checked.
var $checkboxesInScope = $(this).closest('ul.jqtree_common').find('input') || [];
// Get the Index of the currently selected checkbox. (The one checked with holiding shift)
var startIndex = $checkboxesInScope.index(this);
// Get the index of the previously selected checkbox.
var endIndex = $checkboxesInScope.index(lastChecked);
// Get a list of all checkboxes inbetween both the indexes and make them checked.
$checkboxesInScope.slice(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex) + 1).each(function (i, el) {
$(el).prop('checked', true);
$(el).trigger('change');
});
}
lastChecked = this;
});

};

self.addChoice = function(id) {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/apostrophe-pieces-widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ module.exports = {
all: {
value: 'all',
label: options.byAllLabel || 'All',
showFields: [ 'limitByAll' ]
showFields: options.limitByAll ? undefined : [ 'limitByAll' ]
},
tag: {
value: 'tag',
label: options.byTagLabel || 'By Tag',
showFields: [ 'tags', 'limitByTag' ]
showFields: [ 'tags' ].concat(options.limitByTag ? [] : [ 'limitByTag' ])
}
};

Expand Down
31 changes: 31 additions & 0 deletions lib/modules/apostrophe-pieces/public/js/manager-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,37 @@ apos.define('apostrophe-pieces-manager-modal', {
self.removeChoice(id);
}
});

// Add ability to select multiple checkboxes (Using Left Shift)
var lastChecked;
// Clicks on checkbox directly are not possible because as visibility:hidden is set on it and clicks won't be detected.
self.$el.on('click', '.apos-field-input-checkbox-indicator', function (e) {
var box = $(this).siblings('.apos-field-input-checkbox')[0];

// Store a variable called lastchecked to point to the last checked checkbox. If it is undefined it's the first checkbox that's selected.
if (!lastChecked) {
lastChecked = box;
return;
}

// If shift key is pressed and the checkbox is not checked.
if (e.shiftKey && !box.checked) {
// Get the siblings for the checkboxes that are being checked.
var $checkboxesInScope = $(box).closest('[data-items]').find('input') || [];
// Get the Index of the currently selected checkbox. (The one checked with holiding shift)
var startIndex = $checkboxesInScope.index(box);
// Get the index of the previously selected checkbox.
var endIndex = $checkboxesInScope.index(lastChecked);
// Get a list of all checkboxes inbetween both the indexes and make them checked.
$checkboxesInScope.slice(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex) + 1).each(function (i, el) {
if (el !== box) {
$(el).prop('checked', true);
$(el).trigger('change');
}
});
}
lastChecked = box;
});
};

// shrink and grow make visual reflectments to accommodate the the new Select Everything element
Expand Down

0 comments on commit 2ef6406

Please sign in to comment.