// attach 'shiftSelectable' to jquery
(function($, _) {
var augmentedSelectedCallback, methods;
augmentedSelectedCallback = function(selected, $element, event, ui) {
if ($element.length) {
$element.addClass('ui-selected');
// honor original "ui.selectable" callback with new selected element passed
ui = _.extend({}, ui, {selected: $element.get(0)});
_.isFunction(selected) && selected(event, ui);
}
};
methods = {
init: function(options) {
var settings = _.extend({}, options),
selected = settings.selected,
unselected = settings.unselected,
$lastSelected;
settings.selected = function(event, ui) {
var $selected = $(ui.selected),
isShiftSelect = false;
// enable shift+click if the user has clicked on something already
// OR has not deselected the last item clicked.
if (event.shiftKey && $lastSelected) {
// currently only supports elements that are siblings of each
// other, so lists made of tables are out right now.
$selected.siblings('.ui-selectee').andSelf().each(function(){
var $element = $(this);
// To support click, then shift+click both up a list and down a list; turn
// selection on when encountering either actions and off on the other one.
if ($element.is($selected) || $element.is($lastSelected)) {
isShiftSelect = !isShiftSelect;
augmentedSelectedCallback(selected, $element, event, ui);
} else if (isShiftSelect) {
augmentedSelectedCallback(selected, $element, event, ui);
}
});
// otherwise just treat click like a normal click, which can include
// shift+click with no previous click.
} else {
$lastSelected = $selected;
// honor original "ui.selectable" callback
_.isFunction(selected) && selected(event, ui);
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!