From b60c7135a698528020e1558423a981e022d934c0 2015-03-20 20:12:22 From: Matthias Bussonnier Date: 2015-03-20 20:12:22 Subject: [PATCH] Merge pull request #8059 from minrk/deselect-click deselect all when clicking partial checkbox --- diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index 4ccb2d9..b3f2db9 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -124,14 +124,25 @@ define([ $('.delete-button').click($.proxy(this.delete_selected, this)); // Bind events for selection menu buttons. - $('#selector-menu').click(function(event){that.select($(event.target).attr('id'))}); - $('#select-all').change(function(){that.select($(this).is(':checked') ? 'select-all' : 'select-none')}); - $('#button-select-all').click(function(e) { + $('#selector-menu').click(function (event) { + that.select($(event.target).attr('id')); + }); + var select_all = $('#select-all'); + select_all.change(function () { + if (!select_all.prop('checked') || select_all.data('indeterminate')) { + that.select('select-none'); + } else { + that.select('select-all'); + } + }); + $('#button-select-all').click(function (e) { // toggle checkbox if the click doesn't come from the checkbox already if (!$(e.target).is('input[type=checkbox]')) { - var checkbox = $('#select-all'); - checkbox.prop('checked', !checkbox.prop('checked')); - that.select(checkbox.prop('checked') ? 'select-all' : 'select-none'); + if (select_all.prop('checked') || select_all.data('indeterminate')) { + that.select('select-none'); + } else { + that.select('select-all'); + } } }); } @@ -481,15 +492,20 @@ define([ total++; } }); + + var select_all = $("#select-all"); if (checked === 0) { - $('#tree-selector input[type=checkbox]')[0].indeterminate = false; - $('#tree-selector input[type=checkbox]').prop('checked', false); + select_all.prop('checked', false); + select_all.prop('indeterminate', false); + select_all.data('indeterminate', false); } else if (checked === total) { - $('#tree-selector input[type=checkbox]')[0].indeterminate = false; - $('#tree-selector input[type=checkbox]').prop('checked', true); + select_all.prop('checked', true); + select_all.prop('indeterminate', false); + select_all.data('indeterminate', false); } else { - $('#tree-selector input[type=checkbox]').prop('checked', false); - $('#tree-selector input[type=checkbox]')[0].indeterminate = true; + select_all.prop('checked', false); + select_all.prop('indeterminate', true); + select_all.data('indeterminate', true); } // Update total counter $('#counter-select-all').html(checked===0 ? ' ' : checked);