[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/ -> media-grid.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     var __webpack_modules__ = ({
   3  
   4  /***/ 659
   5  (module) {
   6  
   7  var l10n = wp.media.view.l10n,
   8      EditAttachmentMetadata;
   9  
  10  /**
  11   * wp.media.controller.EditAttachmentMetadata
  12   *
  13   * A state for editing an attachment's metadata.
  14   *
  15   * @memberOf wp.media.controller
  16   *
  17   * @class
  18   * @augments wp.media.controller.State
  19   * @augments Backbone.Model
  20   */
  21  EditAttachmentMetadata = wp.media.controller.State.extend(/** @lends wp.media.controller.EditAttachmentMetadata.prototype */{
  22      defaults: {
  23          id:      'edit-attachment',
  24          // Title string passed to the frame's title region view.
  25          title:   l10n.attachmentDetails,
  26          // Region mode defaults.
  27          content: 'edit-metadata',
  28          menu:    false,
  29          toolbar: false,
  30          router:  false
  31      }
  32  });
  33  
  34  module.exports = EditAttachmentMetadata;
  35  
  36  
  37  /***/ },
  38  
  39  /***/ 2429
  40  (module) {
  41  
  42  /**
  43   * wp.media.view.MediaFrame.Manage.Router
  44   *
  45   * A router for handling the browser history and application state.
  46   *
  47   * @memberOf wp.media.view.MediaFrame.Manage
  48   *
  49   * @class
  50   * @augments Backbone.Router
  51   */
  52  var Router = Backbone.Router.extend(/** @lends wp.media.view.MediaFrame.Manage.Router.prototype */{
  53      routes: {
  54          'upload.php?item=:slug&mode=edit': 'editItem',
  55          'upload.php?item=:slug':           'showItem',
  56          'upload.php?search=:query':        'search',
  57          'upload.php':                      'reset'
  58      },
  59  
  60      // Map routes against the page URL.
  61      baseUrl: function( url ) {
  62          return 'upload.php' + url;
  63      },
  64  
  65      reset: function() {
  66          var frame = wp.media.frames.edit;
  67  
  68          if ( frame ) {
  69              frame.close();
  70          }
  71      },
  72  
  73      // Respond to the search route by filling the search field and triggering the input event.
  74      search: function( query ) {
  75          jQuery( '#media-search-input' ).val( query ).trigger( 'input' );
  76      },
  77  
  78      // Show the modal with a specific item.
  79      showItem: function( query ) {
  80          var media = wp.media,
  81              frame = media.frames.browse,
  82              library = frame.state().get('library'),
  83              item;
  84  
  85          // Trigger the media frame to open the correct item.
  86          item = library.findWhere( { id: parseInt( query, 10 ) } );
  87  
  88          if ( item ) {
  89              item.set( 'skipHistory', true );
  90              frame.trigger( 'edit:attachment', item );
  91          } else {
  92              item = media.attachment( query );
  93              frame.listenTo( item, 'change', function( model ) {
  94                  frame.stopListening( item );
  95                  frame.trigger( 'edit:attachment', model );
  96              } );
  97              item.fetch();
  98          }
  99      },
 100  
 101      // Show the modal in edit mode with a specific item.
 102      editItem: function( query ) {
 103          this.showItem( query );
 104          wp.media.frames.edit.content.mode( 'edit-details' );
 105      }
 106  });
 107  
 108  module.exports = Router;
 109  
 110  
 111  /***/ },
 112  
 113  /***/ 1312
 114  (module) {
 115  
 116  var Details = wp.media.view.Attachment.Details,
 117      TwoColumn;
 118  
 119  /**
 120   * wp.media.view.Attachment.Details.TwoColumn
 121   *
 122   * A similar view to media.view.Attachment.Details
 123   * for use in the Edit Attachment modal.
 124   *
 125   * @memberOf wp.media.view.Attachment.Details
 126   *
 127   * @class
 128   * @augments wp.media.view.Attachment.Details
 129   * @augments wp.media.view.Attachment
 130   * @augments wp.media.View
 131   * @augments wp.Backbone.View
 132   * @augments Backbone.View
 133   */
 134  TwoColumn = Details.extend(/** @lends wp.media.view.Attachment.Details.TwoColumn.prototype */{
 135      template: wp.template( 'attachment-details-two-column' ),
 136  
 137      initialize: function() {
 138          this.controller.on( 'content:activate:edit-details', _.bind( this.editAttachment, this ) );
 139  
 140          Details.prototype.initialize.apply( this, arguments );
 141      },
 142  
 143      editAttachment: function( event ) {
 144          if ( event ) {
 145              event.preventDefault();
 146          }
 147          this.controller.content.mode( 'edit-image' );
 148      },
 149  
 150      /**
 151       * Noop this from parent class, doesn't apply here.
 152       */
 153      toggleSelectionHandler: function() {}
 154  
 155  });
 156  
 157  module.exports = TwoColumn;
 158  
 159  
 160  /***/ },
 161  
 162  /***/ 5806
 163  (module) {
 164  
 165  var Button = wp.media.view.Button,
 166      DeleteSelected = wp.media.view.DeleteSelectedButton,
 167      DeleteSelectedPermanently;
 168  
 169  /**
 170   * wp.media.view.DeleteSelectedPermanentlyButton
 171   *
 172   * When MEDIA_TRASH is true, a button that handles bulk Delete Permanently logic
 173   *
 174   * @memberOf wp.media.view
 175   *
 176   * @class
 177   * @augments wp.media.view.DeleteSelectedButton
 178   * @augments wp.media.view.Button
 179   * @augments wp.media.View
 180   * @augments wp.Backbone.View
 181   * @augments Backbone.View
 182   */
 183  DeleteSelectedPermanently = DeleteSelected.extend(/** @lends wp.media.view.DeleteSelectedPermanentlyButton.prototype */{
 184      initialize: function() {
 185          DeleteSelected.prototype.initialize.apply( this, arguments );
 186          this.controller.on( 'select:activate', this.selectActivate, this );
 187          this.controller.on( 'select:deactivate', this.selectDeactivate, this );
 188      },
 189  
 190      filterChange: function( model ) {
 191          this.canShow = ( 'trash' === model.get( 'status' ) );
 192      },
 193  
 194      selectActivate: function() {
 195          this.toggleDisabled();
 196          this.$el.toggleClass( 'hidden', ! this.canShow );
 197      },
 198  
 199      selectDeactivate: function() {
 200          this.toggleDisabled();
 201          this.$el.addClass( 'hidden' );
 202      },
 203  
 204      render: function() {
 205          Button.prototype.render.apply( this, arguments );
 206          this.selectActivate();
 207          return this;
 208      }
 209  });
 210  
 211  module.exports = DeleteSelectedPermanently;
 212  
 213  
 214  /***/ },
 215  
 216  /***/ 6606
 217  (module) {
 218  
 219  var Button = wp.media.view.Button,
 220      l10n = wp.media.view.l10n,
 221      DeleteSelected;
 222  
 223  /**
 224   * wp.media.view.DeleteSelectedButton
 225   *
 226   * A button that handles bulk Delete/Trash logic
 227   *
 228   * @memberOf wp.media.view
 229   *
 230   * @class
 231   * @augments wp.media.view.Button
 232   * @augments wp.media.View
 233   * @augments wp.Backbone.View
 234   * @augments Backbone.View
 235   */
 236  DeleteSelected = Button.extend(/** @lends wp.media.view.DeleteSelectedButton.prototype */{
 237      initialize: function() {
 238          Button.prototype.initialize.apply( this, arguments );
 239          if ( this.options.filters ) {
 240              this.options.filters.model.on( 'change', this.filterChange, this );
 241          }
 242          this.controller.on( 'selection:toggle', this.toggleDisabled, this );
 243          this.controller.on( 'select:activate', this.toggleDisabled, this );
 244      },
 245  
 246      filterChange: function( model ) {
 247          if ( 'trash' === model.get( 'status' ) ) {
 248              this.model.set( 'text', l10n.restoreSelected );
 249          } else if ( wp.media.view.settings.mediaTrash ) {
 250              this.model.set( 'text', l10n.trashSelected );
 251          } else {
 252              this.model.set( 'text', l10n.deletePermanently );
 253          }
 254      },
 255  
 256      toggleDisabled: function() {
 257          this.model.set( 'disabled', ! this.controller.state().get( 'selection' ).length );
 258      },
 259  
 260      render: function() {
 261          Button.prototype.render.apply( this, arguments );
 262          if ( this.controller.isModeActive( 'select' ) ) {
 263              this.$el.addClass( 'delete-selected-button' );
 264          } else {
 265              this.$el.addClass( 'delete-selected-button hidden' );
 266          }
 267          this.toggleDisabled();
 268          return this;
 269      }
 270  });
 271  
 272  module.exports = DeleteSelected;
 273  
 274  
 275  /***/ },
 276  
 277  /***/ 682
 278  (module) {
 279  
 280  
 281  var Button = wp.media.view.Button,
 282      l10n = wp.media.view.l10n,
 283      SelectModeToggle;
 284  
 285  /**
 286   * wp.media.view.SelectModeToggleButton
 287   *
 288   * @memberOf wp.media.view
 289   *
 290   * @class
 291   * @augments wp.media.view.Button
 292   * @augments wp.media.View
 293   * @augments wp.Backbone.View
 294   * @augments Backbone.View
 295   */
 296  SelectModeToggle = Button.extend(/** @lends wp.media.view.SelectModeToggle.prototype */{
 297      initialize: function() {
 298          _.defaults( this.options, {
 299              size : ''
 300          } );
 301  
 302          Button.prototype.initialize.apply( this, arguments );
 303          this.controller.on( 'select:activate select:deactivate', this.toggleBulkEditHandler, this );
 304          this.controller.on( 'selection:action:done', this.back, this );
 305      },
 306  
 307      back: function () {
 308          this.controller.deactivateMode( 'select' ).activateMode( 'edit' );
 309      },
 310  
 311      click: function() {
 312          Button.prototype.click.apply( this, arguments );
 313          if ( this.controller.isModeActive( 'select' ) ) {
 314              this.back();
 315          } else {
 316              this.controller.deactivateMode( 'edit' ).activateMode( 'select' );
 317          }
 318      },
 319  
 320      render: function() {
 321          Button.prototype.render.apply( this, arguments );
 322          this.$el.addClass( 'select-mode-toggle-button button-compact' );
 323          return this;
 324      },
 325  
 326      toggleBulkEditHandler: function() {
 327          var toolbar = this.controller.content.get().toolbar, children;
 328  
 329          children = toolbar.$( '.media-toolbar-secondary > *, .media-toolbar-primary > *' );
 330  
 331          // @todo The Frame should be doing all of this.
 332          if ( this.controller.isModeActive( 'select' ) ) {
 333              this.model.set( {
 334                  size: 'large',
 335                  text: l10n.cancel
 336              } );
 337              children.not( '.spinner, .media-button' ).hide();
 338              this.$el.show();
 339              toolbar.$el.addClass( 'media-toolbar-mode-select' );
 340              toolbar.$( '.delete-selected-button' ).removeClass( 'hidden' );
 341          } else {
 342              this.model.set( {
 343                  size: '',
 344                  text: l10n.bulkSelect
 345              } );
 346              this.controller.content.get().$el.removeClass( 'fixed' );
 347              toolbar.$el.css( 'width', '' );
 348              toolbar.$el.removeClass( 'media-toolbar-mode-select' );
 349              toolbar.$( '.delete-selected-button' ).addClass( 'hidden' );
 350              children.not( '.media-button' ).show();
 351              this.controller.state().get( 'selection' ).reset();
 352          }
 353      }
 354  });
 355  
 356  module.exports = SelectModeToggle;
 357  
 358  
 359  /***/ },
 360  
 361  /***/ 8521
 362  (module) {
 363  
 364  var View = wp.media.View,
 365      EditImage = wp.media.view.EditImage,
 366      Details;
 367  
 368  /**
 369   * wp.media.view.EditImage.Details
 370   *
 371   * @memberOf wp.media.view.EditImage
 372   *
 373   * @class
 374   * @augments wp.media.view.EditImage
 375   * @augments wp.media.View
 376   * @augments wp.Backbone.View
 377   * @augments Backbone.View
 378   */
 379  Details = EditImage.extend(/** @lends wp.media.view.EditImage.Details.prototype */{
 380      initialize: function( options ) {
 381          this.editor = window.imageEdit;
 382          this.frame = options.frame;
 383          this.controller = options.controller;
 384          View.prototype.initialize.apply( this, arguments );
 385      },
 386  
 387      back: function() {
 388          this.frame.content.mode( 'edit-metadata' );
 389      },
 390  
 391      save: function() {
 392          this.model.fetch().done( _.bind( function() {
 393              this.frame.content.mode( 'edit-metadata' );
 394          }, this ) );
 395      }
 396  });
 397  
 398  module.exports = Details;
 399  
 400  
 401  /***/ },
 402  
 403  /***/ 1003
 404  (module) {
 405  
 406  var Frame = wp.media.view.Frame,
 407      MediaFrame = wp.media.view.MediaFrame,
 408      l10n = wp.media.view.l10n,
 409  
 410      $ = jQuery,
 411      EditAttachments;
 412  
 413  /**
 414   * wp.media.view.MediaFrame.EditAttachments
 415   *
 416   * A frame for editing the details of a specific media item.
 417   *
 418   * Opens in a modal by default.
 419   *
 420   * Requires an attachment model to be passed in the options hash under `model`.
 421   *
 422   * @memberOf wp.media.view.MediaFrame
 423   *
 424   * @class
 425   * @augments wp.media.view.Frame
 426   * @augments wp.media.View
 427   * @augments wp.Backbone.View
 428   * @augments Backbone.View
 429   * @mixes wp.media.controller.StateMachine
 430   */
 431  EditAttachments = MediaFrame.extend(/** @lends wp.media.view.MediaFrame.EditAttachments.prototype */{
 432  
 433      className: 'edit-attachment-frame',
 434      template:  wp.template( 'edit-attachment-frame' ),
 435      regions:   [ 'title', 'content' ],
 436  
 437      events: {
 438          'click .left':  'previousMediaItem',
 439          'click .right': 'nextMediaItem'
 440      },
 441  
 442      /**
 443       * Announces to screen readers the attachment shown after previous/next navigation.
 444       *
 445       * @since 7.1.0
 446       *
 447       * @param {Object} model The attachment model.
 448       * @return {void}
 449       */
 450      announceMediaItemDebounced: _.debounce( function( model ) {
 451          var title;
 452  
 453          if ( ! model ) {
 454              return;
 455          }
 456  
 457          title = model.get( 'title' ) || model.get( 'filename' ) || model.get( 'id' );
 458  
 459          if ( ! title ) {
 460              return;
 461          }
 462  
 463          wp.a11y.speak( l10n.mediaItemViewed.replace( '%s', title ) );
 464      }, 500 ),
 465  
 466      initialize: function() {
 467          Frame.prototype.initialize.apply( this, arguments );
 468  
 469          _.defaults( this.options, {
 470              modal: true,
 471              state: 'edit-attachment'
 472          });
 473  
 474          this.controller = this.options.controller;
 475          this.gridRouter = this.controller.gridRouter;
 476          this.library = this.options.library;
 477  
 478          if ( this.options.model ) {
 479              this.model = this.options.model;
 480          }
 481  
 482          this.bindHandlers();
 483          this.createStates();
 484          this.createModal();
 485  
 486          this.title.mode( 'default' );
 487          this.toggleNav();
 488      },
 489  
 490      bindHandlers: function() {
 491          // Bind default title creation.
 492          this.on( 'title:create:default', this.createTitle, this );
 493  
 494          this.on( 'content:create:edit-metadata', this.editMetadataMode, this );
 495          this.on( 'content:create:edit-image', this.editImageMode, this );
 496          this.on( 'content:render:edit-image', this.editImageModeRender, this );
 497          this.on( 'refresh', this.rerender, this );
 498          this.on( 'close', this.detach );
 499  
 500          this.bindModelHandlers();
 501          this.listenTo( this.gridRouter, 'route:search', this.close, this );
 502      },
 503  
 504      bindModelHandlers: function() {
 505          // Close the modal if the attachment is deleted.
 506          this.listenTo( this.model, 'change:status destroy', this.close, this );
 507      },
 508  
 509      createModal: function() {
 510          // Initialize modal container view.
 511          if ( this.options.modal ) {
 512              this.modal = new wp.media.view.Modal({
 513                  controller:     this,
 514                  title:          this.options.title,
 515                  hasCloseButton: false
 516              });
 517  
 518              this.modal.on( 'open', _.bind( function () {
 519                  $( 'body' ).on( 'keydown.media-modal', _.bind( this.keyEvent, this ) );
 520              }, this ) );
 521  
 522              // Completely destroy the modal DOM element when closing it.
 523              this.modal.on( 'close', _.bind( function() {
 524                  // Remove the keydown event.
 525                  $( 'body' ).off( 'keydown.media-modal' );
 526                  // Move focus back to the original item in the grid if possible.
 527                  $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).trigger( 'focus' );
 528                  this.resetRoute();
 529                  // Cancel any pending navigation announcement.
 530                  this.announceMediaItemDebounced.cancel();
 531              }, this ) );
 532  
 533              // Set this frame as the modal's content.
 534              this.modal.content( this );
 535              this.modal.open();
 536          }
 537      },
 538  
 539      /**
 540       * Add the default states to the frame.
 541       */
 542      createStates: function() {
 543          this.states.add([
 544              new wp.media.controller.EditAttachmentMetadata({
 545                  model:   this.model,
 546                  library: this.library
 547              })
 548          ]);
 549      },
 550  
 551      /**
 552       * Content region rendering callback for the `edit-metadata` mode.
 553       *
 554       * @param {Object} contentRegion Basic object with a `view` property, which
 555       *                               should be set with the proper region view.
 556       */
 557      editMetadataMode: function( contentRegion ) {
 558          contentRegion.view = new wp.media.view.Attachment.Details.TwoColumn({
 559              controller: this,
 560              model:      this.model
 561          });
 562  
 563          /**
 564           * Attach a subview to display fields added via the
 565           * `attachment_fields_to_edit` filter.
 566           */
 567          contentRegion.view.views.set( '.attachment-compat', new wp.media.view.AttachmentCompat({
 568              controller: this,
 569              model:      this.model
 570          }) );
 571  
 572          // Update browser url when navigating media details, except on load.
 573          if ( this.model && ! this.model.get( 'skipHistory' ) ) {
 574              this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) );
 575          }
 576      },
 577  
 578      /**
 579       * Render the EditImage view into the frame's content region.
 580       *
 581       * @param {Object} contentRegion Basic object with a `view` property, which
 582       *                               should be set with the proper region view.
 583       */
 584      editImageMode: function( contentRegion ) {
 585          var editImageController = new wp.media.controller.EditImage( {
 586              model: this.model,
 587              frame: this
 588          } );
 589          // Noop some methods.
 590          editImageController._toolbar = function() {};
 591          editImageController._router = function() {};
 592          editImageController._menu = function() {};
 593  
 594          contentRegion.view = new wp.media.view.EditImage.Details( {
 595              model: this.model,
 596              frame: this,
 597              controller: editImageController
 598          } );
 599  
 600          this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id + '&mode=edit' ) );
 601  
 602      },
 603  
 604      editImageModeRender: function( view ) {
 605          view.on( 'ready', view.loadEditor );
 606      },
 607  
 608      toggleNav: function() {
 609          this.$( '.left' ).prop( 'disabled', ! this.hasPrevious() );
 610          this.$( '.right' ).prop( 'disabled', ! this.hasNext() );
 611      },
 612  
 613      /**
 614       * Rerender the view.
 615       */
 616      rerender: function( model ) {
 617          this.stopListening( this.model );
 618  
 619          this.model = model;
 620  
 621          this.bindModelHandlers();
 622  
 623          // Only rerender the `content` region.
 624          if ( this.content.mode() !== 'edit-metadata' ) {
 625              this.content.mode( 'edit-metadata' );
 626          } else {
 627              this.content.render();
 628          }
 629  
 630          this.toggleNav();
 631      },
 632  
 633      /**
 634       * Click handler to switch to the previous media item.
 635       */
 636      previousMediaItem: function() {
 637          var model;
 638  
 639          if ( ! this.hasPrevious() ) {
 640              return;
 641          }
 642  
 643          model = this.library.at( this.getCurrentIndex() - 1 );
 644          this.trigger( 'refresh', model );
 645          // Move focus to the Previous button. When there are no more items, to the Next button.
 646          this.focusNavButton( this.hasPrevious() ? '.left' : '.right' );
 647          this.announceMediaItemDebounced( model );
 648      },
 649  
 650      /**
 651       * Click handler to switch to the next media item.
 652       */
 653      nextMediaItem: function() {
 654          var model;
 655  
 656          if ( ! this.hasNext() ) {
 657              return;
 658          }
 659  
 660          model = this.library.at( this.getCurrentIndex() + 1 );
 661          this.trigger( 'refresh', model );
 662          // Move focus to the Next button. When there are no more items, to the Previous button.
 663          this.focusNavButton( this.hasNext() ? '.right' : '.left' );
 664          this.announceMediaItemDebounced( model );
 665      },
 666  
 667      /**
 668       * Set focus to the navigation buttons depending on the browsing direction.
 669       *
 670       * @since 5.3.0
 671       *
 672       * @param {string} which A CSS selector to target the button to focus.
 673       */
 674      focusNavButton: function( which ) {
 675          $( which ).trigger( 'focus' );
 676      },
 677  
 678      getCurrentIndex: function() {
 679          return this.library.indexOf( this.model );
 680      },
 681  
 682      hasNext: function() {
 683          return ( this.getCurrentIndex() + 1 ) < this.library.length;
 684      },
 685  
 686      hasPrevious: function() {
 687          return ( this.getCurrentIndex() - 1 ) > -1;
 688      },
 689      /**
 690       * Respond to the keyboard events: Alt + right arrow, Alt + left arrow,
 691       * except when focus is in a form field. Requires the Alt modifier key to
 692       * avoid interfering with screen reader navigation.
 693       */
 694      keyEvent: function( event ) {
 695          if ( ( 'INPUT' === event.target.nodeName || 'TEXTAREA' === event.target.nodeName || 'SELECT' === event.target.nodeName ) && ! event.target.disabled ) {
 696              return;
 697          }
 698  
 699          // Arrow key navigation requires Alt key to avoid interfering with screen reader navigation.
 700          if ( ! event.altKey ) {
 701              return;
 702          }
 703  
 704          // Alt + right arrow key.
 705          if ( 39 === event.keyCode ) {
 706              event.preventDefault();
 707              this.nextMediaItem();
 708          }
 709          // Alt + left arrow key.
 710          if ( 37 === event.keyCode ) {
 711              event.preventDefault();
 712              this.previousMediaItem();
 713          }
 714      },
 715  
 716      resetRoute: function() {
 717          var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(),
 718              url = '' !== searchTerm ? '?search=' + searchTerm : '';
 719          this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } );
 720      }
 721  });
 722  
 723  module.exports = EditAttachments;
 724  
 725  
 726  /***/ },
 727  
 728  /***/ 8359
 729  (module) {
 730  
 731  var MediaFrame = wp.media.view.MediaFrame,
 732      Library = wp.media.controller.Library,
 733  
 734      $ = Backbone.$,
 735      Manage;
 736  
 737  /**
 738   * wp.media.view.MediaFrame.Manage
 739   *
 740   * A generic management frame workflow.
 741   *
 742   * Used in the media grid view.
 743   *
 744   * @memberOf wp.media.view.MediaFrame
 745   *
 746   * @class
 747   * @augments wp.media.view.MediaFrame
 748   * @augments wp.media.view.Frame
 749   * @augments wp.media.View
 750   * @augments wp.Backbone.View
 751   * @augments Backbone.View
 752   * @mixes wp.media.controller.StateMachine
 753   */
 754  Manage = MediaFrame.extend(/** @lends wp.media.view.MediaFrame.Manage.prototype */{
 755      /**
 756       * @constructs
 757       */
 758      initialize: function() {
 759          _.defaults( this.options, {
 760              title:     '',
 761              modal:     false,
 762              selection: [],
 763              library:   {}, // Options hash for the query to the media library.
 764              multiple:  'add',
 765              state:     'library',
 766              uploader:  true,
 767              mode:      [ 'grid', 'edit' ]
 768          });
 769  
 770          this.$body = $( document.body );
 771          this.$window = $( window );
 772          this.$adminBar = $( '#wpadminbar' );
 773          // Store the Add New button for later reuse in wp.media.view.UploaderInline.
 774          this.$uploaderToggler = $( '.page-title-action' )
 775              .attr( 'aria-expanded', 'false' )
 776              .on( 'click', _.bind( this.addNewClickHandler, this ) );
 777  
 778          this.$window.on( 'scroll resize', _.debounce( _.bind( this.fixPosition, this ), 15 ) );
 779  
 780          // Ensure core and media grid view UI is enabled.
 781          this.$el.addClass('wp-core-ui');
 782  
 783          // Force the uploader off if the upload limit has been exceeded or
 784          // if the browser isn't supported.
 785          if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
 786              this.options.uploader = false;
 787          }
 788  
 789          // Initialize a window-wide uploader.
 790          if ( this.options.uploader ) {
 791              this.uploader = new wp.media.view.UploaderWindow({
 792                  controller: this,
 793                  uploader: {
 794                      dropzone:  document.body,
 795                      container: document.body
 796                  }
 797              }).render();
 798              this.uploader.ready();
 799              $('body').append( this.uploader.el );
 800  
 801              this.options.uploader = false;
 802          }
 803  
 804          this.gridRouter = new wp.media.view.MediaFrame.Manage.Router();
 805  
 806          // Call 'initialize' directly on the parent class.
 807          MediaFrame.prototype.initialize.apply( this, arguments );
 808  
 809          // Append the frame view directly the supplied container.
 810          this.$el.appendTo( this.options.container );
 811  
 812          this.createStates();
 813          this.bindRegionModeHandlers();
 814          this.render();
 815          this.bindSearchHandler();
 816  
 817          wp.media.frames.browse = this;
 818      },
 819  
 820      bindSearchHandler: function() {
 821          var search = this.$( '#media-search-input' ),
 822              searchView = this.browserView.toolbar.get( 'search' ).$el,
 823              listMode = this.$( '.view-list' ),
 824  
 825              input  = _.throttle( function (e) {
 826                  var val = $( e.currentTarget ).val(),
 827                      url = '';
 828  
 829                  if ( val ) {
 830                      url += '?search=' + val;
 831                  }
 832  
 833                  this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } );
 834              }, 1000 );
 835  
 836          // Update the URL when entering search string (at most once per second).
 837          search.on( 'input', _.bind( input, this ) );
 838  
 839          this.gridRouter
 840              .on( 'route:search', function () {
 841                  var href = window.location.href;
 842                  if ( href.indexOf( 'mode=' ) > -1 ) {
 843                      href = href.replace( /mode=[^&]+/g, 'mode=list' );
 844                  } else {
 845                      href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
 846                  }
 847                  href = href.replace( 'search=', 's=' );
 848                  listMode.prop( 'href', href );
 849              })
 850              .on( 'route:reset', function() {
 851                  searchView.val( '' ).trigger( 'input' );
 852              });
 853      },
 854  
 855      /**
 856       * Create the default states for the frame.
 857       */
 858      createStates: function() {
 859          var options = this.options;
 860  
 861          if ( this.options.states ) {
 862              return;
 863          }
 864  
 865          // Add the default states.
 866          this.states.add([
 867              new Library({
 868                  library:            wp.media.query( options.library ),
 869                  multiple:           options.multiple,
 870                  title:              options.title,
 871                  content:            'browse',
 872                  toolbar:            'select',
 873                  contentUserSetting: false,
 874                  filterable:         'all',
 875                  autoSelect:         false
 876              })
 877          ]);
 878      },
 879  
 880      /**
 881       * Bind region mode activation events to proper handlers.
 882       */
 883      bindRegionModeHandlers: function() {
 884          this.on( 'content:create:browse', this.browseContent, this );
 885  
 886          // Handle a frame-level event for editing an attachment.
 887          this.on( 'edit:attachment', this.openEditAttachmentModal, this );
 888  
 889          this.on( 'select:activate', this.bindKeydown, this );
 890          this.on( 'select:deactivate', this.unbindKeydown, this );
 891      },
 892  
 893      handleKeydown: function( e ) {
 894          if ( 27 === e.which ) {
 895              e.preventDefault();
 896              this.deactivateMode( 'select' ).activateMode( 'edit' );
 897          }
 898      },
 899  
 900      bindKeydown: function() {
 901          this.$body.on( 'keydown.select', _.bind( this.handleKeydown, this ) );
 902      },
 903  
 904      unbindKeydown: function() {
 905          this.$body.off( 'keydown.select' );
 906      },
 907  
 908      fixPosition: function() {
 909          var $browser, $toolbar;
 910          if ( ! this.isModeActive( 'select' ) ) {
 911              return;
 912          }
 913  
 914          $browser = this.$('.attachments-browser');
 915          $toolbar = $browser.find('.media-toolbar');
 916  
 917          // Offset doesn't appear to take top margin into account, hence +16.
 918          if ( ( $browser.offset().top + 16 ) < this.$window.scrollTop() + this.$adminBar.height() ) {
 919              $browser.addClass( 'fixed' );
 920              $toolbar.css('width', $browser.width() + 'px');
 921          } else {
 922              $browser.removeClass( 'fixed' );
 923              $toolbar.css('width', '');
 924          }
 925      },
 926  
 927      /**
 928       * Click handler for the `Add New` button.
 929       */
 930      addNewClickHandler: function( event ) {
 931          event.preventDefault();
 932          this.trigger( 'toggle:upload:attachment' );
 933  
 934          if ( this.uploader ) {
 935              this.uploader.refresh();
 936          }
 937      },
 938  
 939      /**
 940       * Open the Edit Attachment modal.
 941       */
 942      openEditAttachmentModal: function( model ) {
 943          // Create a new EditAttachment frame, passing along the library and the attachment model.
 944          if ( wp.media.frames.edit ) {
 945              wp.media.frames.edit.open().trigger( 'refresh', model );
 946          } else {
 947              wp.media.frames.edit = wp.media( {
 948                  frame:       'edit-attachments',
 949                  controller:  this,
 950                  library:     this.state().get('library'),
 951                  model:       model
 952              } );
 953          }
 954      },
 955  
 956      /**
 957       * Create an attachments browser view within the content region.
 958       *
 959       * @param {Object} contentRegion Basic object with a `view` property, which
 960       *                               should be set with the proper region view.
 961       * @this wp.media.controller.Region
 962       */
 963      browseContent: function( contentRegion ) {
 964          var state = this.state();
 965  
 966          // Browse our library of attachments.
 967          this.browserView = contentRegion.view = new wp.media.view.AttachmentsBrowser({
 968              controller: this,
 969              collection: state.get('library'),
 970              selection:  state.get('selection'),
 971              model:      state,
 972              sortable:   state.get('sortable'),
 973              search:     state.get('searchable'),
 974              filters:    state.get('filterable'),
 975              date:       state.get('date'),
 976              display:    state.get('displaySettings'),
 977              dragInfo:   state.get('dragInfo'),
 978              sidebar:    'errors',
 979  
 980              suggestedWidth:  state.get('suggestedWidth'),
 981              suggestedHeight: state.get('suggestedHeight'),
 982  
 983              AttachmentView: state.get('AttachmentView'),
 984  
 985              scrollElement: document
 986          });
 987          this.browserView.on( 'ready', _.bind( this.bindDeferred, this ) );
 988  
 989          this.errors = wp.Uploader.errors;
 990          this.errors.on( 'add remove reset', this.sidebarVisibility, this );
 991      },
 992  
 993      sidebarVisibility: function() {
 994          this.browserView.$( '.media-sidebar' ).toggle( !! this.errors.length );
 995      },
 996  
 997      bindDeferred: function() {
 998          if ( ! this.browserView.dfd ) {
 999              return;
1000          }
1001          this.browserView.dfd.done( _.bind( this.startHistory, this ) );
1002      },
1003  
1004      startHistory: function() {
1005          // Verify pushState support and activate.
1006          if ( window.history && window.history.pushState ) {
1007              if ( Backbone.History.started ) {
1008                  Backbone.history.stop();
1009              }
1010              Backbone.history.start( {
1011                  root: window._wpMediaGridSettings.adminUrl,
1012                  pushState: true
1013              } );
1014          }
1015      }
1016  });
1017  
1018  module.exports = Manage;
1019  
1020  
1021  /***/ }
1022  
1023  /******/     });
1024  /************************************************************************/
1025  /******/     // The module cache
1026  /******/     const __webpack_module_cache__ = {};
1027  /******/     
1028  /******/     // The require function
1029  /******/ 	function __webpack_require__(moduleId) {
1030  /******/         // Check if module is in cache
1031  /******/         const cachedModule = __webpack_module_cache__[moduleId];
1032  /******/         if (cachedModule !== undefined) {
1033  /******/             return cachedModule.exports;
1034  /******/         }
1035  /******/         // Create a new module (and put it into the cache)
1036  /******/         const module = __webpack_module_cache__[moduleId] = {
1037  /******/             // no module.id needed
1038  /******/             // no module.loaded needed
1039  /******/             exports: {}
1040  /******/         };
1041  /******/     
1042  /******/         // Execute the module function
1043  /******/         __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1044  /******/     
1045  /******/         // Return the exports of the module
1046  /******/         return module.exports;
1047  /******/     }
1048  /******/     
1049  /************************************************************************/
1050  /**
1051   * @output wp-includes/js/media-grid.js
1052   */
1053  
1054  var media = wp.media;
1055  
1056  media.controller.EditAttachmentMetadata = __webpack_require__( 659 );
1057  media.view.MediaFrame.Manage = __webpack_require__( 8359 );
1058  media.view.Attachment.Details.TwoColumn = __webpack_require__( 1312 );
1059  media.view.MediaFrame.Manage.Router = __webpack_require__( 2429 );
1060  media.view.EditImage.Details = __webpack_require__( 8521 );
1061  media.view.MediaFrame.EditAttachments = __webpack_require__( 1003 );
1062  media.view.SelectModeToggleButton = __webpack_require__( 682 );
1063  media.view.DeleteSelectedButton = __webpack_require__( 6606 );
1064  media.view.DeleteSelectedPermanentlyButton = __webpack_require__( 5806 );
1065  
1066  /******/ })()
1067  ;


Generated : Fri Jul 31 08:20:18 2026 Cross-referenced by PHPXref