I've been trying to piece together various SO answers on this topic but I can't quite figure it out. This answer shows how to select multiple items but I can't figure out how to add the condition of the shift key being pressed.
Dragging over multiple items selects them all, that's great. Clicking single items selects that item, that's great. But If the shift key is pressed, clicking multiple items should select them all, clicking them again should deselect them.
Here's a fiddle.
HTML
<div id="canvas">
<div class="elemContainer ui-selected" style="position: absolute; top: 50px;
left: 50px; width: 100px; height: 100px;">
<div class="elem" style="position: absolute; width: 100%; height: 100%;
background: pink;"></div>
</div>
<div class="elemContainer ui-selected" style="position: absolute; top: 50px;
left: 50px; width: 100px; height: 100px;">
<div class="elem" style="position: absolute; width: 100%; height: 100%;
background: coral;"></div>
</div>
</div>
Javascript
$('#canvas').selectable();
$('.elemContainer').draggable();
// Fix single click selection
$(".elemContainer").click(function() {
if (!$(this).hasClass("ui-selected")) {
$(this).addClass("ui-selected").siblings().removeClass("ui-selected");
}
})