diff options
Diffstat (limited to 'wp-admin/js/inline-edit-post.js')
-rw-r--r-- | wp-admin/js/inline-edit-post.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/wp-admin/js/inline-edit-post.js b/wp-admin/js/inline-edit-post.js index e7d4496..65cd342 100644 --- a/wp-admin/js/inline-edit-post.js +++ b/wp-admin/js/inline-edit-post.js @@ -178,6 +178,8 @@ window.wp = window.wp || {}; */ setBulk : function(){ var te = '', type = this.type, c = true; + var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' ); + var categories = {}; this.revert(); $( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); @@ -217,6 +219,44 @@ window.wp = window.wp || {}; // Populate the list of items to bulk edit. $( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' ); + // Gather up some statistics on which of these checked posts are in which categories. + checkedPosts.each( function() { + var id = $( this ).val(); + var checked = $( '#category_' + id ).text().split( ',' ); + + checked.map( function( cid ) { + categories[ cid ] || ( categories[ cid ] = 0 ); + // Just record that this category is checked. + categories[ cid ]++; + } ); + } ); + + // Compute initial states. + $( '.inline-edit-categories input[name="post_category[]"]' ).each( function() { + if ( categories[ $( this ).val() ] == checkedPosts.length ) { + // If the number of checked categories matches the number of selected posts, then all posts are in this category. + $( this ).prop( 'checked', true ); + } else if ( categories[ $( this ).val() ] > 0 ) { + // If the number is less than the number of selected posts, then it's indeterminate. + $( this ).prop( 'indeterminate', true ); + if ( ! $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).length ) { + // Get the term label text. + var label = $( this ).parent().text(); + // Set indeterminate states for the backend. Add accessible text for indeterminate inputs. + $( this ).after( '<input type="hidden" name="indeterminate_post_category[]" value="' + $( this ).val() + '">' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) ); + } + } + } ); + + $( '.inline-edit-categories input[name="post_category[]"]:indeterminate' ).on( 'change', function() { + // Remove accessible label text. Remove the indeterminate flags as there was a specific state change. + $( this ).removeAttr( 'aria-label' ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove(); + } ); + + $( '.inline-edit-save button' ).on( 'click', function() { + $( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false ); + } ); + /** * Binds on click events to handle the list of items to bulk edit. * @@ -228,6 +268,7 @@ window.wp = window.wp || {}; $prev = $this.parent().prev().children( '.ntdelbutton' ), $next = $this.parent().next().children( '.ntdelbutton' ); + $( 'input#cb-select-all-1, input#cb-select-all-2' ).prop( 'checked', false ); $( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false ); $( '#_' + id ).parent().remove(); wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' ); |