1 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
3 * wp.media.controller.EditAttachmentMetadata
5 * A state for editing an attachment's metadata.
8 * @augments wp.media.controller.State
9 * @augments Backbone.Model
11 var l10n = wp.media.view.l10n,
12 EditAttachmentMetadata;
14 EditAttachmentMetadata = wp.media.controller.State.extend({
16 id: 'edit-attachment',
17 // Title string passed to the frame's title region view.
18 title: l10n.attachmentDetails,
19 // Region mode defaults.
20 content: 'edit-metadata',
27 module.exports = EditAttachmentMetadata;
29 },{}],2:[function(require,module,exports){
32 media.controller.EditAttachmentMetadata = require( './controllers/edit-attachment-metadata.js' );
33 media.view.MediaFrame.Manage = require( './views/frame/manage.js' );
34 media.view.Attachment.Details.TwoColumn = require( './views/attachment/details-two-column.js' );
35 media.view.MediaFrame.Manage.Router = require( './routers/manage.js' );
36 media.view.EditImage.Details = require( './views/edit-image-details.js' );
37 media.view.MediaFrame.EditAttachments = require( './views/frame/edit-attachments.js' );
38 media.view.SelectModeToggleButton = require( './views/button/select-mode-toggle.js' );
39 media.view.DeleteSelectedButton = require( './views/button/delete-selected.js' );
40 media.view.DeleteSelectedPermanentlyButton = require( './views/button/delete-selected-permanently.js' );
42 },{"./controllers/edit-attachment-metadata.js":1,"./routers/manage.js":3,"./views/attachment/details-two-column.js":4,"./views/button/delete-selected-permanently.js":5,"./views/button/delete-selected.js":6,"./views/button/select-mode-toggle.js":7,"./views/edit-image-details.js":8,"./views/frame/edit-attachments.js":9,"./views/frame/manage.js":10}],3:[function(require,module,exports){
44 * wp.media.view.MediaFrame.Manage.Router
46 * A router for handling the browser history and application state.
49 * @augments Backbone.Router
51 var Router = Backbone.Router.extend({
53 'upload.php?item=:slug': 'showItem',
54 'upload.php?search=:query': 'search'
57 // Map routes against the page URL
58 baseUrl: function( url ) {
59 return 'upload.php' + url;
62 // Respond to the search route by filling the search field and trigggering the input event
63 search: function( query ) {
64 jQuery( '#media-search-input' ).val( query ).trigger( 'input' );
67 // Show the modal with a specific item
68 showItem: function( query ) {
70 library = media.frame.state().get('library'),
73 // Trigger the media frame to open the correct item
74 item = library.findWhere( { id: parseInt( query, 10 ) } );
76 media.frame.trigger( 'edit:attachment', item );
78 item = media.attachment( query );
79 media.frame.listenTo( item, 'change', function( model ) {
80 media.frame.stopListening( item );
81 media.frame.trigger( 'edit:attachment', model );
88 module.exports = Router;
90 },{}],4:[function(require,module,exports){
92 * wp.media.view.Attachment.Details.TwoColumn
94 * A similar view to media.view.Attachment.Details
95 * for use in the Edit Attachment modal.
98 * @augments wp.media.view.Attachment.Details
99 * @augments wp.media.view.Attachment
100 * @augments wp.media.View
101 * @augments wp.Backbone.View
102 * @augments Backbone.View
104 var Details = wp.media.view.Attachment.Details,
107 TwoColumn = Details.extend({
108 template: wp.template( 'attachment-details-two-column' ),
110 editAttachment: function( event ) {
111 event.preventDefault();
112 this.controller.content.mode( 'edit-image' );
116 * Noop this from parent class, doesn't apply here.
118 toggleSelectionHandler: function() {},
121 Details.prototype.render.apply( this, arguments );
123 wp.media.mixin.removeAllPlayers();
124 this.$( 'audio, video' ).each( function (i, elem) {
125 var el = wp.media.view.MediaDetails.prepareSrc( elem );
126 new window.MediaElementPlayer( el, wp.media.mixin.mejsSettings );
131 module.exports = TwoColumn;
133 },{}],5:[function(require,module,exports){
135 * wp.media.view.DeleteSelectedPermanentlyButton
137 * When MEDIA_TRASH is true, a button that handles bulk Delete Permanently logic
140 * @augments wp.media.view.DeleteSelectedButton
141 * @augments wp.media.view.Button
142 * @augments wp.media.View
143 * @augments wp.Backbone.View
144 * @augments Backbone.View
146 var Button = wp.media.view.Button,
147 DeleteSelected = wp.media.view.DeleteSelectedButton,
148 DeleteSelectedPermanently;
150 DeleteSelectedPermanently = DeleteSelected.extend({
151 initialize: function() {
152 DeleteSelected.prototype.initialize.apply( this, arguments );
153 this.listenTo( this.controller, 'select:activate', this.selectActivate );
154 this.listenTo( this.controller, 'select:deactivate', this.selectDeactivate );
157 filterChange: function( model ) {
158 this.canShow = ( 'trash' === model.get( 'status' ) );
161 selectActivate: function() {
162 this.toggleDisabled();
163 this.$el.toggleClass( 'hidden', ! this.canShow );
166 selectDeactivate: function() {
167 this.toggleDisabled();
168 this.$el.addClass( 'hidden' );
172 Button.prototype.render.apply( this, arguments );
173 this.selectActivate();
178 module.exports = DeleteSelectedPermanently;
180 },{}],6:[function(require,module,exports){
182 * wp.media.view.DeleteSelectedButton
184 * A button that handles bulk Delete/Trash logic
187 * @augments wp.media.view.Button
188 * @augments wp.media.View
189 * @augments wp.Backbone.View
190 * @augments Backbone.View
192 var Button = wp.media.view.Button,
193 l10n = wp.media.view.l10n,
196 DeleteSelected = Button.extend({
197 initialize: function() {
198 Button.prototype.initialize.apply( this, arguments );
199 if ( this.options.filters ) {
200 this.listenTo( this.options.filters.model, 'change', this.filterChange );
202 this.listenTo( this.controller, 'selection:toggle', this.toggleDisabled );
205 filterChange: function( model ) {
206 if ( 'trash' === model.get( 'status' ) ) {
207 this.model.set( 'text', l10n.untrashSelected );
208 } else if ( wp.media.view.settings.mediaTrash ) {
209 this.model.set( 'text', l10n.trashSelected );
211 this.model.set( 'text', l10n.deleteSelected );
215 toggleDisabled: function() {
216 this.model.set( 'disabled', ! this.controller.state().get( 'selection' ).length );
220 Button.prototype.render.apply( this, arguments );
221 if ( this.controller.isModeActive( 'select' ) ) {
222 this.$el.addClass( 'delete-selected-button' );
224 this.$el.addClass( 'delete-selected-button hidden' );
226 this.toggleDisabled();
231 module.exports = DeleteSelected;
233 },{}],7:[function(require,module,exports){
235 * wp.media.view.SelectModeToggleButton
238 * @augments wp.media.view.Button
239 * @augments wp.media.View
240 * @augments wp.Backbone.View
241 * @augments Backbone.View
243 var Button = wp.media.view.Button,
244 l10n = wp.media.view.l10n,
247 SelectModeToggle = Button.extend({
248 initialize: function() {
249 _.defaults( this.options, {
253 Button.prototype.initialize.apply( this, arguments );
254 this.listenTo( this.controller, 'select:activate select:deactivate', this.toggleBulkEditHandler );
255 this.listenTo( this.controller, 'selection:action:done', this.back );
259 this.controller.deactivateMode( 'select' ).activateMode( 'edit' );
263 Button.prototype.click.apply( this, arguments );
264 if ( this.controller.isModeActive( 'select' ) ) {
267 this.controller.deactivateMode( 'edit' ).activateMode( 'select' );
272 Button.prototype.render.apply( this, arguments );
273 this.$el.addClass( 'select-mode-toggle-button' );
277 toggleBulkEditHandler: function() {
278 var toolbar = this.controller.content.get().toolbar, children;
280 children = toolbar.$( '.media-toolbar-secondary > *, .media-toolbar-primary > *' );
282 // TODO: the Frame should be doing all of this.
283 if ( this.controller.isModeActive( 'select' ) ) {
286 text: l10n.cancelSelection
288 children.not( '.spinner, .media-button' ).hide();
290 toolbar.$( '.delete-selected-button' ).removeClass( 'hidden' );
294 text: l10n.bulkSelect
296 this.controller.content.get().$el.removeClass( 'fixed' );
297 toolbar.$el.css( 'width', '' );
298 toolbar.$( '.delete-selected-button' ).addClass( 'hidden' );
299 children.not( '.media-button' ).show();
300 this.controller.state().get( 'selection' ).reset();
305 module.exports = SelectModeToggle;
307 },{}],8:[function(require,module,exports){
309 * wp.media.view.EditImage.Details
312 * @augments wp.media.view.EditImage
313 * @augments wp.media.View
314 * @augments wp.Backbone.View
315 * @augments Backbone.View
317 var View = wp.media.View,
318 EditImage = wp.media.view.EditImage,
321 Details = EditImage.extend({
322 initialize: function( options ) {
323 this.editor = window.imageEdit;
324 this.frame = options.frame;
325 this.controller = options.controller;
326 View.prototype.initialize.apply( this, arguments );
330 this.frame.content.mode( 'edit-metadata' );
334 this.model.fetch().done( _.bind( function() {
335 this.frame.content.mode( 'edit-metadata' );
340 module.exports = Details;
342 },{}],9:[function(require,module,exports){
344 * wp.media.view.MediaFrame.EditAttachments
346 * A frame for editing the details of a specific media item.
348 * Opens in a modal by default.
350 * Requires an attachment model to be passed in the options hash under `model`.
353 * @augments wp.media.view.Frame
354 * @augments wp.media.View
355 * @augments wp.Backbone.View
356 * @augments Backbone.View
357 * @mixes wp.media.controller.StateMachine
359 var Frame = wp.media.view.Frame,
360 MediaFrame = wp.media.view.MediaFrame,
365 EditAttachments = MediaFrame.extend({
367 className: 'edit-attachment-frame',
368 template: wp.template( 'edit-attachment-frame' ),
369 regions: [ 'title', 'content' ],
372 'click .left': 'previousMediaItem',
373 'click .right': 'nextMediaItem'
376 initialize: function() {
377 Frame.prototype.initialize.apply( this, arguments );
379 _.defaults( this.options, {
381 state: 'edit-attachment'
384 this.controller = this.options.controller;
385 this.gridRouter = this.controller.gridRouter;
386 this.library = this.options.library;
388 if ( this.options.model ) {
389 this.model = this.options.model;
396 this.title.mode( 'default' );
400 bindHandlers: function() {
401 // Bind default title creation.
402 this.on( 'title:create:default', this.createTitle, this );
404 // Close the modal if the attachment is deleted.
405 this.listenTo( this.model, 'change:status destroy', this.close, this );
407 this.on( 'content:create:edit-metadata', this.editMetadataMode, this );
408 this.on( 'content:create:edit-image', this.editImageMode, this );
409 this.on( 'content:render:edit-image', this.editImageModeRender, this );
410 this.on( 'close', this.detach );
413 createModal: function() {
414 // Initialize modal container view.
415 if ( this.options.modal ) {
416 this.modal = new wp.media.view.Modal({
418 title: this.options.title
421 this.modal.on( 'open', _.bind( function () {
422 $( 'body' ).on( 'keydown.media-modal', _.bind( this.keyEvent, this ) );
425 // Completely destroy the modal DOM element when closing it.
426 this.modal.on( 'close', _.bind( function() {
428 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
429 // Restore the original focus item if possible
430 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
434 // Set this frame as the modal's content.
435 this.modal.content( this );
441 * Add the default states to the frame.
443 createStates: function() {
445 new wp.media.controller.EditAttachmentMetadata( { model: this.model } )
450 * Content region rendering callback for the `edit-metadata` mode.
452 * @param {Object} contentRegion Basic object with a `view` property, which
453 * should be set with the proper region view.
455 editMetadataMode: function( contentRegion ) {
456 contentRegion.view = new wp.media.view.Attachment.Details.TwoColumn({
462 * Attach a subview to display fields added via the
463 * `attachment_fields_to_edit` filter.
465 contentRegion.view.views.set( '.attachment-compat', new wp.media.view.AttachmentCompat({
470 // Update browser url when navigating media details
472 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) );
477 * Render the EditImage view into the frame's content region.
479 * @param {Object} contentRegion Basic object with a `view` property, which
480 * should be set with the proper region view.
482 editImageMode: function( contentRegion ) {
483 var editImageController = new wp.media.controller.EditImage( {
487 // Noop some methods.
488 editImageController._toolbar = function() {};
489 editImageController._router = function() {};
490 editImageController._menu = function() {};
492 contentRegion.view = new wp.media.view.EditImage.Details( {
495 controller: editImageController
499 editImageModeRender: function( view ) {
500 view.on( 'ready', view.loadEditor );
503 toggleNav: function() {
504 this.$('.left').toggleClass( 'disabled', ! this.hasPrevious() );
505 this.$('.right').toggleClass( 'disabled', ! this.hasNext() );
511 rerender: function() {
512 // Only rerender the `content` region.
513 if ( this.content.mode() !== 'edit-metadata' ) {
514 this.content.mode( 'edit-metadata' );
516 this.content.render();
523 * Click handler to switch to the previous media item.
525 previousMediaItem: function() {
526 if ( ! this.hasPrevious() ) {
527 this.$( '.left' ).blur();
530 this.model = this.library.at( this.getCurrentIndex() - 1 );
532 this.$( '.left' ).focus();
536 * Click handler to switch to the next media item.
538 nextMediaItem: function() {
539 if ( ! this.hasNext() ) {
540 this.$( '.right' ).blur();
543 this.model = this.library.at( this.getCurrentIndex() + 1 );
545 this.$( '.right' ).focus();
548 getCurrentIndex: function() {
549 return this.library.indexOf( this.model );
552 hasNext: function() {
553 return ( this.getCurrentIndex() + 1 ) < this.library.length;
556 hasPrevious: function() {
557 return ( this.getCurrentIndex() - 1 ) > -1;
560 * Respond to the keyboard events: right arrow, left arrow, except when
561 * focus is in a textarea or input field.
563 keyEvent: function( event ) {
564 if ( ( 'INPUT' === event.target.nodeName || 'TEXTAREA' === event.target.nodeName ) && ! ( event.target.readOnly || event.target.disabled ) ) {
568 // The right arrow key
569 if ( 39 === event.keyCode ) {
570 this.nextMediaItem();
572 // The left arrow key
573 if ( 37 === event.keyCode ) {
574 this.previousMediaItem();
578 resetRoute: function() {
579 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) );
583 module.exports = EditAttachments;
585 },{}],10:[function(require,module,exports){
587 * wp.media.view.MediaFrame.Manage
589 * A generic management frame workflow.
591 * Used in the media grid view.
594 * @augments wp.media.view.MediaFrame
595 * @augments wp.media.view.Frame
596 * @augments wp.media.View
597 * @augments wp.Backbone.View
598 * @augments Backbone.View
599 * @mixes wp.media.controller.StateMachine
601 var MediaFrame = wp.media.view.MediaFrame,
602 Library = wp.media.controller.Library,
607 Manage = MediaFrame.extend({
609 * @global wp.Uploader
611 initialize: function() {
612 _.defaults( this.options, {
616 library: {}, // Options hash for the query to the media library.
620 mode: [ 'grid', 'edit' ]
623 this.$body = $( document.body );
624 this.$window = $( window );
625 this.$adminBar = $( '#wpadminbar' );
626 this.$window.on( 'scroll resize', _.debounce( _.bind( this.fixPosition, this ), 15 ) );
627 $( document ).on( 'click', '.page-title-action', _.bind( this.addNewClickHandler, this ) );
629 // Ensure core and media grid view UI is enabled.
630 this.$el.addClass('wp-core-ui');
632 // Force the uploader off if the upload limit has been exceeded or
633 // if the browser isn't supported.
634 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
635 this.options.uploader = false;
638 // Initialize a window-wide uploader.
639 if ( this.options.uploader ) {
640 this.uploader = new wp.media.view.UploaderWindow({
643 dropzone: document.body,
644 container: document.body
647 this.uploader.ready();
648 $('body').append( this.uploader.el );
650 this.options.uploader = false;
653 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router();
655 // Call 'initialize' directly on the parent class.
656 MediaFrame.prototype.initialize.apply( this, arguments );
658 // Append the frame view directly the supplied container.
659 this.$el.appendTo( this.options.container );
662 this.bindRegionModeHandlers();
664 this.bindSearchHandler();
667 bindSearchHandler: function() {
668 var search = this.$( '#media-search-input' ),
669 currentSearch = this.options.container.data( 'search' ),
670 searchView = this.browserView.toolbar.get( 'search' ).$el,
671 listMode = this.$( '.view-list' ),
673 input = _.debounce( function (e) {
674 var val = $( e.currentTarget ).val(),
678 url += '?search=' + val;
680 this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );
683 // Update the URL when entering search string (at most once per second)
684 search.on( 'input', _.bind( input, this ) );
685 searchView.val( currentSearch ).trigger( 'input' );
687 this.gridRouter.on( 'route:search', function () {
688 var href = window.location.href;
689 if ( href.indexOf( 'mode=' ) > -1 ) {
690 href = href.replace( /mode=[^&]+/g, 'mode=list' );
692 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
694 href = href.replace( 'search=', 's=' );
695 listMode.prop( 'href', href );
700 * Create the default states for the frame.
702 createStates: function() {
703 var options = this.options;
705 if ( this.options.states ) {
709 // Add the default states.
712 library: wp.media.query( options.library ),
713 multiple: options.multiple,
714 title: options.title,
717 contentUserSetting: false,
725 * Bind region mode activation events to proper handlers.
727 bindRegionModeHandlers: function() {
728 this.on( 'content:create:browse', this.browseContent, this );
730 // Handle a frame-level event for editing an attachment.
731 this.on( 'edit:attachment', this.openEditAttachmentModal, this );
733 this.on( 'select:activate', this.bindKeydown, this );
734 this.on( 'select:deactivate', this.unbindKeydown, this );
737 handleKeydown: function( e ) {
738 if ( 27 === e.which ) {
740 this.deactivateMode( 'select' ).activateMode( 'edit' );
744 bindKeydown: function() {
745 this.$body.on( 'keydown.select', _.bind( this.handleKeydown, this ) );
748 unbindKeydown: function() {
749 this.$body.off( 'keydown.select' );
752 fixPosition: function() {
753 var $browser, $toolbar;
754 if ( ! this.isModeActive( 'select' ) ) {
758 $browser = this.$('.attachments-browser');
759 $toolbar = $browser.find('.media-toolbar');
761 // Offset doesn't appear to take top margin into account, hence +16
762 if ( ( $browser.offset().top + 16 ) < this.$window.scrollTop() + this.$adminBar.height() ) {
763 $browser.addClass( 'fixed' );
764 $toolbar.css('width', $browser.width() + 'px');
766 $browser.removeClass( 'fixed' );
767 $toolbar.css('width', '');
772 * Click handler for the `Add New` button.
774 addNewClickHandler: function( event ) {
775 event.preventDefault();
776 this.trigger( 'toggle:upload:attachment' );
780 * Open the Edit Attachment modal.
782 openEditAttachmentModal: function( model ) {
783 // Create a new EditAttachment frame, passing along the library and the attachment model.
785 frame: 'edit-attachments',
787 library: this.state().get('library'),
793 * Create an attachments browser view within the content region.
795 * @param {Object} contentRegion Basic object with a `view` property, which
796 * should be set with the proper region view.
797 * @this wp.media.controller.Region
799 browseContent: function( contentRegion ) {
800 var state = this.state();
802 // Browse our library of attachments.
803 this.browserView = contentRegion.view = new wp.media.view.AttachmentsBrowser({
805 collection: state.get('library'),
806 selection: state.get('selection'),
808 sortable: state.get('sortable'),
809 search: state.get('searchable'),
810 filters: state.get('filterable'),
811 date: state.get('date'),
812 display: state.get('displaySettings'),
813 dragInfo: state.get('dragInfo'),
816 suggestedWidth: state.get('suggestedWidth'),
817 suggestedHeight: state.get('suggestedHeight'),
819 AttachmentView: state.get('AttachmentView'),
821 scrollElement: document
823 this.browserView.on( 'ready', _.bind( this.bindDeferred, this ) );
825 this.errors = wp.Uploader.errors;
826 this.errors.on( 'add remove reset', this.sidebarVisibility, this );
829 sidebarVisibility: function() {
830 this.browserView.$( '.media-sidebar' ).toggle( !! this.errors.length );
833 bindDeferred: function() {
834 if ( ! this.browserView.dfd ) {
837 this.browserView.dfd.done( _.bind( this.startHistory, this ) );
840 startHistory: function() {
841 // Verify pushState support and activate
842 if ( window.history && window.history.pushState ) {
843 Backbone.history.start( {
844 root: window._wpMediaGridSettings.adminUrl,
851 module.exports = Manage;