You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1026 lines
26 KiB

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