From affc879cde972aca84688f47bca15e66ea5f7505 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 28 Aug 2011 15:21:53 -0400 Subject: [PATCH] Shift+Click multiselect for files --- files/js/files.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/files/js/files.js b/files/js/files.js index f30f80aee8..7b37837d9c 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -26,11 +26,30 @@ $(document).ready(function() { FileActions.hide(); }); + var lastChecked; + // Sets the file link behaviour : $('td.filename a').live('click',function(event) { - if (event.ctrlKey) { - event.preventDefault(); + event.preventDefault(); + if (event.ctrlKey || event.shiftKey) { + if (event.shiftKey) { + var last = $(lastChecked).parent().parent().prevAll().length; + var first = $(this).parent().parent().prevAll().length; + var start = Math.min(first, last); + var end = Math.max(first, last); + var rows = $(this).parent().parent().parent().children('tr'); + for (var i = start; i < end; i++) { + $(rows).each(function(index) { + if (index == i) { + var checkbox = $(this).children().children('input:checkbox'); + $(checkbox).attr('checked', 'checked'); + $(checkbox).parent().parent().addClass('selected'); + } + }); + } + } var checkbox = $(this).parent().children('input:checkbox'); + lastChecked = checkbox; if ($(checkbox).attr('checked')) { $(checkbox).removeAttr('checked'); $(checkbox).parent().parent().removeClass('selected'); @@ -45,7 +64,6 @@ $(document).ready(function() { } procesSelection(); } else { - event.preventDefault(); var filename=$(this).parent().parent().data('file'); if(!FileList.isLoading(filename)){ var mime=$(this).parent().parent().data('mime'); @@ -73,7 +91,23 @@ $(document).ready(function() { procesSelection(); }); - $('td.filename input:checkbox').live('click',function() { + $('td.filename input:checkbox').live('click',function(event) { + if (event.shiftKey) { + var last = $(lastChecked).parent().parent().prevAll().length; + var first = $(this).parent().parent().prevAll().length; + var start = Math.min(first, last); + var end = Math.max(first, last); + var rows = $(this).parent().parent().parent().children('tr'); + for (var i = start; i < end; i++) { + $(rows).each(function(index) { + if (index == i) { + var checkbox = $(this).children().children('input:checkbox'); + $(checkbox).attr('checked', 'checked'); + $(checkbox).parent().parent().addClass('selected'); + } + }); + } + } var selectedCount=$('td.filename input:checkbox:checked').length; $(this).parent().parent().toggleClass('selected'); if(!$(this).attr('checked')){