diff --git a/src/wp-includes/css/media-views.css b/src/wp-includes/css/media-views.css
index 541f488..da1cd9c 100644
|
a
|
b
|
|
| 944 | 944 | 0 0 0 2px #1e8cbe; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | | .media-frame.mode-grid .attachment .check { |
| 948 | | display: block; |
| 949 | | } |
| 950 | | |
| 951 | | .media-frame.mode-grid .attachment .check div { |
| 952 | | background-position: 21px 0; |
| 953 | | } |
| 954 | | |
| 955 | 947 | .attachment.details .check div, |
| 956 | 948 | .media-frame.mode-grid .attachment.selected .check div { |
| 957 | 949 | background-position: -21px 0; |
| … |
… |
|
| 997 | 989 | .attachments-browser .media-toolbar-primary > .media-button-group, |
| 998 | 990 | .attachments-browser .media-toolbar-secondary > .media-button, |
| 999 | 991 | .attachments-browser .media-toolbar-secondary > .media-button-group { |
| 1000 | | margin-top: 10px; |
| | 992 | margin: 11px 0; |
| 1001 | 993 | } |
| 1002 | 994 | |
| 1003 | 995 | .attachments-browser .attachments, |
| … |
… |
|
| 2453 | 2445 | |
| 2454 | 2446 | /* Regions we don't use at all */ |
| 2455 | 2447 | .media-frame.mode-grid .media-frame-title, |
| 2456 | | .media-frame.mode-grid .media-frame-toolbar, |
| 2457 | 2448 | .media-frame.mode-grid .media-frame-router, |
| 2458 | 2449 | .media-frame.mode-grid .media-frame-menu { |
| 2459 | 2450 | display: none; |
| 2460 | 2451 | } |
| 2461 | 2452 | |
| | 2453 | .media-frame.mode-grid .media-frame-toolbar { |
| | 2454 | position: fixed; |
| | 2455 | bottom: 0; |
| | 2456 | left: 0; |
| | 2457 | right: 0; |
| | 2458 | } |
| | 2459 | |
| 2462 | 2460 | .media-frame.mode-grid .media-frame-content { |
| 2463 | 2461 | background-color: transparent; |
| 2464 | 2462 | border: none; |
| … |
… |
|
| 2485 | 2483 | } |
| 2486 | 2484 | |
| 2487 | 2485 | .media-frame.mode-grid .attachments { |
| 2488 | | padding: 2px; |
| | 2486 | padding: 92px 2px 2px; |
| 2489 | 2487 | } |
| 2490 | 2488 | |
| 2491 | 2489 | /** |
| … |
… |
|
| 2493 | 2491 | * |
| 2494 | 2492 | * This should be OOCSS'd so both use a shared selector. |
| 2495 | 2493 | */ |
| | 2494 | .media-frame.mode-grid .media-toolbar, |
| 2496 | 2495 | .media-frame.mode-grid .attachments-browser .media-toolbar { |
| 2497 | 2496 | background: #fff; |
| 2498 | 2497 | -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); |
| … |
… |
|
| 2501 | 2500 | -moz-box-sizing: border-box; |
| 2502 | 2501 | box-sizing: border-box; |
| 2503 | 2502 | color: #555; |
| 2504 | | display: inline-block; |
| 2505 | 2503 | font-size: 13px; |
| 2506 | 2504 | margin: 20px 0; |
| 2507 | 2505 | padding: 0 20px; |
| 2508 | | position: relative; |
| 2509 | | width: 100%; |
| 2510 | 2506 | height: auto; |
| 2511 | 2507 | border: none; |
| 2512 | 2508 | } |
| 2513 | 2509 | |
| | 2510 | .media-frame.mode-grid .media-frame-toolbar .media-toolbar { |
| | 2511 | position: fixed; |
| | 2512 | height: 60px; |
| | 2513 | top: auto; |
| | 2514 | right: 20px; |
| | 2515 | bottom: 0; |
| | 2516 | left: 182px; |
| | 2517 | } |
| | 2518 | |
| | 2519 | .media-frame.mode-grid.hide-toolbar .media-frame-toolbar .media-toolbar { |
| | 2520 | display: none; |
| | 2521 | } |
| | 2522 | |
| | 2523 | .media-frame.mode-grid .attachments-browser .media-toolbar { |
| | 2524 | position: absolute; |
| | 2525 | width: 100%; |
| | 2526 | } |
| | 2527 | |
| | 2528 | .media-frame.mode-grid .attachments-browser .media-toolbar.fixed { |
| | 2529 | position: fixed; |
| | 2530 | top: 28px; |
| | 2531 | left: 182px; |
| | 2532 | right: 20px; |
| | 2533 | width: auto; |
| | 2534 | } |
| | 2535 | |
| 2514 | 2536 | .media-frame.mode-grid input[type="search"] { |
| 2515 | 2537 | margin: 1px; |
| 2516 | 2538 | padding: 3px 5px; |
diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js
index bf864fe..68a9acd 100644
|
a
|
b
|
|
| 62 | 62 | multiple: 'add', |
| 63 | 63 | state: 'library', |
| 64 | 64 | uploader: true, |
| 65 | | mode: [ 'grid' ] |
| | 65 | mode: [ 'grid', 'edit' ] |
| 66 | 66 | }); |
| 67 | 67 | |
| 68 | 68 | $(document).on( 'click', '.add-new-h2', _.bind( this.addNewClickHandler, this ) ); |
| … |
… |
|
| 103 | 103 | this.bindRegionModeHandlers(); |
| 104 | 104 | this.render(); |
| 105 | 105 | |
| | 106 | this.toggleToolbar(); |
| | 107 | this.on( 'select:activate edit:activate', _.bind( this.toggleToolbar, this ) ); |
| | 108 | |
| 106 | 109 | // Update the URL when entering search string (at most once per second) |
| 107 | 110 | $( '#media-search-input' ).on( 'input', _.debounce( function(e) { |
| 108 | 111 | var val = $( e.currentTarget ).val(), url = ''; |
| … |
… |
|
| 130 | 133 | multiple: options.multiple, |
| 131 | 134 | title: options.title, |
| 132 | 135 | content: 'browse', |
| | 136 | toolbar: 'select', |
| 133 | 137 | contentUserSetting: false, |
| 134 | 138 | filterable: 'all' |
| 135 | 139 | }) |
| … |
… |
|
| 144 | 148 | |
| 145 | 149 | // Handle a frame-level event for editing an attachment. |
| 146 | 150 | this.on( 'edit:attachment', this.openEditAttachmentModal, this ); |
| | 151 | this.on( 'toolbar:create:select', this.createToolbar, this ); |
| 147 | 152 | }, |
| 148 | 153 | |
| 149 | 154 | /** |
| … |
… |
|
| 203 | 208 | this.errors.on( 'add remove reset', this.sidebarVisibility, this ); |
| 204 | 209 | }, |
| 205 | 210 | |
| | 211 | createToolbar: function( toolbar ) { |
| | 212 | toolbar.view = new media.view.Toolbar({ |
| | 213 | controller: this, |
| | 214 | items: { |
| | 215 | delete: { |
| | 216 | style: 'primary', |
| | 217 | text: 'Delete Selected', |
| | 218 | priority: 10, |
| | 219 | click: function() { |
| | 220 | // media.view.Button.prototype.click.apply( this, arguments ); |
| | 221 | while ( this.controller.state().get('selection').length > 0 ) { |
| | 222 | this.controller.state().get('selection').at(0).destroy(); |
| | 223 | } |
| | 224 | } |
| | 225 | } |
| | 226 | } |
| | 227 | }); |
| | 228 | }, |
| | 229 | |
| 206 | 230 | sidebarVisibility: function() { |
| 207 | 231 | this.browserView.$( '.media-sidebar' ).toggle( this.errors.length ); |
| 208 | 232 | }, |
| … |
… |
|
| 219 | 243 | pushState: true |
| 220 | 244 | } ); |
| 221 | 245 | } |
| | 246 | }, |
| | 247 | |
| | 248 | toggleToolbar: function() { |
| | 249 | if ( this.isModeActive( 'edit' ) ) { |
| | 250 | this.$el.addClass( 'hide-toolbar' ); |
| | 251 | } else { |
| | 252 | this.$el.removeClass( 'hide-toolbar' ); |
| | 253 | } |
| 222 | 254 | } |
| 223 | 255 | }); |
| 224 | 256 | |
| … |
… |
|
| 507 | 539 | } |
| 508 | 540 | }); |
| 509 | 541 | |
| 510 | | /** |
| 511 | | * Controller for bulk selection. |
| 512 | | */ |
| 513 | | media.view.BulkSelection = media.View.extend({ |
| 514 | | className: 'bulk-select', |
| 515 | | |
| 516 | | initialize: function() { |
| 517 | | this.model = new Backbone.Model({ |
| 518 | | currentAction: '' |
| 519 | | |
| 520 | | }); |
| 521 | | |
| 522 | | this.views.add( new media.view.Label({ |
| 523 | | value: l10n.bulkActionsLabel, |
| 524 | | attributes: { |
| 525 | | 'for': 'bulk-select-dropdown' |
| 526 | | } |
| 527 | | }) ); |
| 528 | | |
| 529 | | this.views.add( |
| 530 | | new media.view.BulkSelectionActionDropdown({ |
| 531 | | controller: this |
| 532 | | }) |
| 533 | | ); |
| 534 | | |
| 535 | | this.views.add( |
| 536 | | new media.view.BulkSelectionActionButton({ |
| 537 | | disabled: true, |
| 538 | | text: l10n.apply, |
| 539 | | controller: this |
| 540 | | }) |
| 541 | | ); |
| 542 | | } |
| 543 | | }); |
| 544 | | |
| 545 | | /** |
| 546 | | * Bulk Selection dropdown view. |
| 547 | | * |
| 548 | | * @constructor |
| 549 | | * @augments wp.media.View |
| 550 | | * @augments wp.Backbone.View |
| 551 | | * @augments Backbone.View |
| 552 | | */ |
| 553 | | media.view.BulkSelectionActionDropdown = media.View.extend({ |
| 554 | | tagName: 'select', |
| 555 | | id: 'bulk-select-dropdown', |
| 556 | | |
| | 542 | media.view.SelectModeToggleButton = media.view.Button.extend({ |
| 557 | 543 | initialize: function() { |
| 558 | 544 | media.view.Button.prototype.initialize.apply( this, arguments ); |
| 559 | | this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) ); |
| 560 | | this.$el.append( $('<option></option>').val( '' ).html( l10n.bulkActions ) ) |
| 561 | | .append( $('<option></option>').val( 'delete' ).html( l10n.deletePermanently ) ); |
| 562 | | this.$el.prop( 'disabled', true ); |
| 563 | | this.$el.on( 'change', _.bind( this.changeHandler, this ) ); |
| | 545 | this.listenTo( this.controller, 'select:activate select:deactivate', _.bind( this.toggleBulkEditHandler, this ) ); |
| 564 | 546 | }, |
| 565 | 547 | |
| 566 | | /** |
| 567 | | * Change handler for the dropdown. |
| 568 | | * |
| 569 | | * Sets the bulk selection controller's currentAction. |
| 570 | | */ |
| 571 | | changeHandler: function() { |
| 572 | | this.controller.model.set( { 'currentAction': this.$el.val() } ); |
| 573 | | }, |
| 574 | | |
| 575 | | /** |
| 576 | | * Enable or disable the dropdown if attachments have been selected. |
| 577 | | */ |
| 578 | | enabled: function() { |
| 579 | | var disabled = ! this.controller.controller.state().get('selection').length; |
| 580 | | this.$el.prop( 'disabled', disabled ); |
| 581 | | } |
| 582 | | }); |
| 583 | | |
| 584 | | /** |
| 585 | | * Bulk Selection dropdown view. |
| 586 | | * |
| 587 | | * @constructor |
| 588 | | * |
| 589 | | * @augments wp.media.view.Button |
| 590 | | * @augments wp.media.View |
| 591 | | * @augments wp.Backbone.View |
| 592 | | * @augments Backbone.View |
| 593 | | */ |
| 594 | | media.view.BulkSelectionActionButton = media.view.Button.extend({ |
| 595 | | tagName: 'button', |
| 596 | | |
| 597 | | initialize: function() { |
| 598 | | media.view.Button.prototype.initialize.apply( this, arguments ); |
| 599 | | |
| 600 | | this.listenTo( this.controller.model, 'change', this.enabled, this ); |
| 601 | | this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) ); |
| 602 | | }, |
| 603 | | /** |
| 604 | | * Button click handler. |
| 605 | | */ |
| 606 | 548 | click: function() { |
| 607 | | var selection = this.controller.controller.state().get('selection'); |
| 608 | 549 | media.view.Button.prototype.click.apply( this, arguments ); |
| 609 | | |
| 610 | | if ( 'delete' === this.controller.model.get( 'currentAction' ) ) { |
| 611 | | // Currently assumes delete is the only action |
| 612 | | if ( confirm( l10n.warnBulkDelete ) ) { |
| 613 | | while ( selection.length > 0 ) { |
| 614 | | selection.at(0).destroy(); |
| 615 | | } |
| 616 | | } |
| | 550 | if ( this.controller.isModeActive( 'select' ) ) { |
| | 551 | this.controller.deactivateMode( 'select' ).activateMode( 'edit' ); |
| | 552 | } else { |
| | 553 | this.controller.deactivateMode( 'edit' ).activateMode( 'select' ); |
| 617 | 554 | } |
| | 555 | }, |
| 618 | 556 | |
| 619 | | this.enabled(); |
| | 557 | render: function() { |
| | 558 | media.view.Button.prototype.render.apply( this, arguments ); |
| | 559 | this.el.className = this.el.className + ' select-mode-toggle-button'; |
| | 560 | return this; |
| 620 | 561 | }, |
| 621 | | /** |
| 622 | | * Enable or disable the button depending if a bulk action is selected |
| 623 | | * in the bulk select dropdown, and if attachments have been selected. |
| 624 | | */ |
| 625 | | enabled: function() { |
| 626 | | var currentAction = this.controller.model.get( 'currentAction' ), |
| 627 | | selection = this.controller.controller.state().get('selection'), |
| 628 | | disabled = ! currentAction || ! selection.length; |
| 629 | | this.$el.prop( 'disabled', disabled ); |
| | 562 | |
| | 563 | toggleBulkEditHandler: function() { |
| | 564 | if ( this.controller.isModeActive( 'select' ) ) { |
| | 565 | this.model.set( 'text', 'Cancel' ); |
| | 566 | this.controller.content.get().toolbar.$el.find( '.media-toolbar-secondary > *, .media-toolbar-primary > *').hide(); |
| | 567 | this.controller.content.get().toolbar.$el.find( '.select-mode-toggle-button').show(); |
| | 568 | } else { |
| | 569 | this.model.set( 'text', 'Select' ); |
| | 570 | this.controller.content.get().toolbar.$el.find( '.media-toolbar-secondary > *, .media-toolbar-primary > *').not('.spinner').show(); |
| | 571 | this.controller.state().get('selection').reset(); |
| | 572 | } |
| 630 | 573 | } |
| 631 | 574 | }); |
| 632 | 575 | |
diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js
index 4fa1303..d1dbfb1 100644
|
a
|
b
|
|
| 1792 | 1792 | deactivateMode: function( mode ) { |
| 1793 | 1793 | // Bail if the mode isn't active. |
| 1794 | 1794 | if ( ! this.isModeActive( mode ) ) { |
| 1795 | | return; |
| | 1795 | return this; |
| 1796 | 1796 | } |
| 1797 | 1797 | this.activeModes.remove( this.activeModes.where( { id: mode } ) ); |
| 1798 | 1798 | this.$el.removeClass( 'mode-' + mode ); |
| … |
… |
|
| 3947 | 3947 | |
| 3948 | 3948 | this._views = {}; |
| 3949 | 3949 | |
| | 3950 | $(window).on( 'scroll', this.fixPosition ); |
| 3950 | 3951 | // The toolbar is composed of two `PriorityList` views. |
| 3951 | 3952 | this.primary = new media.view.PriorityList(); |
| 3952 | 3953 | this.secondary = new media.view.PriorityList(); |
| … |
… |
|
| 3971 | 3972 | library.on( 'add remove reset', this.refresh, this ); |
| 3972 | 3973 | } |
| 3973 | 3974 | }, |
| | 3975 | |
| | 3976 | fixPosition: function() { |
| | 3977 | $adminBar = $( '#wpadminbar' ); |
| | 3978 | var parentOffset = $('.attachments-browser').offset().top; |
| | 3979 | // debugger; |
| | 3980 | if ( parentOffset < $(window).scrollTop() + $adminBar.height() ) { |
| | 3981 | $('.attachments-browser .media-toolbar').addClass( 'fixed' ); |
| | 3982 | } else { |
| | 3983 | $('.attachments-browser .media-toolbar').removeClass( 'fixed' ); |
| | 3984 | } |
| | 3985 | }, |
| 3974 | 3986 | /** |
| 3975 | 3987 | * @returns {wp.media.view.Toolbar} Returns itsef to allow chaining |
| 3976 | 3988 | */ |
| … |
… |
|
| 4804 | 4816 | } |
| 4805 | 4817 | |
| 4806 | 4818 | // In the grid view, bubble up an edit:attachment event to the controller. |
| 4807 | | if ( this.controller.isModeActive( 'grid' ) ) { |
| | 4819 | if ( this.controller.isModeActive( 'grid' ) && this.controller.isModeActive( 'edit' ) ) { |
| 4808 | 4820 | // Pass the current target to restore focus when closing |
| 4809 | 4821 | this.controller.trigger( 'edit:attachment', this.model, event.currentTarget ); |
| 4810 | 4822 | |
| … |
… |
|
| 5758 | 5770 | // browser view. Is this a use case for doAction( 'add:toolbar-items:attachments-browser', this.toolbar ); |
| 5759 | 5771 | // which the controller can tap into and add this view? |
| 5760 | 5772 | if ( this.controller.activeModes.where( { id: 'grid' } ).length ) { |
| 5761 | | LibraryViewSwitcher = media.View.extend({ |
| | 5773 | var LibraryViewSwitcher = media.View.extend({ |
| 5762 | 5774 | className: 'view-switch media-grid-view-switch', |
| 5763 | 5775 | template: media.template( 'media-library-view-switcher') |
| 5764 | 5776 | }); |
| … |
… |
|
| 5769 | 5781 | }).render() ); |
| 5770 | 5782 | |
| 5771 | 5783 | // BulkSelection is a <div> with subviews, including screen reader text |
| 5772 | | this.toolbar.set( 'bulkSelection', new media.view.BulkSelection({ |
| | 5784 | this.toolbar.set( 'selectModeToggleButton', new media.view.SelectModeToggleButton({ |
| | 5785 | text: 'Select', |
| 5773 | 5786 | controller: this.controller, |
| 5774 | 5787 | priority: -70 |
| 5775 | 5788 | }).render() ); |