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.CollectionAdd
5 * A state for adding attachments to a collection (e.g. video playlist).
8 * @augments wp.media.controller.Library
9 * @augments wp.media.controller.State
10 * @augments Backbone.Model
12 * @param {object} [attributes] The attributes hash passed to the state.
13 * @param {string} [attributes.id=library] Unique identifier.
14 * @param {string} attributes.title Title for the state. Displays in the frame's title region.
15 * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
16 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
17 * If one is not supplied, a collection of attachments of the specified type will be created.
18 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
19 * Accepts 'all', 'uploaded', or 'unattached'.
20 * @param {string} [attributes.menu=gallery] Initial mode for the menu region.
21 * @param {string} [attributes.content=upload] Initial mode for the content region.
22 * Overridden by persistent user setting if 'contentUserSetting' is true.
23 * @param {string} [attributes.router=browse] Initial mode for the router region.
24 * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
25 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
26 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
27 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
28 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
29 * @param {int} [attributes.priority=100] The priority for the state link in the media menu.
30 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
31 * Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
32 * @param {string} attributes.type The collection's media type. (e.g. 'video').
33 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist').
35 var Selection = wp.media.model.Selection,
36 Library = wp.media.controller.Library,
39 CollectionAdd = Library.extend({
40 defaults: _.defaults( {
41 // Selection defaults. @see media.model.Selection
43 // Attachments browser defaults. @see media.view.AttachmentsBrowser
44 filterable: 'uploaded',
48 }, Library.prototype.defaults ),
53 initialize: function() {
54 var collectionType = this.get('collectionType');
56 if ( 'video' === this.get( 'type' ) ) {
57 collectionType = 'video-' + collectionType;
60 this.set( 'id', collectionType + '-library' );
61 this.set( 'toolbar', collectionType + '-add' );
62 this.set( 'menu', collectionType );
64 // If we haven't been provided a `library`, create a `Selection`.
65 if ( ! this.get('library') ) {
66 this.set( 'library', wp.media.query({ type: this.get('type') }) );
68 Library.prototype.initialize.apply( this, arguments );
74 activate: function() {
75 var library = this.get('library'),
76 editLibrary = this.get('editLibrary'),
77 edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
79 if ( editLibrary && editLibrary !== edit ) {
80 library.unobserve( editLibrary );
83 // Accepts attachments that exist in the original library and
84 // that do not exist in gallery's library.
85 library.validator = function( attachment ) {
86 return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments );
89 // Reset the library to ensure that all attachments are re-added
90 // to the collection. Do so silently, as calling `observe` will
91 // trigger the `reset` event.
92 library.reset( library.mirroring.models, { silent: true });
93 library.observe( edit );
94 this.set('editLibrary', edit);
96 Library.prototype.activate.apply( this, arguments );
100 module.exports = CollectionAdd;
102 },{}],2:[function(require,module,exports){
104 * wp.media.controller.CollectionEdit
106 * A state for editing a collection, which is used by audio and video playlists,
107 * and can be used for other collections.
110 * @augments wp.media.controller.Library
111 * @augments wp.media.controller.State
112 * @augments Backbone.Model
114 * @param {object} [attributes] The attributes hash passed to the state.
115 * @param {string} attributes.title Title for the state. Displays in the media menu and the frame's title region.
116 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to edit.
117 * If one is not supplied, an empty media.model.Selection collection is created.
118 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
119 * @param {string} [attributes.content=browse] Initial mode for the content region.
120 * @param {string} attributes.menu Initial mode for the menu region. @todo this needs a better explanation.
121 * @param {boolean} [attributes.searchable=false] Whether the library is searchable.
122 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
123 * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar.
124 * @param {boolean} [attributes.describe=true] Whether to offer UI to describe the attachments - e.g. captioning images in a gallery.
125 * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable.
126 * @param {boolean} [attributes.dragInfoText] Instructional text about the attachments being sortable.
127 * @param {int} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments.
128 * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance.
129 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
130 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
131 * Defaults to false for this state, because the library passed in *is* the selection.
132 * @param {view} [attributes.SettingsView] The view to edit the collection instance settings (e.g. Playlist settings with "Show tracklist" checkbox).
133 * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
134 * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
135 * @param {string} attributes.type The collection's media type. (e.g. 'video').
136 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist').
138 var Library = wp.media.controller.Library,
139 l10n = wp.media.view.l10n,
143 CollectionEdit = Library.extend({
152 idealColumnWidth: 170,
162 initialize: function() {
163 var collectionType = this.get('collectionType');
165 if ( 'video' === this.get( 'type' ) ) {
166 collectionType = 'video-' + collectionType;
169 this.set( 'id', collectionType + '-edit' );
170 this.set( 'toolbar', collectionType + '-edit' );
172 // If we haven't been provided a `library`, create a `Selection`.
173 if ( ! this.get('library') ) {
174 this.set( 'library', new wp.media.model.Selection() );
176 // The single `Attachment` view to be used in the `Attachments` view.
177 if ( ! this.get('AttachmentView') ) {
178 this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary );
180 Library.prototype.initialize.apply( this, arguments );
186 activate: function() {
187 var library = this.get('library');
189 // Limit the library to images only.
190 library.props.set( 'type', this.get( 'type' ) );
192 // Watch for uploaded attachments.
193 this.get('library').observe( wp.Uploader.queue );
195 this.frame.on( 'content:render:browse', this.renderSettings, this );
197 Library.prototype.activate.apply( this, arguments );
203 deactivate: function() {
204 // Stop watching for uploaded attachments.
205 this.get('library').unobserve( wp.Uploader.queue );
207 this.frame.off( 'content:render:browse', this.renderSettings, this );
209 Library.prototype.deactivate.apply( this, arguments );
213 * Render the collection embed settings view in the browser sidebar.
215 * @todo This is against the pattern elsewhere in media. Typically the frame
216 * is responsible for adding region mode callbacks. Explain.
220 * @param {wp.media.view.attachmentsBrowser} The attachments browser view.
222 renderSettings: function( attachmentsBrowserView ) {
223 var library = this.get('library'),
224 collectionType = this.get('collectionType'),
225 dragInfoText = this.get('dragInfoText'),
226 SettingsView = this.get('SettingsView'),
229 if ( ! library || ! attachmentsBrowserView ) {
233 library[ collectionType ] = library[ collectionType ] || new Backbone.Model();
235 obj[ collectionType ] = new SettingsView({
237 model: library[ collectionType ],
241 attachmentsBrowserView.sidebar.set( obj );
243 if ( dragInfoText ) {
244 attachmentsBrowserView.toolbar.set( 'dragInfo', new wp.media.View({
245 el: $( '<div class="instructions">' + dragInfoText + '</div>' )[0],
250 // Add the 'Reverse order' button to the toolbar.
251 attachmentsBrowserView.toolbar.set( 'reverse', {
252 text: l10n.reverseOrder,
256 library.reset( library.toArray().reverse() );
262 module.exports = CollectionEdit;
264 },{}],3:[function(require,module,exports){
266 * wp.media.controller.Cropper
268 * A state for cropping an image.
271 * @augments wp.media.controller.State
272 * @augments Backbone.Model
274 var l10n = wp.media.view.l10n,
277 Cropper = wp.media.controller.State.extend({
280 title: l10n.cropImage,
281 // Region mode defaults.
289 activate: function() {
290 this.frame.on( 'content:create:crop', this.createCropContent, this );
291 this.frame.on( 'close', this.removeCropper, this );
292 this.set('selection', new Backbone.Collection(this.frame._selection.single));
295 deactivate: function() {
296 this.frame.toolbar.mode('browse');
299 createCropContent: function() {
300 this.cropperView = new wp.media.view.Cropper({
302 attachment: this.get('selection').first()
304 this.cropperView.on('image-loaded', this.createCropToolbar, this);
305 this.frame.content.set(this.cropperView);
308 removeCropper: function() {
309 this.imgSelect.cancelSelection();
310 this.imgSelect.setOptions({remove: true});
311 this.imgSelect.update();
312 this.cropperView.remove();
314 createCropToolbar: function() {
315 var canSkipCrop, toolbarOptions;
317 canSkipCrop = this.get('canSkipCrop') || false;
320 controller: this.frame,
324 text: l10n.cropImage,
326 requires: { library: false, selection: false },
329 var controller = this.controller,
332 selection = controller.state().get('selection').first();
333 selection.set({cropDetails: controller.state().imgSelect.getSelection()});
335 this.$el.text(l10n.cropping);
336 this.$el.attr('disabled', true);
338 controller.state().doCrop( selection ).done( function( croppedImage ) {
339 controller.trigger('cropped', croppedImage );
341 }).fail( function() {
342 controller.trigger('content:error:crop');
350 _.extend( toolbarOptions.items, {
353 text: l10n.skipCropping,
355 requires: { library: false, selection: false },
357 var selection = this.controller.state().get('selection').first();
358 this.controller.state().cropperView.remove();
359 this.controller.trigger('skippedcrop', selection);
360 this.controller.close();
366 this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
369 doCrop: function( attachment ) {
370 return wp.ajax.post( 'custom-header-crop', {
371 nonce: attachment.get('nonces').edit,
372 id: attachment.get('id'),
373 cropDetails: attachment.get('cropDetails')
378 module.exports = Cropper;
380 },{}],4:[function(require,module,exports){
382 * wp.media.controller.CustomizeImageCropper
384 * A state for cropping an image.
387 * @augments wp.media.controller.Cropper
388 * @augments wp.media.controller.State
389 * @augments Backbone.Model
391 var Controller = wp.media.controller,
392 CustomizeImageCropper;
394 CustomizeImageCropper = Controller.Cropper.extend({
395 doCrop: function( attachment ) {
396 var cropDetails = attachment.get( 'cropDetails' ),
397 control = this.get( 'control' );
399 cropDetails.dst_width = control.params.width;
400 cropDetails.dst_height = control.params.height;
402 return wp.ajax.post( 'crop-image', {
404 nonce: attachment.get( 'nonces' ).edit,
405 id: attachment.get( 'id' ),
407 cropDetails: cropDetails
412 module.exports = CustomizeImageCropper;
414 },{}],5:[function(require,module,exports){
416 * wp.media.controller.EditImage
418 * A state for editing (cropping, etc.) an image.
421 * @augments wp.media.controller.State
422 * @augments Backbone.Model
424 * @param {object} attributes The attributes hash passed to the state.
425 * @param {wp.media.model.Attachment} attributes.model The attachment.
426 * @param {string} [attributes.id=edit-image] Unique identifier.
427 * @param {string} [attributes.title=Edit Image] Title for the state. Displays in the media menu and the frame's title region.
428 * @param {string} [attributes.content=edit-image] Initial mode for the content region.
429 * @param {string} [attributes.toolbar=edit-image] Initial mode for the toolbar region.
430 * @param {string} [attributes.menu=false] Initial mode for the menu region.
431 * @param {string} [attributes.url] Unused. @todo Consider removal.
433 var l10n = wp.media.view.l10n,
436 EditImage = wp.media.controller.State.extend({
439 title: l10n.editImage,
441 toolbar: 'edit-image',
442 content: 'edit-image',
449 activate: function() {
450 this.listenTo( this.frame, 'toolbar:render:edit-image', this.toolbar );
456 deactivate: function() {
457 this.stopListening( this.frame );
463 toolbar: function() {
464 var frame = this.frame,
465 lastState = frame.lastState(),
466 previous = lastState && lastState.id;
468 frame.toolbar.set( new wp.media.view.Toolbar({
477 frame.setState( previous );
488 module.exports = EditImage;
490 },{}],6:[function(require,module,exports){
492 * wp.media.controller.Embed
494 * A state for embedding media from a URL.
497 * @augments wp.media.controller.State
498 * @augments Backbone.Model
500 * @param {object} attributes The attributes hash passed to the state.
501 * @param {string} [attributes.id=embed] Unique identifier.
502 * @param {string} [attributes.title=Insert From URL] Title for the state. Displays in the media menu and the frame's title region.
503 * @param {string} [attributes.content=embed] Initial mode for the content region.
504 * @param {string} [attributes.menu=default] Initial mode for the menu region.
505 * @param {string} [attributes.toolbar=main-embed] Initial mode for the toolbar region.
506 * @param {string} [attributes.menu=false] Initial mode for the menu region.
507 * @param {int} [attributes.priority=120] The priority for the state link in the media menu.
508 * @param {string} [attributes.type=link] The type of embed. Currently only link is supported.
509 * @param {string} [attributes.url] The embed URL.
510 * @param {object} [attributes.metadata={}] Properties of the embed, which will override attributes.url if set.
512 var l10n = wp.media.view.l10n,
516 Embed = wp.media.controller.State.extend({
519 title: l10n.insertFromUrlTitle,
522 toolbar: 'main-embed',
529 // The amount of time used when debouncing the scan.
532 initialize: function(options) {
533 this.metadata = options.metadata;
534 this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
535 this.props = new Backbone.Model( this.metadata || { url: '' });
536 this.props.on( 'change:url', this.debouncedScan, this );
537 this.props.on( 'change:url', this.refresh, this );
538 this.on( 'scan', this.scanImage, this );
542 * Trigger a scan of the embedded URL's content for metadata required to embed.
544 * @fires wp.media.controller.Embed#scan
554 // Scan is triggered with the list of `attributes` to set on the
555 // state, useful for the 'type' attribute and 'scanners' attribute,
556 // an array of promise objects for asynchronous scan operations.
557 if ( this.props.get('url') ) {
558 this.trigger( 'scan', attributes );
561 if ( attributes.scanners.length ) {
562 scanners = attributes.scanners = $.when.apply( $, attributes.scanners );
563 scanners.always( function() {
564 if ( embed.get('scanners') === scanners ) {
565 embed.set( 'loading', false );
569 attributes.scanners = null;
572 attributes.loading = !! attributes.scanners;
573 this.set( attributes );
576 * Try scanning the embed as an image to discover its dimensions.
578 * @param {Object} attributes
580 scanImage: function( attributes ) {
581 var frame = this.frame,
583 url = this.props.get('url'),
585 deferred = $.Deferred();
587 attributes.scanners.push( deferred.promise() );
589 // Try to load the image and find its width/height.
590 image.onload = function() {
593 if ( state !== frame.state() || url !== state.props.get('url') ) {
607 image.onerror = deferred.reject;
611 refresh: function() {
612 this.frame.toolbar.get().refresh();
616 this.props.clear().set({ url: '' });
624 module.exports = Embed;
626 },{}],7:[function(require,module,exports){
628 * wp.media.controller.FeaturedImage
630 * A state for selecting a featured image for a post.
633 * @augments wp.media.controller.Library
634 * @augments wp.media.controller.State
635 * @augments Backbone.Model
637 * @param {object} [attributes] The attributes hash passed to the state.
638 * @param {string} [attributes.id=featured-image] Unique identifier.
639 * @param {string} [attributes.title=Set Featured Image] Title for the state. Displays in the media menu and the frame's title region.
640 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
641 * If one is not supplied, a collection of all images will be created.
642 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
643 * @param {string} [attributes.content=upload] Initial mode for the content region.
644 * Overridden by persistent user setting if 'contentUserSetting' is true.
645 * @param {string} [attributes.menu=default] Initial mode for the menu region.
646 * @param {string} [attributes.router=browse] Initial mode for the router region.
647 * @param {string} [attributes.toolbar=featured-image] Initial mode for the toolbar region.
648 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
649 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
650 * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
651 * Accepts 'all', 'uploaded', or 'unattached'.
652 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
653 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
654 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
655 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
656 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
658 var Attachment = wp.media.model.Attachment,
659 Library = wp.media.controller.Library,
660 l10n = wp.media.view.l10n,
663 FeaturedImage = Library.extend({
664 defaults: _.defaults({
665 id: 'featured-image',
666 title: l10n.setFeaturedImageTitle,
668 filterable: 'uploaded',
669 toolbar: 'featured-image',
672 }, Library.prototype.defaults ),
677 initialize: function() {
678 var library, comparator;
680 // If we haven't been provided a `library`, create a `Selection`.
681 if ( ! this.get('library') ) {
682 this.set( 'library', wp.media.query({ type: 'image' }) );
685 Library.prototype.initialize.apply( this, arguments );
687 library = this.get('library');
688 comparator = library.comparator;
690 // Overload the library's comparator to push items that are not in
691 // the mirrored query to the front of the aggregate collection.
692 library.comparator = function( a, b ) {
693 var aInQuery = !! this.mirroring.get( a.cid ),
694 bInQuery = !! this.mirroring.get( b.cid );
696 if ( ! aInQuery && bInQuery ) {
698 } else if ( aInQuery && ! bInQuery ) {
701 return comparator.apply( this, arguments );
705 // Add all items in the selection to the library, so any featured
706 // images that are not initially loaded still appear.
707 library.observe( this.get('selection') );
713 activate: function() {
714 this.updateSelection();
715 this.frame.on( 'open', this.updateSelection, this );
717 Library.prototype.activate.apply( this, arguments );
723 deactivate: function() {
724 this.frame.off( 'open', this.updateSelection, this );
726 Library.prototype.deactivate.apply( this, arguments );
732 updateSelection: function() {
733 var selection = this.get('selection'),
734 id = wp.media.view.settings.post.featuredImageId,
737 if ( '' !== id && -1 !== id ) {
738 attachment = Attachment.get( id );
742 selection.reset( attachment ? [ attachment ] : [] );
746 module.exports = FeaturedImage;
748 },{}],8:[function(require,module,exports){
750 * wp.media.controller.GalleryAdd
752 * A state for selecting more images to add to a gallery.
755 * @augments wp.media.controller.Library
756 * @augments wp.media.controller.State
757 * @augments Backbone.Model
759 * @param {object} [attributes] The attributes hash passed to the state.
760 * @param {string} [attributes.id=gallery-library] Unique identifier.
761 * @param {string} [attributes.title=Add to Gallery] Title for the state. Displays in the frame's title region.
762 * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
763 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
764 * If one is not supplied, a collection of all images will be created.
765 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
766 * Accepts 'all', 'uploaded', or 'unattached'.
767 * @param {string} [attributes.menu=gallery] Initial mode for the menu region.
768 * @param {string} [attributes.content=upload] Initial mode for the content region.
769 * Overridden by persistent user setting if 'contentUserSetting' is true.
770 * @param {string} [attributes.router=browse] Initial mode for the router region.
771 * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
772 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
773 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
774 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
775 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
776 * @param {int} [attributes.priority=100] The priority for the state link in the media menu.
777 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
778 * Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
780 var Selection = wp.media.model.Selection,
781 Library = wp.media.controller.Library,
782 l10n = wp.media.view.l10n,
785 GalleryAdd = Library.extend({
786 defaults: _.defaults({
787 id: 'gallery-library',
788 title: l10n.addToGalleryTitle,
790 filterable: 'uploaded',
792 toolbar: 'gallery-add',
795 }, Library.prototype.defaults ),
800 initialize: function() {
801 // If a library wasn't supplied, create a library of images.
802 if ( ! this.get('library') ) {
803 this.set( 'library', wp.media.query({ type: 'image' }) );
806 Library.prototype.initialize.apply( this, arguments );
812 activate: function() {
813 var library = this.get('library'),
814 edit = this.frame.state('gallery-edit').get('library');
816 if ( this.editLibrary && this.editLibrary !== edit ) {
817 library.unobserve( this.editLibrary );
820 // Accepts attachments that exist in the original library and
821 // that do not exist in gallery's library.
822 library.validator = function( attachment ) {
823 return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments );
826 // Reset the library to ensure that all attachments are re-added
827 // to the collection. Do so silently, as calling `observe` will
828 // trigger the `reset` event.
829 library.reset( library.mirroring.models, { silent: true });
830 library.observe( edit );
831 this.editLibrary = edit;
833 Library.prototype.activate.apply( this, arguments );
837 module.exports = GalleryAdd;
839 },{}],9:[function(require,module,exports){
841 * wp.media.controller.GalleryEdit
843 * A state for editing a gallery's images and settings.
846 * @augments wp.media.controller.Library
847 * @augments wp.media.controller.State
848 * @augments Backbone.Model
850 * @param {object} [attributes] The attributes hash passed to the state.
851 * @param {string} [attributes.id=gallery-edit] Unique identifier.
852 * @param {string} [attributes.title=Edit Gallery] Title for the state. Displays in the frame's title region.
853 * @param {wp.media.model.Attachments} [attributes.library] The collection of attachments in the gallery.
854 * If one is not supplied, an empty media.model.Selection collection is created.
855 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
856 * @param {boolean} [attributes.searchable=false] Whether the library is searchable.
857 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
858 * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar.
859 * @param {string|false} [attributes.content=browse] Initial mode for the content region.
860 * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
861 * @param {boolean} [attributes.describe=true] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
862 * @param {boolean} [attributes.displaySettings=true] Whether to show the attachment display settings interface.
863 * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable.
864 * @param {int} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments.
865 * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance.
866 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
867 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
868 * Defaults to false for this state, because the library passed in *is* the selection.
869 * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
870 * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
872 var Library = wp.media.controller.Library,
873 l10n = wp.media.view.l10n,
876 GalleryEdit = Library.extend({
879 title: l10n.editGalleryTitle,
886 toolbar: 'gallery-edit',
888 displaySettings: true,
890 idealColumnWidth: 170,
899 initialize: function() {
900 // If we haven't been provided a `library`, create a `Selection`.
901 if ( ! this.get('library') ) {
902 this.set( 'library', new wp.media.model.Selection() );
905 // The single `Attachment` view to be used in the `Attachments` view.
906 if ( ! this.get('AttachmentView') ) {
907 this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary );
910 Library.prototype.initialize.apply( this, arguments );
916 activate: function() {
917 var library = this.get('library');
919 // Limit the library to images only.
920 library.props.set( 'type', 'image' );
922 // Watch for uploaded attachments.
923 this.get('library').observe( wp.Uploader.queue );
925 this.frame.on( 'content:render:browse', this.gallerySettings, this );
927 Library.prototype.activate.apply( this, arguments );
933 deactivate: function() {
934 // Stop watching for uploaded attachments.
935 this.get('library').unobserve( wp.Uploader.queue );
937 this.frame.off( 'content:render:browse', this.gallerySettings, this );
939 Library.prototype.deactivate.apply( this, arguments );
947 gallerySettings: function( browser ) {
948 if ( ! this.get('displaySettings') ) {
952 var library = this.get('library');
954 if ( ! library || ! browser ) {
958 library.gallery = library.gallery || new Backbone.Model();
960 browser.sidebar.set({
961 gallery: new wp.media.view.Settings.Gallery({
963 model: library.gallery,
968 browser.toolbar.set( 'reverse', {
969 text: l10n.reverseOrder,
973 library.reset( library.toArray().reverse() );
979 module.exports = GalleryEdit;
981 },{}],10:[function(require,module,exports){
983 * wp.media.controller.ImageDetails
985 * A state for editing the attachment display settings of an image that's been
986 * inserted into the editor.
989 * @augments wp.media.controller.State
990 * @augments Backbone.Model
992 * @param {object} [attributes] The attributes hash passed to the state.
993 * @param {string} [attributes.id=image-details] Unique identifier.
994 * @param {string} [attributes.title=Image Details] Title for the state. Displays in the frame's title region.
995 * @param {wp.media.model.Attachment} attributes.image The image's model.
996 * @param {string|false} [attributes.content=image-details] Initial mode for the content region.
997 * @param {string|false} [attributes.menu=false] Initial mode for the menu region.
998 * @param {string|false} [attributes.router=false] Initial mode for the router region.
999 * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
1000 * @param {boolean} [attributes.editing=false] Unused.
1001 * @param {int} [attributes.priority=60] Unused.
1003 * @todo This state inherits some defaults from media.controller.Library.prototype.defaults,
1004 * however this may not do anything.
1006 var State = wp.media.controller.State,
1007 Library = wp.media.controller.Library,
1008 l10n = wp.media.view.l10n,
1011 ImageDetails = State.extend({
1012 defaults: _.defaults({
1013 id: 'image-details',
1014 title: l10n.imageDetailsTitle,
1015 content: 'image-details',
1018 toolbar: 'image-details',
1021 }, Library.prototype.defaults ),
1026 * @param options Attributes
1028 initialize: function( options ) {
1029 this.image = options.image;
1030 State.prototype.initialize.apply( this, arguments );
1036 activate: function() {
1037 this.frame.modal.$el.addClass('image-details');
1041 module.exports = ImageDetails;
1043 },{}],11:[function(require,module,exports){
1045 * wp.media.controller.Library
1047 * A state for choosing an attachment or group of attachments from the media library.
1050 * @augments wp.media.controller.State
1051 * @augments Backbone.Model
1052 * @mixes media.selectionSync
1054 * @param {object} [attributes] The attributes hash passed to the state.
1055 * @param {string} [attributes.id=library] Unique identifier.
1056 * @param {string} [attributes.title=Media library] Title for the state. Displays in the media menu and the frame's title region.
1057 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
1058 * If one is not supplied, a collection of all attachments will be created.
1059 * @param {wp.media.model.Selection|object} [attributes.selection] A collection to contain attachment selections within the state.
1060 * If the 'selection' attribute is a plain JS object,
1061 * a Selection will be created using its values as the selection instance's `props` model.
1062 * Otherwise, it will copy the library's `props` model.
1063 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
1064 * @param {string} [attributes.content=upload] Initial mode for the content region.
1065 * Overridden by persistent user setting if 'contentUserSetting' is true.
1066 * @param {string} [attributes.menu=default] Initial mode for the menu region.
1067 * @param {string} [attributes.router=browse] Initial mode for the router region.
1068 * @param {string} [attributes.toolbar=select] Initial mode for the toolbar region.
1069 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
1070 * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
1071 * Accepts 'all', 'uploaded', or 'unattached'.
1072 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
1073 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
1074 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
1075 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
1076 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
1078 var l10n = wp.media.view.l10n,
1079 getUserSetting = window.getUserSetting,
1080 setUserSetting = window.setUserSetting,
1083 Library = wp.media.controller.State.extend({
1086 title: l10n.mediaLibraryTitle,
1097 contentUserSetting: true,
1102 * If a library isn't provided, query all media items.
1103 * If a selection instance isn't provided, create one.
1107 initialize: function() {
1108 var selection = this.get('selection'),
1111 if ( ! this.get('library') ) {
1112 this.set( 'library', wp.media.query() );
1115 if ( ! ( selection instanceof wp.media.model.Selection ) ) {
1119 props = this.get('library').props.toJSON();
1120 props = _.omit( props, 'orderby', 'query' );
1123 this.set( 'selection', new wp.media.model.Selection( null, {
1124 multiple: this.get('multiple'),
1129 this.resetDisplays();
1135 activate: function() {
1136 this.syncSelection();
1138 wp.Uploader.queue.on( 'add', this.uploading, this );
1140 this.get('selection').on( 'add remove reset', this.refreshContent, this );
1142 if ( this.get( 'router' ) && this.get('contentUserSetting') ) {
1143 this.frame.on( 'content:activate', this.saveContentMode, this );
1144 this.set( 'content', getUserSetting( 'libraryContent', this.get('content') ) );
1151 deactivate: function() {
1152 this.recordSelection();
1154 this.frame.off( 'content:activate', this.saveContentMode, this );
1156 // Unbind all event handlers that use this state as the context
1157 // from the selection.
1158 this.get('selection').off( null, null, this );
1160 wp.Uploader.queue.off( null, null, this );
1164 * Reset the library to its initial state.
1169 this.get('selection').reset();
1170 this.resetDisplays();
1171 this.refreshContent();
1175 * Reset the attachment display settings defaults to the site options.
1177 * If site options don't define them, fall back to a persistent user setting.
1181 resetDisplays: function() {
1182 var defaultProps = wp.media.view.settings.defaultProps;
1183 this._displays = [];
1184 this._defaultDisplaySettings = {
1185 align: defaultProps.align || getUserSetting( 'align', 'none' ),
1186 size: defaultProps.size || getUserSetting( 'imgsize', 'medium' ),
1187 link: defaultProps.link || getUserSetting( 'urlbutton', 'file' )
1192 * Create a model to represent display settings (alignment, etc.) for an attachment.
1196 * @param {wp.media.model.Attachment} attachment
1197 * @returns {Backbone.Model}
1199 display: function( attachment ) {
1200 var displays = this._displays;
1202 if ( ! displays[ attachment.cid ] ) {
1203 displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) );
1205 return displays[ attachment.cid ];
1209 * Given an attachment, create attachment display settings properties.
1213 * @param {wp.media.model.Attachment} attachment
1216 defaultDisplaySettings: function( attachment ) {
1217 var settings = this._defaultDisplaySettings;
1218 if ( settings.canEmbed = this.canEmbed( attachment ) ) {
1219 settings.link = 'embed';
1225 * Whether an attachment can be embedded (audio or video).
1229 * @param {wp.media.model.Attachment} attachment
1230 * @returns {Boolean}
1232 canEmbed: function( attachment ) {
1233 // If uploading, we know the filename but not the mime type.
1234 if ( ! attachment.get('uploading') ) {
1235 var type = attachment.get('type');
1236 if ( type !== 'audio' && type !== 'video' ) {
1241 return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
1246 * If the state is active, no items are selected, and the current
1247 * content mode is not an option in the state's router (provided
1248 * the state has a router), reset the content mode to the default.
1252 refreshContent: function() {
1253 var selection = this.get('selection'),
1255 router = frame.router.get(),
1256 mode = frame.content.mode();
1258 if ( this.active && ! selection.length && router && ! router.get( mode ) ) {
1259 this.frame.content.render( this.get('content') );
1264 * Callback handler when an attachment is uploaded.
1266 * Switch to the Media Library if uploaded from the 'Upload Files' tab.
1268 * Adds any uploading attachments to the selection.
1270 * If the state only supports one attachment to be selected and multiple
1271 * attachments are uploaded, the last attachment in the upload queue will
1276 * @param {wp.media.model.Attachment} attachment
1278 uploading: function( attachment ) {
1279 var content = this.frame.content;
1281 if ( 'upload' === content.mode() ) {
1282 this.frame.content.mode('browse');
1285 if ( this.get( 'autoSelect' ) ) {
1286 this.get('selection').add( attachment );
1287 this.frame.trigger( 'library:selection:add' );
1292 * Persist the mode of the content region as a user setting.
1296 saveContentMode: function() {
1297 if ( 'browse' !== this.get('router') ) {
1301 var mode = this.frame.content.mode(),
1302 view = this.frame.router.get();
1304 if ( view && view.get( mode ) ) {
1305 setUserSetting( 'libraryContent', mode );
1310 // Make selectionSync available on any Media Library state.
1311 _.extend( Library.prototype, wp.media.selectionSync );
1313 module.exports = Library;
1315 },{}],12:[function(require,module,exports){
1317 * wp.media.controller.MediaLibrary
1320 * @augments wp.media.controller.Library
1321 * @augments wp.media.controller.State
1322 * @augments Backbone.Model
1324 var Library = wp.media.controller.Library,
1327 MediaLibrary = Library.extend({
1328 defaults: _.defaults({
1329 // Attachments browser defaults. @see media.view.AttachmentsBrowser
1330 filterable: 'uploaded',
1332 displaySettings: false,
1334 syncSelection: false
1335 }, Library.prototype.defaults ),
1342 initialize: function( options ) {
1343 this.media = options.media;
1344 this.type = options.type;
1345 this.set( 'library', wp.media.query({ type: this.type }) );
1347 Library.prototype.initialize.apply( this, arguments );
1353 activate: function() {
1354 // @todo this should use this.frame.
1355 if ( wp.media.frame.lastMime ) {
1356 this.set( 'library', wp.media.query({ type: wp.media.frame.lastMime }) );
1357 delete wp.media.frame.lastMime;
1359 Library.prototype.activate.apply( this, arguments );
1363 module.exports = MediaLibrary;
1365 },{}],13:[function(require,module,exports){
1367 * wp.media.controller.Region
1369 * A region is a persistent application layout area.
1371 * A region assumes one mode at any time, and can be switched to another.
1373 * When mode changes, events are triggered on the region's parent view.
1374 * The parent view will listen to specific events and fill the region with an
1375 * appropriate view depending on mode. For example, a frame listens for the
1376 * 'browse' mode t be activated on the 'content' view and then fills the region
1377 * with an AttachmentsBrowser view.
1381 * @param {object} options Options hash for the region.
1382 * @param {string} options.id Unique identifier for the region.
1383 * @param {Backbone.View} options.view A parent view the region exists within.
1384 * @param {string} options.selector jQuery selector for the region within the parent view.
1386 var Region = function( options ) {
1387 _.extend( this, _.pick( options || {}, 'id', 'view', 'selector' ) );
1390 // Use Backbone's self-propagating `extend` inheritance method.
1391 Region.extend = Backbone.Model.extend;
1393 _.extend( Region.prototype, {
1399 * @param {string} mode
1401 * @fires this.view#{this.id}:activate:{this._mode}
1402 * @fires this.view#{this.id}:activate
1403 * @fires this.view#{this.id}:deactivate:{this._mode}
1404 * @fires this.view#{this.id}:deactivate
1406 * @returns {wp.media.controller.Region} Returns itself to allow chaining.
1408 mode: function( mode ) {
1412 // Bail if we're trying to change to the current mode.
1413 if ( mode === this._mode ) {
1418 * Region mode deactivation event.
1420 * @event this.view#{this.id}:deactivate:{this._mode}
1421 * @event this.view#{this.id}:deactivate
1423 this.trigger('deactivate');
1426 this.render( mode );
1429 * Region mode activation event.
1431 * @event this.view#{this.id}:activate:{this._mode}
1432 * @event this.view#{this.id}:activate
1434 this.trigger('activate');
1442 * @param {string} mode
1444 * @fires this.view#{this.id}:create:{this._mode}
1445 * @fires this.view#{this.id}:create
1446 * @fires this.view#{this.id}:render:{this._mode}
1447 * @fires this.view#{this.id}:render
1449 * @returns {wp.media.controller.Region} Returns itself to allow chaining
1451 render: function( mode ) {
1452 // If the mode isn't active, activate it.
1453 if ( mode && mode !== this._mode ) {
1454 return this.mode( mode );
1457 var set = { view: null },
1461 * Create region view event.
1463 * Region view creation takes place in an event callback on the frame.
1465 * @event this.view#{this.id}:create:{this._mode}
1466 * @event this.view#{this.id}:create
1468 this.trigger( 'create', set );
1472 * Render region view event.
1474 * Region view creation takes place in an event callback on the frame.
1476 * @event this.view#{this.id}:create:{this._mode}
1477 * @event this.view#{this.id}:create
1479 this.trigger( 'render', view );
1487 * Get the region's view.
1491 * @returns {wp.media.View}
1494 return this.view.views.first( this.selector );
1498 * Set the region's view as a subview of the frame.
1502 * @param {Array|Object} views
1503 * @param {Object} [options={}]
1504 * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining
1506 set: function( views, options ) {
1508 options.add = false;
1510 return this.view.views.set( this.selector, views, options );
1514 * Trigger regional view events on the frame.
1518 * @param {string} event
1519 * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining.
1521 trigger: function( event ) {
1524 if ( ! this._mode ) {
1528 args = _.toArray( arguments );
1529 base = this.id + ':' + event;
1531 // Trigger `{this.id}:{event}:{this._mode}` event on the frame.
1532 args[0] = base + ':' + this._mode;
1533 this.view.trigger.apply( this.view, args );
1535 // Trigger `{this.id}:{event}` event on the frame.
1537 this.view.trigger.apply( this.view, args );
1542 module.exports = Region;
1544 },{}],14:[function(require,module,exports){
1546 * wp.media.controller.ReplaceImage
1548 * A state for replacing an image.
1551 * @augments wp.media.controller.Library
1552 * @augments wp.media.controller.State
1553 * @augments Backbone.Model
1555 * @param {object} [attributes] The attributes hash passed to the state.
1556 * @param {string} [attributes.id=replace-image] Unique identifier.
1557 * @param {string} [attributes.title=Replace Image] Title for the state. Displays in the media menu and the frame's title region.
1558 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
1559 * If one is not supplied, a collection of all images will be created.
1560 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
1561 * @param {string} [attributes.content=upload] Initial mode for the content region.
1562 * Overridden by persistent user setting if 'contentUserSetting' is true.
1563 * @param {string} [attributes.menu=default] Initial mode for the menu region.
1564 * @param {string} [attributes.router=browse] Initial mode for the router region.
1565 * @param {string} [attributes.toolbar=replace] Initial mode for the toolbar region.
1566 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
1567 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
1568 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
1569 * Accepts 'all', 'uploaded', or 'unattached'.
1570 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
1571 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
1572 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
1573 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
1574 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
1576 var Library = wp.media.controller.Library,
1577 l10n = wp.media.view.l10n,
1580 ReplaceImage = Library.extend({
1581 defaults: _.defaults({
1582 id: 'replace-image',
1583 title: l10n.replaceImageTitle,
1585 filterable: 'uploaded',
1590 }, Library.prototype.defaults ),
1597 initialize: function( options ) {
1598 var library, comparator;
1600 this.image = options.image;
1601 // If we haven't been provided a `library`, create a `Selection`.
1602 if ( ! this.get('library') ) {
1603 this.set( 'library', wp.media.query({ type: 'image' }) );
1606 Library.prototype.initialize.apply( this, arguments );
1608 library = this.get('library');
1609 comparator = library.comparator;
1611 // Overload the library's comparator to push items that are not in
1612 // the mirrored query to the front of the aggregate collection.
1613 library.comparator = function( a, b ) {
1614 var aInQuery = !! this.mirroring.get( a.cid ),
1615 bInQuery = !! this.mirroring.get( b.cid );
1617 if ( ! aInQuery && bInQuery ) {
1619 } else if ( aInQuery && ! bInQuery ) {
1622 return comparator.apply( this, arguments );
1626 // Add all items in the selection to the library, so any featured
1627 // images that are not initially loaded still appear.
1628 library.observe( this.get('selection') );
1634 activate: function() {
1635 this.updateSelection();
1636 Library.prototype.activate.apply( this, arguments );
1642 updateSelection: function() {
1643 var selection = this.get('selection'),
1644 attachment = this.image.attachment;
1646 selection.reset( attachment ? [ attachment ] : [] );
1650 module.exports = ReplaceImage;
1652 },{}],15:[function(require,module,exports){
1654 * wp.media.controller.SiteIconCropper
1656 * A state for cropping a Site Icon.
1659 * @augments wp.media.controller.Cropper
1660 * @augments wp.media.controller.State
1661 * @augments Backbone.Model
1663 var Controller = wp.media.controller,
1666 SiteIconCropper = Controller.Cropper.extend({
1667 activate: function() {
1668 this.frame.on( 'content:create:crop', this.createCropContent, this );
1669 this.frame.on( 'close', this.removeCropper, this );
1670 this.set('selection', new Backbone.Collection(this.frame._selection.single));
1673 createCropContent: function() {
1674 this.cropperView = new wp.media.view.SiteIconCropper({
1676 attachment: this.get('selection').first()
1678 this.cropperView.on('image-loaded', this.createCropToolbar, this);
1679 this.frame.content.set(this.cropperView);
1683 doCrop: function( attachment ) {
1684 var cropDetails = attachment.get( 'cropDetails' ),
1685 control = this.get( 'control' );
1687 cropDetails.dst_width = control.params.width;
1688 cropDetails.dst_height = control.params.height;
1690 return wp.ajax.post( 'crop-image', {
1691 nonce: attachment.get( 'nonces' ).edit,
1692 id: attachment.get( 'id' ),
1693 context: 'site-icon',
1694 cropDetails: cropDetails
1699 module.exports = SiteIconCropper;
1701 },{}],16:[function(require,module,exports){
1703 * wp.media.controller.StateMachine
1705 * A state machine keeps track of state. It is in one state at a time,
1706 * and can change from one state to another.
1708 * States are stored as models in a Backbone collection.
1713 * @augments Backbone.Model
1715 * @mixes Backbone.Events
1717 * @param {Array} states
1719 var StateMachine = function( states ) {
1720 // @todo This is dead code. The states collection gets created in media.view.Frame._createStates.
1721 this.states = new Backbone.Collection( states );
1724 // Use Backbone's self-propagating `extend` inheritance method.
1725 StateMachine.extend = Backbone.Model.extend;
1727 _.extend( StateMachine.prototype, Backbone.Events, {
1731 * If no `id` is provided, returns the active state.
1733 * Implicitly creates states.
1735 * Ensure that the `states` collection exists so the `StateMachine`
1736 * can be used as a mixin.
1740 * @param {string} id
1741 * @returns {wp.media.controller.State} Returns a State model
1742 * from the StateMachine collection
1744 state: function( id ) {
1745 this.states = this.states || new Backbone.Collection();
1747 // Default to the active state.
1748 id = id || this._state;
1750 if ( id && ! this.states.get( id ) ) {
1751 this.states.add({ id: id });
1753 return this.states.get( id );
1757 * Sets the active state.
1759 * Bail if we're trying to select the current state, if we haven't
1760 * created the `states` collection, or are trying to select a state
1761 * that does not exist.
1765 * @param {string} id
1767 * @fires wp.media.controller.State#deactivate
1768 * @fires wp.media.controller.State#activate
1770 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining
1772 setState: function( id ) {
1773 var previous = this.state();
1775 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) {
1780 previous.trigger('deactivate');
1781 this._lastState = previous.id;
1785 this.state().trigger('activate');
1791 * Returns the previous active state.
1793 * Call the `state()` method with no parameters to retrieve the current
1798 * @returns {wp.media.controller.State} Returns a State model
1799 * from the StateMachine collection
1801 lastState: function() {
1802 if ( this._lastState ) {
1803 return this.state( this._lastState );
1808 // Map all event binding and triggering on a StateMachine to its `states` collection.
1809 _.each([ 'on', 'off', 'trigger' ], function( method ) {
1811 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining.
1813 StateMachine.prototype[ method ] = function() {
1814 // Ensure that the `states` collection exists so the `StateMachine`
1815 // can be used as a mixin.
1816 this.states = this.states || new Backbone.Collection();
1817 // Forward the method to the `states` collection.
1818 this.states[ method ].apply( this.states, arguments );
1823 module.exports = StateMachine;
1825 },{}],17:[function(require,module,exports){
1827 * wp.media.controller.State
1829 * A state is a step in a workflow that when set will trigger the controllers
1830 * for the regions to be updated as specified in the frame.
1832 * A state has an event-driven lifecycle:
1834 * 'ready' triggers when a state is added to a state machine's collection.
1835 * 'activate' triggers when a state is activated by a state machine.
1836 * 'deactivate' triggers when a state is deactivated by a state machine.
1837 * 'reset' is not triggered automatically. It should be invoked by the
1838 * proper controller to reset the state to its default.
1841 * @augments Backbone.Model
1843 var State = Backbone.Model.extend({
1849 constructor: function() {
1850 this.on( 'activate', this._preActivate, this );
1851 this.on( 'activate', this.activate, this );
1852 this.on( 'activate', this._postActivate, this );
1853 this.on( 'deactivate', this._deactivate, this );
1854 this.on( 'deactivate', this.deactivate, this );
1855 this.on( 'reset', this.reset, this );
1856 this.on( 'ready', this._ready, this );
1857 this.on( 'ready', this.ready, this );
1859 * Call parent constructor with passed arguments
1861 Backbone.Model.apply( this, arguments );
1862 this.on( 'change:menu', this._updateMenu, this );
1865 * Ready event callback.
1870 ready: function() {},
1873 * Activate event callback.
1878 activate: function() {},
1881 * Deactivate event callback.
1886 deactivate: function() {},
1889 * Reset event callback.
1894 reset: function() {},
1900 _ready: function() {
1908 _preActivate: function() {
1916 _postActivate: function() {
1917 this.on( 'change:menu', this._menu, this );
1918 this.on( 'change:titleMode', this._title, this );
1919 this.on( 'change:content', this._content, this );
1920 this.on( 'change:toolbar', this._toolbar, this );
1922 this.frame.on( 'title:render:default', this._renderTitle, this );
1935 _deactivate: function() {
1936 this.active = false;
1938 this.frame.off( 'title:render:default', this._renderTitle, this );
1940 this.off( 'change:menu', this._menu, this );
1941 this.off( 'change:titleMode', this._title, this );
1942 this.off( 'change:content', this._content, this );
1943 this.off( 'change:toolbar', this._toolbar, this );
1950 _title: function() {
1951 this.frame.title.render( this.get('titleMode') || 'default' );
1958 _renderTitle: function( view ) {
1959 view.$el.text( this.get('title') || '' );
1966 _router: function() {
1967 var router = this.frame.router,
1968 mode = this.get('router'),
1971 this.frame.$el.toggleClass( 'hide-router', ! mode );
1976 this.frame.router.render( mode );
1978 view = router.get();
1979 if ( view && view.select ) {
1980 view.select( this.frame.content.mode() );
1989 var menu = this.frame.menu,
1990 mode = this.get('menu'),
1993 this.frame.$el.toggleClass( 'hide-menu', ! mode );
2001 if ( view && view.select ) {
2002 view.select( this.id );
2010 _updateMenu: function() {
2011 var previous = this.previous('menu'),
2012 menu = this.get('menu');
2015 this.frame.off( 'menu:render:' + previous, this._renderMenu, this );
2019 this.frame.on( 'menu:render:' + menu, this._renderMenu, this );
2024 * Create a view in the media menu for the state.
2029 * @param {media.view.Menu} view The menu view.
2031 _renderMenu: function( view ) {
2032 var menuItem = this.get('menuItem'),
2033 title = this.get('title'),
2034 priority = this.get('priority');
2036 if ( ! menuItem && title ) {
2037 menuItem = { text: title };
2040 menuItem.priority = priority;
2048 view.set( this.id, menuItem );
2052 _.each(['toolbar','content'], function( region ) {
2056 State.prototype[ '_' + region ] = function() {
2057 var mode = this.get( region );
2059 this.frame[ region ].render( mode );
2064 module.exports = State;
2066 },{}],18:[function(require,module,exports){
2068 * wp.media.selectionSync
2070 * Sync an attachments selection in a state with another state.
2072 * Allows for selecting multiple images in the Insert Media workflow, and then
2073 * switching to the Insert Gallery workflow while preserving the attachments selection.
2077 var selectionSync = {
2081 syncSelection: function() {
2082 var selection = this.get('selection'),
2083 manager = this.frame._selection;
2085 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2089 // If the selection supports multiple items, validate the stored
2090 // attachments based on the new selection's conditions. Record
2091 // the attachments that are not included; we'll maintain a
2092 // reference to those. Other attachments are considered in flux.
2093 if ( selection.multiple ) {
2094 selection.reset( [], { silent: true });
2095 selection.validateAll( manager.attachments );
2096 manager.difference = _.difference( manager.attachments.models, selection.models );
2099 // Sync the selection's single item with the master.
2100 selection.single( manager.single );
2104 * Record the currently active attachments, which is a combination
2105 * of the selection's attachments and the set of selected
2106 * attachments that this specific selection considered invalid.
2107 * Reset the difference and record the single attachment.
2111 recordSelection: function() {
2112 var selection = this.get('selection'),
2113 manager = this.frame._selection;
2115 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2119 if ( selection.multiple ) {
2120 manager.attachments.reset( selection.toArray().concat( manager.difference ) );
2121 manager.difference = [];
2123 manager.attachments.add( selection.toArray() );
2126 manager.single = selection._single;
2130 module.exports = selectionSync;
2132 },{}],19:[function(require,module,exports){
2133 var media = wp.media,
2137 media.isTouchDevice = ( 'ontouchend' in document );
2139 // Link any localized strings.
2140 l10n = media.view.l10n = window._wpMediaViewsL10n || {};
2142 // Link any settings.
2143 media.view.settings = l10n.settings || {};
2144 delete l10n.settings;
2146 // Copy the `post` setting over to the model settings.
2147 media.model.settings.post = media.view.settings.post;
2149 // Check if the browser supports CSS 3.0 transitions
2150 $.support.transition = (function(){
2151 var style = document.documentElement.style,
2153 WebkitTransition: 'webkitTransitionEnd',
2154 MozTransition: 'transitionend',
2155 OTransition: 'oTransitionEnd otransitionend',
2156 transition: 'transitionend'
2159 transition = _.find( _.keys( transitions ), function( transition ) {
2160 return ! _.isUndefined( style[ transition ] );
2163 return transition && {
2164 end: transitions[ transition ]
2169 * A shared event bus used to provide events into
2170 * the media workflows that 3rd-party devs can use to hook
2173 media.events = _.extend( {}, Backbone.Events );
2176 * Makes it easier to bind events using transitions.
2178 * @param {string} selector
2179 * @param {Number} sensitivity
2180 * @returns {Promise}
2182 media.transition = function( selector, sensitivity ) {
2183 var deferred = $.Deferred();
2185 sensitivity = sensitivity || 2000;
2187 if ( $.support.transition ) {
2188 if ( ! (selector instanceof $) ) {
2189 selector = $( selector );
2192 // Resolve the deferred when the first element finishes animating.
2193 selector.first().one( $.support.transition.end, deferred.resolve );
2195 // Just in case the event doesn't trigger, fire a callback.
2196 _.delay( deferred.resolve, sensitivity );
2198 // Otherwise, execute on the spot.
2203 return deferred.promise();
2206 media.controller.Region = require( './controllers/region.js' );
2207 media.controller.StateMachine = require( './controllers/state-machine.js' );
2208 media.controller.State = require( './controllers/state.js' );
2210 media.selectionSync = require( './utils/selection-sync.js' );
2211 media.controller.Library = require( './controllers/library.js' );
2212 media.controller.ImageDetails = require( './controllers/image-details.js' );
2213 media.controller.GalleryEdit = require( './controllers/gallery-edit.js' );
2214 media.controller.GalleryAdd = require( './controllers/gallery-add.js' );
2215 media.controller.CollectionEdit = require( './controllers/collection-edit.js' );
2216 media.controller.CollectionAdd = require( './controllers/collection-add.js' );
2217 media.controller.FeaturedImage = require( './controllers/featured-image.js' );
2218 media.controller.ReplaceImage = require( './controllers/replace-image.js' );
2219 media.controller.EditImage = require( './controllers/edit-image.js' );
2220 media.controller.MediaLibrary = require( './controllers/media-library.js' );
2221 media.controller.Embed = require( './controllers/embed.js' );
2222 media.controller.Cropper = require( './controllers/cropper.js' );
2223 media.controller.CustomizeImageCropper = require( './controllers/customize-image-cropper.js' );
2224 media.controller.SiteIconCropper = require( './controllers/site-icon-cropper.js' );
2226 media.View = require( './views/view.js' );
2227 media.view.Frame = require( './views/frame.js' );
2228 media.view.MediaFrame = require( './views/media-frame.js' );
2229 media.view.MediaFrame.Select = require( './views/frame/select.js' );
2230 media.view.MediaFrame.Post = require( './views/frame/post.js' );
2231 media.view.MediaFrame.ImageDetails = require( './views/frame/image-details.js' );
2232 media.view.Modal = require( './views/modal.js' );
2233 media.view.FocusManager = require( './views/focus-manager.js' );
2234 media.view.UploaderWindow = require( './views/uploader/window.js' );
2235 media.view.EditorUploader = require( './views/uploader/editor.js' );
2236 media.view.UploaderInline = require( './views/uploader/inline.js' );
2237 media.view.UploaderStatus = require( './views/uploader/status.js' );
2238 media.view.UploaderStatusError = require( './views/uploader/status-error.js' );
2239 media.view.Toolbar = require( './views/toolbar.js' );
2240 media.view.Toolbar.Select = require( './views/toolbar/select.js' );
2241 media.view.Toolbar.Embed = require( './views/toolbar/embed.js' );
2242 media.view.Button = require( './views/button.js' );
2243 media.view.ButtonGroup = require( './views/button-group.js' );
2244 media.view.PriorityList = require( './views/priority-list.js' );
2245 media.view.MenuItem = require( './views/menu-item.js' );
2246 media.view.Menu = require( './views/menu.js' );
2247 media.view.RouterItem = require( './views/router-item.js' );
2248 media.view.Router = require( './views/router.js' );
2249 media.view.Sidebar = require( './views/sidebar.js' );
2250 media.view.Attachment = require( './views/attachment.js' );
2251 media.view.Attachment.Library = require( './views/attachment/library.js' );
2252 media.view.Attachment.EditLibrary = require( './views/attachment/edit-library.js' );
2253 media.view.Attachments = require( './views/attachments.js' );
2254 media.view.Search = require( './views/search.js' );
2255 media.view.AttachmentFilters = require( './views/attachment-filters.js' );
2256 media.view.DateFilter = require( './views/attachment-filters/date.js' );
2257 media.view.AttachmentFilters.Uploaded = require( './views/attachment-filters/uploaded.js' );
2258 media.view.AttachmentFilters.All = require( './views/attachment-filters/all.js' );
2259 media.view.AttachmentsBrowser = require( './views/attachments/browser.js' );
2260 media.view.Selection = require( './views/selection.js' );
2261 media.view.Attachment.Selection = require( './views/attachment/selection.js' );
2262 media.view.Attachments.Selection = require( './views/attachments/selection.js' );
2263 media.view.Attachment.EditSelection = require( './views/attachment/edit-selection.js' );
2264 media.view.Settings = require( './views/settings.js' );
2265 media.view.Settings.AttachmentDisplay = require( './views/settings/attachment-display.js' );
2266 media.view.Settings.Gallery = require( './views/settings/gallery.js' );
2267 media.view.Settings.Playlist = require( './views/settings/playlist.js' );
2268 media.view.Attachment.Details = require( './views/attachment/details.js' );
2269 media.view.AttachmentCompat = require( './views/attachment-compat.js' );
2270 media.view.Iframe = require( './views/iframe.js' );
2271 media.view.Embed = require( './views/embed.js' );
2272 media.view.Label = require( './views/label.js' );
2273 media.view.EmbedUrl = require( './views/embed/url.js' );
2274 media.view.EmbedLink = require( './views/embed/link.js' );
2275 media.view.EmbedImage = require( './views/embed/image.js' );
2276 media.view.ImageDetails = require( './views/image-details.js' );
2277 media.view.Cropper = require( './views/cropper.js' );
2278 media.view.SiteIconCropper = require( './views/site-icon-cropper.js' );
2279 media.view.SiteIconPreview = require( './views/site-icon-preview.js' );
2280 media.view.EditImage = require( './views/edit-image.js' );
2281 media.view.Spinner = require( './views/spinner.js' );
2283 },{"./controllers/collection-add.js":1,"./controllers/collection-edit.js":2,"./controllers/cropper.js":3,"./controllers/customize-image-cropper.js":4,"./controllers/edit-image.js":5,"./controllers/embed.js":6,"./controllers/featured-image.js":7,"./controllers/gallery-add.js":8,"./controllers/gallery-edit.js":9,"./controllers/image-details.js":10,"./controllers/library.js":11,"./controllers/media-library.js":12,"./controllers/region.js":13,"./controllers/replace-image.js":14,"./controllers/site-icon-cropper.js":15,"./controllers/state-machine.js":16,"./controllers/state.js":17,"./utils/selection-sync.js":18,"./views/attachment-compat.js":20,"./views/attachment-filters.js":21,"./views/attachment-filters/all.js":22,"./views/attachment-filters/date.js":23,"./views/attachment-filters/uploaded.js":24,"./views/attachment.js":25,"./views/attachment/details.js":26,"./views/attachment/edit-library.js":27,"./views/attachment/edit-selection.js":28,"./views/attachment/library.js":29,"./views/attachment/selection.js":30,"./views/attachments.js":31,"./views/attachments/browser.js":32,"./views/attachments/selection.js":33,"./views/button-group.js":34,"./views/button.js":35,"./views/cropper.js":36,"./views/edit-image.js":37,"./views/embed.js":38,"./views/embed/image.js":39,"./views/embed/link.js":40,"./views/embed/url.js":41,"./views/focus-manager.js":42,"./views/frame.js":43,"./views/frame/image-details.js":44,"./views/frame/post.js":45,"./views/frame/select.js":46,"./views/iframe.js":47,"./views/image-details.js":48,"./views/label.js":49,"./views/media-frame.js":50,"./views/menu-item.js":51,"./views/menu.js":52,"./views/modal.js":53,"./views/priority-list.js":54,"./views/router-item.js":55,"./views/router.js":56,"./views/search.js":57,"./views/selection.js":58,"./views/settings.js":59,"./views/settings/attachment-display.js":60,"./views/settings/gallery.js":61,"./views/settings/playlist.js":62,"./views/sidebar.js":63,"./views/site-icon-cropper.js":64,"./views/site-icon-preview.js":65,"./views/spinner.js":66,"./views/toolbar.js":67,"./views/toolbar/embed.js":68,"./views/toolbar/select.js":69,"./views/uploader/editor.js":70,"./views/uploader/inline.js":71,"./views/uploader/status-error.js":72,"./views/uploader/status.js":73,"./views/uploader/window.js":74,"./views/view.js":75}],20:[function(require,module,exports){
2285 * wp.media.view.AttachmentCompat
2287 * A view to display fields added via the `attachment_fields_to_edit` filter.
2290 * @augments wp.media.View
2291 * @augments wp.Backbone.View
2292 * @augments Backbone.View
2294 var View = wp.media.View,
2297 AttachmentCompat = View.extend({
2299 className: 'compat-item',
2302 'submit': 'preventDefault',
2303 'change input': 'save',
2304 'change select': 'save',
2305 'change textarea': 'save'
2308 initialize: function() {
2309 this.listenTo( this.model, 'change:compat', this.render );
2312 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2314 dispose: function() {
2315 if ( this.$(':focus').length ) {
2319 * call 'dispose' directly on the parent class
2321 return View.prototype.dispose.apply( this, arguments );
2324 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2326 render: function() {
2327 var compat = this.model.get('compat');
2328 if ( ! compat || ! compat.item ) {
2332 this.views.detach();
2333 this.$el.html( compat.item );
2334 this.views.render();
2338 * @param {Object} event
2340 preventDefault: function( event ) {
2341 event.preventDefault();
2344 * @param {Object} event
2346 save: function( event ) {
2350 event.preventDefault();
2353 _.each( this.$el.serializeArray(), function( pair ) {
2354 data[ pair.name ] = pair.value;
2357 this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
2358 this.model.saveCompat( data ).always( _.bind( this.postSave, this ) );
2361 postSave: function() {
2362 this.controller.trigger( 'attachment:compat:ready', ['ready'] );
2366 module.exports = AttachmentCompat;
2368 },{}],21:[function(require,module,exports){
2370 * wp.media.view.AttachmentFilters
2373 * @augments wp.media.View
2374 * @augments wp.Backbone.View
2375 * @augments Backbone.View
2380 AttachmentFilters = wp.media.View.extend({
2382 className: 'attachment-filters',
2383 id: 'media-attachment-filters',
2391 initialize: function() {
2392 this.createFilters();
2393 _.extend( this.filters, this.options.filters );
2395 // Build `<option>` elements.
2396 this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
2398 el: $( '<option></option>' ).val( value ).html( filter.text )[0],
2399 priority: filter.priority || 50
2401 }, this ).sortBy('priority').pluck('el').value() );
2403 this.listenTo( this.model, 'change', this.select );
2410 createFilters: function() {
2415 * When the selected filter changes, update the Attachment Query properties to match.
2417 change: function() {
2418 var filter = this.filters[ this.el.value ];
2420 this.model.set( filter.props );
2424 select: function() {
2425 var model = this.model,
2427 props = model.toJSON();
2429 _.find( this.filters, function( filter, id ) {
2430 var equal = _.all( filter.props, function( prop, key ) {
2431 return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] );
2439 this.$el.val( value );
2443 module.exports = AttachmentFilters;
2445 },{}],22:[function(require,module,exports){
2447 * wp.media.view.AttachmentFilters.All
2450 * @augments wp.media.view.AttachmentFilters
2451 * @augments wp.media.View
2452 * @augments wp.Backbone.View
2453 * @augments Backbone.View
2455 var l10n = wp.media.view.l10n,
2458 All = wp.media.view.AttachmentFilters.extend({
2459 createFilters: function() {
2462 _.each( wp.media.view.settings.mimeTypes || {}, function( text, key ) {
2476 text: l10n.allMediaItems,
2487 if ( wp.media.view.settings.post.id ) {
2488 filters.uploaded = {
2489 text: l10n.uploadedToThisPost,
2493 uploadedTo: wp.media.view.settings.post.id,
2494 orderby: 'menuOrder',
2501 filters.unattached = {
2502 text: l10n.unattached,
2507 orderby: 'menuOrder',
2513 if ( wp.media.view.settings.mediaTrash &&
2514 this.controller.isModeActive( 'grid' ) ) {
2529 this.filters = filters;
2533 module.exports = All;
2535 },{}],23:[function(require,module,exports){
2537 * A filter dropdown for month/dates.
2540 * @augments wp.media.view.AttachmentFilters
2541 * @augments wp.media.View
2542 * @augments wp.Backbone.View
2543 * @augments Backbone.View
2545 var l10n = wp.media.view.l10n,
2548 DateFilter = wp.media.view.AttachmentFilters.extend({
2549 id: 'media-attachment-date-filters',
2551 createFilters: function() {
2553 _.each( wp.media.view.settings.months || {}, function( value, index ) {
2554 filters[ index ] = {
2558 monthnum: value.month
2563 text: l10n.allDates,
2570 this.filters = filters;
2574 module.exports = DateFilter;
2576 },{}],24:[function(require,module,exports){
2578 * wp.media.view.AttachmentFilters.Uploaded
2581 * @augments wp.media.view.AttachmentFilters
2582 * @augments wp.media.View
2583 * @augments wp.Backbone.View
2584 * @augments Backbone.View
2586 var l10n = wp.media.view.l10n,
2589 Uploaded = wp.media.view.AttachmentFilters.extend({
2590 createFilters: function() {
2591 var type = this.model.get('type'),
2592 types = wp.media.view.settings.mimeTypes,
2595 if ( types && type ) {
2596 text = types[ type ];
2601 text: text || l10n.allMediaItems,
2611 text: l10n.uploadedToThisPost,
2613 uploadedTo: wp.media.view.settings.post.id,
2614 orderby: 'menuOrder',
2621 text: l10n.unattached,
2624 orderby: 'menuOrder',
2633 module.exports = Uploaded;
2635 },{}],25:[function(require,module,exports){
2637 * wp.media.view.Attachment
2640 * @augments wp.media.View
2641 * @augments wp.Backbone.View
2642 * @augments Backbone.View
2644 var View = wp.media.View,
2648 Attachment = View.extend({
2650 className: 'attachment',
2651 template: wp.template('attachment'),
2653 attributes: function() {
2657 'aria-label': this.model.get( 'title' ),
2658 'aria-checked': false,
2659 'data-id': this.model.get( 'id' )
2664 'click .js--select-attachment': 'toggleSelectionHandler',
2665 'change [data-setting]': 'updateSetting',
2666 'change [data-setting] input': 'updateSetting',
2667 'change [data-setting] select': 'updateSetting',
2668 'change [data-setting] textarea': 'updateSetting',
2669 'click .attachment-close': 'removeFromLibrary',
2670 'click .check': 'checkClickHandler',
2671 'keydown': 'toggleSelectionHandler'
2676 initialize: function() {
2677 var selection = this.options.selection,
2678 options = _.defaults( this.options, {
2679 rerenderOnModelChange: true
2682 if ( options.rerenderOnModelChange ) {
2683 this.listenTo( this.model, 'change', this.render );
2685 this.listenTo( this.model, 'change:percent', this.progress );
2687 this.listenTo( this.model, 'change:title', this._syncTitle );
2688 this.listenTo( this.model, 'change:caption', this._syncCaption );
2689 this.listenTo( this.model, 'change:artist', this._syncArtist );
2690 this.listenTo( this.model, 'change:album', this._syncAlbum );
2692 // Update the selection.
2693 this.listenTo( this.model, 'add', this.select );
2694 this.listenTo( this.model, 'remove', this.deselect );
2696 selection.on( 'reset', this.updateSelect, this );
2697 // Update the model's details view.
2698 this.listenTo( this.model, 'selection:single selection:unsingle', this.details );
2699 this.details( this.model, this.controller.state().get('selection') );
2702 this.listenTo( this.controller, 'attachment:compat:waiting attachment:compat:ready', this.updateSave );
2705 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2707 dispose: function() {
2708 var selection = this.options.selection;
2710 // Make sure all settings are saved before removing the view.
2714 selection.off( null, null, this );
2717 * call 'dispose' directly on the parent class
2719 View.prototype.dispose.apply( this, arguments );
2723 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2725 render: function() {
2726 var options = _.defaults( this.model.toJSON(), {
2727 orientation: 'landscape',
2743 options.buttons = this.buttons;
2744 options.describe = this.controller.state().get('describe');
2746 if ( 'image' === options.type ) {
2747 options.size = this.imageSize();
2751 if ( options.nonces ) {
2752 options.can.remove = !! options.nonces['delete'];
2753 options.can.save = !! options.nonces.update;
2756 if ( this.controller.state().get('allowLocalEdits') ) {
2757 options.allowLocalEdits = true;
2760 if ( options.uploading && ! options.percent ) {
2761 options.percent = 0;
2764 this.views.detach();
2765 this.$el.html( this.template( options ) );
2767 this.$el.toggleClass( 'uploading', options.uploading );
2769 if ( options.uploading ) {
2770 this.$bar = this.$('.media-progress-bar div');
2775 // Check if the model is selected.
2776 this.updateSelect();
2778 // Update the save status.
2781 this.views.render();
2786 progress: function() {
2787 if ( this.$bar && this.$bar.length ) {
2788 this.$bar.width( this.model.get('percent') + '%' );
2793 * @param {Object} event
2795 toggleSelectionHandler: function( event ) {
2798 // Don't do anything inside inputs and on the attachment check and remove buttons.
2799 if ( 'INPUT' === event.target.nodeName || 'BUTTON' === event.target.nodeName ) {
2803 // Catch arrow events
2804 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
2805 this.controller.trigger( 'attachment:keydown:arrow', event );
2809 // Catch enter and space events
2810 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
2814 event.preventDefault();
2816 // In the grid view, bubble up an edit:attachment event to the controller.
2817 if ( this.controller.isModeActive( 'grid' ) ) {
2818 if ( this.controller.isModeActive( 'edit' ) ) {
2819 // Pass the current target to restore focus when closing
2820 this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
2824 if ( this.controller.isModeActive( 'select' ) ) {
2829 if ( event.shiftKey ) {
2831 } else if ( event.ctrlKey || event.metaKey ) {
2835 this.toggleSelection({
2839 this.controller.trigger( 'selection:toggle' );
2842 * @param {Object} options
2844 toggleSelection: function( options ) {
2845 var collection = this.collection,
2846 selection = this.options.selection,
2848 method = options && options.method,
2849 single, models, singleIndex, modelIndex;
2851 if ( ! selection ) {
2855 single = selection.single();
2856 method = _.isUndefined( method ) ? selection.multiple : method;
2858 // If the `method` is set to `between`, select all models that
2859 // exist between the current and the selected model.
2860 if ( 'between' === method && single && selection.multiple ) {
2861 // If the models are the same, short-circuit.
2862 if ( single === model ) {
2866 singleIndex = collection.indexOf( single );
2867 modelIndex = collection.indexOf( this.model );
2869 if ( singleIndex < modelIndex ) {
2870 models = collection.models.slice( singleIndex, modelIndex + 1 );
2872 models = collection.models.slice( modelIndex, singleIndex + 1 );
2875 selection.add( models );
2876 selection.single( model );
2879 // If the `method` is set to `toggle`, just flip the selection
2880 // status, regardless of whether the model is the single model.
2881 } else if ( 'toggle' === method ) {
2882 selection[ this.selected() ? 'remove' : 'add' ]( model );
2883 selection.single( model );
2885 } else if ( 'add' === method ) {
2886 selection.add( model );
2887 selection.single( model );
2891 // Fixes bug that loses focus when selecting a featured image
2896 if ( method !== 'add' ) {
2900 if ( this.selected() ) {
2901 // If the model is the single model, remove it.
2902 // If it is not the same as the single model,
2903 // it now becomes the single model.
2904 selection[ single === model ? 'remove' : 'single' ]( model );
2906 // If the model is not selected, run the `method` on the
2907 // selection. By default, we `reset` the selection, but the
2908 // `method` can be set to `add` the model to the selection.
2909 selection[ method ]( model );
2910 selection.single( model );
2914 updateSelect: function() {
2915 this[ this.selected() ? 'select' : 'deselect' ]();
2918 * @returns {unresolved|Boolean}
2920 selected: function() {
2921 var selection = this.options.selection;
2923 return !! selection.get( this.model.cid );
2927 * @param {Backbone.Model} model
2928 * @param {Backbone.Collection} collection
2930 select: function( model, collection ) {
2931 var selection = this.options.selection,
2932 controller = this.controller;
2934 // Check if a selection exists and if it's the collection provided.
2935 // If they're not the same collection, bail; we're in another
2936 // selection's event loop.
2937 if ( ! selection || ( collection && collection !== selection ) ) {
2941 // Bail if the model is already selected.
2942 if ( this.$el.hasClass( 'selected' ) ) {
2946 // Add 'selected' class to model, set aria-checked to true.
2947 this.$el.addClass( 'selected' ).attr( 'aria-checked', true );
2948 // Make the checkbox tabable, except in media grid (bulk select mode).
2949 if ( ! ( controller.isModeActive( 'grid' ) && controller.isModeActive( 'select' ) ) ) {
2950 this.$( '.check' ).attr( 'tabindex', '0' );
2954 * @param {Backbone.Model} model
2955 * @param {Backbone.Collection} collection
2957 deselect: function( model, collection ) {
2958 var selection = this.options.selection;
2960 // Check if a selection exists and if it's the collection provided.
2961 // If they're not the same collection, bail; we're in another
2962 // selection's event loop.
2963 if ( ! selection || ( collection && collection !== selection ) ) {
2966 this.$el.removeClass( 'selected' ).attr( 'aria-checked', false )
2967 .find( '.check' ).attr( 'tabindex', '-1' );
2970 * @param {Backbone.Model} model
2971 * @param {Backbone.Collection} collection
2973 details: function( model, collection ) {
2974 var selection = this.options.selection,
2977 if ( selection !== collection ) {
2981 details = selection.single();
2982 this.$el.toggleClass( 'details', details === this.model );
2985 * @param {string} size
2988 imageSize: function( size ) {
2989 var sizes = this.model.get('sizes'), matched = false;
2991 size = size || 'medium';
2993 // Use the provided image size if possible.
2995 if ( sizes[ size ] ) {
2996 matched = sizes[ size ];
2997 } else if ( sizes.large ) {
2998 matched = sizes.large;
2999 } else if ( sizes.thumbnail ) {
3000 matched = sizes.thumbnail;
3001 } else if ( sizes.full ) {
3002 matched = sizes.full;
3006 return _.clone( matched );
3011 url: this.model.get('url'),
3012 width: this.model.get('width'),
3013 height: this.model.get('height'),
3014 orientation: this.model.get('orientation')
3018 * @param {Object} event
3020 updateSetting: function( event ) {
3021 var $setting = $( event.target ).closest('[data-setting]'),
3024 if ( ! $setting.length ) {
3028 setting = $setting.data('setting');
3029 value = event.target.value;
3031 if ( this.model.get( setting ) !== value ) {
3032 this.save( setting, value );
3037 * Pass all the arguments to the model's save method.
3039 * Records the aggregate status of all save requests and updates the
3040 * view's classes accordingly.
3044 save = this._save = this._save || { status: 'ready' },
3045 request = this.model.save.apply( this.model, arguments ),
3046 requests = save.requests ? $.when( request, save.requests ) : request;
3048 // If we're waiting to remove 'Saved.', stop.
3049 if ( save.savedTimer ) {
3050 clearTimeout( save.savedTimer );
3053 this.updateSave('waiting');
3054 save.requests = requests;
3055 requests.always( function() {
3056 // If we've performed another request since this one, bail.
3057 if ( save.requests !== requests ) {
3061 view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' );
3062 save.savedTimer = setTimeout( function() {
3063 view.updateSave('ready');
3064 delete save.savedTimer;
3069 * @param {string} status
3070 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3072 updateSave: function( status ) {
3073 var save = this._save = this._save || { status: 'ready' };
3075 if ( status && status !== save.status ) {
3076 this.$el.removeClass( 'save-' + save.status );
3077 save.status = status;
3080 this.$el.addClass( 'save-' + save.status );
3084 updateAll: function() {
3085 var $settings = this.$('[data-setting]'),
3089 changed = _.chain( $settings ).map( function( el ) {
3090 var $input = $('input, textarea, select, [value]', el ),
3093 if ( ! $input.length ) {
3097 setting = $(el).data('setting');
3098 value = $input.val();
3100 // Record the value if it changed.
3101 if ( model.get( setting ) !== value ) {
3102 return [ setting, value ];
3104 }).compact().object().value();
3106 if ( ! _.isEmpty( changed ) ) {
3107 model.save( changed );
3111 * @param {Object} event
3113 removeFromLibrary: function( event ) {
3114 // Catch enter and space events
3115 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
3119 // Stop propagation so the model isn't selected.
3120 event.stopPropagation();
3122 this.collection.remove( this.model );
3126 * Add the model if it isn't in the selection, if it is in the selection,
3129 * @param {[type]} event [description]
3130 * @return {[type]} [description]
3132 checkClickHandler: function ( event ) {
3133 var selection = this.options.selection;
3134 if ( ! selection ) {
3137 event.stopPropagation();
3138 if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
3139 selection.remove( this.model );
3140 // Move focus back to the attachment tile (from the check).
3143 selection.add( this.model );
3148 // Ensure settings remain in sync between attachment views.
3150 caption: '_syncCaption',
3151 title: '_syncTitle',
3152 artist: '_syncArtist',
3154 }, function( method, setting ) {
3156 * @param {Backbone.Model} model
3157 * @param {string} value
3158 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3160 Attachment.prototype[ method ] = function( model, value ) {
3161 var $setting = this.$('[data-setting="' + setting + '"]');
3163 if ( ! $setting.length ) {
3167 // If the updated value is in sync with the value in the DOM, there
3168 // is no need to re-render. If we're currently editing the value,
3169 // it will automatically be in sync, suppressing the re-render for
3170 // the view we're editing, while updating any others.
3171 if ( value === $setting.find('input, textarea, select, [value]').val() ) {
3175 return this.render();
3179 module.exports = Attachment;
3181 },{}],26:[function(require,module,exports){
3183 * wp.media.view.Attachment.Details
3186 * @augments wp.media.view.Attachment
3187 * @augments wp.media.View
3188 * @augments wp.Backbone.View
3189 * @augments Backbone.View
3191 var Attachment = wp.media.view.Attachment,
3192 l10n = wp.media.view.l10n,
3195 Details = Attachment.extend({
3197 className: 'attachment-details',
3198 template: wp.template('attachment-details'),
3200 attributes: function() {
3203 'data-id': this.model.get( 'id' )
3208 'change [data-setting]': 'updateSetting',
3209 'change [data-setting] input': 'updateSetting',
3210 'change [data-setting] select': 'updateSetting',
3211 'change [data-setting] textarea': 'updateSetting',
3212 'click .delete-attachment': 'deleteAttachment',
3213 'click .trash-attachment': 'trashAttachment',
3214 'click .untrash-attachment': 'untrashAttachment',
3215 'click .edit-attachment': 'editAttachment',
3216 'keydown': 'toggleSelectionHandler'
3219 initialize: function() {
3220 this.options = _.defaults( this.options, {
3221 rerenderOnModelChange: false
3224 this.on( 'ready', this.initialFocus );
3225 // Call 'initialize' directly on the parent class.
3226 Attachment.prototype.initialize.apply( this, arguments );
3229 initialFocus: function() {
3230 if ( ! wp.media.isTouchDevice ) {
3232 Previously focused the first ':input' (the readonly URL text field).
3233 Since the first ':input' is now a button (delete/trash): when pressing
3234 spacebar on an attachment, Firefox fires deleteAttachment/trashAttachment
3235 as soon as focus is moved. Explicitly target the first text field for now.
3236 @todo change initial focus logic, also for accessibility.
3238 this.$( 'input[type="text"]' ).eq( 0 ).focus();
3242 * @param {Object} event
3244 deleteAttachment: function( event ) {
3245 event.preventDefault();
3247 if ( window.confirm( l10n.warnDelete ) ) {
3248 this.model.destroy();
3249 // Keep focus inside media modal
3250 // after image is deleted
3251 this.controller.modal.focusManager.focus();
3255 * @param {Object} event
3257 trashAttachment: function( event ) {
3258 var library = this.controller.library;
3259 event.preventDefault();
3261 if ( wp.media.view.settings.mediaTrash &&
3262 'edit-metadata' === this.controller.content.mode() ) {
3264 this.model.set( 'status', 'trash' );
3265 this.model.save().done( function() {
3266 library._requery( true );
3269 this.model.destroy();
3273 * @param {Object} event
3275 untrashAttachment: function( event ) {
3276 var library = this.controller.library;
3277 event.preventDefault();
3279 this.model.set( 'status', 'inherit' );
3280 this.model.save().done( function() {
3281 library._requery( true );
3285 * @param {Object} event
3287 editAttachment: function( event ) {
3288 var editState = this.controller.states.get( 'edit-image' );
3289 if ( window.imageEdit && editState ) {
3290 event.preventDefault();
3292 editState.set( 'image', this.model );
3293 this.controller.setState( 'edit-image' );
3295 this.$el.addClass('needs-refresh');
3299 * When reverse tabbing(shift+tab) out of the right details panel, deliver
3300 * the focus to the item in the list that was being edited.
3302 * @param {Object} event
3304 toggleSelectionHandler: function( event ) {
3305 if ( 'keydown' === event.type && 9 === event.keyCode && event.shiftKey && event.target === this.$( ':tabbable' ).get( 0 ) ) {
3306 this.controller.trigger( 'attachment:details:shift-tab', event );
3310 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
3311 this.controller.trigger( 'attachment:keydown:arrow', event );
3317 module.exports = Details;
3319 },{}],27:[function(require,module,exports){
3321 * wp.media.view.Attachment.EditLibrary
3324 * @augments wp.media.view.Attachment
3325 * @augments wp.media.View
3326 * @augments wp.Backbone.View
3327 * @augments Backbone.View
3329 var EditLibrary = wp.media.view.Attachment.extend({
3335 module.exports = EditLibrary;
3337 },{}],28:[function(require,module,exports){
3339 * wp.media.view.Attachments.EditSelection
3342 * @augments wp.media.view.Attachment.Selection
3343 * @augments wp.media.view.Attachment
3344 * @augments wp.media.View
3345 * @augments wp.Backbone.View
3346 * @augments Backbone.View
3348 var EditSelection = wp.media.view.Attachment.Selection.extend({
3354 module.exports = EditSelection;
3356 },{}],29:[function(require,module,exports){
3358 * wp.media.view.Attachment.Library
3361 * @augments wp.media.view.Attachment
3362 * @augments wp.media.View
3363 * @augments wp.Backbone.View
3364 * @augments Backbone.View
3366 var Library = wp.media.view.Attachment.extend({
3372 module.exports = Library;
3374 },{}],30:[function(require,module,exports){
3376 * wp.media.view.Attachment.Selection
3379 * @augments wp.media.view.Attachment
3380 * @augments wp.media.View
3381 * @augments wp.Backbone.View
3382 * @augments Backbone.View
3384 var Selection = wp.media.view.Attachment.extend({
3385 className: 'attachment selection',
3387 // On click, just select the model, instead of removing the model from
3389 toggleSelection: function() {
3390 this.options.selection.single( this.model );
3394 module.exports = Selection;
3396 },{}],31:[function(require,module,exports){
3398 * wp.media.view.Attachments
3401 * @augments wp.media.View
3402 * @augments wp.Backbone.View
3403 * @augments Backbone.View
3405 var View = wp.media.View,
3409 Attachments = View.extend({
3411 className: 'attachments',
3417 initialize: function() {
3418 this.el.id = _.uniqueId('__attachments-view-');
3420 _.defaults( this.options, {
3421 refreshSensitivity: wp.media.isTouchDevice ? 300 : 200,
3422 refreshThreshold: 3,
3423 AttachmentView: wp.media.view.Attachment,
3426 idealColumnWidth: $( window ).width() < 640 ? 135 : 150
3429 this._viewsByCid = {};
3430 this.$window = $( window );
3431 this.resizeEvent = 'resize.media-modal-columns';
3433 this.collection.on( 'add', function( attachment ) {
3434 this.views.add( this.createAttachmentView( attachment ), {
3435 at: this.collection.indexOf( attachment )
3439 this.collection.on( 'remove', function( attachment ) {
3440 var view = this._viewsByCid[ attachment.cid ];
3441 delete this._viewsByCid[ attachment.cid ];
3448 this.collection.on( 'reset', this.render, this );
3450 this.listenTo( this.controller, 'library:selection:add', this.attachmentFocus );
3452 // Throttle the scroll handler and bind this.
3453 this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
3455 this.options.scrollElement = this.options.scrollElement || this.el;
3456 $( this.options.scrollElement ).on( 'scroll', this.scroll );
3458 this.initSortable();
3460 _.bindAll( this, 'setColumns' );
3462 if ( this.options.resize ) {
3463 this.on( 'ready', this.bindEvents );
3464 this.controller.on( 'open', this.setColumns );
3466 // Call this.setColumns() after this view has been rendered in the DOM so
3467 // attachments get proper width applied.
3468 _.defer( this.setColumns, this );
3472 bindEvents: function() {
3473 this.$window.off( this.resizeEvent ).on( this.resizeEvent, _.debounce( this.setColumns, 50 ) );
3476 attachmentFocus: function() {
3477 this.$( 'li:first' ).focus();
3480 restoreFocus: function() {
3481 this.$( 'li.selected:first' ).focus();
3484 arrowEvent: function( event ) {
3485 var attachments = this.$el.children( 'li' ),
3486 perRow = this.columns,
3487 index = attachments.filter( ':focus' ).index(),
3488 row = ( index + 1 ) <= perRow ? 1 : Math.ceil( ( index + 1 ) / perRow );
3490 if ( index === -1 ) {
3495 if ( 37 === event.keyCode ) {
3496 if ( 0 === index ) {
3499 attachments.eq( index - 1 ).focus();
3503 if ( 38 === event.keyCode ) {
3507 attachments.eq( index - perRow ).focus();
3511 if ( 39 === event.keyCode ) {
3512 if ( attachments.length === index ) {
3515 attachments.eq( index + 1 ).focus();
3519 if ( 40 === event.keyCode ) {
3520 if ( Math.ceil( attachments.length / perRow ) === row ) {
3523 attachments.eq( index + perRow ).focus();
3527 dispose: function() {
3528 this.collection.props.off( null, null, this );
3529 if ( this.options.resize ) {
3530 this.$window.off( this.resizeEvent );
3534 * call 'dispose' directly on the parent class
3536 View.prototype.dispose.apply( this, arguments );
3539 setColumns: function() {
3540 var prev = this.columns,
3541 width = this.$el.width();
3544 this.columns = Math.min( Math.round( width / this.options.idealColumnWidth ), 12 ) || 1;
3546 if ( ! prev || prev !== this.columns ) {
3547 this.$el.closest( '.media-frame-content' ).attr( 'data-columns', this.columns );
3552 initSortable: function() {
3553 var collection = this.collection;
3555 if ( wp.media.isTouchDevice || ! this.options.sortable || ! $.fn.sortable ) {
3559 this.$el.sortable( _.extend({
3560 // If the `collection` has a `comparator`, disable sorting.
3561 disabled: !! collection.comparator,
3563 // Change the position of the attachment as soon as the
3564 // mouse pointer overlaps a thumbnail.
3565 tolerance: 'pointer',
3567 // Record the initial `index` of the dragged model.
3568 start: function( event, ui ) {
3569 ui.item.data('sortableIndexStart', ui.item.index());
3572 // Update the model's index in the collection.
3573 // Do so silently, as the view is already accurate.
3574 update: function( event, ui ) {
3575 var model = collection.at( ui.item.data('sortableIndexStart') ),
3576 comparator = collection.comparator;
3578 // Temporarily disable the comparator to prevent `add`
3580 delete collection.comparator;
3582 // Silently shift the model to its new index.
3583 collection.remove( model, {
3586 collection.add( model, {
3591 // Restore the comparator.
3592 collection.comparator = comparator;
3594 // Fire the `reset` event to ensure other collections sync.
3595 collection.trigger( 'reset', collection );
3597 // If the collection is sorted by menu order,
3598 // update the menu order.
3599 collection.saveMenuOrder();
3601 }, this.options.sortable ) );
3603 // If the `orderby` property is changed on the `collection`,
3604 // check to see if we have a `comparator`. If so, disable sorting.
3605 collection.props.on( 'change:orderby', function() {
3606 this.$el.sortable( 'option', 'disabled', !! collection.comparator );
3609 this.collection.props.on( 'change:orderby', this.refreshSortable, this );
3610 this.refreshSortable();
3613 refreshSortable: function() {
3614 if ( wp.media.isTouchDevice || ! this.options.sortable || ! $.fn.sortable ) {
3618 // If the `collection` has a `comparator`, disable sorting.
3619 var collection = this.collection,
3620 orderby = collection.props.get('orderby'),
3621 enabled = 'menuOrder' === orderby || ! collection.comparator;
3623 this.$el.sortable( 'option', 'disabled', ! enabled );
3627 * @param {wp.media.model.Attachment} attachment
3628 * @returns {wp.media.View}
3630 createAttachmentView: function( attachment ) {
3631 var view = new this.options.AttachmentView({
3632 controller: this.controller,
3634 collection: this.collection,
3635 selection: this.options.selection
3638 return this._viewsByCid[ attachment.cid ] = view;
3641 prepare: function() {
3642 // Create all of the Attachment views, and replace
3643 // the list in a single DOM operation.
3644 if ( this.collection.length ) {
3645 this.views.set( this.collection.map( this.createAttachmentView, this ) );
3647 // If there are no elements, clear the views and load some.
3650 this.collection.more().done( this.scroll );
3655 // Trigger the scroll event to check if we're within the
3656 // threshold to query for additional attachments.
3660 scroll: function() {
3662 el = this.options.scrollElement,
3663 scrollTop = el.scrollTop,
3666 // The scroll event occurs on the document, but the element
3667 // that should be checked is the document body.
3668 if ( el === document ) {
3670 scrollTop = $(document).scrollTop();
3673 if ( ! $(el).is(':visible') || ! this.collection.hasMore() ) {
3677 toolbar = this.views.parent.toolbar;
3679 // Show the spinner only if we are close to the bottom.
3680 if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 ) {
3681 toolbar.get('spinner').show();
3684 if ( el.scrollHeight < scrollTop + ( el.clientHeight * this.options.refreshThreshold ) ) {
3685 this.collection.more().done(function() {
3687 toolbar.get('spinner').hide();
3693 module.exports = Attachments;
3695 },{}],32:[function(require,module,exports){
3697 * wp.media.view.AttachmentsBrowser
3700 * @augments wp.media.View
3701 * @augments wp.Backbone.View
3702 * @augments Backbone.View
3704 * @param {object} [options] The options hash passed to the view.
3705 * @param {boolean|string} [options.filters=false] Which filters to show in the browser's toolbar.
3706 * Accepts 'uploaded' and 'all'.
3707 * @param {boolean} [options.search=true] Whether to show the search interface in the
3708 * browser's toolbar.
3709 * @param {boolean} [options.date=true] Whether to show the date filter in the
3710 * browser's toolbar.
3711 * @param {boolean} [options.display=false] Whether to show the attachments display settings
3712 * view in the sidebar.
3713 * @param {boolean|string} [options.sidebar=true] Whether to create a sidebar for the browser.
3714 * Accepts true, false, and 'errors'.
3716 var View = wp.media.View,
3717 mediaTrash = wp.media.view.settings.mediaTrash,
3718 l10n = wp.media.view.l10n,
3722 AttachmentsBrowser = View.extend({
3724 className: 'attachments-browser',
3726 initialize: function() {
3727 _.defaults( this.options, {
3733 AttachmentView: wp.media.view.Attachment.Library
3736 this.listenTo( this.controller, 'toggle:upload:attachment', _.bind( this.toggleUploader, this ) );
3737 this.controller.on( 'edit:selection', this.editSelection );
3738 this.createToolbar();
3739 if ( this.options.sidebar ) {
3740 this.createSidebar();
3742 this.createUploader();
3743 this.createAttachments();
3744 this.updateContent();
3746 if ( ! this.options.sidebar || 'errors' === this.options.sidebar ) {
3747 this.$el.addClass( 'hide-sidebar' );
3749 if ( 'errors' === this.options.sidebar ) {
3750 this.$el.addClass( 'sidebar-for-errors' );
3754 this.collection.on( 'add remove reset', this.updateContent, this );
3757 editSelection: function( modal ) {
3758 modal.$( '.media-button-backToLibrary' ).focus();
3762 * @returns {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining
3764 dispose: function() {
3765 this.options.selection.off( null, null, this );
3766 View.prototype.dispose.apply( this, arguments );
3770 createToolbar: function() {
3771 var LibraryViewSwitcher, Filters, toolbarOptions;
3774 controller: this.controller
3777 if ( this.controller.isModeActive( 'grid' ) ) {
3778 toolbarOptions.className = 'media-toolbar wp-filter';
3782 * @member {wp.media.view.Toolbar}
3784 this.toolbar = new wp.media.view.Toolbar( toolbarOptions );
3786 this.views.add( this.toolbar );
3788 this.toolbar.set( 'spinner', new wp.media.view.Spinner({
3792 if ( -1 !== $.inArray( this.options.filters, [ 'uploaded', 'all' ] ) ) {
3793 // "Filters" will return a <select>, need to render
3794 // screen reader text before
3795 this.toolbar.set( 'filtersLabel', new wp.media.view.Label({
3796 value: l10n.filterByType,
3798 'for': 'media-attachment-filters'
3803 if ( 'uploaded' === this.options.filters ) {
3804 this.toolbar.set( 'filters', new wp.media.view.AttachmentFilters.Uploaded({
3805 controller: this.controller,
3806 model: this.collection.props,
3810 Filters = new wp.media.view.AttachmentFilters.All({
3811 controller: this.controller,
3812 model: this.collection.props,
3816 this.toolbar.set( 'filters', Filters.render() );
3820 // Feels odd to bring the global media library switcher into the Attachment
3821 // browser view. Is this a use case for doAction( 'add:toolbar-items:attachments-browser', this.toolbar );
3822 // which the controller can tap into and add this view?
3823 if ( this.controller.isModeActive( 'grid' ) ) {
3824 LibraryViewSwitcher = View.extend({
3825 className: 'view-switch media-grid-view-switch',
3826 template: wp.template( 'media-library-view-switcher')
3829 this.toolbar.set( 'libraryViewSwitcher', new LibraryViewSwitcher({
3830 controller: this.controller,
3834 // DateFilter is a <select>, screen reader text needs to be rendered before
3835 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3836 value: l10n.filterByDate,
3838 'for': 'media-attachment-date-filters'
3842 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3843 controller: this.controller,
3844 model: this.collection.props,
3848 // BulkSelection is a <div> with subviews, including screen reader text
3849 this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({
3850 text: l10n.bulkSelect,
3851 controller: this.controller,
3855 this.toolbar.set( 'deleteSelectedButton', new wp.media.view.DeleteSelectedButton({
3859 text: mediaTrash ? l10n.trashSelected : l10n.deleteSelected,
3860 controller: this.controller,
3863 var changed = [], removed = [],
3864 selection = this.controller.state().get( 'selection' ),
3865 library = this.controller.state().get( 'library' );
3867 if ( ! selection.length ) {
3871 if ( ! mediaTrash && ! window.confirm( l10n.warnBulkDelete ) ) {
3876 'trash' !== selection.at( 0 ).get( 'status' ) &&
3877 ! window.confirm( l10n.warnBulkTrash ) ) {
3882 selection.each( function( model ) {
3883 if ( ! model.get( 'nonces' )['delete'] ) {
3884 removed.push( model );
3888 if ( mediaTrash && 'trash' === model.get( 'status' ) ) {
3889 model.set( 'status', 'inherit' );
3890 changed.push( model.save() );
3891 removed.push( model );
3892 } else if ( mediaTrash ) {
3893 model.set( 'status', 'trash' );
3894 changed.push( model.save() );
3895 removed.push( model );
3897 model.destroy({wait: true});
3901 if ( changed.length ) {
3902 selection.remove( removed );
3904 $.when.apply( null, changed ).then( _.bind( function() {
3905 library._requery( true );
3906 this.controller.trigger( 'selection:action:done' );
3909 this.controller.trigger( 'selection:action:done' );
3915 this.toolbar.set( 'deleteSelectedPermanentlyButton', new wp.media.view.DeleteSelectedPermanentlyButton({
3919 text: l10n.deleteSelected,
3920 controller: this.controller,
3923 var removed = [], selection = this.controller.state().get( 'selection' );
3925 if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
3929 selection.each( function( model ) {
3930 if ( ! model.get( 'nonces' )['delete'] ) {
3931 removed.push( model );
3938 selection.remove( removed );
3939 this.controller.trigger( 'selection:action:done' );
3944 } else if ( this.options.date ) {
3945 // DateFilter is a <select>, screen reader text needs to be rendered before
3946 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3947 value: l10n.filterByDate,
3949 'for': 'media-attachment-date-filters'
3953 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3954 controller: this.controller,
3955 model: this.collection.props,
3960 if ( this.options.search ) {
3961 // Search is an input, screen reader text needs to be rendered before
3962 this.toolbar.set( 'searchLabel', new wp.media.view.Label({
3963 value: l10n.searchMediaLabel,
3965 'for': 'media-search-input'
3969 this.toolbar.set( 'search', new wp.media.view.Search({
3970 controller: this.controller,
3971 model: this.collection.props,
3976 if ( this.options.dragInfo ) {
3977 this.toolbar.set( 'dragInfo', new View({
3978 el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0],
3983 if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
3984 this.toolbar.set( 'suggestedDimensions', new View({
3985 el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + this.options.suggestedWidth + ' × ' + this.options.suggestedHeight + '</div>' )[0],
3991 updateContent: function() {
3995 if ( this.controller.isModeActive( 'grid' ) ) {
3996 noItemsView = view.attachmentsNoResults;
3998 noItemsView = view.uploader;
4001 if ( ! this.collection.length ) {
4002 this.toolbar.get( 'spinner' ).show();
4003 this.dfd = this.collection.more().done( function() {
4004 if ( ! view.collection.length ) {
4005 noItemsView.$el.removeClass( 'hidden' );
4007 noItemsView.$el.addClass( 'hidden' );
4009 view.toolbar.get( 'spinner' ).hide();
4012 noItemsView.$el.addClass( 'hidden' );
4013 view.toolbar.get( 'spinner' ).hide();
4017 createUploader: function() {
4018 this.uploader = new wp.media.view.UploaderInline({
4019 controller: this.controller,
4021 message: this.controller.isModeActive( 'grid' ) ? '' : l10n.noItemsFound,
4022 canClose: this.controller.isModeActive( 'grid' )
4025 this.uploader.hide();
4026 this.views.add( this.uploader );
4029 toggleUploader: function() {
4030 if ( this.uploader.$el.hasClass( 'hidden' ) ) {
4031 this.uploader.show();
4033 this.uploader.hide();
4037 createAttachments: function() {
4038 this.attachments = new wp.media.view.Attachments({
4039 controller: this.controller,
4040 collection: this.collection,
4041 selection: this.options.selection,
4043 sortable: this.options.sortable,
4044 scrollElement: this.options.scrollElement,
4045 idealColumnWidth: this.options.idealColumnWidth,
4047 // The single `Attachment` view to be used in the `Attachments` view.
4048 AttachmentView: this.options.AttachmentView
4051 // Add keydown listener to the instance of the Attachments view
4052 this.attachments.listenTo( this.controller, 'attachment:keydown:arrow', this.attachments.arrowEvent );
4053 this.attachments.listenTo( this.controller, 'attachment:details:shift-tab', this.attachments.restoreFocus );
4055 this.views.add( this.attachments );
4058 if ( this.controller.isModeActive( 'grid' ) ) {
4059 this.attachmentsNoResults = new View({
4060 controller: this.controller,
4064 this.attachmentsNoResults.$el.addClass( 'hidden no-media' );
4065 this.attachmentsNoResults.$el.html( l10n.noMedia );
4067 this.views.add( this.attachmentsNoResults );
4071 createSidebar: function() {
4072 var options = this.options,
4073 selection = options.selection,
4074 sidebar = this.sidebar = new wp.media.view.Sidebar({
4075 controller: this.controller
4078 this.views.add( sidebar );
4080 if ( this.controller.uploader ) {
4081 sidebar.set( 'uploads', new wp.media.view.UploaderStatus({
4082 controller: this.controller,
4087 selection.on( 'selection:single', this.createSingle, this );
4088 selection.on( 'selection:unsingle', this.disposeSingle, this );
4090 if ( selection.single() ) {
4091 this.createSingle();
4095 createSingle: function() {
4096 var sidebar = this.sidebar,
4097 single = this.options.selection.single();
4099 sidebar.set( 'details', new wp.media.view.Attachment.Details({
4100 controller: this.controller,
4105 sidebar.set( 'compat', new wp.media.view.AttachmentCompat({
4106 controller: this.controller,
4111 if ( this.options.display ) {
4112 sidebar.set( 'display', new wp.media.view.Settings.AttachmentDisplay({
4113 controller: this.controller,
4114 model: this.model.display( single ),
4117 userSettings: this.model.get('displayUserSettings')
4121 // Show the sidebar on mobile
4122 if ( this.model.id === 'insert' ) {
4123 sidebar.$el.addClass( 'visible' );
4127 disposeSingle: function() {
4128 var sidebar = this.sidebar;
4129 sidebar.unset('details');
4130 sidebar.unset('compat');
4131 sidebar.unset('display');
4132 // Hide the sidebar on mobile
4133 sidebar.$el.removeClass( 'visible' );
4137 module.exports = AttachmentsBrowser;
4139 },{}],33:[function(require,module,exports){
4141 * wp.media.view.Attachments.Selection
4144 * @augments wp.media.view.Attachments
4145 * @augments wp.media.View
4146 * @augments wp.Backbone.View
4147 * @augments Backbone.View
4149 var Attachments = wp.media.view.Attachments,
4152 Selection = Attachments.extend({
4154 initialize: function() {
4155 _.defaults( this.options, {
4159 // The single `Attachment` view to be used in the `Attachments` view.
4160 AttachmentView: wp.media.view.Attachment.Selection
4162 // Call 'initialize' directly on the parent class.
4163 return Attachments.prototype.initialize.apply( this, arguments );
4167 module.exports = Selection;
4169 },{}],34:[function(require,module,exports){
4171 * wp.media.view.ButtonGroup
4174 * @augments wp.media.View
4175 * @augments wp.Backbone.View
4176 * @augments Backbone.View
4181 ButtonGroup = wp.media.View.extend({
4183 className: 'button-group button-large media-button-group',
4185 initialize: function() {
4187 * @member {wp.media.view.Button[]}
4189 this.buttons = _.map( this.options.buttons || [], function( button ) {
4190 if ( button instanceof Backbone.View ) {
4193 return new wp.media.view.Button( button ).render();
4197 delete this.options.buttons;
4199 if ( this.options.classes ) {
4200 this.$el.addClass( this.options.classes );
4205 * @returns {wp.media.view.ButtonGroup}
4207 render: function() {
4208 this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() );
4213 module.exports = ButtonGroup;
4215 },{}],35:[function(require,module,exports){
4217 * wp.media.view.Button
4220 * @augments wp.media.View
4221 * @augments wp.Backbone.View
4222 * @augments Backbone.View
4224 var Button = wp.media.View.extend({
4226 className: 'media-button',
4227 attributes: { type: 'button' },
4240 initialize: function() {
4242 * Create a model with the provided `defaults`.
4244 * @member {Backbone.Model}
4246 this.model = new Backbone.Model( this.defaults );
4248 // If any of the `options` have a key from `defaults`, apply its
4249 // value to the `model` and remove it from the `options object.
4250 _.each( this.defaults, function( def, key ) {
4251 var value = this.options[ key ];
4252 if ( _.isUndefined( value ) ) {
4256 this.model.set( key, value );
4257 delete this.options[ key ];
4260 this.listenTo( this.model, 'change', this.render );
4263 * @returns {wp.media.view.Button} Returns itself to allow chaining
4265 render: function() {
4266 var classes = [ 'button', this.className ],
4267 model = this.model.toJSON();
4269 if ( model.style ) {
4270 classes.push( 'button-' + model.style );
4274 classes.push( 'button-' + model.size );
4277 classes = _.uniq( classes.concat( this.options.classes ) );
4278 this.el.className = classes.join(' ');
4280 this.$el.attr( 'disabled', model.disabled );
4281 this.$el.text( this.model.get('text') );
4286 * @param {Object} event
4288 click: function( event ) {
4289 if ( '#' === this.attributes.href ) {
4290 event.preventDefault();
4293 if ( this.options.click && ! this.model.get('disabled') ) {
4294 this.options.click.apply( this, arguments );
4299 module.exports = Button;
4301 },{}],36:[function(require,module,exports){
4303 * wp.media.view.Cropper
4305 * Uses the imgAreaSelect plugin to allow a user to crop an image.
4307 * Takes imgAreaSelect options from
4308 * wp.customize.HeaderControl.calculateImageSelectOptions via
4309 * wp.customize.HeaderControl.openMM.
4312 * @augments wp.media.View
4313 * @augments wp.Backbone.View
4314 * @augments Backbone.View
4316 var View = wp.media.View,
4317 UploaderStatus = wp.media.view.UploaderStatus,
4318 l10n = wp.media.view.l10n,
4322 Cropper = View.extend({
4323 className: 'crop-content',
4324 template: wp.template('crop-content'),
4325 initialize: function() {
4326 _.bindAll(this, 'onImageLoad');
4329 this.controller.frame.on('content:error:crop', this.onError, this);
4330 this.$image = this.$el.find('.crop-image');
4331 this.$image.on('load', this.onImageLoad);
4332 $(window).on('resize.cropper', _.debounce(this.onImageLoad, 250));
4334 remove: function() {
4335 $(window).off('resize.cropper');
4338 View.prototype.remove.apply(this, arguments);
4340 prepare: function() {
4342 title: l10n.cropYourImage,
4343 url: this.options.attachment.get('url')
4346 onImageLoad: function() {
4347 var imgOptions = this.controller.get('imgSelectOptions');
4348 if (typeof imgOptions === 'function') {
4349 imgOptions = imgOptions(this.options.attachment, this.controller);
4352 imgOptions = _.extend(imgOptions, {parent: this.$el});
4353 this.trigger('image-loaded');
4354 this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
4356 onError: function() {
4357 var filename = this.options.attachment.get('filename');
4359 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
4360 filename: UploaderStatus.prototype.filename(filename),
4361 message: window._wpMediaViewsL10n.cropError
4366 module.exports = Cropper;
4368 },{}],37:[function(require,module,exports){
4370 * wp.media.view.EditImage
4373 * @augments wp.media.View
4374 * @augments wp.Backbone.View
4375 * @augments Backbone.View
4377 var View = wp.media.View,
4380 EditImage = View.extend({
4381 className: 'image-editor',
4382 template: wp.template('image-editor'),
4384 initialize: function( options ) {
4385 this.editor = window.imageEdit;
4386 this.controller = options.controller;
4387 View.prototype.initialize.apply( this, arguments );
4390 prepare: function() {
4391 return this.model.toJSON();
4394 loadEditor: function() {
4395 var dfd = this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this );
4396 dfd.done( _.bind( this.focus, this ) );
4400 this.$( '.imgedit-submit .button' ).eq( 0 ).focus();
4404 var lastState = this.controller.lastState();
4405 this.controller.setState( lastState );
4408 refresh: function() {
4413 var lastState = this.controller.lastState();
4415 this.model.fetch().done( _.bind( function() {
4416 this.controller.setState( lastState );
4422 module.exports = EditImage;
4424 },{}],38:[function(require,module,exports){
4426 * wp.media.view.Embed
4429 * @augments wp.media.View
4430 * @augments wp.Backbone.View
4431 * @augments Backbone.View
4433 var Embed = wp.media.View.extend({
4434 className: 'media-embed',
4436 initialize: function() {
4438 * @member {wp.media.view.EmbedUrl}
4440 this.url = new wp.media.view.EmbedUrl({
4441 controller: this.controller,
4442 model: this.model.props
4445 this.views.set([ this.url ]);
4447 this.listenTo( this.model, 'change:type', this.refresh );
4448 this.listenTo( this.model, 'change:loading', this.loading );
4452 * @param {Object} view
4454 settings: function( view ) {
4455 if ( this._settings ) {
4456 this._settings.remove();
4458 this._settings = view;
4459 this.views.add( view );
4462 refresh: function() {
4463 var type = this.model.get('type'),
4466 if ( 'image' === type ) {
4467 constructor = wp.media.view.EmbedImage;
4468 } else if ( 'link' === type ) {
4469 constructor = wp.media.view.EmbedLink;
4474 this.settings( new constructor({
4475 controller: this.controller,
4476 model: this.model.props,
4481 loading: function() {
4482 this.$el.toggleClass( 'embed-loading', this.model.get('loading') );
4486 module.exports = Embed;
4488 },{}],39:[function(require,module,exports){
4490 * wp.media.view.EmbedImage
4493 * @augments wp.media.view.Settings.AttachmentDisplay
4494 * @augments wp.media.view.Settings
4495 * @augments wp.media.View
4496 * @augments wp.Backbone.View
4497 * @augments Backbone.View
4499 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
4502 EmbedImage = AttachmentDisplay.extend({
4503 className: 'embed-media-settings',
4504 template: wp.template('embed-image-settings'),
4506 initialize: function() {
4508 * Call `initialize` directly on parent class with passed arguments
4510 AttachmentDisplay.prototype.initialize.apply( this, arguments );
4511 this.listenTo( this.model, 'change:url', this.updateImage );
4514 updateImage: function() {
4515 this.$('img').attr( 'src', this.model.get('url') );
4519 module.exports = EmbedImage;
4521 },{}],40:[function(require,module,exports){
4523 * wp.media.view.EmbedLink
4526 * @augments wp.media.view.Settings
4527 * @augments wp.media.View
4528 * @augments wp.Backbone.View
4529 * @augments Backbone.View
4534 EmbedLink = wp.media.view.Settings.extend({
4535 className: 'embed-link-settings',
4536 template: wp.template('embed-link-settings'),
4538 initialize: function() {
4539 this.listenTo( this.model, 'change:url', this.updateoEmbed );
4542 updateoEmbed: _.debounce( function() {
4543 var url = this.model.get( 'url' );
4545 // clear out previous results
4546 this.$('.embed-container').hide().find('.embed-preview').empty();
4547 this.$( '.setting' ).hide();
4549 // only proceed with embed if the field contains more than 11 characters
4550 // Example: http://a.io is 11 chars
4551 if ( url && ( url.length < 11 || ! url.match(/^http(s)?:\/\//) ) ) {
4556 }, wp.media.controller.Embed.sensitivity ),
4561 // check if they haven't typed in 500 ms
4562 if ( $('#embed-url-field').val() !== this.model.get('url') ) {
4566 if ( this.dfd && 'pending' === this.dfd.state() ) {
4570 embed = new wp.shortcode({
4572 attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
4573 content: this.model.get('url')
4578 url: wp.ajax.settings.url,
4581 action: 'parse-embed',
4582 post_ID: wp.media.view.settings.post.id,
4583 shortcode: embed.string()
4586 .done( this.renderoEmbed )
4587 .fail( this.renderFail );
4590 renderFail: function ( response, status ) {
4591 if ( 'abort' === status ) {
4594 this.$( '.link-text' ).show();
4597 renderoEmbed: function( response ) {
4598 var html = ( response && response.data && response.data.body ) || '';
4601 this.$('.embed-container').show().find('.embed-preview').html( html );
4608 module.exports = EmbedLink;
4610 },{}],41:[function(require,module,exports){
4612 * wp.media.view.EmbedUrl
4615 * @augments wp.media.View
4616 * @augments wp.Backbone.View
4617 * @augments Backbone.View
4619 var View = wp.media.View,
4623 EmbedUrl = View.extend({
4625 className: 'embed-url',
4633 initialize: function() {
4634 this.$input = $('<input id="embed-url-field" type="url" />').val( this.model.get('url') );
4635 this.input = this.$input[0];
4637 this.spinner = $('<span class="spinner" />')[0];
4638 this.$el.append([ this.input, this.spinner ]);
4640 this.listenTo( this.model, 'change:url', this.render );
4642 if ( this.model.get( 'url' ) ) {
4643 _.delay( _.bind( function () {
4644 this.model.trigger( 'change:url' );
4649 * @returns {wp.media.view.EmbedUrl} Returns itself to allow chaining
4651 render: function() {
4652 var $input = this.$input;
4654 if ( $input.is(':focus') ) {
4658 this.input.value = this.model.get('url') || 'http://';
4660 * Call `render` directly on parent class with passed arguments
4662 View.prototype.render.apply( this, arguments );
4667 if ( ! wp.media.isTouchDevice ) {
4672 url: function( event ) {
4673 this.model.set( 'url', event.target.value );
4677 * If the input is visible, focus and select its contents.
4680 var $input = this.$input;
4681 if ( $input.is(':visible') ) {
4682 $input.focus()[0].select();
4687 module.exports = EmbedUrl;
4689 },{}],42:[function(require,module,exports){
4691 * wp.media.view.FocusManager
4694 * @augments wp.media.View
4695 * @augments wp.Backbone.View
4696 * @augments Backbone.View
4698 var FocusManager = wp.media.View.extend({
4701 'keydown': 'constrainTabbing'
4704 focus: function() { // Reset focus on first left menu item
4705 this.$('.media-menu-item').first().focus();
4708 * @param {Object} event
4710 constrainTabbing: function( event ) {
4713 // Look for the tab key.
4714 if ( 9 !== event.keyCode ) {
4718 // Skip the file input added by Plupload.
4719 tabbables = this.$( ':tabbable' ).not( '.moxie-shim input[type="file"]' );
4721 // Keep tab focus within media modal while it's open
4722 if ( tabbables.last()[0] === event.target && ! event.shiftKey ) {
4723 tabbables.first().focus();
4725 } else if ( tabbables.first()[0] === event.target && event.shiftKey ) {
4726 tabbables.last().focus();
4733 module.exports = FocusManager;
4735 },{}],43:[function(require,module,exports){
4737 * wp.media.view.Frame
4739 * A frame is a composite view consisting of one or more regions and one or more
4742 * @see wp.media.controller.State
4743 * @see wp.media.controller.Region
4746 * @augments wp.media.View
4747 * @augments wp.Backbone.View
4748 * @augments Backbone.View
4749 * @mixes wp.media.controller.StateMachine
4751 var Frame = wp.media.View.extend({
4752 initialize: function() {
4753 _.defaults( this.options, {
4756 this._createRegions();
4757 this._createStates();
4758 this._createModes();
4761 _createRegions: function() {
4762 // Clone the regions array.
4763 this.regions = this.regions ? this.regions.slice() : [];
4765 // Initialize regions.
4766 _.each( this.regions, function( region ) {
4767 this[ region ] = new wp.media.controller.Region({
4770 selector: '.media-frame-' + region
4775 * Create the frame's states.
4777 * @see wp.media.controller.State
4778 * @see wp.media.controller.StateMachine
4780 * @fires wp.media.controller.State#ready
4782 _createStates: function() {
4783 // Create the default `states` collection.
4784 this.states = new Backbone.Collection( null, {
4785 model: wp.media.controller.State
4788 // Ensure states have a reference to the frame.
4789 this.states.on( 'add', function( model ) {
4791 model.trigger('ready');
4794 if ( this.options.states ) {
4795 this.states.add( this.options.states );
4800 * A frame can be in a mode or multiple modes at one time.
4802 * For example, the manage media frame can be in the `Bulk Select` or `Edit` mode.
4804 _createModes: function() {
4805 // Store active "modes" that the frame is in. Unrelated to region modes.
4806 this.activeModes = new Backbone.Collection();
4807 this.activeModes.on( 'add remove reset', _.bind( this.triggerModeEvents, this ) );
4809 _.each( this.options.mode, function( mode ) {
4810 this.activateMode( mode );
4814 * Reset all states on the frame to their defaults.
4816 * @returns {wp.media.view.Frame} Returns itself to allow chaining
4819 this.states.invoke( 'trigger', 'reset' );
4823 * Map activeMode collection events to the frame.
4825 triggerModeEvents: function( model, collection, options ) {
4826 var collectionEvent,
4829 remove: 'deactivate'
4832 // Probably a better way to do this.
4833 _.each( options, function( value, key ) {
4835 collectionEvent = key;
4839 if ( ! _.has( modeEventMap, collectionEvent ) ) {
4843 eventToTrigger = model.get('id') + ':' + modeEventMap[collectionEvent];
4844 this.trigger( eventToTrigger );
4847 * Activate a mode on the frame.
4849 * @param string mode Mode ID.
4850 * @returns {this} Returns itself to allow chaining.
4852 activateMode: function( mode ) {
4853 // Bail if the mode is already active.
4854 if ( this.isModeActive( mode ) ) {
4857 this.activeModes.add( [ { id: mode } ] );
4858 // Add a CSS class to the frame so elements can be styled for the mode.
4859 this.$el.addClass( 'mode-' + mode );
4864 * Deactivate a mode on the frame.
4866 * @param string mode Mode ID.
4867 * @returns {this} Returns itself to allow chaining.
4869 deactivateMode: function( mode ) {
4870 // Bail if the mode isn't active.
4871 if ( ! this.isModeActive( mode ) ) {
4874 this.activeModes.remove( this.activeModes.where( { id: mode } ) );
4875 this.$el.removeClass( 'mode-' + mode );
4877 * Frame mode deactivation event.
4879 * @event this#{mode}:deactivate
4881 this.trigger( mode + ':deactivate' );
4886 * Check if a mode is enabled on the frame.
4888 * @param string mode Mode ID.
4891 isModeActive: function( mode ) {
4892 return Boolean( this.activeModes.where( { id: mode } ).length );
4896 // Make the `Frame` a `StateMachine`.
4897 _.extend( Frame.prototype, wp.media.controller.StateMachine.prototype );
4899 module.exports = Frame;
4901 },{}],44:[function(require,module,exports){
4903 * wp.media.view.MediaFrame.ImageDetails
4905 * A media frame for manipulating an image that's already been inserted
4909 * @augments wp.media.view.MediaFrame.Select
4910 * @augments wp.media.view.MediaFrame
4911 * @augments wp.media.view.Frame
4912 * @augments wp.media.View
4913 * @augments wp.Backbone.View
4914 * @augments Backbone.View
4915 * @mixes wp.media.controller.StateMachine
4917 var Select = wp.media.view.MediaFrame.Select,
4918 l10n = wp.media.view.l10n,
4921 ImageDetails = Select.extend({
4925 menu: 'image-details',
4926 content: 'image-details',
4927 toolbar: 'image-details',
4929 title: l10n.imageDetailsTitle,
4933 initialize: function( options ) {
4934 this.image = new wp.media.model.PostImage( options.metadata );
4935 this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } );
4936 Select.prototype.initialize.apply( this, arguments );
4939 bindHandlers: function() {
4940 Select.prototype.bindHandlers.apply( this, arguments );
4941 this.on( 'menu:create:image-details', this.createMenu, this );
4942 this.on( 'content:create:image-details', this.imageDetailsContent, this );
4943 this.on( 'content:render:edit-image', this.editImageContent, this );
4944 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this );
4945 // override the select toolbar
4946 this.on( 'toolbar:render:replace', this.renderReplaceImageToolbar, this );
4949 createStates: function() {
4951 new wp.media.controller.ImageDetails({
4955 new wp.media.controller.ReplaceImage({
4956 id: 'replace-image',
4957 library: wp.media.query( { type: 'image' } ),
4960 title: l10n.imageReplaceTitle,
4963 displaySettings: true
4965 new wp.media.controller.EditImage( {
4967 selection: this.options.selection
4972 imageDetailsContent: function( options ) {
4973 options.view = new wp.media.view.ImageDetails({
4975 model: this.state().image,
4976 attachment: this.state().image.attachment
4980 editImageContent: function() {
4981 var state = this.state(),
4982 model = state.get('image'),
4989 view = new wp.media.view.EditImage( { model: model, controller: this } ).render();
4991 this.content.set( view );
4993 // after bringing in the frame, load the actual editor via an ajax call
4998 renderImageDetailsToolbar: function() {
4999 this.toolbar.set( new wp.media.view.Toolbar({
5008 var controller = this.controller,
5009 state = controller.state();
5013 // not sure if we want to use wp.media.string.image which will create a shortcode or
5014 // perhaps wp.html.string to at least to build the <img />
5015 state.trigger( 'update', controller.image.toJSON() );
5017 // Restore and reset the default state.
5018 controller.setState( controller.options.state );
5026 renderReplaceImageToolbar: function() {
5028 lastState = frame.lastState(),
5029 previous = lastState && lastState.id;
5031 this.toolbar.set( new wp.media.view.Toolbar({
5039 frame.setState( previous );
5052 var controller = this.controller,
5053 state = controller.state(),
5054 selection = state.get( 'selection' ),
5055 attachment = selection.single();
5059 controller.image.changeAttachment( attachment, state.display( attachment ) );
5061 // not sure if we want to use wp.media.string.image which will create a shortcode or
5062 // perhaps wp.html.string to at least to build the <img />
5063 state.trigger( 'replace', controller.image.toJSON() );
5065 // Restore and reset the default state.
5066 controller.setState( controller.options.state );
5076 module.exports = ImageDetails;
5078 },{}],45:[function(require,module,exports){
5080 * wp.media.view.MediaFrame.Post
5082 * The frame for manipulating media on the Edit Post page.
5085 * @augments wp.media.view.MediaFrame.Select
5086 * @augments wp.media.view.MediaFrame
5087 * @augments wp.media.view.Frame
5088 * @augments wp.media.View
5089 * @augments wp.Backbone.View
5090 * @augments Backbone.View
5091 * @mixes wp.media.controller.StateMachine
5093 var Select = wp.media.view.MediaFrame.Select,
5094 Library = wp.media.controller.Library,
5095 l10n = wp.media.view.l10n,
5098 Post = Select.extend({
5099 initialize: function() {
5102 count: wp.media.view.settings.attachmentCounts.audio,
5106 count: wp.media.view.settings.attachmentCounts.video,
5107 state: 'video-playlist'
5111 _.defaults( this.options, {
5118 // Call 'initialize' directly on the parent class.
5119 Select.prototype.initialize.apply( this, arguments );
5120 this.createIframeStates();
5125 * Create the default states.
5127 createStates: function() {
5128 var options = this.options;
5134 title: l10n.insertMediaTitle,
5136 toolbar: 'main-insert',
5138 library: wp.media.query( options.library ),
5139 multiple: options.multiple ? 'reset' : false,
5142 // If the user isn't allowed to edit fields,
5143 // can they still edit it locally?
5144 allowLocalEdits: true,
5146 // Show the attachment display settings.
5147 displaySettings: true,
5148 // Update user settings when users adjust the
5149 // attachment display settings.
5150 displayUserSettings: true
5155 title: l10n.createGalleryTitle,
5157 toolbar: 'main-gallery',
5158 filterable: 'uploaded',
5162 library: wp.media.query( _.defaults({
5164 }, options.library ) )
5168 new wp.media.controller.Embed( { metadata: options.metadata } ),
5170 new wp.media.controller.EditImage( { model: options.editImage } ),
5173 new wp.media.controller.GalleryEdit({
5174 library: options.selection,
5175 editing: options.editing,
5179 new wp.media.controller.GalleryAdd(),
5183 title: l10n.createPlaylistTitle,
5185 toolbar: 'main-playlist',
5186 filterable: 'uploaded',
5190 library: wp.media.query( _.defaults({
5192 }, options.library ) )
5196 new wp.media.controller.CollectionEdit({
5198 collectionType: 'playlist',
5199 title: l10n.editPlaylistTitle,
5200 SettingsView: wp.media.view.Settings.Playlist,
5201 library: options.selection,
5202 editing: options.editing,
5204 dragInfoText: l10n.playlistDragInfo,
5208 new wp.media.controller.CollectionAdd({
5210 collectionType: 'playlist',
5211 title: l10n.addToPlaylistTitle
5215 id: 'video-playlist',
5216 title: l10n.createVideoPlaylistTitle,
5218 toolbar: 'main-video-playlist',
5219 filterable: 'uploaded',
5223 library: wp.media.query( _.defaults({
5225 }, options.library ) )
5228 new wp.media.controller.CollectionEdit({
5230 collectionType: 'playlist',
5231 title: l10n.editVideoPlaylistTitle,
5232 SettingsView: wp.media.view.Settings.Playlist,
5233 library: options.selection,
5234 editing: options.editing,
5235 menu: 'video-playlist',
5236 dragInfoText: l10n.videoPlaylistDragInfo,
5240 new wp.media.controller.CollectionAdd({
5242 collectionType: 'playlist',
5243 title: l10n.addToVideoPlaylistTitle
5247 if ( wp.media.view.settings.post.featuredImageId ) {
5248 this.states.add( new wp.media.controller.FeaturedImage() );
5252 bindHandlers: function() {
5253 var handlers, checkCounts;
5255 Select.prototype.bindHandlers.apply( this, arguments );
5257 this.on( 'activate', this.activate, this );
5259 // Only bother checking media type counts if one of the counts is zero
5260 checkCounts = _.find( this.counts, function( type ) {
5261 return type.count === 0;
5264 if ( typeof checkCounts !== 'undefined' ) {
5265 this.listenTo( wp.media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
5268 this.on( 'menu:create:gallery', this.createMenu, this );
5269 this.on( 'menu:create:playlist', this.createMenu, this );
5270 this.on( 'menu:create:video-playlist', this.createMenu, this );
5271 this.on( 'toolbar:create:main-insert', this.createToolbar, this );
5272 this.on( 'toolbar:create:main-gallery', this.createToolbar, this );
5273 this.on( 'toolbar:create:main-playlist', this.createToolbar, this );
5274 this.on( 'toolbar:create:main-video-playlist', this.createToolbar, this );
5275 this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
5276 this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
5280 'default': 'mainMenu',
5281 'gallery': 'galleryMenu',
5282 'playlist': 'playlistMenu',
5283 'video-playlist': 'videoPlaylistMenu'
5287 'embed': 'embedContent',
5288 'edit-image': 'editImageContent',
5289 'edit-selection': 'editSelectionContent'
5293 'main-insert': 'mainInsertToolbar',
5294 'main-gallery': 'mainGalleryToolbar',
5295 'gallery-edit': 'galleryEditToolbar',
5296 'gallery-add': 'galleryAddToolbar',
5297 'main-playlist': 'mainPlaylistToolbar',
5298 'playlist-edit': 'playlistEditToolbar',
5299 'playlist-add': 'playlistAddToolbar',
5300 'main-video-playlist': 'mainVideoPlaylistToolbar',
5301 'video-playlist-edit': 'videoPlaylistEditToolbar',
5302 'video-playlist-add': 'videoPlaylistAddToolbar'
5306 _.each( handlers, function( regionHandlers, region ) {
5307 _.each( regionHandlers, function( callback, handler ) {
5308 this.on( region + ':render:' + handler, this[ callback ], this );
5313 activate: function() {
5314 // Hide menu items for states tied to particular media types if there are no items
5315 _.each( this.counts, function( type ) {
5316 if ( type.count < 1 ) {
5317 this.menuItemVisibility( type.state, 'hide' );
5322 mediaTypeCounts: function( model, attr ) {
5323 if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
5324 this.counts[ attr ].count++;
5325 this.menuItemVisibility( this.counts[ attr ].state, 'show' );
5331 * @param {wp.Backbone.View} view
5333 mainMenu: function( view ) {
5335 'library-separator': new wp.media.View({
5336 className: 'separator',
5342 menuItemVisibility: function( state, visibility ) {
5343 var menu = this.menu.get();
5344 if ( visibility === 'hide' ) {
5346 } else if ( visibility === 'show' ) {
5351 * @param {wp.Backbone.View} view
5353 galleryMenu: function( view ) {
5354 var lastState = this.lastState(),
5355 previous = lastState && lastState.id,
5360 text: l10n.cancelGalleryTitle,
5364 frame.setState( previous );
5369 // Keep focus inside media modal
5370 // after canceling a gallery
5371 this.controller.modal.focusManager.focus();
5374 separateCancel: new wp.media.View({
5375 className: 'separator',
5381 playlistMenu: function( view ) {
5382 var lastState = this.lastState(),
5383 previous = lastState && lastState.id,
5388 text: l10n.cancelPlaylistTitle,
5392 frame.setState( previous );
5398 separateCancel: new wp.media.View({
5399 className: 'separator',
5405 videoPlaylistMenu: function( view ) {
5406 var lastState = this.lastState(),
5407 previous = lastState && lastState.id,
5412 text: l10n.cancelVideoPlaylistTitle,
5416 frame.setState( previous );
5422 separateCancel: new wp.media.View({
5423 className: 'separator',
5430 embedContent: function() {
5431 var view = new wp.media.view.Embed({
5436 this.content.set( view );
5438 if ( ! wp.media.isTouchDevice ) {
5443 editSelectionContent: function() {
5444 var state = this.state(),
5445 selection = state.get('selection'),
5448 view = new wp.media.view.AttachmentsBrowser({
5450 collection: selection,
5451 selection: selection,
5458 AttachmentView: wp.media.view.Attachments.EditSelection
5461 view.toolbar.set( 'backToLibrary', {
5462 text: l10n.returnToLibrary,
5466 this.controller.content.mode('browse');
5470 // Browse our library of attachments.
5471 this.content.set( view );
5473 // Trigger the controller to set focus
5474 this.trigger( 'edit:selection', this );
5477 editImageContent: function() {
5478 var image = this.state().get('image'),
5479 view = new wp.media.view.EditImage( { model: image, controller: this } ).render();
5481 this.content.set( view );
5483 // after creating the wrapper view, load the actual editor via an ajax call
5491 * @param {wp.Backbone.View} view
5493 selectionStatusToolbar: function( view ) {
5494 var editable = this.state().get('editable');
5496 view.set( 'selection', new wp.media.view.Selection({
5498 collection: this.state().get('selection'),
5501 // If the selection is editable, pass the callback to
5502 // switch the content mode.
5503 editable: editable && function() {
5504 this.controller.content.mode('edit-selection');
5510 * @param {wp.Backbone.View} view
5512 mainInsertToolbar: function( view ) {
5513 var controller = this;
5515 this.selectionStatusToolbar( view );
5517 view.set( 'insert', {
5520 text: l10n.insertIntoPost,
5521 requires: { selection: true },
5524 * @fires wp.media.controller.State#insert
5527 var state = controller.state(),
5528 selection = state.get('selection');
5531 state.trigger( 'insert', selection ).reset();
5537 * @param {wp.Backbone.View} view
5539 mainGalleryToolbar: function( view ) {
5540 var controller = this;
5542 this.selectionStatusToolbar( view );
5544 view.set( 'gallery', {
5546 text: l10n.createNewGallery,
5548 requires: { selection: true },
5551 var selection = controller.state().get('selection'),
5552 edit = controller.state('gallery-edit'),
5553 models = selection.where({ type: 'image' });
5555 edit.set( 'library', new wp.media.model.Selection( models, {
5556 props: selection.props.toJSON(),
5560 this.controller.setState('gallery-edit');
5562 // Keep focus inside media modal
5563 // after jumping to gallery view
5564 this.controller.modal.focusManager.focus();
5569 mainPlaylistToolbar: function( view ) {
5570 var controller = this;
5572 this.selectionStatusToolbar( view );
5574 view.set( 'playlist', {
5576 text: l10n.createNewPlaylist,
5578 requires: { selection: true },
5581 var selection = controller.state().get('selection'),
5582 edit = controller.state('playlist-edit'),
5583 models = selection.where({ type: 'audio' });
5585 edit.set( 'library', new wp.media.model.Selection( models, {
5586 props: selection.props.toJSON(),
5590 this.controller.setState('playlist-edit');
5592 // Keep focus inside media modal
5593 // after jumping to playlist view
5594 this.controller.modal.focusManager.focus();
5599 mainVideoPlaylistToolbar: function( view ) {
5600 var controller = this;
5602 this.selectionStatusToolbar( view );
5604 view.set( 'video-playlist', {
5606 text: l10n.createNewVideoPlaylist,
5608 requires: { selection: true },
5611 var selection = controller.state().get('selection'),
5612 edit = controller.state('video-playlist-edit'),
5613 models = selection.where({ type: 'video' });
5615 edit.set( 'library', new wp.media.model.Selection( models, {
5616 props: selection.props.toJSON(),
5620 this.controller.setState('video-playlist-edit');
5622 // Keep focus inside media modal
5623 // after jumping to video playlist view
5624 this.controller.modal.focusManager.focus();
5629 featuredImageToolbar: function( toolbar ) {
5630 this.createSelectToolbar( toolbar, {
5631 text: l10n.setFeaturedImage,
5632 state: this.options.state
5636 mainEmbedToolbar: function( toolbar ) {
5637 toolbar.view = new wp.media.view.Toolbar.Embed({
5642 galleryEditToolbar: function() {
5643 var editing = this.state().get('editing');
5644 this.toolbar.set( new wp.media.view.Toolbar({
5649 text: editing ? l10n.updateGallery : l10n.insertGallery,
5651 requires: { library: true },
5654 * @fires wp.media.controller.State#update
5657 var controller = this.controller,
5658 state = controller.state();
5661 state.trigger( 'update', state.get('library') );
5663 // Restore and reset the default state.
5664 controller.setState( controller.options.state );
5672 galleryAddToolbar: function() {
5673 this.toolbar.set( new wp.media.view.Toolbar({
5678 text: l10n.addToGallery,
5680 requires: { selection: true },
5683 * @fires wp.media.controller.State#reset
5686 var controller = this.controller,
5687 state = controller.state(),
5688 edit = controller.state('gallery-edit');
5690 edit.get('library').add( state.get('selection').models );
5691 state.trigger('reset');
5692 controller.setState('gallery-edit');
5699 playlistEditToolbar: function() {
5700 var editing = this.state().get('editing');
5701 this.toolbar.set( new wp.media.view.Toolbar({
5706 text: editing ? l10n.updatePlaylist : l10n.insertPlaylist,
5708 requires: { library: true },
5711 * @fires wp.media.controller.State#update
5714 var controller = this.controller,
5715 state = controller.state();
5718 state.trigger( 'update', state.get('library') );
5720 // Restore and reset the default state.
5721 controller.setState( controller.options.state );
5729 playlistAddToolbar: function() {
5730 this.toolbar.set( new wp.media.view.Toolbar({
5735 text: l10n.addToPlaylist,
5737 requires: { selection: true },
5740 * @fires wp.media.controller.State#reset
5743 var controller = this.controller,
5744 state = controller.state(),
5745 edit = controller.state('playlist-edit');
5747 edit.get('library').add( state.get('selection').models );
5748 state.trigger('reset');
5749 controller.setState('playlist-edit');
5756 videoPlaylistEditToolbar: function() {
5757 var editing = this.state().get('editing');
5758 this.toolbar.set( new wp.media.view.Toolbar({
5763 text: editing ? l10n.updateVideoPlaylist : l10n.insertVideoPlaylist,
5765 requires: { library: true },
5768 var controller = this.controller,
5769 state = controller.state(),
5770 library = state.get('library');
5772 library.type = 'video';
5775 state.trigger( 'update', library );
5777 // Restore and reset the default state.
5778 controller.setState( controller.options.state );
5786 videoPlaylistAddToolbar: function() {
5787 this.toolbar.set( new wp.media.view.Toolbar({
5792 text: l10n.addToVideoPlaylist,
5794 requires: { selection: true },
5797 var controller = this.controller,
5798 state = controller.state(),
5799 edit = controller.state('video-playlist-edit');
5801 edit.get('library').add( state.get('selection').models );
5802 state.trigger('reset');
5803 controller.setState('video-playlist-edit');
5811 module.exports = Post;
5813 },{}],46:[function(require,module,exports){
5815 * wp.media.view.MediaFrame.Select
5817 * A frame for selecting an item or items from the media library.
5820 * @augments wp.media.view.MediaFrame
5821 * @augments wp.media.view.Frame
5822 * @augments wp.media.View
5823 * @augments wp.Backbone.View
5824 * @augments Backbone.View
5825 * @mixes wp.media.controller.StateMachine
5828 var MediaFrame = wp.media.view.MediaFrame,
5829 l10n = wp.media.view.l10n,
5832 Select = MediaFrame.extend({
5833 initialize: function() {
5834 // Call 'initialize' directly on the parent class.
5835 MediaFrame.prototype.initialize.apply( this, arguments );
5837 _.defaults( this.options, {
5844 this.createSelection();
5845 this.createStates();
5846 this.bindHandlers();
5850 * Attach a selection collection to the frame.
5852 * A selection is a collection of attachments used for a specific purpose
5853 * by a media frame. e.g. Selecting an attachment (or many) to insert into
5856 * @see media.model.Selection
5858 createSelection: function() {
5859 var selection = this.options.selection;
5861 if ( ! (selection instanceof wp.media.model.Selection) ) {
5862 this.options.selection = new wp.media.model.Selection( selection, {
5863 multiple: this.options.multiple
5868 attachments: new wp.media.model.Attachments(),
5874 * Create the default states on the frame.
5876 createStates: function() {
5877 var options = this.options;
5879 if ( this.options.states ) {
5883 // Add the default states.
5886 new wp.media.controller.Library({
5887 library: wp.media.query( options.library ),
5888 multiple: options.multiple,
5889 title: options.title,
5896 * Bind region mode event callbacks.
5898 * @see media.controller.Region.render
5900 bindHandlers: function() {
5901 this.on( 'router:create:browse', this.createRouter, this );
5902 this.on( 'router:render:browse', this.browseRouter, this );
5903 this.on( 'content:create:browse', this.browseContent, this );
5904 this.on( 'content:render:upload', this.uploadContent, this );
5905 this.on( 'toolbar:create:select', this.createSelectToolbar, this );
5909 * Render callback for the router region in the `browse` mode.
5911 * @param {wp.media.view.Router} routerView
5913 browseRouter: function( routerView ) {
5916 text: l10n.uploadFilesTitle,
5920 text: l10n.mediaLibraryTitle,
5927 * Render callback for the content region in the `browse` mode.
5929 * @param {wp.media.controller.Region} contentRegion
5931 browseContent: function( contentRegion ) {
5932 var state = this.state();
5934 this.$el.removeClass('hide-toolbar');
5936 // Browse our library of attachments.
5937 contentRegion.view = new wp.media.view.AttachmentsBrowser({
5939 collection: state.get('library'),
5940 selection: state.get('selection'),
5942 sortable: state.get('sortable'),
5943 search: state.get('searchable'),
5944 filters: state.get('filterable'),
5945 date: state.get('date'),
5946 display: state.has('display') ? state.get('display') : state.get('displaySettings'),
5947 dragInfo: state.get('dragInfo'),
5949 idealColumnWidth: state.get('idealColumnWidth'),
5950 suggestedWidth: state.get('suggestedWidth'),
5951 suggestedHeight: state.get('suggestedHeight'),
5953 AttachmentView: state.get('AttachmentView')
5958 * Render callback for the content region in the `upload` mode.
5960 uploadContent: function() {
5961 this.$el.removeClass( 'hide-toolbar' );
5962 this.content.set( new wp.media.view.UploaderInline({
5970 * @param {Object} toolbar
5971 * @param {Object} [options={}]
5972 * @this wp.media.controller.Region
5974 createSelectToolbar: function( toolbar, options ) {
5975 options = options || this.options.button || {};
5976 options.controller = this;
5978 toolbar.view = new wp.media.view.Toolbar.Select( options );
5982 module.exports = Select;
5984 },{}],47:[function(require,module,exports){
5986 * wp.media.view.Iframe
5989 * @augments wp.media.View
5990 * @augments wp.Backbone.View
5991 * @augments Backbone.View
5993 var Iframe = wp.media.View.extend({
5994 className: 'media-iframe',
5996 * @returns {wp.media.view.Iframe} Returns itself to allow chaining
5998 render: function() {
5999 this.views.detach();
6000 this.$el.html( '<iframe src="' + this.controller.state().get('src') + '" />' );
6001 this.views.render();
6006 module.exports = Iframe;
6008 },{}],48:[function(require,module,exports){
6010 * wp.media.view.ImageDetails
6013 * @augments wp.media.view.Settings.AttachmentDisplay
6014 * @augments wp.media.view.Settings
6015 * @augments wp.media.View
6016 * @augments wp.Backbone.View
6017 * @augments Backbone.View
6019 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
6023 ImageDetails = AttachmentDisplay.extend({
6024 className: 'image-details',
6025 template: wp.template('image-details'),
6026 events: _.defaults( AttachmentDisplay.prototype.events, {
6027 'click .edit-attachment': 'editAttachment',
6028 'click .replace-attachment': 'replaceAttachment',
6029 'click .advanced-toggle': 'onToggleAdvanced',
6030 'change [data-setting="customWidth"]': 'onCustomSize',
6031 'change [data-setting="customHeight"]': 'onCustomSize',
6032 'keyup [data-setting="customWidth"]': 'onCustomSize',
6033 'keyup [data-setting="customHeight"]': 'onCustomSize'
6035 initialize: function() {
6036 // used in AttachmentDisplay.prototype.updateLinkTo
6037 this.options.attachment = this.model.attachment;
6038 this.listenTo( this.model, 'change:url', this.updateUrl );
6039 this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
6040 this.listenTo( this.model, 'change:size', this.toggleCustomSize );
6042 AttachmentDisplay.prototype.initialize.apply( this, arguments );
6045 prepare: function() {
6046 var attachment = false;
6048 if ( this.model.attachment ) {
6049 attachment = this.model.attachment.toJSON();
6052 model: this.model.toJSON(),
6053 attachment: attachment
6057 render: function() {
6058 var args = arguments;
6060 if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
6062 .done( _.bind( function() {
6063 AttachmentDisplay.prototype.render.apply( this, args );
6066 .fail( _.bind( function() {
6067 this.model.attachment = false;
6068 AttachmentDisplay.prototype.render.apply( this, args );
6072 AttachmentDisplay.prototype.render.apply( this, arguments );
6079 postRender: function() {
6080 setTimeout( _.bind( this.resetFocus, this ), 10 );
6081 this.toggleLinkSettings();
6082 if ( window.getUserSetting( 'advImgDetails' ) === 'show' ) {
6083 this.toggleAdvanced( true );
6085 this.trigger( 'post-render' );
6088 resetFocus: function() {
6089 this.$( '.link-to-custom' ).blur();
6090 this.$( '.embed-media-settings' ).scrollTop( 0 );
6093 updateUrl: function() {
6094 this.$( '.image img' ).attr( 'src', this.model.get( 'url' ) );
6095 this.$( '.url' ).val( this.model.get( 'url' ) );
6098 toggleLinkSettings: function() {
6099 if ( this.model.get( 'link' ) === 'none' ) {
6100 this.$( '.link-settings' ).addClass('hidden');
6102 this.$( '.link-settings' ).removeClass('hidden');
6106 toggleCustomSize: function() {
6107 if ( this.model.get( 'size' ) !== 'custom' ) {
6108 this.$( '.custom-size' ).addClass('hidden');
6110 this.$( '.custom-size' ).removeClass('hidden');
6114 onCustomSize: function( event ) {
6115 var dimension = $( event.target ).data('setting'),
6116 num = $( event.target ).val(),
6119 // Ignore bogus input
6120 if ( ! /^\d+/.test( num ) || parseInt( num, 10 ) < 1 ) {
6121 event.preventDefault();
6125 if ( dimension === 'customWidth' ) {
6126 value = Math.round( 1 / this.model.get( 'aspectRatio' ) * num );
6127 this.model.set( 'customHeight', value, { silent: true } );
6128 this.$( '[data-setting="customHeight"]' ).val( value );
6130 value = Math.round( this.model.get( 'aspectRatio' ) * num );
6131 this.model.set( 'customWidth', value, { silent: true } );
6132 this.$( '[data-setting="customWidth"]' ).val( value );
6136 onToggleAdvanced: function( event ) {
6137 event.preventDefault();
6138 this.toggleAdvanced();
6141 toggleAdvanced: function( show ) {
6142 var $advanced = this.$el.find( '.advanced-section' ),
6145 if ( $advanced.hasClass('advanced-visible') || show === false ) {
6146 $advanced.removeClass('advanced-visible');
6147 $advanced.find('.advanced-settings').addClass('hidden');
6150 $advanced.addClass('advanced-visible');
6151 $advanced.find('.advanced-settings').removeClass('hidden');
6155 window.setUserSetting( 'advImgDetails', mode );
6158 editAttachment: function( event ) {
6159 var editState = this.controller.states.get( 'edit-image' );
6161 if ( window.imageEdit && editState ) {
6162 event.preventDefault();
6163 editState.set( 'image', this.model.attachment );
6164 this.controller.setState( 'edit-image' );
6168 replaceAttachment: function( event ) {
6169 event.preventDefault();
6170 this.controller.setState( 'replace-image' );
6174 module.exports = ImageDetails;
6176 },{}],49:[function(require,module,exports){
6178 * wp.media.view.Label
6181 * @augments wp.media.View
6182 * @augments wp.Backbone.View
6183 * @augments Backbone.View
6185 var Label = wp.media.View.extend({
6187 className: 'screen-reader-text',
6189 initialize: function() {
6190 this.value = this.options.value;
6193 render: function() {
6194 this.$el.html( this.value );
6200 module.exports = Label;
6202 },{}],50:[function(require,module,exports){
6204 * wp.media.view.MediaFrame
6206 * The frame used to create the media modal.
6209 * @augments wp.media.view.Frame
6210 * @augments wp.media.View
6211 * @augments wp.Backbone.View
6212 * @augments Backbone.View
6213 * @mixes wp.media.controller.StateMachine
6215 var Frame = wp.media.view.Frame,
6219 MediaFrame = Frame.extend({
6220 className: 'media-frame',
6221 template: wp.template('media-frame'),
6222 regions: ['menu','title','content','toolbar','router'],
6225 'click div.media-frame-title h1': 'toggleMenu'
6229 * @global wp.Uploader
6231 initialize: function() {
6232 Frame.prototype.initialize.apply( this, arguments );
6234 _.defaults( this.options, {
6240 // Ensure core UI is enabled.
6241 this.$el.addClass('wp-core-ui');
6243 // Initialize modal container view.
6244 if ( this.options.modal ) {
6245 this.modal = new wp.media.view.Modal({
6247 title: this.options.title
6250 this.modal.content( this );
6253 // Force the uploader off if the upload limit has been exceeded or
6254 // if the browser isn't supported.
6255 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
6256 this.options.uploader = false;
6259 // Initialize window-wide uploader.
6260 if ( this.options.uploader ) {
6261 this.uploader = new wp.media.view.UploaderWindow({
6264 dropzone: this.modal ? this.modal.$el : this.$el,
6268 this.views.set( '.media-frame-uploader', this.uploader );
6271 this.on( 'attach', _.bind( this.views.ready, this.views ), this );
6273 // Bind default title creation.
6274 this.on( 'title:create:default', this.createTitle, this );
6275 this.title.mode('default');
6277 this.on( 'title:render', function( view ) {
6278 view.$el.append( '<span class="dashicons dashicons-arrow-down"></span>' );
6281 // Bind default menu.
6282 this.on( 'menu:create:default', this.createMenu, this );
6285 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6287 render: function() {
6288 // Activate the default state if no active state exists.
6289 if ( ! this.state() && this.options.state ) {
6290 this.setState( this.options.state );
6293 * call 'render' directly on the parent class
6295 return Frame.prototype.render.apply( this, arguments );
6298 * @param {Object} title
6299 * @this wp.media.controller.Region
6301 createTitle: function( title ) {
6302 title.view = new wp.media.View({
6308 * @param {Object} menu
6309 * @this wp.media.controller.Region
6311 createMenu: function( menu ) {
6312 menu.view = new wp.media.view.Menu({
6317 toggleMenu: function() {
6318 this.$el.find( '.media-menu' ).toggleClass( 'visible' );
6322 * @param {Object} toolbar
6323 * @this wp.media.controller.Region
6325 createToolbar: function( toolbar ) {
6326 toolbar.view = new wp.media.view.Toolbar({
6331 * @param {Object} router
6332 * @this wp.media.controller.Region
6334 createRouter: function( router ) {
6335 router.view = new wp.media.view.Router({
6340 * @param {Object} options
6342 createIframeStates: function( options ) {
6343 var settings = wp.media.view.settings,
6344 tabs = settings.tabs,
6345 tabUrl = settings.tabUrl,
6348 if ( ! tabs || ! tabUrl ) {
6352 // Add the post ID to the tab URL if it exists.
6353 $postId = $('#post_ID');
6354 if ( $postId.length ) {
6355 tabUrl += '&post_id=' + $postId.val();
6358 // Generate the tab states.
6359 _.each( tabs, function( title, id ) {
6360 this.state( 'iframe:' + id ).set( _.defaults({
6362 src: tabUrl + '&tab=' + id,
6369 this.on( 'content:create:iframe', this.iframeContent, this );
6370 this.on( 'content:deactivate:iframe', this.iframeContentCleanup, this );
6371 this.on( 'menu:render:default', this.iframeMenu, this );
6372 this.on( 'open', this.hijackThickbox, this );
6373 this.on( 'close', this.restoreThickbox, this );
6377 * @param {Object} content
6378 * @this wp.media.controller.Region
6380 iframeContent: function( content ) {
6381 this.$el.addClass('hide-toolbar');
6382 content.view = new wp.media.view.Iframe({
6387 iframeContentCleanup: function() {
6388 this.$el.removeClass('hide-toolbar');
6391 iframeMenu: function( view ) {
6398 _.each( wp.media.view.settings.tabs, function( title, id ) {
6399 views[ 'iframe:' + id ] = {
6400 text: this.state( 'iframe:' + id ).get('title'),
6408 hijackThickbox: function() {
6411 if ( ! window.tb_remove || this._tb_remove ) {
6415 this._tb_remove = window.tb_remove;
6416 window.tb_remove = function() {
6419 frame.setState( frame.options.state );
6420 frame._tb_remove.call( window );
6424 restoreThickbox: function() {
6425 if ( ! this._tb_remove ) {
6429 window.tb_remove = this._tb_remove;
6430 delete this._tb_remove;
6434 // Map some of the modal's methods to the frame.
6435 _.each(['open','close','attach','detach','escape'], function( method ) {
6437 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6439 MediaFrame.prototype[ method ] = function() {
6441 this.modal[ method ].apply( this.modal, arguments );
6447 module.exports = MediaFrame;
6449 },{}],51:[function(require,module,exports){
6451 * wp.media.view.MenuItem
6454 * @augments wp.media.View
6455 * @augments wp.Backbone.View
6456 * @augments Backbone.View
6461 MenuItem = wp.media.View.extend({
6463 className: 'media-menu-item',
6473 * @param {Object} event
6475 _click: function( event ) {
6476 var clickOverride = this.options.click;
6479 event.preventDefault();
6482 if ( clickOverride ) {
6483 clickOverride.call( this );
6488 // When selecting a tab along the left side,
6489 // focus should be transferred into the main panel
6490 if ( ! wp.media.isTouchDevice ) {
6491 $('.media-frame-content input').first().focus();
6496 var state = this.options.state;
6499 this.controller.setState( state );
6500 this.views.parent.$el.removeClass( 'visible' ); // TODO: or hide on any click, see below
6504 * @returns {wp.media.view.MenuItem} returns itself to allow chaining
6506 render: function() {
6507 var options = this.options;
6509 if ( options.text ) {
6510 this.$el.text( options.text );
6511 } else if ( options.html ) {
6512 this.$el.html( options.html );
6519 module.exports = MenuItem;
6521 },{}],52:[function(require,module,exports){
6523 * wp.media.view.Menu
6526 * @augments wp.media.view.PriorityList
6527 * @augments wp.media.View
6528 * @augments wp.Backbone.View
6529 * @augments Backbone.View
6531 var MenuItem = wp.media.view.MenuItem,
6532 PriorityList = wp.media.view.PriorityList,
6535 Menu = PriorityList.extend({
6537 className: 'media-menu',
6542 /* TODO: alternatively hide on any click anywhere
6548 this.$el.removeClass( 'visible' );
6553 * @param {Object} options
6554 * @param {string} id
6555 * @returns {wp.media.View}
6557 toView: function( options, id ) {
6558 options = options || {};
6559 options[ this.property ] = options[ this.property ] || id;
6560 return new this.ItemView( options ).render();
6565 * call 'ready' directly on the parent class
6567 PriorityList.prototype.ready.apply( this, arguments );
6573 * call 'set' directly on the parent class
6575 PriorityList.prototype.set.apply( this, arguments );
6581 * call 'unset' directly on the parent class
6583 PriorityList.prototype.unset.apply( this, arguments );
6587 visibility: function() {
6588 var region = this.region,
6589 view = this.controller[ region ].get(),
6590 views = this.views.get(),
6591 hide = ! views || views.length < 2;
6593 if ( this === view ) {
6594 this.controller.$el.toggleClass( 'hide-' + region, hide );
6598 * @param {string} id
6600 select: function( id ) {
6601 var view = this.get( id );
6608 view.$el.addClass('active');
6611 deselect: function() {
6612 this.$el.children().removeClass('active');
6615 hide: function( id ) {
6616 var view = this.get( id );
6622 view.$el.addClass('hidden');
6625 show: function( id ) {
6626 var view = this.get( id );
6632 view.$el.removeClass('hidden');
6636 module.exports = Menu;
6638 },{}],53:[function(require,module,exports){
6640 * wp.media.view.Modal
6642 * A modal view, which the media modal uses as its default container.
6645 * @augments wp.media.View
6646 * @augments wp.Backbone.View
6647 * @augments Backbone.View
6652 Modal = wp.media.View.extend({
6654 template: wp.template('media-modal'),
6661 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler',
6662 'keydown': 'keydown'
6665 initialize: function() {
6666 _.defaults( this.options, {
6667 container: document.body,
6673 this.focusManager = new wp.media.view.FocusManager({
6680 prepare: function() {
6682 title: this.options.title
6687 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6689 attach: function() {
6690 if ( this.views.attached ) {
6694 if ( ! this.views.rendered ) {
6698 this.$el.appendTo( this.options.container );
6700 // Manually mark the view as attached and trigger ready.
6701 this.views.attached = true;
6704 return this.propagate('attach');
6708 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6710 detach: function() {
6711 if ( this.$el.is(':visible') ) {
6716 this.views.attached = false;
6717 return this.propagate('detach');
6721 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6725 options = this.options,
6728 if ( $el.is(':visible') ) {
6732 if ( ! this.views.attached ) {
6736 // If the `freeze` option is set, record the window's scroll position.
6737 if ( options.freeze ) {
6739 scrollTop: $( window ).scrollTop()
6743 // Disable page scrolling.
6744 $( 'body' ).addClass( 'modal-open' );
6748 // Try to close the onscreen keyboard
6749 if ( 'ontouchend' in document ) {
6750 if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor ) && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
6751 mceEditor.iframeElement.focus();
6752 mceEditor.iframeElement.blur();
6754 setTimeout( function() {
6755 mceEditor.iframeElement.blur();
6762 return this.propagate('open');
6766 * @param {Object} options
6767 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6769 close: function( options ) {
6770 var freeze = this._freeze;
6772 if ( ! this.views.attached || ! this.$el.is(':visible') ) {
6776 // Enable page scrolling.
6777 $( 'body' ).removeClass( 'modal-open' );
6779 // Hide modal and remove restricted media modal tab focus once it's closed
6780 this.$el.hide().undelegate( 'keydown' );
6782 // Put focus back in useful location once modal is closed
6783 $('#wpbody-content').focus();
6785 this.propagate('close');
6787 // If the `freeze` option is set, restore the container's scroll position.
6789 $( window ).scrollTop( freeze.scrollTop );
6792 if ( options && options.escape ) {
6793 this.propagate('escape');
6799 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6801 escape: function() {
6802 return this.close({ escape: true });
6805 * @param {Object} event
6807 escapeHandler: function( event ) {
6808 event.preventDefault();
6813 * @param {Array|Object} content Views to register to '.media-modal-content'
6814 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6816 content: function( content ) {
6817 this.views.set( '.media-modal-content', content );
6822 * Triggers a modal event and if the `propagate` option is set,
6823 * forwards events to the modal's controller.
6825 * @param {string} id
6826 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6828 propagate: function( id ) {
6831 if ( this.options.propagate ) {
6832 this.controller.trigger( id );
6838 * @param {Object} event
6840 keydown: function( event ) {
6841 // Close the modal when escape is pressed.
6842 if ( 27 === event.which && this.$el.is(':visible') ) {
6844 event.stopImmediatePropagation();
6849 module.exports = Modal;
6851 },{}],54:[function(require,module,exports){
6853 * wp.media.view.PriorityList
6856 * @augments wp.media.View
6857 * @augments wp.Backbone.View
6858 * @augments Backbone.View
6860 var PriorityList = wp.media.View.extend({
6863 initialize: function() {
6866 this.set( _.extend( {}, this._views, this.options.views ), { silent: true });
6867 delete this.options.views;
6869 if ( ! this.options.silent ) {
6874 * @param {string} id
6875 * @param {wp.media.View|Object} view
6876 * @param {Object} options
6877 * @returns {wp.media.view.PriorityList} Returns itself to allow chaining
6879 set: function( id, view, options ) {
6880 var priority, views, index;
6882 options = options || {};
6884 // Accept an object with an `id` : `view` mapping.
6885 if ( _.isObject( id ) ) {
6886 _.each( id, function( view, id ) {
6887 this.set( id, view );
6892 if ( ! (view instanceof Backbone.View) ) {
6893 view = this.toView( view, id, options );
6895 view.controller = view.controller || this.controller;
6899 priority = view.options.priority || 10;
6900 views = this.views.get() || [];
6902 _.find( views, function( existing, i ) {
6903 if ( existing.options.priority > priority ) {
6909 this._views[ id ] = view;
6910 this.views.add( view, {
6911 at: _.isNumber( index ) ? index : views.length || 0
6917 * @param {string} id
6918 * @returns {wp.media.View}
6920 get: function( id ) {
6921 return this._views[ id ];
6924 * @param {string} id
6925 * @returns {wp.media.view.PriorityList}
6927 unset: function( id ) {
6928 var view = this.get( id );
6934 delete this._views[ id ];
6938 * @param {Object} options
6939 * @returns {wp.media.View}
6941 toView: function( options ) {
6942 return new wp.media.View( options );
6946 module.exports = PriorityList;
6948 },{}],55:[function(require,module,exports){
6950 * wp.media.view.RouterItem
6953 * @augments wp.media.view.MenuItem
6954 * @augments wp.media.View
6955 * @augments wp.Backbone.View
6956 * @augments Backbone.View
6958 var RouterItem = wp.media.view.MenuItem.extend({
6960 * On click handler to activate the content region's corresponding mode.
6963 var contentMode = this.options.contentMode;
6964 if ( contentMode ) {
6965 this.controller.content.mode( contentMode );
6970 module.exports = RouterItem;
6972 },{}],56:[function(require,module,exports){
6974 * wp.media.view.Router
6977 * @augments wp.media.view.Menu
6978 * @augments wp.media.view.PriorityList
6979 * @augments wp.media.View
6980 * @augments wp.Backbone.View
6981 * @augments Backbone.View
6983 var Menu = wp.media.view.Menu,
6986 Router = Menu.extend({
6988 className: 'media-router',
6989 property: 'contentMode',
6990 ItemView: wp.media.view.RouterItem,
6993 initialize: function() {
6994 this.controller.on( 'content:render', this.update, this );
6995 // Call 'initialize' directly on the parent class.
6996 Menu.prototype.initialize.apply( this, arguments );
6999 update: function() {
7000 var mode = this.controller.content.mode();
7002 this.select( mode );
7007 module.exports = Router;
7009 },{}],57:[function(require,module,exports){
7011 * wp.media.view.Search
7014 * @augments wp.media.View
7015 * @augments wp.Backbone.View
7016 * @augments Backbone.View
7018 var l10n = wp.media.view.l10n,
7021 Search = wp.media.View.extend({
7023 className: 'search',
7024 id: 'media-search-input',
7028 placeholder: l10n.search
7039 * @returns {wp.media.view.Search} Returns itself to allow chaining
7041 render: function() {
7042 this.el.value = this.model.escape('search');
7046 search: function( event ) {
7047 if ( event.target.value ) {
7048 this.model.set( 'search', event.target.value );
7050 this.model.unset('search');
7055 module.exports = Search;
7057 },{}],58:[function(require,module,exports){
7059 * wp.media.view.Selection
7062 * @augments wp.media.View
7063 * @augments wp.Backbone.View
7064 * @augments Backbone.View
7066 var l10n = wp.media.view.l10n,
7069 Selection = wp.media.View.extend({
7071 className: 'media-selection',
7072 template: wp.template('media-selection'),
7075 'click .edit-selection': 'edit',
7076 'click .clear-selection': 'clear'
7079 initialize: function() {
7080 _.defaults( this.options, {
7086 * @member {wp.media.view.Attachments.Selection}
7088 this.attachments = new wp.media.view.Attachments.Selection({
7089 controller: this.controller,
7090 collection: this.collection,
7091 selection: this.collection,
7092 model: new Backbone.Model()
7095 this.views.set( '.selection-view', this.attachments );
7096 this.collection.on( 'add remove reset', this.refresh, this );
7097 this.controller.on( 'content:activate', this.refresh, this );
7104 refresh: function() {
7105 // If the selection hasn't been rendered, bail.
7106 if ( ! this.$el.children().length ) {
7110 var collection = this.collection,
7111 editing = 'edit-selection' === this.controller.content.mode();
7113 // If nothing is selected, display nothing.
7114 this.$el.toggleClass( 'empty', ! collection.length );
7115 this.$el.toggleClass( 'one', 1 === collection.length );
7116 this.$el.toggleClass( 'editing', editing );
7118 this.$('.count').text( l10n.selected.replace('%d', collection.length) );
7121 edit: function( event ) {
7122 event.preventDefault();
7123 if ( this.options.editable ) {
7124 this.options.editable.call( this, this.collection );
7128 clear: function( event ) {
7129 event.preventDefault();
7130 this.collection.reset();
7132 // Keep focus inside media modal
7133 // after clear link is selected
7134 this.controller.modal.focusManager.focus();
7138 module.exports = Selection;
7140 },{}],59:[function(require,module,exports){
7142 * wp.media.view.Settings
7145 * @augments wp.media.View
7146 * @augments wp.Backbone.View
7147 * @augments Backbone.View
7149 var View = wp.media.View,
7153 Settings = View.extend({
7155 'click button': 'updateHandler',
7156 'change input': 'updateHandler',
7157 'change select': 'updateHandler',
7158 'change textarea': 'updateHandler'
7161 initialize: function() {
7162 this.model = this.model || new Backbone.Model();
7163 this.listenTo( this.model, 'change', this.updateChanges );
7166 prepare: function() {
7168 model: this.model.toJSON()
7172 * @returns {wp.media.view.Settings} Returns itself to allow chaining
7174 render: function() {
7175 View.prototype.render.apply( this, arguments );
7176 // Select the correct values.
7177 _( this.model.attributes ).chain().keys().each( this.update, this );
7181 * @param {string} key
7183 update: function( key ) {
7184 var value = this.model.get( key ),
7185 $setting = this.$('[data-setting="' + key + '"]'),
7188 // Bail if we didn't find a matching setting.
7189 if ( ! $setting.length ) {
7193 // Attempt to determine how the setting is rendered and update
7194 // the selected value.
7196 // Handle dropdowns.
7197 if ( $setting.is('select') ) {
7198 $value = $setting.find('[value="' + value + '"]');
7200 if ( $value.length ) {
7201 $setting.find('option').prop( 'selected', false );
7202 $value.prop( 'selected', true );
7204 // If we can't find the desired value, record what *is* selected.
7205 this.model.set( key, $setting.find(':selected').val() );
7208 // Handle button groups.
7209 } else if ( $setting.hasClass('button-group') ) {
7210 $buttons = $setting.find('button').removeClass('active');
7211 $buttons.filter( '[value="' + value + '"]' ).addClass('active');
7213 // Handle text inputs and textareas.
7214 } else if ( $setting.is('input[type="text"], textarea') ) {
7215 if ( ! $setting.is(':focus') ) {
7216 $setting.val( value );
7218 // Handle checkboxes.
7219 } else if ( $setting.is('input[type="checkbox"]') ) {
7220 $setting.prop( 'checked', !! value && 'false' !== value );
7224 * @param {Object} event
7226 updateHandler: function( event ) {
7227 var $setting = $( event.target ).closest('[data-setting]'),
7228 value = event.target.value,
7231 event.preventDefault();
7233 if ( ! $setting.length ) {
7237 // Use the correct value for checkboxes.
7238 if ( $setting.is('input[type="checkbox"]') ) {
7239 value = $setting[0].checked;
7242 // Update the corresponding setting.
7243 this.model.set( $setting.data('setting'), value );
7245 // If the setting has a corresponding user setting,
7246 // update that as well.
7247 if ( userSetting = $setting.data('userSetting') ) {
7248 window.setUserSetting( userSetting, value );
7252 updateChanges: function( model ) {
7253 if ( model.hasChanged() ) {
7254 _( model.changed ).chain().keys().each( this.update, this );
7259 module.exports = Settings;
7261 },{}],60:[function(require,module,exports){
7263 * wp.media.view.Settings.AttachmentDisplay
7266 * @augments wp.media.view.Settings
7267 * @augments wp.media.View
7268 * @augments wp.Backbone.View
7269 * @augments Backbone.View
7271 var Settings = wp.media.view.Settings,
7274 AttachmentDisplay = Settings.extend({
7275 className: 'attachment-display-settings',
7276 template: wp.template('attachment-display-settings'),
7278 initialize: function() {
7279 var attachment = this.options.attachment;
7281 _.defaults( this.options, {
7284 // Call 'initialize' directly on the parent class.
7285 Settings.prototype.initialize.apply( this, arguments );
7286 this.listenTo( this.model, 'change:link', this.updateLinkTo );
7289 attachment.on( 'change:uploading', this.render, this );
7293 dispose: function() {
7294 var attachment = this.options.attachment;
7296 attachment.off( null, null, this );
7299 * call 'dispose' directly on the parent class
7301 Settings.prototype.dispose.apply( this, arguments );
7304 * @returns {wp.media.view.AttachmentDisplay} Returns itself to allow chaining
7306 render: function() {
7307 var attachment = this.options.attachment;
7309 _.extend( this.options, {
7310 sizes: attachment.get('sizes'),
7311 type: attachment.get('type')
7315 * call 'render' directly on the parent class
7317 Settings.prototype.render.call( this );
7318 this.updateLinkTo();
7322 updateLinkTo: function() {
7323 var linkTo = this.model.get('link'),
7324 $input = this.$('.link-to-custom'),
7325 attachment = this.options.attachment;
7327 if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
7328 $input.addClass( 'hidden' );
7333 if ( 'post' === linkTo ) {
7334 $input.val( attachment.get('link') );
7335 } else if ( 'file' === linkTo ) {
7336 $input.val( attachment.get('url') );
7337 } else if ( ! this.model.get('linkUrl') ) {
7338 $input.val('http://');
7341 $input.prop( 'readonly', 'custom' !== linkTo );
7344 $input.removeClass( 'hidden' );
7346 // If the input is visible, focus and select its contents.
7347 if ( ! wp.media.isTouchDevice && $input.is(':visible') ) {
7348 $input.focus()[0].select();
7353 module.exports = AttachmentDisplay;
7355 },{}],61:[function(require,module,exports){
7357 * wp.media.view.Settings.Gallery
7360 * @augments wp.media.view.Settings
7361 * @augments wp.media.View
7362 * @augments wp.Backbone.View
7363 * @augments Backbone.View
7365 var Gallery = wp.media.view.Settings.extend({
7366 className: 'collection-settings gallery-settings',
7367 template: wp.template('gallery-settings')
7370 module.exports = Gallery;
7372 },{}],62:[function(require,module,exports){
7374 * wp.media.view.Settings.Playlist
7377 * @augments wp.media.view.Settings
7378 * @augments wp.media.View
7379 * @augments wp.Backbone.View
7380 * @augments Backbone.View
7382 var Playlist = wp.media.view.Settings.extend({
7383 className: 'collection-settings playlist-settings',
7384 template: wp.template('playlist-settings')
7387 module.exports = Playlist;
7389 },{}],63:[function(require,module,exports){
7391 * wp.media.view.Sidebar
7394 * @augments wp.media.view.PriorityList
7395 * @augments wp.media.View
7396 * @augments wp.Backbone.View
7397 * @augments Backbone.View
7399 var Sidebar = wp.media.view.PriorityList.extend({
7400 className: 'media-sidebar'
7403 module.exports = Sidebar;
7405 },{}],64:[function(require,module,exports){
7407 * wp.media.view.SiteIconCropper
7409 * Uses the imgAreaSelect plugin to allow a user to crop a Site Icon.
7411 * Takes imgAreaSelect options from
7412 * wp.customize.SiteIconControl.calculateImageSelectOptions.
7415 * @augments wp.media.view.Cropper
7416 * @augments wp.media.View
7417 * @augments wp.Backbone.View
7418 * @augments Backbone.View
7420 var View = wp.media.view,
7423 SiteIconCropper = View.Cropper.extend({
7424 className: 'crop-content site-icon',
7426 ready: function () {
7427 View.Cropper.prototype.ready.apply( this, arguments );
7429 this.$( '.crop-image' ).on( 'load', _.bind( this.addSidebar, this ) );
7432 addSidebar: function() {
7433 this.sidebar = new wp.media.view.Sidebar({
7434 controller: this.controller
7437 this.sidebar.set( 'preview', new wp.media.view.SiteIconPreview({
7438 controller: this.controller,
7439 attachment: this.options.attachment
7442 this.controller.cropperView.views.add( this.sidebar );
7446 module.exports = SiteIconCropper;
7448 },{}],65:[function(require,module,exports){
7450 * wp.media.view.SiteIconPreview
7452 * Shows a preview of the Site Icon as a favicon and app icon while cropping.
7455 * @augments wp.media.View
7456 * @augments wp.Backbone.View
7457 * @augments Backbone.View
7459 var View = wp.media.View,
7463 SiteIconPreview = View.extend({
7464 className: 'site-icon-preview',
7465 template: wp.template( 'site-icon-preview' ),
7468 this.controller.imgSelect.setOptions({
7469 onInit: this.updatePreview,
7470 onSelectChange: this.updatePreview
7474 prepare: function() {
7476 url: this.options.attachment.get( 'url' )
7480 updatePreview: function( img, coords ) {
7481 var rx = 64 / coords.width,
7482 ry = 64 / coords.height,
7483 preview_rx = 16 / coords.width,
7484 preview_ry = 16 / coords.height;
7486 $( '#preview-app-icon' ).css({
7487 width: Math.round(rx * this.imageWidth ) + 'px',
7488 height: Math.round(ry * this.imageHeight ) + 'px',
7489 marginLeft: '-' + Math.round(rx * coords.x1) + 'px',
7490 marginTop: '-' + Math.round(ry * coords.y1) + 'px'
7493 $( '#preview-favicon' ).css({
7494 width: Math.round( preview_rx * this.imageWidth ) + 'px',
7495 height: Math.round( preview_ry * this.imageHeight ) + 'px',
7496 marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px',
7497 marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px'
7502 module.exports = SiteIconPreview;
7504 },{}],66:[function(require,module,exports){
7506 * wp.media.view.Spinner
7509 * @augments wp.media.View
7510 * @augments wp.Backbone.View
7511 * @augments Backbone.View
7513 var Spinner = wp.media.View.extend({
7515 className: 'spinner',
7516 spinnerTimeout: false,
7520 if ( ! this.spinnerTimeout ) {
7521 this.spinnerTimeout = _.delay(function( $el ) {
7522 $el.addClass( 'is-active' );
7523 }, this.delay, this.$el );
7530 this.$el.removeClass( 'is-active' );
7531 this.spinnerTimeout = clearTimeout( this.spinnerTimeout );
7537 module.exports = Spinner;
7539 },{}],67:[function(require,module,exports){
7541 * wp.media.view.Toolbar
7543 * A toolbar which consists of a primary and a secondary section. Each sections
7544 * can be filled with views.
7547 * @augments wp.media.View
7548 * @augments wp.Backbone.View
7549 * @augments Backbone.View
7551 var View = wp.media.View,
7554 Toolbar = View.extend({
7556 className: 'media-toolbar',
7558 initialize: function() {
7559 var state = this.controller.state(),
7560 selection = this.selection = state.get('selection'),
7561 library = this.library = state.get('library');
7565 // The toolbar is composed of two `PriorityList` views.
7566 this.primary = new wp.media.view.PriorityList();
7567 this.secondary = new wp.media.view.PriorityList();
7568 this.primary.$el.addClass('media-toolbar-primary search-form');
7569 this.secondary.$el.addClass('media-toolbar-secondary');
7571 this.views.set([ this.secondary, this.primary ]);
7573 if ( this.options.items ) {
7574 this.set( this.options.items, { silent: true });
7577 if ( ! this.options.silent ) {
7582 selection.on( 'add remove reset', this.refresh, this );
7586 library.on( 'add remove reset', this.refresh, this );
7590 * @returns {wp.media.view.Toolbar} Returns itsef to allow chaining
7592 dispose: function() {
7593 if ( this.selection ) {
7594 this.selection.off( null, null, this );
7597 if ( this.library ) {
7598 this.library.off( null, null, this );
7601 * call 'dispose' directly on the parent class
7603 return View.prototype.dispose.apply( this, arguments );
7611 * @param {string} id
7612 * @param {Backbone.View|Object} view
7613 * @param {Object} [options={}]
7614 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7616 set: function( id, view, options ) {
7618 options = options || {};
7620 // Accept an object with an `id` : `view` mapping.
7621 if ( _.isObject( id ) ) {
7622 _.each( id, function( view, id ) {
7623 this.set( id, view, { silent: true });
7627 if ( ! ( view instanceof Backbone.View ) ) {
7628 view.classes = [ 'media-button-' + id ].concat( view.classes || [] );
7629 view = new wp.media.view.Button( view ).render();
7632 view.controller = view.controller || this.controller;
7634 this._views[ id ] = view;
7636 list = view.options.priority < 0 ? 'secondary' : 'primary';
7637 this[ list ].set( id, view, options );
7640 if ( ! options.silent ) {
7647 * @param {string} id
7648 * @returns {wp.media.view.Button}
7650 get: function( id ) {
7651 return this._views[ id ];
7654 * @param {string} id
7655 * @param {Object} options
7656 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7658 unset: function( id, options ) {
7659 delete this._views[ id ];
7660 this.primary.unset( id, options );
7661 this.secondary.unset( id, options );
7663 if ( ! options || ! options.silent ) {
7669 refresh: function() {
7670 var state = this.controller.state(),
7671 library = state.get('library'),
7672 selection = state.get('selection');
7674 _.each( this._views, function( button ) {
7675 if ( ! button.model || ! button.options || ! button.options.requires ) {
7679 var requires = button.options.requires,
7682 // Prevent insertion of attachments if any of them are still uploading
7683 disabled = _.some( selection.models, function( attachment ) {
7684 return attachment.get('uploading') === true;
7687 if ( requires.selection && selection && ! selection.length ) {
7689 } else if ( requires.library && library && ! library.length ) {
7692 button.model.set( 'disabled', disabled );
7697 module.exports = Toolbar;
7699 },{}],68:[function(require,module,exports){
7701 * wp.media.view.Toolbar.Embed
7704 * @augments wp.media.view.Toolbar.Select
7705 * @augments wp.media.view.Toolbar
7706 * @augments wp.media.View
7707 * @augments wp.Backbone.View
7708 * @augments Backbone.View
7710 var Select = wp.media.view.Toolbar.Select,
7711 l10n = wp.media.view.l10n,
7714 Embed = Select.extend({
7715 initialize: function() {
7716 _.defaults( this.options, {
7717 text: l10n.insertIntoPost,
7720 // Call 'initialize' directly on the parent class.
7721 Select.prototype.initialize.apply( this, arguments );
7724 refresh: function() {
7725 var url = this.controller.state().props.get('url');
7726 this.get('select').model.set( 'disabled', ! url || url === 'http://' );
7728 * call 'refresh' directly on the parent class
7730 Select.prototype.refresh.apply( this, arguments );
7734 module.exports = Embed;
7736 },{}],69:[function(require,module,exports){
7738 * wp.media.view.Toolbar.Select
7741 * @augments wp.media.view.Toolbar
7742 * @augments wp.media.View
7743 * @augments wp.Backbone.View
7744 * @augments Backbone.View
7746 var Toolbar = wp.media.view.Toolbar,
7747 l10n = wp.media.view.l10n,
7750 Select = Toolbar.extend({
7751 initialize: function() {
7752 var options = this.options;
7754 _.bindAll( this, 'clickSelect' );
7756 _.defaults( options, {
7763 // Does the button rely on the selection?
7769 options.items = _.defaults( options.items || {}, {
7774 click: this.clickSelect,
7775 requires: options.requires
7778 // Call 'initialize' directly on the parent class.
7779 Toolbar.prototype.initialize.apply( this, arguments );
7782 clickSelect: function() {
7783 var options = this.options,
7784 controller = this.controller;
7786 if ( options.close ) {
7790 if ( options.event ) {
7791 controller.state().trigger( options.event );
7794 if ( options.state ) {
7795 controller.setState( options.state );
7798 if ( options.reset ) {
7804 module.exports = Select;
7806 },{}],70:[function(require,module,exports){
7808 * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap)
7809 * and relays drag'n'dropped files to a media workflow.
7811 * wp.media.view.EditorUploader
7814 * @augments wp.media.View
7815 * @augments wp.Backbone.View
7816 * @augments Backbone.View
7818 var View = wp.media.View,
7819 l10n = wp.media.view.l10n,
7823 EditorUploader = View.extend({
7825 className: 'uploader-editor',
7826 template: wp.template( 'uploader-editor' ),
7829 overContainer: false,
7830 overDropzone: false,
7834 * Bind drag'n'drop events to callbacks.
7836 initialize: function() {
7837 this.initialized = false;
7839 // Bail if not enabled or UA does not support drag'n'drop or File API.
7840 if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) {
7844 this.$document = $(document);
7845 this.dropzones = [];
7848 this.$document.on( 'drop', '.uploader-editor', _.bind( this.drop, this ) );
7849 this.$document.on( 'dragover', '.uploader-editor', _.bind( this.dropzoneDragover, this ) );
7850 this.$document.on( 'dragleave', '.uploader-editor', _.bind( this.dropzoneDragleave, this ) );
7851 this.$document.on( 'click', '.uploader-editor', _.bind( this.click, this ) );
7853 this.$document.on( 'dragover', _.bind( this.containerDragover, this ) );
7854 this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
7856 this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
7857 this.localDrag = event.type === 'dragstart';
7860 this.initialized = true;
7865 * Check browser support for drag'n'drop.
7869 browserSupport: function() {
7870 var supports = false, div = document.createElement('div');
7872 supports = ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div );
7873 supports = supports && !! ( window.File && window.FileList && window.FileReader );
7877 isDraggingFile: function( event ) {
7878 if ( this.draggingFile !== null ) {
7879 return this.draggingFile;
7882 if ( _.isUndefined( event.originalEvent ) || _.isUndefined( event.originalEvent.dataTransfer ) ) {
7886 this.draggingFile = _.indexOf( event.originalEvent.dataTransfer.types, 'Files' ) > -1 &&
7887 _.indexOf( event.originalEvent.dataTransfer.types, 'text/plain' ) === -1;
7889 return this.draggingFile;
7892 refresh: function( e ) {
7894 for ( dropzone_id in this.dropzones ) {
7895 // Hide the dropzones only if dragging has left the screen.
7896 this.dropzones[ dropzone_id ].toggle( this.overContainer || this.overDropzone );
7899 if ( ! _.isUndefined( e ) ) {
7900 $( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone );
7903 if ( ! this.overContainer && ! this.overDropzone ) {
7904 this.draggingFile = null;
7910 render: function() {
7911 if ( ! this.initialized ) {
7915 View.prototype.render.apply( this, arguments );
7916 $( '.wp-editor-wrap' ).each( _.bind( this.attach, this ) );
7920 attach: function( index, editor ) {
7921 // Attach a dropzone to an editor.
7922 var dropzone = this.$el.clone();
7923 this.dropzones.push( dropzone );
7924 $( editor ).append( dropzone );
7929 * When a file is dropped on the editor uploader, open up an editor media workflow
7930 * and upload the file immediately.
7932 * @param {jQuery.Event} event The 'drop' event.
7934 drop: function( event ) {
7935 var $wrap, uploadView;
7937 this.containerDragleave( event );
7938 this.dropzoneDragleave( event );
7940 this.files = event.originalEvent.dataTransfer.files;
7941 if ( this.files.length < 1 ) {
7945 // Set the active editor to the drop target.
7946 $wrap = $( event.target ).parents( '.wp-editor-wrap' );
7947 if ( $wrap.length > 0 && $wrap[0].id ) {
7948 window.wpActiveEditor = $wrap[0].id.slice( 3, -5 );
7951 if ( ! this.workflow ) {
7952 this.workflow = wp.media.editor.open( window.wpActiveEditor, {
7955 title: l10n.addMedia,
7959 uploadView = this.workflow.uploader;
7961 if ( uploadView.uploader && uploadView.uploader.ready ) {
7962 this.addFiles.apply( this );
7964 this.workflow.on( 'uploader:ready', this.addFiles, this );
7967 this.workflow.state().reset();
7968 this.addFiles.apply( this );
7969 this.workflow.open();
7976 * Add the files to the uploader.
7978 addFiles: function() {
7979 if ( this.files.length ) {
7980 this.workflow.uploader.uploader.uploader.addFile( _.toArray( this.files ) );
7986 containerDragover: function( event ) {
7987 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
7991 this.overContainer = true;
7995 containerDragleave: function() {
7996 this.overContainer = false;
7998 // Throttle dragleave because it's called when bouncing from some elements to others.
7999 _.delay( _.bind( this.refresh, this ), 50 );
8002 dropzoneDragover: function( event ) {
8003 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
8007 this.overDropzone = true;
8008 this.refresh( event );
8012 dropzoneDragleave: function( e ) {
8013 this.overDropzone = false;
8014 _.delay( _.bind( this.refresh, this, e ), 50 );
8017 click: function( e ) {
8018 // In the rare case where the dropzone gets stuck, hide it on click.
8019 this.containerDragleave( e );
8020 this.dropzoneDragleave( e );
8021 this.localDrag = false;
8025 module.exports = EditorUploader;
8027 },{}],71:[function(require,module,exports){
8029 * wp.media.view.UploaderInline
8031 * The inline uploader that shows up in the 'Upload Files' tab.
8034 * @augments wp.media.View
8035 * @augments wp.Backbone.View
8036 * @augments Backbone.View
8038 var View = wp.media.View,
8041 UploaderInline = View.extend({
8043 className: 'uploader-inline',
8044 template: wp.template('uploader-inline'),
8047 'click .close': 'hide'
8050 initialize: function() {
8051 _.defaults( this.options, {
8057 if ( ! this.options.$browser && this.controller.uploader ) {
8058 this.options.$browser = this.controller.uploader.$browser;
8061 if ( _.isUndefined( this.options.postId ) ) {
8062 this.options.postId = wp.media.view.settings.post.id;
8065 if ( this.options.status ) {
8066 this.views.set( '.upload-inline-status', new wp.media.view.UploaderStatus({
8067 controller: this.controller
8072 prepare: function() {
8073 var suggestedWidth = this.controller.state().get('suggestedWidth'),
8074 suggestedHeight = this.controller.state().get('suggestedHeight'),
8077 data.message = this.options.message;
8078 data.canClose = this.options.canClose;
8080 if ( suggestedWidth && suggestedHeight ) {
8081 data.suggestedWidth = suggestedWidth;
8082 data.suggestedHeight = suggestedHeight;
8088 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8090 dispose: function() {
8091 if ( this.disposing ) {
8093 * call 'dispose' directly on the parent class
8095 return View.prototype.dispose.apply( this, arguments );
8098 // Run remove on `dispose`, so we can be sure to refresh the
8099 // uploader with a view-less DOM. Track whether we're disposing
8100 // so we don't trigger an infinite loop.
8101 this.disposing = true;
8102 return this.remove();
8105 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8107 remove: function() {
8109 * call 'remove' directly on the parent class
8111 var result = View.prototype.remove.apply( this, arguments );
8113 _.defer( _.bind( this.refresh, this ) );
8117 refresh: function() {
8118 var uploader = this.controller.uploader;
8125 * @returns {wp.media.view.UploaderInline}
8128 var $browser = this.options.$browser,
8131 if ( this.controller.uploader ) {
8132 $placeholder = this.$('.browser');
8134 // Check if we've already replaced the placeholder.
8135 if ( $placeholder[0] === $browser[0] ) {
8139 $browser.detach().text( $placeholder.text() );
8140 $browser[0].className = $placeholder[0].className;
8141 $placeholder.replaceWith( $browser.show() );
8148 this.$el.removeClass( 'hidden' );
8151 this.$el.addClass( 'hidden' );
8156 module.exports = UploaderInline;
8158 },{}],72:[function(require,module,exports){
8160 * wp.media.view.UploaderStatusError
8163 * @augments wp.media.View
8164 * @augments wp.Backbone.View
8165 * @augments Backbone.View
8167 var UploaderStatusError = wp.media.View.extend({
8168 className: 'upload-error',
8169 template: wp.template('uploader-status-error')
8172 module.exports = UploaderStatusError;
8174 },{}],73:[function(require,module,exports){
8176 * wp.media.view.UploaderStatus
8178 * An uploader status for on-going uploads.
8181 * @augments wp.media.View
8182 * @augments wp.Backbone.View
8183 * @augments Backbone.View
8185 var View = wp.media.View,
8188 UploaderStatus = View.extend({
8189 className: 'media-uploader-status',
8190 template: wp.template('uploader-status'),
8193 'click .upload-dismiss-errors': 'dismiss'
8196 initialize: function() {
8197 this.queue = wp.Uploader.queue;
8198 this.queue.on( 'add remove reset', this.visibility, this );
8199 this.queue.on( 'add remove reset change:percent', this.progress, this );
8200 this.queue.on( 'add remove reset change:uploading', this.info, this );
8202 this.errors = wp.Uploader.errors;
8203 this.errors.reset();
8204 this.errors.on( 'add remove reset', this.visibility, this );
8205 this.errors.on( 'add', this.error, this );
8208 * @global wp.Uploader
8209 * @returns {wp.media.view.UploaderStatus}
8211 dispose: function() {
8212 wp.Uploader.queue.off( null, null, this );
8214 * call 'dispose' directly on the parent class
8216 View.prototype.dispose.apply( this, arguments );
8220 visibility: function() {
8221 this.$el.toggleClass( 'uploading', !! this.queue.length );
8222 this.$el.toggleClass( 'errors', !! this.errors.length );
8223 this.$el.toggle( !! this.queue.length || !! this.errors.length );
8228 '$bar': '.media-progress-bar div',
8229 '$index': '.upload-index',
8230 '$total': '.upload-total',
8231 '$filename': '.upload-filename'
8232 }, function( selector, key ) {
8233 this[ key ] = this.$( selector );
8241 progress: function() {
8242 var queue = this.queue,
8245 if ( ! $bar || ! queue.length ) {
8249 $bar.width( ( queue.reduce( function( memo, attachment ) {
8250 if ( ! attachment.get('uploading') ) {
8254 var percent = attachment.get('percent');
8255 return memo + ( _.isNumber( percent ) ? percent : 100 );
8256 }, 0 ) / queue.length ) + '%' );
8260 var queue = this.queue,
8263 if ( ! queue.length ) {
8267 active = this.queue.find( function( attachment, i ) {
8269 return attachment.get('uploading');
8272 this.$index.text( index + 1 );
8273 this.$total.text( queue.length );
8274 this.$filename.html( active ? this.filename( active.get('filename') ) : '' );
8277 * @param {string} filename
8280 filename: function( filename ) {
8281 return _.escape( filename );
8284 * @param {Backbone.Model} error
8286 error: function( error ) {
8287 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
8288 filename: this.filename( error.get('file').name ),
8289 message: error.get('message')
8294 * @global wp.Uploader
8296 * @param {Object} event
8298 dismiss: function( event ) {
8299 var errors = this.views.get('.upload-errors');
8301 event.preventDefault();
8304 _.invoke( errors, 'remove' );
8306 wp.Uploader.errors.reset();
8310 module.exports = UploaderStatus;
8312 },{}],74:[function(require,module,exports){
8314 * wp.media.view.UploaderWindow
8316 * An uploader window that allows for dragging and dropping media.
8319 * @augments wp.media.View
8320 * @augments wp.Backbone.View
8321 * @augments Backbone.View
8323 * @param {object} [options] Options hash passed to the view.
8324 * @param {object} [options.uploader] Uploader properties.
8325 * @param {jQuery} [options.uploader.browser]
8326 * @param {jQuery} [options.uploader.dropzone] jQuery collection of the dropzone.
8327 * @param {object} [options.uploader.params]
8332 UploaderWindow = wp.media.View.extend({
8334 className: 'uploader-window',
8335 template: wp.template('uploader-window'),
8337 initialize: function() {
8340 this.$browser = $('<a href="#" class="browser" />').hide().appendTo('body');
8342 uploader = this.options.uploader = _.defaults( this.options.uploader || {}, {
8344 browser: this.$browser,
8348 // Ensure the dropzone is a jQuery collection.
8349 if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) {
8350 uploader.dropzone = $( uploader.dropzone );
8353 this.controller.on( 'activate', this.refresh, this );
8355 this.controller.on( 'detach', function() {
8356 this.$browser.remove();
8360 refresh: function() {
8361 if ( this.uploader ) {
8362 this.uploader.refresh();
8367 var postId = wp.media.view.settings.post.id,
8370 // If the uploader already exists, bail.
8371 if ( this.uploader ) {
8376 this.options.uploader.params.post_id = postId;
8378 this.uploader = new wp.Uploader( this.options.uploader );
8380 dropzone = this.uploader.dropzone;
8381 dropzone.on( 'dropzone:enter', _.bind( this.show, this ) );
8382 dropzone.on( 'dropzone:leave', _.bind( this.hide, this ) );
8384 $( this.uploader ).on( 'uploader:ready', _.bind( this._ready, this ) );
8387 _ready: function() {
8388 this.controller.trigger( 'uploader:ready' );
8392 var $el = this.$el.show();
8394 // Ensure that the animation is triggered by waiting until
8395 // the transparent element is painted into the DOM.
8396 _.defer( function() {
8397 $el.css({ opacity: 1 });
8402 var $el = this.$el.css({ opacity: 0 });
8404 wp.media.transition( $el ).done( function() {
8405 // Transition end events are subject to race conditions.
8406 // Make sure that the value is set as intended.
8407 if ( '0' === $el.css('opacity') ) {
8412 // https://core.trac.wordpress.org/ticket/27341
8413 _.delay( function() {
8414 if ( '0' === $el.css('opacity') && $el.is(':visible') ) {
8421 module.exports = UploaderWindow;
8423 },{}],75:[function(require,module,exports){
8427 * The base view class for media.
8429 * Undelegating events, removing events from the model, and
8430 * removing events from the controller mirror the code for
8431 * `Backbone.View.dispose` in Backbone 0.9.8 development.
8433 * This behavior has since been removed, and should not be used
8434 * outside of the media manager.
8437 * @augments wp.Backbone.View
8438 * @augments Backbone.View
8440 var View = wp.Backbone.View.extend({
8441 constructor: function( options ) {
8442 if ( options && options.controller ) {
8443 this.controller = options.controller;
8445 wp.Backbone.View.apply( this, arguments );
8448 * @todo The internal comment mentions this might have been a stop-gap
8449 * before Backbone 0.9.8 came out. Figure out if Backbone core takes
8450 * care of this in Backbone.View now.
8452 * @returns {wp.media.View} Returns itself to allow chaining
8454 dispose: function() {
8455 // Undelegating events, removing events from the model, and
8456 // removing events from the controller mirror the code for
8457 // `Backbone.View.dispose` in Backbone 0.9.8 development.
8458 this.undelegateEvents();
8460 if ( this.model && this.model.off ) {
8461 this.model.off( null, null, this );
8464 if ( this.collection && this.collection.off ) {
8465 this.collection.off( null, null, this );
8468 // Unbind controller events.
8469 if ( this.controller && this.controller.off ) {
8470 this.controller.off( null, null, this );
8476 * @returns {wp.media.View} Returns itself to allow chaining
8478 remove: function() {
8481 * call 'remove' directly on the parent class
8483 return wp.Backbone.View.prototype.remove.apply( this, arguments );
8487 module.exports = View;