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: getUserSetting( 'align', defaultProps.align ) || 'none',
1186 size: getUserSetting( 'imgsize', defaultProps.size ) || 'medium',
1187 link: getUserSetting( 'urlbutton', defaultProps.link ) || 'none'
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 = _.clone( this._defaultDisplaySettings );
1219 if ( settings.canEmbed = this.canEmbed( attachment ) ) {
1220 settings.link = 'embed';
1221 } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) {
1222 settings.link = 'file';
1229 * Whether an attachment is image.
1233 * @param {wp.media.model.Attachment} attachment
1234 * @returns {Boolean}
1236 isImageAttachment: function( attachment ) {
1237 // If uploading, we know the filename but not the mime type.
1238 if ( attachment.get('uploading') ) {
1239 return /\.(jpe?g|png|gif)$/i.test( attachment.get('filename') );
1242 return attachment.get('type') === 'image';
1246 * Whether an attachment can be embedded (audio or video).
1250 * @param {wp.media.model.Attachment} attachment
1251 * @returns {Boolean}
1253 canEmbed: function( attachment ) {
1254 // If uploading, we know the filename but not the mime type.
1255 if ( ! attachment.get('uploading') ) {
1256 var type = attachment.get('type');
1257 if ( type !== 'audio' && type !== 'video' ) {
1262 return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
1267 * If the state is active, no items are selected, and the current
1268 * content mode is not an option in the state's router (provided
1269 * the state has a router), reset the content mode to the default.
1273 refreshContent: function() {
1274 var selection = this.get('selection'),
1276 router = frame.router.get(),
1277 mode = frame.content.mode();
1279 if ( this.active && ! selection.length && router && ! router.get( mode ) ) {
1280 this.frame.content.render( this.get('content') );
1285 * Callback handler when an attachment is uploaded.
1287 * Switch to the Media Library if uploaded from the 'Upload Files' tab.
1289 * Adds any uploading attachments to the selection.
1291 * If the state only supports one attachment to be selected and multiple
1292 * attachments are uploaded, the last attachment in the upload queue will
1297 * @param {wp.media.model.Attachment} attachment
1299 uploading: function( attachment ) {
1300 var content = this.frame.content;
1302 if ( 'upload' === content.mode() ) {
1303 this.frame.content.mode('browse');
1306 if ( this.get( 'autoSelect' ) ) {
1307 this.get('selection').add( attachment );
1308 this.frame.trigger( 'library:selection:add' );
1313 * Persist the mode of the content region as a user setting.
1317 saveContentMode: function() {
1318 if ( 'browse' !== this.get('router') ) {
1322 var mode = this.frame.content.mode(),
1323 view = this.frame.router.get();
1325 if ( view && view.get( mode ) ) {
1326 setUserSetting( 'libraryContent', mode );
1331 // Make selectionSync available on any Media Library state.
1332 _.extend( Library.prototype, wp.media.selectionSync );
1334 module.exports = Library;
1336 },{}],12:[function(require,module,exports){
1338 * wp.media.controller.MediaLibrary
1341 * @augments wp.media.controller.Library
1342 * @augments wp.media.controller.State
1343 * @augments Backbone.Model
1345 var Library = wp.media.controller.Library,
1348 MediaLibrary = Library.extend({
1349 defaults: _.defaults({
1350 // Attachments browser defaults. @see media.view.AttachmentsBrowser
1351 filterable: 'uploaded',
1353 displaySettings: false,
1355 syncSelection: false
1356 }, Library.prototype.defaults ),
1363 initialize: function( options ) {
1364 this.media = options.media;
1365 this.type = options.type;
1366 this.set( 'library', wp.media.query({ type: this.type }) );
1368 Library.prototype.initialize.apply( this, arguments );
1374 activate: function() {
1375 // @todo this should use this.frame.
1376 if ( wp.media.frame.lastMime ) {
1377 this.set( 'library', wp.media.query({ type: wp.media.frame.lastMime }) );
1378 delete wp.media.frame.lastMime;
1380 Library.prototype.activate.apply( this, arguments );
1384 module.exports = MediaLibrary;
1386 },{}],13:[function(require,module,exports){
1388 * wp.media.controller.Region
1390 * A region is a persistent application layout area.
1392 * A region assumes one mode at any time, and can be switched to another.
1394 * When mode changes, events are triggered on the region's parent view.
1395 * The parent view will listen to specific events and fill the region with an
1396 * appropriate view depending on mode. For example, a frame listens for the
1397 * 'browse' mode t be activated on the 'content' view and then fills the region
1398 * with an AttachmentsBrowser view.
1402 * @param {object} options Options hash for the region.
1403 * @param {string} options.id Unique identifier for the region.
1404 * @param {Backbone.View} options.view A parent view the region exists within.
1405 * @param {string} options.selector jQuery selector for the region within the parent view.
1407 var Region = function( options ) {
1408 _.extend( this, _.pick( options || {}, 'id', 'view', 'selector' ) );
1411 // Use Backbone's self-propagating `extend` inheritance method.
1412 Region.extend = Backbone.Model.extend;
1414 _.extend( Region.prototype, {
1420 * @param {string} mode
1422 * @fires this.view#{this.id}:activate:{this._mode}
1423 * @fires this.view#{this.id}:activate
1424 * @fires this.view#{this.id}:deactivate:{this._mode}
1425 * @fires this.view#{this.id}:deactivate
1427 * @returns {wp.media.controller.Region} Returns itself to allow chaining.
1429 mode: function( mode ) {
1433 // Bail if we're trying to change to the current mode.
1434 if ( mode === this._mode ) {
1439 * Region mode deactivation event.
1441 * @event this.view#{this.id}:deactivate:{this._mode}
1442 * @event this.view#{this.id}:deactivate
1444 this.trigger('deactivate');
1447 this.render( mode );
1450 * Region mode activation event.
1452 * @event this.view#{this.id}:activate:{this._mode}
1453 * @event this.view#{this.id}:activate
1455 this.trigger('activate');
1463 * @param {string} mode
1465 * @fires this.view#{this.id}:create:{this._mode}
1466 * @fires this.view#{this.id}:create
1467 * @fires this.view#{this.id}:render:{this._mode}
1468 * @fires this.view#{this.id}:render
1470 * @returns {wp.media.controller.Region} Returns itself to allow chaining
1472 render: function( mode ) {
1473 // If the mode isn't active, activate it.
1474 if ( mode && mode !== this._mode ) {
1475 return this.mode( mode );
1478 var set = { view: null },
1482 * Create region view event.
1484 * Region view creation takes place in an event callback on the frame.
1486 * @event this.view#{this.id}:create:{this._mode}
1487 * @event this.view#{this.id}:create
1489 this.trigger( 'create', set );
1493 * Render region view event.
1495 * Region view creation takes place in an event callback on the frame.
1497 * @event this.view#{this.id}:create:{this._mode}
1498 * @event this.view#{this.id}:create
1500 this.trigger( 'render', view );
1508 * Get the region's view.
1512 * @returns {wp.media.View}
1515 return this.view.views.first( this.selector );
1519 * Set the region's view as a subview of the frame.
1523 * @param {Array|Object} views
1524 * @param {Object} [options={}]
1525 * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining
1527 set: function( views, options ) {
1529 options.add = false;
1531 return this.view.views.set( this.selector, views, options );
1535 * Trigger regional view events on the frame.
1539 * @param {string} event
1540 * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining.
1542 trigger: function( event ) {
1545 if ( ! this._mode ) {
1549 args = _.toArray( arguments );
1550 base = this.id + ':' + event;
1552 // Trigger `{this.id}:{event}:{this._mode}` event on the frame.
1553 args[0] = base + ':' + this._mode;
1554 this.view.trigger.apply( this.view, args );
1556 // Trigger `{this.id}:{event}` event on the frame.
1558 this.view.trigger.apply( this.view, args );
1563 module.exports = Region;
1565 },{}],14:[function(require,module,exports){
1567 * wp.media.controller.ReplaceImage
1569 * A state for replacing an image.
1572 * @augments wp.media.controller.Library
1573 * @augments wp.media.controller.State
1574 * @augments Backbone.Model
1576 * @param {object} [attributes] The attributes hash passed to the state.
1577 * @param {string} [attributes.id=replace-image] Unique identifier.
1578 * @param {string} [attributes.title=Replace Image] Title for the state. Displays in the media menu and the frame's title region.
1579 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
1580 * If one is not supplied, a collection of all images will be created.
1581 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
1582 * @param {string} [attributes.content=upload] Initial mode for the content region.
1583 * Overridden by persistent user setting if 'contentUserSetting' is true.
1584 * @param {string} [attributes.menu=default] Initial mode for the menu region.
1585 * @param {string} [attributes.router=browse] Initial mode for the router region.
1586 * @param {string} [attributes.toolbar=replace] Initial mode for the toolbar region.
1587 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
1588 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
1589 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
1590 * Accepts 'all', 'uploaded', or 'unattached'.
1591 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
1592 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
1593 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
1594 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
1595 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
1597 var Library = wp.media.controller.Library,
1598 l10n = wp.media.view.l10n,
1601 ReplaceImage = Library.extend({
1602 defaults: _.defaults({
1603 id: 'replace-image',
1604 title: l10n.replaceImageTitle,
1606 filterable: 'uploaded',
1611 }, Library.prototype.defaults ),
1618 initialize: function( options ) {
1619 var library, comparator;
1621 this.image = options.image;
1622 // If we haven't been provided a `library`, create a `Selection`.
1623 if ( ! this.get('library') ) {
1624 this.set( 'library', wp.media.query({ type: 'image' }) );
1627 Library.prototype.initialize.apply( this, arguments );
1629 library = this.get('library');
1630 comparator = library.comparator;
1632 // Overload the library's comparator to push items that are not in
1633 // the mirrored query to the front of the aggregate collection.
1634 library.comparator = function( a, b ) {
1635 var aInQuery = !! this.mirroring.get( a.cid ),
1636 bInQuery = !! this.mirroring.get( b.cid );
1638 if ( ! aInQuery && bInQuery ) {
1640 } else if ( aInQuery && ! bInQuery ) {
1643 return comparator.apply( this, arguments );
1647 // Add all items in the selection to the library, so any featured
1648 // images that are not initially loaded still appear.
1649 library.observe( this.get('selection') );
1655 activate: function() {
1656 this.updateSelection();
1657 Library.prototype.activate.apply( this, arguments );
1663 updateSelection: function() {
1664 var selection = this.get('selection'),
1665 attachment = this.image.attachment;
1667 selection.reset( attachment ? [ attachment ] : [] );
1671 module.exports = ReplaceImage;
1673 },{}],15:[function(require,module,exports){
1675 * wp.media.controller.SiteIconCropper
1677 * A state for cropping a Site Icon.
1680 * @augments wp.media.controller.Cropper
1681 * @augments wp.media.controller.State
1682 * @augments Backbone.Model
1684 var Controller = wp.media.controller,
1687 SiteIconCropper = Controller.Cropper.extend({
1688 activate: function() {
1689 this.frame.on( 'content:create:crop', this.createCropContent, this );
1690 this.frame.on( 'close', this.removeCropper, this );
1691 this.set('selection', new Backbone.Collection(this.frame._selection.single));
1694 createCropContent: function() {
1695 this.cropperView = new wp.media.view.SiteIconCropper({
1697 attachment: this.get('selection').first()
1699 this.cropperView.on('image-loaded', this.createCropToolbar, this);
1700 this.frame.content.set(this.cropperView);
1704 doCrop: function( attachment ) {
1705 var cropDetails = attachment.get( 'cropDetails' ),
1706 control = this.get( 'control' );
1708 cropDetails.dst_width = control.params.width;
1709 cropDetails.dst_height = control.params.height;
1711 return wp.ajax.post( 'crop-image', {
1712 nonce: attachment.get( 'nonces' ).edit,
1713 id: attachment.get( 'id' ),
1714 context: 'site-icon',
1715 cropDetails: cropDetails
1720 module.exports = SiteIconCropper;
1722 },{}],16:[function(require,module,exports){
1724 * wp.media.controller.StateMachine
1726 * A state machine keeps track of state. It is in one state at a time,
1727 * and can change from one state to another.
1729 * States are stored as models in a Backbone collection.
1734 * @augments Backbone.Model
1736 * @mixes Backbone.Events
1738 * @param {Array} states
1740 var StateMachine = function( states ) {
1741 // @todo This is dead code. The states collection gets created in media.view.Frame._createStates.
1742 this.states = new Backbone.Collection( states );
1745 // Use Backbone's self-propagating `extend` inheritance method.
1746 StateMachine.extend = Backbone.Model.extend;
1748 _.extend( StateMachine.prototype, Backbone.Events, {
1752 * If no `id` is provided, returns the active state.
1754 * Implicitly creates states.
1756 * Ensure that the `states` collection exists so the `StateMachine`
1757 * can be used as a mixin.
1761 * @param {string} id
1762 * @returns {wp.media.controller.State} Returns a State model
1763 * from the StateMachine collection
1765 state: function( id ) {
1766 this.states = this.states || new Backbone.Collection();
1768 // Default to the active state.
1769 id = id || this._state;
1771 if ( id && ! this.states.get( id ) ) {
1772 this.states.add({ id: id });
1774 return this.states.get( id );
1778 * Sets the active state.
1780 * Bail if we're trying to select the current state, if we haven't
1781 * created the `states` collection, or are trying to select a state
1782 * that does not exist.
1786 * @param {string} id
1788 * @fires wp.media.controller.State#deactivate
1789 * @fires wp.media.controller.State#activate
1791 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining
1793 setState: function( id ) {
1794 var previous = this.state();
1796 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) {
1801 previous.trigger('deactivate');
1802 this._lastState = previous.id;
1806 this.state().trigger('activate');
1812 * Returns the previous active state.
1814 * Call the `state()` method with no parameters to retrieve the current
1819 * @returns {wp.media.controller.State} Returns a State model
1820 * from the StateMachine collection
1822 lastState: function() {
1823 if ( this._lastState ) {
1824 return this.state( this._lastState );
1829 // Map all event binding and triggering on a StateMachine to its `states` collection.
1830 _.each([ 'on', 'off', 'trigger' ], function( method ) {
1832 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining.
1834 StateMachine.prototype[ method ] = function() {
1835 // Ensure that the `states` collection exists so the `StateMachine`
1836 // can be used as a mixin.
1837 this.states = this.states || new Backbone.Collection();
1838 // Forward the method to the `states` collection.
1839 this.states[ method ].apply( this.states, arguments );
1844 module.exports = StateMachine;
1846 },{}],17:[function(require,module,exports){
1848 * wp.media.controller.State
1850 * A state is a step in a workflow that when set will trigger the controllers
1851 * for the regions to be updated as specified in the frame.
1853 * A state has an event-driven lifecycle:
1855 * 'ready' triggers when a state is added to a state machine's collection.
1856 * 'activate' triggers when a state is activated by a state machine.
1857 * 'deactivate' triggers when a state is deactivated by a state machine.
1858 * 'reset' is not triggered automatically. It should be invoked by the
1859 * proper controller to reset the state to its default.
1862 * @augments Backbone.Model
1864 var State = Backbone.Model.extend({
1870 constructor: function() {
1871 this.on( 'activate', this._preActivate, this );
1872 this.on( 'activate', this.activate, this );
1873 this.on( 'activate', this._postActivate, this );
1874 this.on( 'deactivate', this._deactivate, this );
1875 this.on( 'deactivate', this.deactivate, this );
1876 this.on( 'reset', this.reset, this );
1877 this.on( 'ready', this._ready, this );
1878 this.on( 'ready', this.ready, this );
1880 * Call parent constructor with passed arguments
1882 Backbone.Model.apply( this, arguments );
1883 this.on( 'change:menu', this._updateMenu, this );
1886 * Ready event callback.
1891 ready: function() {},
1894 * Activate event callback.
1899 activate: function() {},
1902 * Deactivate event callback.
1907 deactivate: function() {},
1910 * Reset event callback.
1915 reset: function() {},
1921 _ready: function() {
1929 _preActivate: function() {
1937 _postActivate: function() {
1938 this.on( 'change:menu', this._menu, this );
1939 this.on( 'change:titleMode', this._title, this );
1940 this.on( 'change:content', this._content, this );
1941 this.on( 'change:toolbar', this._toolbar, this );
1943 this.frame.on( 'title:render:default', this._renderTitle, this );
1956 _deactivate: function() {
1957 this.active = false;
1959 this.frame.off( 'title:render:default', this._renderTitle, this );
1961 this.off( 'change:menu', this._menu, this );
1962 this.off( 'change:titleMode', this._title, this );
1963 this.off( 'change:content', this._content, this );
1964 this.off( 'change:toolbar', this._toolbar, this );
1971 _title: function() {
1972 this.frame.title.render( this.get('titleMode') || 'default' );
1979 _renderTitle: function( view ) {
1980 view.$el.text( this.get('title') || '' );
1987 _router: function() {
1988 var router = this.frame.router,
1989 mode = this.get('router'),
1992 this.frame.$el.toggleClass( 'hide-router', ! mode );
1997 this.frame.router.render( mode );
1999 view = router.get();
2000 if ( view && view.select ) {
2001 view.select( this.frame.content.mode() );
2010 var menu = this.frame.menu,
2011 mode = this.get('menu'),
2014 this.frame.$el.toggleClass( 'hide-menu', ! mode );
2022 if ( view && view.select ) {
2023 view.select( this.id );
2031 _updateMenu: function() {
2032 var previous = this.previous('menu'),
2033 menu = this.get('menu');
2036 this.frame.off( 'menu:render:' + previous, this._renderMenu, this );
2040 this.frame.on( 'menu:render:' + menu, this._renderMenu, this );
2045 * Create a view in the media menu for the state.
2050 * @param {media.view.Menu} view The menu view.
2052 _renderMenu: function( view ) {
2053 var menuItem = this.get('menuItem'),
2054 title = this.get('title'),
2055 priority = this.get('priority');
2057 if ( ! menuItem && title ) {
2058 menuItem = { text: title };
2061 menuItem.priority = priority;
2069 view.set( this.id, menuItem );
2073 _.each(['toolbar','content'], function( region ) {
2077 State.prototype[ '_' + region ] = function() {
2078 var mode = this.get( region );
2080 this.frame[ region ].render( mode );
2085 module.exports = State;
2087 },{}],18:[function(require,module,exports){
2089 * wp.media.selectionSync
2091 * Sync an attachments selection in a state with another state.
2093 * Allows for selecting multiple images in the Insert Media workflow, and then
2094 * switching to the Insert Gallery workflow while preserving the attachments selection.
2098 var selectionSync = {
2102 syncSelection: function() {
2103 var selection = this.get('selection'),
2104 manager = this.frame._selection;
2106 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2110 // If the selection supports multiple items, validate the stored
2111 // attachments based on the new selection's conditions. Record
2112 // the attachments that are not included; we'll maintain a
2113 // reference to those. Other attachments are considered in flux.
2114 if ( selection.multiple ) {
2115 selection.reset( [], { silent: true });
2116 selection.validateAll( manager.attachments );
2117 manager.difference = _.difference( manager.attachments.models, selection.models );
2120 // Sync the selection's single item with the master.
2121 selection.single( manager.single );
2125 * Record the currently active attachments, which is a combination
2126 * of the selection's attachments and the set of selected
2127 * attachments that this specific selection considered invalid.
2128 * Reset the difference and record the single attachment.
2132 recordSelection: function() {
2133 var selection = this.get('selection'),
2134 manager = this.frame._selection;
2136 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2140 if ( selection.multiple ) {
2141 manager.attachments.reset( selection.toArray().concat( manager.difference ) );
2142 manager.difference = [];
2144 manager.attachments.add( selection.toArray() );
2147 manager.single = selection._single;
2151 module.exports = selectionSync;
2153 },{}],19:[function(require,module,exports){
2154 var media = wp.media,
2158 media.isTouchDevice = ( 'ontouchend' in document );
2160 // Link any localized strings.
2161 l10n = media.view.l10n = window._wpMediaViewsL10n || {};
2163 // Link any settings.
2164 media.view.settings = l10n.settings || {};
2165 delete l10n.settings;
2167 // Copy the `post` setting over to the model settings.
2168 media.model.settings.post = media.view.settings.post;
2170 // Check if the browser supports CSS 3.0 transitions
2171 $.support.transition = (function(){
2172 var style = document.documentElement.style,
2174 WebkitTransition: 'webkitTransitionEnd',
2175 MozTransition: 'transitionend',
2176 OTransition: 'oTransitionEnd otransitionend',
2177 transition: 'transitionend'
2180 transition = _.find( _.keys( transitions ), function( transition ) {
2181 return ! _.isUndefined( style[ transition ] );
2184 return transition && {
2185 end: transitions[ transition ]
2190 * A shared event bus used to provide events into
2191 * the media workflows that 3rd-party devs can use to hook
2194 media.events = _.extend( {}, Backbone.Events );
2197 * Makes it easier to bind events using transitions.
2199 * @param {string} selector
2200 * @param {Number} sensitivity
2201 * @returns {Promise}
2203 media.transition = function( selector, sensitivity ) {
2204 var deferred = $.Deferred();
2206 sensitivity = sensitivity || 2000;
2208 if ( $.support.transition ) {
2209 if ( ! (selector instanceof $) ) {
2210 selector = $( selector );
2213 // Resolve the deferred when the first element finishes animating.
2214 selector.first().one( $.support.transition.end, deferred.resolve );
2216 // Just in case the event doesn't trigger, fire a callback.
2217 _.delay( deferred.resolve, sensitivity );
2219 // Otherwise, execute on the spot.
2224 return deferred.promise();
2227 media.controller.Region = require( './controllers/region.js' );
2228 media.controller.StateMachine = require( './controllers/state-machine.js' );
2229 media.controller.State = require( './controllers/state.js' );
2231 media.selectionSync = require( './utils/selection-sync.js' );
2232 media.controller.Library = require( './controllers/library.js' );
2233 media.controller.ImageDetails = require( './controllers/image-details.js' );
2234 media.controller.GalleryEdit = require( './controllers/gallery-edit.js' );
2235 media.controller.GalleryAdd = require( './controllers/gallery-add.js' );
2236 media.controller.CollectionEdit = require( './controllers/collection-edit.js' );
2237 media.controller.CollectionAdd = require( './controllers/collection-add.js' );
2238 media.controller.FeaturedImage = require( './controllers/featured-image.js' );
2239 media.controller.ReplaceImage = require( './controllers/replace-image.js' );
2240 media.controller.EditImage = require( './controllers/edit-image.js' );
2241 media.controller.MediaLibrary = require( './controllers/media-library.js' );
2242 media.controller.Embed = require( './controllers/embed.js' );
2243 media.controller.Cropper = require( './controllers/cropper.js' );
2244 media.controller.CustomizeImageCropper = require( './controllers/customize-image-cropper.js' );
2245 media.controller.SiteIconCropper = require( './controllers/site-icon-cropper.js' );
2247 media.View = require( './views/view.js' );
2248 media.view.Frame = require( './views/frame.js' );
2249 media.view.MediaFrame = require( './views/media-frame.js' );
2250 media.view.MediaFrame.Select = require( './views/frame/select.js' );
2251 media.view.MediaFrame.Post = require( './views/frame/post.js' );
2252 media.view.MediaFrame.ImageDetails = require( './views/frame/image-details.js' );
2253 media.view.Modal = require( './views/modal.js' );
2254 media.view.FocusManager = require( './views/focus-manager.js' );
2255 media.view.UploaderWindow = require( './views/uploader/window.js' );
2256 media.view.EditorUploader = require( './views/uploader/editor.js' );
2257 media.view.UploaderInline = require( './views/uploader/inline.js' );
2258 media.view.UploaderStatus = require( './views/uploader/status.js' );
2259 media.view.UploaderStatusError = require( './views/uploader/status-error.js' );
2260 media.view.Toolbar = require( './views/toolbar.js' );
2261 media.view.Toolbar.Select = require( './views/toolbar/select.js' );
2262 media.view.Toolbar.Embed = require( './views/toolbar/embed.js' );
2263 media.view.Button = require( './views/button.js' );
2264 media.view.ButtonGroup = require( './views/button-group.js' );
2265 media.view.PriorityList = require( './views/priority-list.js' );
2266 media.view.MenuItem = require( './views/menu-item.js' );
2267 media.view.Menu = require( './views/menu.js' );
2268 media.view.RouterItem = require( './views/router-item.js' );
2269 media.view.Router = require( './views/router.js' );
2270 media.view.Sidebar = require( './views/sidebar.js' );
2271 media.view.Attachment = require( './views/attachment.js' );
2272 media.view.Attachment.Library = require( './views/attachment/library.js' );
2273 media.view.Attachment.EditLibrary = require( './views/attachment/edit-library.js' );
2274 media.view.Attachments = require( './views/attachments.js' );
2275 media.view.Search = require( './views/search.js' );
2276 media.view.AttachmentFilters = require( './views/attachment-filters.js' );
2277 media.view.DateFilter = require( './views/attachment-filters/date.js' );
2278 media.view.AttachmentFilters.Uploaded = require( './views/attachment-filters/uploaded.js' );
2279 media.view.AttachmentFilters.All = require( './views/attachment-filters/all.js' );
2280 media.view.AttachmentsBrowser = require( './views/attachments/browser.js' );
2281 media.view.Selection = require( './views/selection.js' );
2282 media.view.Attachment.Selection = require( './views/attachment/selection.js' );
2283 media.view.Attachments.Selection = require( './views/attachments/selection.js' );
2284 media.view.Attachment.EditSelection = require( './views/attachment/edit-selection.js' );
2285 media.view.Settings = require( './views/settings.js' );
2286 media.view.Settings.AttachmentDisplay = require( './views/settings/attachment-display.js' );
2287 media.view.Settings.Gallery = require( './views/settings/gallery.js' );
2288 media.view.Settings.Playlist = require( './views/settings/playlist.js' );
2289 media.view.Attachment.Details = require( './views/attachment/details.js' );
2290 media.view.AttachmentCompat = require( './views/attachment-compat.js' );
2291 media.view.Iframe = require( './views/iframe.js' );
2292 media.view.Embed = require( './views/embed.js' );
2293 media.view.Label = require( './views/label.js' );
2294 media.view.EmbedUrl = require( './views/embed/url.js' );
2295 media.view.EmbedLink = require( './views/embed/link.js' );
2296 media.view.EmbedImage = require( './views/embed/image.js' );
2297 media.view.ImageDetails = require( './views/image-details.js' );
2298 media.view.Cropper = require( './views/cropper.js' );
2299 media.view.SiteIconCropper = require( './views/site-icon-cropper.js' );
2300 media.view.SiteIconPreview = require( './views/site-icon-preview.js' );
2301 media.view.EditImage = require( './views/edit-image.js' );
2302 media.view.Spinner = require( './views/spinner.js' );
2304 },{"./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){
2306 * wp.media.view.AttachmentCompat
2308 * A view to display fields added via the `attachment_fields_to_edit` filter.
2311 * @augments wp.media.View
2312 * @augments wp.Backbone.View
2313 * @augments Backbone.View
2315 var View = wp.media.View,
2318 AttachmentCompat = View.extend({
2320 className: 'compat-item',
2323 'submit': 'preventDefault',
2324 'change input': 'save',
2325 'change select': 'save',
2326 'change textarea': 'save'
2329 initialize: function() {
2330 this.listenTo( this.model, 'change:compat', this.render );
2333 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2335 dispose: function() {
2336 if ( this.$(':focus').length ) {
2340 * call 'dispose' directly on the parent class
2342 return View.prototype.dispose.apply( this, arguments );
2345 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2347 render: function() {
2348 var compat = this.model.get('compat');
2349 if ( ! compat || ! compat.item ) {
2353 this.views.detach();
2354 this.$el.html( compat.item );
2355 this.views.render();
2359 * @param {Object} event
2361 preventDefault: function( event ) {
2362 event.preventDefault();
2365 * @param {Object} event
2367 save: function( event ) {
2371 event.preventDefault();
2374 _.each( this.$el.serializeArray(), function( pair ) {
2375 data[ pair.name ] = pair.value;
2378 this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
2379 this.model.saveCompat( data ).always( _.bind( this.postSave, this ) );
2382 postSave: function() {
2383 this.controller.trigger( 'attachment:compat:ready', ['ready'] );
2387 module.exports = AttachmentCompat;
2389 },{}],21:[function(require,module,exports){
2391 * wp.media.view.AttachmentFilters
2394 * @augments wp.media.View
2395 * @augments wp.Backbone.View
2396 * @augments Backbone.View
2401 AttachmentFilters = wp.media.View.extend({
2403 className: 'attachment-filters',
2404 id: 'media-attachment-filters',
2412 initialize: function() {
2413 this.createFilters();
2414 _.extend( this.filters, this.options.filters );
2416 // Build `<option>` elements.
2417 this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
2419 el: $( '<option></option>' ).val( value ).html( filter.text )[0],
2420 priority: filter.priority || 50
2422 }, this ).sortBy('priority').pluck('el').value() );
2424 this.listenTo( this.model, 'change', this.select );
2431 createFilters: function() {
2436 * When the selected filter changes, update the Attachment Query properties to match.
2438 change: function() {
2439 var filter = this.filters[ this.el.value ];
2441 this.model.set( filter.props );
2445 select: function() {
2446 var model = this.model,
2448 props = model.toJSON();
2450 _.find( this.filters, function( filter, id ) {
2451 var equal = _.all( filter.props, function( prop, key ) {
2452 return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] );
2460 this.$el.val( value );
2464 module.exports = AttachmentFilters;
2466 },{}],22:[function(require,module,exports){
2468 * wp.media.view.AttachmentFilters.All
2471 * @augments wp.media.view.AttachmentFilters
2472 * @augments wp.media.View
2473 * @augments wp.Backbone.View
2474 * @augments Backbone.View
2476 var l10n = wp.media.view.l10n,
2479 All = wp.media.view.AttachmentFilters.extend({
2480 createFilters: function() {
2483 _.each( wp.media.view.settings.mimeTypes || {}, function( text, key ) {
2497 text: l10n.allMediaItems,
2508 if ( wp.media.view.settings.post.id ) {
2509 filters.uploaded = {
2510 text: l10n.uploadedToThisPost,
2514 uploadedTo: wp.media.view.settings.post.id,
2515 orderby: 'menuOrder',
2522 filters.unattached = {
2523 text: l10n.unattached,
2528 orderby: 'menuOrder',
2534 if ( wp.media.view.settings.mediaTrash &&
2535 this.controller.isModeActive( 'grid' ) ) {
2550 this.filters = filters;
2554 module.exports = All;
2556 },{}],23:[function(require,module,exports){
2558 * A filter dropdown for month/dates.
2561 * @augments wp.media.view.AttachmentFilters
2562 * @augments wp.media.View
2563 * @augments wp.Backbone.View
2564 * @augments Backbone.View
2566 var l10n = wp.media.view.l10n,
2569 DateFilter = wp.media.view.AttachmentFilters.extend({
2570 id: 'media-attachment-date-filters',
2572 createFilters: function() {
2574 _.each( wp.media.view.settings.months || {}, function( value, index ) {
2575 filters[ index ] = {
2579 monthnum: value.month
2584 text: l10n.allDates,
2591 this.filters = filters;
2595 module.exports = DateFilter;
2597 },{}],24:[function(require,module,exports){
2599 * wp.media.view.AttachmentFilters.Uploaded
2602 * @augments wp.media.view.AttachmentFilters
2603 * @augments wp.media.View
2604 * @augments wp.Backbone.View
2605 * @augments Backbone.View
2607 var l10n = wp.media.view.l10n,
2610 Uploaded = wp.media.view.AttachmentFilters.extend({
2611 createFilters: function() {
2612 var type = this.model.get('type'),
2613 types = wp.media.view.settings.mimeTypes,
2616 if ( types && type ) {
2617 text = types[ type ];
2622 text: text || l10n.allMediaItems,
2632 text: l10n.uploadedToThisPost,
2634 uploadedTo: wp.media.view.settings.post.id,
2635 orderby: 'menuOrder',
2642 text: l10n.unattached,
2645 orderby: 'menuOrder',
2654 module.exports = Uploaded;
2656 },{}],25:[function(require,module,exports){
2658 * wp.media.view.Attachment
2661 * @augments wp.media.View
2662 * @augments wp.Backbone.View
2663 * @augments Backbone.View
2665 var View = wp.media.View,
2669 Attachment = View.extend({
2671 className: 'attachment',
2672 template: wp.template('attachment'),
2674 attributes: function() {
2678 'aria-label': this.model.get( 'title' ),
2679 'aria-checked': false,
2680 'data-id': this.model.get( 'id' )
2685 'click .js--select-attachment': 'toggleSelectionHandler',
2686 'change [data-setting]': 'updateSetting',
2687 'change [data-setting] input': 'updateSetting',
2688 'change [data-setting] select': 'updateSetting',
2689 'change [data-setting] textarea': 'updateSetting',
2690 'click .attachment-close': 'removeFromLibrary',
2691 'click .check': 'checkClickHandler',
2692 'keydown': 'toggleSelectionHandler'
2697 initialize: function() {
2698 var selection = this.options.selection,
2699 options = _.defaults( this.options, {
2700 rerenderOnModelChange: true
2703 if ( options.rerenderOnModelChange ) {
2704 this.listenTo( this.model, 'change', this.render );
2706 this.listenTo( this.model, 'change:percent', this.progress );
2708 this.listenTo( this.model, 'change:title', this._syncTitle );
2709 this.listenTo( this.model, 'change:caption', this._syncCaption );
2710 this.listenTo( this.model, 'change:artist', this._syncArtist );
2711 this.listenTo( this.model, 'change:album', this._syncAlbum );
2713 // Update the selection.
2714 this.listenTo( this.model, 'add', this.select );
2715 this.listenTo( this.model, 'remove', this.deselect );
2717 selection.on( 'reset', this.updateSelect, this );
2718 // Update the model's details view.
2719 this.listenTo( this.model, 'selection:single selection:unsingle', this.details );
2720 this.details( this.model, this.controller.state().get('selection') );
2723 this.listenTo( this.controller, 'attachment:compat:waiting attachment:compat:ready', this.updateSave );
2726 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2728 dispose: function() {
2729 var selection = this.options.selection;
2731 // Make sure all settings are saved before removing the view.
2735 selection.off( null, null, this );
2738 * call 'dispose' directly on the parent class
2740 View.prototype.dispose.apply( this, arguments );
2744 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2746 render: function() {
2747 var options = _.defaults( this.model.toJSON(), {
2748 orientation: 'landscape',
2764 options.buttons = this.buttons;
2765 options.describe = this.controller.state().get('describe');
2767 if ( 'image' === options.type ) {
2768 options.size = this.imageSize();
2772 if ( options.nonces ) {
2773 options.can.remove = !! options.nonces['delete'];
2774 options.can.save = !! options.nonces.update;
2777 if ( this.controller.state().get('allowLocalEdits') ) {
2778 options.allowLocalEdits = true;
2781 if ( options.uploading && ! options.percent ) {
2782 options.percent = 0;
2785 this.views.detach();
2786 this.$el.html( this.template( options ) );
2788 this.$el.toggleClass( 'uploading', options.uploading );
2790 if ( options.uploading ) {
2791 this.$bar = this.$('.media-progress-bar div');
2796 // Check if the model is selected.
2797 this.updateSelect();
2799 // Update the save status.
2802 this.views.render();
2807 progress: function() {
2808 if ( this.$bar && this.$bar.length ) {
2809 this.$bar.width( this.model.get('percent') + '%' );
2814 * @param {Object} event
2816 toggleSelectionHandler: function( event ) {
2819 // Don't do anything inside inputs and on the attachment check and remove buttons.
2820 if ( 'INPUT' === event.target.nodeName || 'BUTTON' === event.target.nodeName ) {
2824 // Catch arrow events
2825 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
2826 this.controller.trigger( 'attachment:keydown:arrow', event );
2830 // Catch enter and space events
2831 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
2835 event.preventDefault();
2837 // In the grid view, bubble up an edit:attachment event to the controller.
2838 if ( this.controller.isModeActive( 'grid' ) ) {
2839 if ( this.controller.isModeActive( 'edit' ) ) {
2840 // Pass the current target to restore focus when closing
2841 this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
2845 if ( this.controller.isModeActive( 'select' ) ) {
2850 if ( event.shiftKey ) {
2852 } else if ( event.ctrlKey || event.metaKey ) {
2856 this.toggleSelection({
2860 this.controller.trigger( 'selection:toggle' );
2863 * @param {Object} options
2865 toggleSelection: function( options ) {
2866 var collection = this.collection,
2867 selection = this.options.selection,
2869 method = options && options.method,
2870 single, models, singleIndex, modelIndex;
2872 if ( ! selection ) {
2876 single = selection.single();
2877 method = _.isUndefined( method ) ? selection.multiple : method;
2879 // If the `method` is set to `between`, select all models that
2880 // exist between the current and the selected model.
2881 if ( 'between' === method && single && selection.multiple ) {
2882 // If the models are the same, short-circuit.
2883 if ( single === model ) {
2887 singleIndex = collection.indexOf( single );
2888 modelIndex = collection.indexOf( this.model );
2890 if ( singleIndex < modelIndex ) {
2891 models = collection.models.slice( singleIndex, modelIndex + 1 );
2893 models = collection.models.slice( modelIndex, singleIndex + 1 );
2896 selection.add( models );
2897 selection.single( model );
2900 // If the `method` is set to `toggle`, just flip the selection
2901 // status, regardless of whether the model is the single model.
2902 } else if ( 'toggle' === method ) {
2903 selection[ this.selected() ? 'remove' : 'add' ]( model );
2904 selection.single( model );
2906 } else if ( 'add' === method ) {
2907 selection.add( model );
2908 selection.single( model );
2912 // Fixes bug that loses focus when selecting a featured image
2917 if ( method !== 'add' ) {
2921 if ( this.selected() ) {
2922 // If the model is the single model, remove it.
2923 // If it is not the same as the single model,
2924 // it now becomes the single model.
2925 selection[ single === model ? 'remove' : 'single' ]( model );
2927 // If the model is not selected, run the `method` on the
2928 // selection. By default, we `reset` the selection, but the
2929 // `method` can be set to `add` the model to the selection.
2930 selection[ method ]( model );
2931 selection.single( model );
2935 updateSelect: function() {
2936 this[ this.selected() ? 'select' : 'deselect' ]();
2939 * @returns {unresolved|Boolean}
2941 selected: function() {
2942 var selection = this.options.selection;
2944 return !! selection.get( this.model.cid );
2948 * @param {Backbone.Model} model
2949 * @param {Backbone.Collection} collection
2951 select: function( model, collection ) {
2952 var selection = this.options.selection,
2953 controller = this.controller;
2955 // Check if a selection exists and if it's the collection provided.
2956 // If they're not the same collection, bail; we're in another
2957 // selection's event loop.
2958 if ( ! selection || ( collection && collection !== selection ) ) {
2962 // Bail if the model is already selected.
2963 if ( this.$el.hasClass( 'selected' ) ) {
2967 // Add 'selected' class to model, set aria-checked to true.
2968 this.$el.addClass( 'selected' ).attr( 'aria-checked', true );
2969 // Make the checkbox tabable, except in media grid (bulk select mode).
2970 if ( ! ( controller.isModeActive( 'grid' ) && controller.isModeActive( 'select' ) ) ) {
2971 this.$( '.check' ).attr( 'tabindex', '0' );
2975 * @param {Backbone.Model} model
2976 * @param {Backbone.Collection} collection
2978 deselect: function( model, collection ) {
2979 var selection = this.options.selection;
2981 // Check if a selection exists and if it's the collection provided.
2982 // If they're not the same collection, bail; we're in another
2983 // selection's event loop.
2984 if ( ! selection || ( collection && collection !== selection ) ) {
2987 this.$el.removeClass( 'selected' ).attr( 'aria-checked', false )
2988 .find( '.check' ).attr( 'tabindex', '-1' );
2991 * @param {Backbone.Model} model
2992 * @param {Backbone.Collection} collection
2994 details: function( model, collection ) {
2995 var selection = this.options.selection,
2998 if ( selection !== collection ) {
3002 details = selection.single();
3003 this.$el.toggleClass( 'details', details === this.model );
3006 * @param {string} size
3009 imageSize: function( size ) {
3010 var sizes = this.model.get('sizes'), matched = false;
3012 size = size || 'medium';
3014 // Use the provided image size if possible.
3016 if ( sizes[ size ] ) {
3017 matched = sizes[ size ];
3018 } else if ( sizes.large ) {
3019 matched = sizes.large;
3020 } else if ( sizes.thumbnail ) {
3021 matched = sizes.thumbnail;
3022 } else if ( sizes.full ) {
3023 matched = sizes.full;
3027 return _.clone( matched );
3032 url: this.model.get('url'),
3033 width: this.model.get('width'),
3034 height: this.model.get('height'),
3035 orientation: this.model.get('orientation')
3039 * @param {Object} event
3041 updateSetting: function( event ) {
3042 var $setting = $( event.target ).closest('[data-setting]'),
3045 if ( ! $setting.length ) {
3049 setting = $setting.data('setting');
3050 value = event.target.value;
3052 if ( this.model.get( setting ) !== value ) {
3053 this.save( setting, value );
3058 * Pass all the arguments to the model's save method.
3060 * Records the aggregate status of all save requests and updates the
3061 * view's classes accordingly.
3065 save = this._save = this._save || { status: 'ready' },
3066 request = this.model.save.apply( this.model, arguments ),
3067 requests = save.requests ? $.when( request, save.requests ) : request;
3069 // If we're waiting to remove 'Saved.', stop.
3070 if ( save.savedTimer ) {
3071 clearTimeout( save.savedTimer );
3074 this.updateSave('waiting');
3075 save.requests = requests;
3076 requests.always( function() {
3077 // If we've performed another request since this one, bail.
3078 if ( save.requests !== requests ) {
3082 view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' );
3083 save.savedTimer = setTimeout( function() {
3084 view.updateSave('ready');
3085 delete save.savedTimer;
3090 * @param {string} status
3091 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3093 updateSave: function( status ) {
3094 var save = this._save = this._save || { status: 'ready' };
3096 if ( status && status !== save.status ) {
3097 this.$el.removeClass( 'save-' + save.status );
3098 save.status = status;
3101 this.$el.addClass( 'save-' + save.status );
3105 updateAll: function() {
3106 var $settings = this.$('[data-setting]'),
3110 changed = _.chain( $settings ).map( function( el ) {
3111 var $input = $('input, textarea, select, [value]', el ),
3114 if ( ! $input.length ) {
3118 setting = $(el).data('setting');
3119 value = $input.val();
3121 // Record the value if it changed.
3122 if ( model.get( setting ) !== value ) {
3123 return [ setting, value ];
3125 }).compact().object().value();
3127 if ( ! _.isEmpty( changed ) ) {
3128 model.save( changed );
3132 * @param {Object} event
3134 removeFromLibrary: function( event ) {
3135 // Catch enter and space events
3136 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
3140 // Stop propagation so the model isn't selected.
3141 event.stopPropagation();
3143 this.collection.remove( this.model );
3147 * Add the model if it isn't in the selection, if it is in the selection,
3150 * @param {[type]} event [description]
3151 * @return {[type]} [description]
3153 checkClickHandler: function ( event ) {
3154 var selection = this.options.selection;
3155 if ( ! selection ) {
3158 event.stopPropagation();
3159 if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
3160 selection.remove( this.model );
3161 // Move focus back to the attachment tile (from the check).
3164 selection.add( this.model );
3169 // Ensure settings remain in sync between attachment views.
3171 caption: '_syncCaption',
3172 title: '_syncTitle',
3173 artist: '_syncArtist',
3175 }, function( method, setting ) {
3177 * @param {Backbone.Model} model
3178 * @param {string} value
3179 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3181 Attachment.prototype[ method ] = function( model, value ) {
3182 var $setting = this.$('[data-setting="' + setting + '"]');
3184 if ( ! $setting.length ) {
3188 // If the updated value is in sync with the value in the DOM, there
3189 // is no need to re-render. If we're currently editing the value,
3190 // it will automatically be in sync, suppressing the re-render for
3191 // the view we're editing, while updating any others.
3192 if ( value === $setting.find('input, textarea, select, [value]').val() ) {
3196 return this.render();
3200 module.exports = Attachment;
3202 },{}],26:[function(require,module,exports){
3204 * wp.media.view.Attachment.Details
3207 * @augments wp.media.view.Attachment
3208 * @augments wp.media.View
3209 * @augments wp.Backbone.View
3210 * @augments Backbone.View
3212 var Attachment = wp.media.view.Attachment,
3213 l10n = wp.media.view.l10n,
3216 Details = Attachment.extend({
3218 className: 'attachment-details',
3219 template: wp.template('attachment-details'),
3221 attributes: function() {
3224 'data-id': this.model.get( 'id' )
3229 'change [data-setting]': 'updateSetting',
3230 'change [data-setting] input': 'updateSetting',
3231 'change [data-setting] select': 'updateSetting',
3232 'change [data-setting] textarea': 'updateSetting',
3233 'click .delete-attachment': 'deleteAttachment',
3234 'click .trash-attachment': 'trashAttachment',
3235 'click .untrash-attachment': 'untrashAttachment',
3236 'click .edit-attachment': 'editAttachment',
3237 'keydown': 'toggleSelectionHandler'
3240 initialize: function() {
3241 this.options = _.defaults( this.options, {
3242 rerenderOnModelChange: false
3245 this.on( 'ready', this.initialFocus );
3246 // Call 'initialize' directly on the parent class.
3247 Attachment.prototype.initialize.apply( this, arguments );
3250 initialFocus: function() {
3251 if ( ! wp.media.isTouchDevice ) {
3253 Previously focused the first ':input' (the readonly URL text field).
3254 Since the first ':input' is now a button (delete/trash): when pressing
3255 spacebar on an attachment, Firefox fires deleteAttachment/trashAttachment
3256 as soon as focus is moved. Explicitly target the first text field for now.
3257 @todo change initial focus logic, also for accessibility.
3259 this.$( 'input[type="text"]' ).eq( 0 ).focus();
3263 * @param {Object} event
3265 deleteAttachment: function( event ) {
3266 event.preventDefault();
3268 if ( window.confirm( l10n.warnDelete ) ) {
3269 this.model.destroy();
3270 // Keep focus inside media modal
3271 // after image is deleted
3272 this.controller.modal.focusManager.focus();
3276 * @param {Object} event
3278 trashAttachment: function( event ) {
3279 var library = this.controller.library;
3280 event.preventDefault();
3282 if ( wp.media.view.settings.mediaTrash &&
3283 'edit-metadata' === this.controller.content.mode() ) {
3285 this.model.set( 'status', 'trash' );
3286 this.model.save().done( function() {
3287 library._requery( true );
3290 this.model.destroy();
3294 * @param {Object} event
3296 untrashAttachment: function( event ) {
3297 var library = this.controller.library;
3298 event.preventDefault();
3300 this.model.set( 'status', 'inherit' );
3301 this.model.save().done( function() {
3302 library._requery( true );
3306 * @param {Object} event
3308 editAttachment: function( event ) {
3309 var editState = this.controller.states.get( 'edit-image' );
3310 if ( window.imageEdit && editState ) {
3311 event.preventDefault();
3313 editState.set( 'image', this.model );
3314 this.controller.setState( 'edit-image' );
3316 this.$el.addClass('needs-refresh');
3320 * When reverse tabbing(shift+tab) out of the right details panel, deliver
3321 * the focus to the item in the list that was being edited.
3323 * @param {Object} event
3325 toggleSelectionHandler: function( event ) {
3326 if ( 'keydown' === event.type && 9 === event.keyCode && event.shiftKey && event.target === this.$( ':tabbable' ).get( 0 ) ) {
3327 this.controller.trigger( 'attachment:details:shift-tab', event );
3331 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
3332 this.controller.trigger( 'attachment:keydown:arrow', event );
3338 module.exports = Details;
3340 },{}],27:[function(require,module,exports){
3342 * wp.media.view.Attachment.EditLibrary
3345 * @augments wp.media.view.Attachment
3346 * @augments wp.media.View
3347 * @augments wp.Backbone.View
3348 * @augments Backbone.View
3350 var EditLibrary = wp.media.view.Attachment.extend({
3356 module.exports = EditLibrary;
3358 },{}],28:[function(require,module,exports){
3360 * wp.media.view.Attachments.EditSelection
3363 * @augments wp.media.view.Attachment.Selection
3364 * @augments wp.media.view.Attachment
3365 * @augments wp.media.View
3366 * @augments wp.Backbone.View
3367 * @augments Backbone.View
3369 var EditSelection = wp.media.view.Attachment.Selection.extend({
3375 module.exports = EditSelection;
3377 },{}],29:[function(require,module,exports){
3379 * wp.media.view.Attachment.Library
3382 * @augments wp.media.view.Attachment
3383 * @augments wp.media.View
3384 * @augments wp.Backbone.View
3385 * @augments Backbone.View
3387 var Library = wp.media.view.Attachment.extend({
3393 module.exports = Library;
3395 },{}],30:[function(require,module,exports){
3397 * wp.media.view.Attachment.Selection
3400 * @augments wp.media.view.Attachment
3401 * @augments wp.media.View
3402 * @augments wp.Backbone.View
3403 * @augments Backbone.View
3405 var Selection = wp.media.view.Attachment.extend({
3406 className: 'attachment selection',
3408 // On click, just select the model, instead of removing the model from
3410 toggleSelection: function() {
3411 this.options.selection.single( this.model );
3415 module.exports = Selection;
3417 },{}],31:[function(require,module,exports){
3419 * wp.media.view.Attachments
3422 * @augments wp.media.View
3423 * @augments wp.Backbone.View
3424 * @augments Backbone.View
3426 var View = wp.media.View,
3430 Attachments = View.extend({
3432 className: 'attachments',
3438 initialize: function() {
3439 this.el.id = _.uniqueId('__attachments-view-');
3441 _.defaults( this.options, {
3442 refreshSensitivity: wp.media.isTouchDevice ? 300 : 200,
3443 refreshThreshold: 3,
3444 AttachmentView: wp.media.view.Attachment,
3447 idealColumnWidth: $( window ).width() < 640 ? 135 : 150
3450 this._viewsByCid = {};
3451 this.$window = $( window );
3452 this.resizeEvent = 'resize.media-modal-columns';
3454 this.collection.on( 'add', function( attachment ) {
3455 this.views.add( this.createAttachmentView( attachment ), {
3456 at: this.collection.indexOf( attachment )
3460 this.collection.on( 'remove', function( attachment ) {
3461 var view = this._viewsByCid[ attachment.cid ];
3462 delete this._viewsByCid[ attachment.cid ];
3469 this.collection.on( 'reset', this.render, this );
3471 this.listenTo( this.controller, 'library:selection:add', this.attachmentFocus );
3473 // Throttle the scroll handler and bind this.
3474 this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
3476 this.options.scrollElement = this.options.scrollElement || this.el;
3477 $( this.options.scrollElement ).on( 'scroll', this.scroll );
3479 this.initSortable();
3481 _.bindAll( this, 'setColumns' );
3483 if ( this.options.resize ) {
3484 this.on( 'ready', this.bindEvents );
3485 this.controller.on( 'open', this.setColumns );
3487 // Call this.setColumns() after this view has been rendered in the DOM so
3488 // attachments get proper width applied.
3489 _.defer( this.setColumns, this );
3493 bindEvents: function() {
3494 this.$window.off( this.resizeEvent ).on( this.resizeEvent, _.debounce( this.setColumns, 50 ) );
3497 attachmentFocus: function() {
3498 this.$( 'li:first' ).focus();
3501 restoreFocus: function() {
3502 this.$( 'li.selected:first' ).focus();
3505 arrowEvent: function( event ) {
3506 var attachments = this.$el.children( 'li' ),
3507 perRow = this.columns,
3508 index = attachments.filter( ':focus' ).index(),
3509 row = ( index + 1 ) <= perRow ? 1 : Math.ceil( ( index + 1 ) / perRow );
3511 if ( index === -1 ) {
3516 if ( 37 === event.keyCode ) {
3517 if ( 0 === index ) {
3520 attachments.eq( index - 1 ).focus();
3524 if ( 38 === event.keyCode ) {
3528 attachments.eq( index - perRow ).focus();
3532 if ( 39 === event.keyCode ) {
3533 if ( attachments.length === index ) {
3536 attachments.eq( index + 1 ).focus();
3540 if ( 40 === event.keyCode ) {
3541 if ( Math.ceil( attachments.length / perRow ) === row ) {
3544 attachments.eq( index + perRow ).focus();
3548 dispose: function() {
3549 this.collection.props.off( null, null, this );
3550 if ( this.options.resize ) {
3551 this.$window.off( this.resizeEvent );
3555 * call 'dispose' directly on the parent class
3557 View.prototype.dispose.apply( this, arguments );
3560 setColumns: function() {
3561 var prev = this.columns,
3562 width = this.$el.width();
3565 this.columns = Math.min( Math.round( width / this.options.idealColumnWidth ), 12 ) || 1;
3567 if ( ! prev || prev !== this.columns ) {
3568 this.$el.closest( '.media-frame-content' ).attr( 'data-columns', this.columns );
3573 initSortable: function() {
3574 var collection = this.collection;
3576 if ( wp.media.isTouchDevice || ! this.options.sortable || ! $.fn.sortable ) {
3580 this.$el.sortable( _.extend({
3581 // If the `collection` has a `comparator`, disable sorting.
3582 disabled: !! collection.comparator,
3584 // Change the position of the attachment as soon as the
3585 // mouse pointer overlaps a thumbnail.
3586 tolerance: 'pointer',
3588 // Record the initial `index` of the dragged model.
3589 start: function( event, ui ) {
3590 ui.item.data('sortableIndexStart', ui.item.index());
3593 // Update the model's index in the collection.
3594 // Do so silently, as the view is already accurate.
3595 update: function( event, ui ) {
3596 var model = collection.at( ui.item.data('sortableIndexStart') ),
3597 comparator = collection.comparator;
3599 // Temporarily disable the comparator to prevent `add`
3601 delete collection.comparator;
3603 // Silently shift the model to its new index.
3604 collection.remove( model, {
3607 collection.add( model, {
3612 // Restore the comparator.
3613 collection.comparator = comparator;
3615 // Fire the `reset` event to ensure other collections sync.
3616 collection.trigger( 'reset', collection );
3618 // If the collection is sorted by menu order,
3619 // update the menu order.
3620 collection.saveMenuOrder();
3622 }, this.options.sortable ) );
3624 // If the `orderby` property is changed on the `collection`,
3625 // check to see if we have a `comparator`. If so, disable sorting.
3626 collection.props.on( 'change:orderby', function() {
3627 this.$el.sortable( 'option', 'disabled', !! collection.comparator );
3630 this.collection.props.on( 'change:orderby', this.refreshSortable, this );
3631 this.refreshSortable();
3634 refreshSortable: function() {
3635 if ( wp.media.isTouchDevice || ! this.options.sortable || ! $.fn.sortable ) {
3639 // If the `collection` has a `comparator`, disable sorting.
3640 var collection = this.collection,
3641 orderby = collection.props.get('orderby'),
3642 enabled = 'menuOrder' === orderby || ! collection.comparator;
3644 this.$el.sortable( 'option', 'disabled', ! enabled );
3648 * @param {wp.media.model.Attachment} attachment
3649 * @returns {wp.media.View}
3651 createAttachmentView: function( attachment ) {
3652 var view = new this.options.AttachmentView({
3653 controller: this.controller,
3655 collection: this.collection,
3656 selection: this.options.selection
3659 return this._viewsByCid[ attachment.cid ] = view;
3662 prepare: function() {
3663 // Create all of the Attachment views, and replace
3664 // the list in a single DOM operation.
3665 if ( this.collection.length ) {
3666 this.views.set( this.collection.map( this.createAttachmentView, this ) );
3668 // If there are no elements, clear the views and load some.
3671 this.collection.more().done( this.scroll );
3676 // Trigger the scroll event to check if we're within the
3677 // threshold to query for additional attachments.
3681 scroll: function() {
3683 el = this.options.scrollElement,
3684 scrollTop = el.scrollTop,
3687 // The scroll event occurs on the document, but the element
3688 // that should be checked is the document body.
3689 if ( el === document ) {
3691 scrollTop = $(document).scrollTop();
3694 if ( ! $(el).is(':visible') || ! this.collection.hasMore() ) {
3698 toolbar = this.views.parent.toolbar;
3700 // Show the spinner only if we are close to the bottom.
3701 if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 ) {
3702 toolbar.get('spinner').show();
3705 if ( el.scrollHeight < scrollTop + ( el.clientHeight * this.options.refreshThreshold ) ) {
3706 this.collection.more().done(function() {
3708 toolbar.get('spinner').hide();
3714 module.exports = Attachments;
3716 },{}],32:[function(require,module,exports){
3718 * wp.media.view.AttachmentsBrowser
3721 * @augments wp.media.View
3722 * @augments wp.Backbone.View
3723 * @augments Backbone.View
3725 * @param {object} [options] The options hash passed to the view.
3726 * @param {boolean|string} [options.filters=false] Which filters to show in the browser's toolbar.
3727 * Accepts 'uploaded' and 'all'.
3728 * @param {boolean} [options.search=true] Whether to show the search interface in the
3729 * browser's toolbar.
3730 * @param {boolean} [options.date=true] Whether to show the date filter in the
3731 * browser's toolbar.
3732 * @param {boolean} [options.display=false] Whether to show the attachments display settings
3733 * view in the sidebar.
3734 * @param {boolean|string} [options.sidebar=true] Whether to create a sidebar for the browser.
3735 * Accepts true, false, and 'errors'.
3737 var View = wp.media.View,
3738 mediaTrash = wp.media.view.settings.mediaTrash,
3739 l10n = wp.media.view.l10n,
3743 AttachmentsBrowser = View.extend({
3745 className: 'attachments-browser',
3747 initialize: function() {
3748 _.defaults( this.options, {
3754 AttachmentView: wp.media.view.Attachment.Library
3757 this.listenTo( this.controller, 'toggle:upload:attachment', _.bind( this.toggleUploader, this ) );
3758 this.controller.on( 'edit:selection', this.editSelection );
3759 this.createToolbar();
3760 if ( this.options.sidebar ) {
3761 this.createSidebar();
3763 this.createUploader();
3764 this.createAttachments();
3765 this.updateContent();
3767 if ( ! this.options.sidebar || 'errors' === this.options.sidebar ) {
3768 this.$el.addClass( 'hide-sidebar' );
3770 if ( 'errors' === this.options.sidebar ) {
3771 this.$el.addClass( 'sidebar-for-errors' );
3775 this.collection.on( 'add remove reset', this.updateContent, this );
3778 editSelection: function( modal ) {
3779 modal.$( '.media-button-backToLibrary' ).focus();
3783 * @returns {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining
3785 dispose: function() {
3786 this.options.selection.off( null, null, this );
3787 View.prototype.dispose.apply( this, arguments );
3791 createToolbar: function() {
3792 var LibraryViewSwitcher, Filters, toolbarOptions;
3795 controller: this.controller
3798 if ( this.controller.isModeActive( 'grid' ) ) {
3799 toolbarOptions.className = 'media-toolbar wp-filter';
3803 * @member {wp.media.view.Toolbar}
3805 this.toolbar = new wp.media.view.Toolbar( toolbarOptions );
3807 this.views.add( this.toolbar );
3809 this.toolbar.set( 'spinner', new wp.media.view.Spinner({
3813 if ( -1 !== $.inArray( this.options.filters, [ 'uploaded', 'all' ] ) ) {
3814 // "Filters" will return a <select>, need to render
3815 // screen reader text before
3816 this.toolbar.set( 'filtersLabel', new wp.media.view.Label({
3817 value: l10n.filterByType,
3819 'for': 'media-attachment-filters'
3824 if ( 'uploaded' === this.options.filters ) {
3825 this.toolbar.set( 'filters', new wp.media.view.AttachmentFilters.Uploaded({
3826 controller: this.controller,
3827 model: this.collection.props,
3831 Filters = new wp.media.view.AttachmentFilters.All({
3832 controller: this.controller,
3833 model: this.collection.props,
3837 this.toolbar.set( 'filters', Filters.render() );
3841 // Feels odd to bring the global media library switcher into the Attachment
3842 // browser view. Is this a use case for doAction( 'add:toolbar-items:attachments-browser', this.toolbar );
3843 // which the controller can tap into and add this view?
3844 if ( this.controller.isModeActive( 'grid' ) ) {
3845 LibraryViewSwitcher = View.extend({
3846 className: 'view-switch media-grid-view-switch',
3847 template: wp.template( 'media-library-view-switcher')
3850 this.toolbar.set( 'libraryViewSwitcher', new LibraryViewSwitcher({
3851 controller: this.controller,
3855 // DateFilter is a <select>, screen reader text needs to be rendered before
3856 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3857 value: l10n.filterByDate,
3859 'for': 'media-attachment-date-filters'
3863 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3864 controller: this.controller,
3865 model: this.collection.props,
3869 // BulkSelection is a <div> with subviews, including screen reader text
3870 this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({
3871 text: l10n.bulkSelect,
3872 controller: this.controller,
3876 this.toolbar.set( 'deleteSelectedButton', new wp.media.view.DeleteSelectedButton({
3880 text: mediaTrash ? l10n.trashSelected : l10n.deleteSelected,
3881 controller: this.controller,
3884 var changed = [], removed = [],
3885 selection = this.controller.state().get( 'selection' ),
3886 library = this.controller.state().get( 'library' );
3888 if ( ! selection.length ) {
3892 if ( ! mediaTrash && ! window.confirm( l10n.warnBulkDelete ) ) {
3897 'trash' !== selection.at( 0 ).get( 'status' ) &&
3898 ! window.confirm( l10n.warnBulkTrash ) ) {
3903 selection.each( function( model ) {
3904 if ( ! model.get( 'nonces' )['delete'] ) {
3905 removed.push( model );
3909 if ( mediaTrash && 'trash' === model.get( 'status' ) ) {
3910 model.set( 'status', 'inherit' );
3911 changed.push( model.save() );
3912 removed.push( model );
3913 } else if ( mediaTrash ) {
3914 model.set( 'status', 'trash' );
3915 changed.push( model.save() );
3916 removed.push( model );
3918 model.destroy({wait: true});
3922 if ( changed.length ) {
3923 selection.remove( removed );
3925 $.when.apply( null, changed ).then( _.bind( function() {
3926 library._requery( true );
3927 this.controller.trigger( 'selection:action:done' );
3930 this.controller.trigger( 'selection:action:done' );
3936 this.toolbar.set( 'deleteSelectedPermanentlyButton', new wp.media.view.DeleteSelectedPermanentlyButton({
3940 text: l10n.deleteSelected,
3941 controller: this.controller,
3944 var removed = [], selection = this.controller.state().get( 'selection' );
3946 if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
3950 selection.each( function( model ) {
3951 if ( ! model.get( 'nonces' )['delete'] ) {
3952 removed.push( model );
3959 selection.remove( removed );
3960 this.controller.trigger( 'selection:action:done' );
3965 } else if ( this.options.date ) {
3966 // DateFilter is a <select>, screen reader text needs to be rendered before
3967 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3968 value: l10n.filterByDate,
3970 'for': 'media-attachment-date-filters'
3974 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3975 controller: this.controller,
3976 model: this.collection.props,
3981 if ( this.options.search ) {
3982 // Search is an input, screen reader text needs to be rendered before
3983 this.toolbar.set( 'searchLabel', new wp.media.view.Label({
3984 value: l10n.searchMediaLabel,
3986 'for': 'media-search-input'
3990 this.toolbar.set( 'search', new wp.media.view.Search({
3991 controller: this.controller,
3992 model: this.collection.props,
3997 if ( this.options.dragInfo ) {
3998 this.toolbar.set( 'dragInfo', new View({
3999 el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0],
4004 if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
4005 this.toolbar.set( 'suggestedDimensions', new View({
4006 el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + this.options.suggestedWidth + ' × ' + this.options.suggestedHeight + '</div>' )[0],
4012 updateContent: function() {
4016 if ( this.controller.isModeActive( 'grid' ) ) {
4017 noItemsView = view.attachmentsNoResults;
4019 noItemsView = view.uploader;
4022 if ( ! this.collection.length ) {
4023 this.toolbar.get( 'spinner' ).show();
4024 this.dfd = this.collection.more().done( function() {
4025 if ( ! view.collection.length ) {
4026 noItemsView.$el.removeClass( 'hidden' );
4028 noItemsView.$el.addClass( 'hidden' );
4030 view.toolbar.get( 'spinner' ).hide();
4033 noItemsView.$el.addClass( 'hidden' );
4034 view.toolbar.get( 'spinner' ).hide();
4038 createUploader: function() {
4039 this.uploader = new wp.media.view.UploaderInline({
4040 controller: this.controller,
4042 message: this.controller.isModeActive( 'grid' ) ? '' : l10n.noItemsFound,
4043 canClose: this.controller.isModeActive( 'grid' )
4046 this.uploader.hide();
4047 this.views.add( this.uploader );
4050 toggleUploader: function() {
4051 if ( this.uploader.$el.hasClass( 'hidden' ) ) {
4052 this.uploader.show();
4054 this.uploader.hide();
4058 createAttachments: function() {
4059 this.attachments = new wp.media.view.Attachments({
4060 controller: this.controller,
4061 collection: this.collection,
4062 selection: this.options.selection,
4064 sortable: this.options.sortable,
4065 scrollElement: this.options.scrollElement,
4066 idealColumnWidth: this.options.idealColumnWidth,
4068 // The single `Attachment` view to be used in the `Attachments` view.
4069 AttachmentView: this.options.AttachmentView
4072 // Add keydown listener to the instance of the Attachments view
4073 this.attachments.listenTo( this.controller, 'attachment:keydown:arrow', this.attachments.arrowEvent );
4074 this.attachments.listenTo( this.controller, 'attachment:details:shift-tab', this.attachments.restoreFocus );
4076 this.views.add( this.attachments );
4079 if ( this.controller.isModeActive( 'grid' ) ) {
4080 this.attachmentsNoResults = new View({
4081 controller: this.controller,
4085 this.attachmentsNoResults.$el.addClass( 'hidden no-media' );
4086 this.attachmentsNoResults.$el.html( l10n.noMedia );
4088 this.views.add( this.attachmentsNoResults );
4092 createSidebar: function() {
4093 var options = this.options,
4094 selection = options.selection,
4095 sidebar = this.sidebar = new wp.media.view.Sidebar({
4096 controller: this.controller
4099 this.views.add( sidebar );
4101 if ( this.controller.uploader ) {
4102 sidebar.set( 'uploads', new wp.media.view.UploaderStatus({
4103 controller: this.controller,
4108 selection.on( 'selection:single', this.createSingle, this );
4109 selection.on( 'selection:unsingle', this.disposeSingle, this );
4111 if ( selection.single() ) {
4112 this.createSingle();
4116 createSingle: function() {
4117 var sidebar = this.sidebar,
4118 single = this.options.selection.single();
4120 sidebar.set( 'details', new wp.media.view.Attachment.Details({
4121 controller: this.controller,
4126 sidebar.set( 'compat', new wp.media.view.AttachmentCompat({
4127 controller: this.controller,
4132 if ( this.options.display ) {
4133 sidebar.set( 'display', new wp.media.view.Settings.AttachmentDisplay({
4134 controller: this.controller,
4135 model: this.model.display( single ),
4138 userSettings: this.model.get('displayUserSettings')
4142 // Show the sidebar on mobile
4143 if ( this.model.id === 'insert' ) {
4144 sidebar.$el.addClass( 'visible' );
4148 disposeSingle: function() {
4149 var sidebar = this.sidebar;
4150 sidebar.unset('details');
4151 sidebar.unset('compat');
4152 sidebar.unset('display');
4153 // Hide the sidebar on mobile
4154 sidebar.$el.removeClass( 'visible' );
4158 module.exports = AttachmentsBrowser;
4160 },{}],33:[function(require,module,exports){
4162 * wp.media.view.Attachments.Selection
4165 * @augments wp.media.view.Attachments
4166 * @augments wp.media.View
4167 * @augments wp.Backbone.View
4168 * @augments Backbone.View
4170 var Attachments = wp.media.view.Attachments,
4173 Selection = Attachments.extend({
4175 initialize: function() {
4176 _.defaults( this.options, {
4180 // The single `Attachment` view to be used in the `Attachments` view.
4181 AttachmentView: wp.media.view.Attachment.Selection
4183 // Call 'initialize' directly on the parent class.
4184 return Attachments.prototype.initialize.apply( this, arguments );
4188 module.exports = Selection;
4190 },{}],34:[function(require,module,exports){
4192 * wp.media.view.ButtonGroup
4195 * @augments wp.media.View
4196 * @augments wp.Backbone.View
4197 * @augments Backbone.View
4202 ButtonGroup = wp.media.View.extend({
4204 className: 'button-group button-large media-button-group',
4206 initialize: function() {
4208 * @member {wp.media.view.Button[]}
4210 this.buttons = _.map( this.options.buttons || [], function( button ) {
4211 if ( button instanceof Backbone.View ) {
4214 return new wp.media.view.Button( button ).render();
4218 delete this.options.buttons;
4220 if ( this.options.classes ) {
4221 this.$el.addClass( this.options.classes );
4226 * @returns {wp.media.view.ButtonGroup}
4228 render: function() {
4229 this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() );
4234 module.exports = ButtonGroup;
4236 },{}],35:[function(require,module,exports){
4238 * wp.media.view.Button
4241 * @augments wp.media.View
4242 * @augments wp.Backbone.View
4243 * @augments Backbone.View
4245 var Button = wp.media.View.extend({
4247 className: 'media-button',
4248 attributes: { type: 'button' },
4261 initialize: function() {
4263 * Create a model with the provided `defaults`.
4265 * @member {Backbone.Model}
4267 this.model = new Backbone.Model( this.defaults );
4269 // If any of the `options` have a key from `defaults`, apply its
4270 // value to the `model` and remove it from the `options object.
4271 _.each( this.defaults, function( def, key ) {
4272 var value = this.options[ key ];
4273 if ( _.isUndefined( value ) ) {
4277 this.model.set( key, value );
4278 delete this.options[ key ];
4281 this.listenTo( this.model, 'change', this.render );
4284 * @returns {wp.media.view.Button} Returns itself to allow chaining
4286 render: function() {
4287 var classes = [ 'button', this.className ],
4288 model = this.model.toJSON();
4290 if ( model.style ) {
4291 classes.push( 'button-' + model.style );
4295 classes.push( 'button-' + model.size );
4298 classes = _.uniq( classes.concat( this.options.classes ) );
4299 this.el.className = classes.join(' ');
4301 this.$el.attr( 'disabled', model.disabled );
4302 this.$el.text( this.model.get('text') );
4307 * @param {Object} event
4309 click: function( event ) {
4310 if ( '#' === this.attributes.href ) {
4311 event.preventDefault();
4314 if ( this.options.click && ! this.model.get('disabled') ) {
4315 this.options.click.apply( this, arguments );
4320 module.exports = Button;
4322 },{}],36:[function(require,module,exports){
4324 * wp.media.view.Cropper
4326 * Uses the imgAreaSelect plugin to allow a user to crop an image.
4328 * Takes imgAreaSelect options from
4329 * wp.customize.HeaderControl.calculateImageSelectOptions via
4330 * wp.customize.HeaderControl.openMM.
4333 * @augments wp.media.View
4334 * @augments wp.Backbone.View
4335 * @augments Backbone.View
4337 var View = wp.media.View,
4338 UploaderStatus = wp.media.view.UploaderStatus,
4339 l10n = wp.media.view.l10n,
4343 Cropper = View.extend({
4344 className: 'crop-content',
4345 template: wp.template('crop-content'),
4346 initialize: function() {
4347 _.bindAll(this, 'onImageLoad');
4350 this.controller.frame.on('content:error:crop', this.onError, this);
4351 this.$image = this.$el.find('.crop-image');
4352 this.$image.on('load', this.onImageLoad);
4353 $(window).on('resize.cropper', _.debounce(this.onImageLoad, 250));
4355 remove: function() {
4356 $(window).off('resize.cropper');
4359 View.prototype.remove.apply(this, arguments);
4361 prepare: function() {
4363 title: l10n.cropYourImage,
4364 url: this.options.attachment.get('url')
4367 onImageLoad: function() {
4368 var imgOptions = this.controller.get('imgSelectOptions');
4369 if (typeof imgOptions === 'function') {
4370 imgOptions = imgOptions(this.options.attachment, this.controller);
4373 imgOptions = _.extend(imgOptions, {parent: this.$el});
4374 this.trigger('image-loaded');
4375 this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
4377 onError: function() {
4378 var filename = this.options.attachment.get('filename');
4380 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
4381 filename: UploaderStatus.prototype.filename(filename),
4382 message: window._wpMediaViewsL10n.cropError
4387 module.exports = Cropper;
4389 },{}],37:[function(require,module,exports){
4391 * wp.media.view.EditImage
4394 * @augments wp.media.View
4395 * @augments wp.Backbone.View
4396 * @augments Backbone.View
4398 var View = wp.media.View,
4401 EditImage = View.extend({
4402 className: 'image-editor',
4403 template: wp.template('image-editor'),
4405 initialize: function( options ) {
4406 this.editor = window.imageEdit;
4407 this.controller = options.controller;
4408 View.prototype.initialize.apply( this, arguments );
4411 prepare: function() {
4412 return this.model.toJSON();
4415 loadEditor: function() {
4416 var dfd = this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this );
4417 dfd.done( _.bind( this.focus, this ) );
4421 this.$( '.imgedit-submit .button' ).eq( 0 ).focus();
4425 var lastState = this.controller.lastState();
4426 this.controller.setState( lastState );
4429 refresh: function() {
4434 var lastState = this.controller.lastState();
4436 this.model.fetch().done( _.bind( function() {
4437 this.controller.setState( lastState );
4443 module.exports = EditImage;
4445 },{}],38:[function(require,module,exports){
4447 * wp.media.view.Embed
4450 * @augments wp.media.View
4451 * @augments wp.Backbone.View
4452 * @augments Backbone.View
4454 var Embed = wp.media.View.extend({
4455 className: 'media-embed',
4457 initialize: function() {
4459 * @member {wp.media.view.EmbedUrl}
4461 this.url = new wp.media.view.EmbedUrl({
4462 controller: this.controller,
4463 model: this.model.props
4466 this.views.set([ this.url ]);
4468 this.listenTo( this.model, 'change:type', this.refresh );
4469 this.listenTo( this.model, 'change:loading', this.loading );
4473 * @param {Object} view
4475 settings: function( view ) {
4476 if ( this._settings ) {
4477 this._settings.remove();
4479 this._settings = view;
4480 this.views.add( view );
4483 refresh: function() {
4484 var type = this.model.get('type'),
4487 if ( 'image' === type ) {
4488 constructor = wp.media.view.EmbedImage;
4489 } else if ( 'link' === type ) {
4490 constructor = wp.media.view.EmbedLink;
4495 this.settings( new constructor({
4496 controller: this.controller,
4497 model: this.model.props,
4502 loading: function() {
4503 this.$el.toggleClass( 'embed-loading', this.model.get('loading') );
4507 module.exports = Embed;
4509 },{}],39:[function(require,module,exports){
4511 * wp.media.view.EmbedImage
4514 * @augments wp.media.view.Settings.AttachmentDisplay
4515 * @augments wp.media.view.Settings
4516 * @augments wp.media.View
4517 * @augments wp.Backbone.View
4518 * @augments Backbone.View
4520 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
4523 EmbedImage = AttachmentDisplay.extend({
4524 className: 'embed-media-settings',
4525 template: wp.template('embed-image-settings'),
4527 initialize: function() {
4529 * Call `initialize` directly on parent class with passed arguments
4531 AttachmentDisplay.prototype.initialize.apply( this, arguments );
4532 this.listenTo( this.model, 'change:url', this.updateImage );
4535 updateImage: function() {
4536 this.$('img').attr( 'src', this.model.get('url') );
4540 module.exports = EmbedImage;
4542 },{}],40:[function(require,module,exports){
4544 * wp.media.view.EmbedLink
4547 * @augments wp.media.view.Settings
4548 * @augments wp.media.View
4549 * @augments wp.Backbone.View
4550 * @augments Backbone.View
4555 EmbedLink = wp.media.view.Settings.extend({
4556 className: 'embed-link-settings',
4557 template: wp.template('embed-link-settings'),
4559 initialize: function() {
4560 this.listenTo( this.model, 'change:url', this.updateoEmbed );
4563 updateoEmbed: _.debounce( function() {
4564 var url = this.model.get( 'url' );
4566 // clear out previous results
4567 this.$('.embed-container').hide().find('.embed-preview').empty();
4568 this.$( '.setting' ).hide();
4570 // only proceed with embed if the field contains more than 11 characters
4571 // Example: http://a.io is 11 chars
4572 if ( url && ( url.length < 11 || ! url.match(/^http(s)?:\/\//) ) ) {
4577 }, wp.media.controller.Embed.sensitivity ),
4582 // check if they haven't typed in 500 ms
4583 if ( $('#embed-url-field').val() !== this.model.get('url') ) {
4587 if ( this.dfd && 'pending' === this.dfd.state() ) {
4591 embed = new wp.shortcode({
4593 attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
4594 content: this.model.get('url')
4599 url: wp.ajax.settings.url,
4602 action: 'parse-embed',
4603 post_ID: wp.media.view.settings.post.id,
4604 shortcode: embed.string()
4607 .done( this.renderoEmbed )
4608 .fail( this.renderFail );
4611 renderFail: function ( response, status ) {
4612 if ( 'abort' === status ) {
4615 this.$( '.link-text' ).show();
4618 renderoEmbed: function( response ) {
4619 var html = ( response && response.data && response.data.body ) || '';
4622 this.$('.embed-container').show().find('.embed-preview').html( html );
4629 module.exports = EmbedLink;
4631 },{}],41:[function(require,module,exports){
4633 * wp.media.view.EmbedUrl
4636 * @augments wp.media.View
4637 * @augments wp.Backbone.View
4638 * @augments Backbone.View
4640 var View = wp.media.View,
4644 EmbedUrl = View.extend({
4646 className: 'embed-url',
4654 initialize: function() {
4655 this.$input = $('<input id="embed-url-field" type="url" />').val( this.model.get('url') );
4656 this.input = this.$input[0];
4658 this.spinner = $('<span class="spinner" />')[0];
4659 this.$el.append([ this.input, this.spinner ]);
4661 this.listenTo( this.model, 'change:url', this.render );
4663 if ( this.model.get( 'url' ) ) {
4664 _.delay( _.bind( function () {
4665 this.model.trigger( 'change:url' );
4670 * @returns {wp.media.view.EmbedUrl} Returns itself to allow chaining
4672 render: function() {
4673 var $input = this.$input;
4675 if ( $input.is(':focus') ) {
4679 this.input.value = this.model.get('url') || 'http://';
4681 * Call `render` directly on parent class with passed arguments
4683 View.prototype.render.apply( this, arguments );
4688 if ( ! wp.media.isTouchDevice ) {
4693 url: function( event ) {
4694 this.model.set( 'url', event.target.value );
4698 * If the input is visible, focus and select its contents.
4701 var $input = this.$input;
4702 if ( $input.is(':visible') ) {
4703 $input.focus()[0].select();
4708 module.exports = EmbedUrl;
4710 },{}],42:[function(require,module,exports){
4712 * wp.media.view.FocusManager
4715 * @augments wp.media.View
4716 * @augments wp.Backbone.View
4717 * @augments Backbone.View
4719 var FocusManager = wp.media.View.extend({
4722 'keydown': 'constrainTabbing'
4725 focus: function() { // Reset focus on first left menu item
4726 this.$('.media-menu-item').first().focus();
4729 * @param {Object} event
4731 constrainTabbing: function( event ) {
4734 // Look for the tab key.
4735 if ( 9 !== event.keyCode ) {
4739 // Skip the file input added by Plupload.
4740 tabbables = this.$( ':tabbable' ).not( '.moxie-shim input[type="file"]' );
4742 // Keep tab focus within media modal while it's open
4743 if ( tabbables.last()[0] === event.target && ! event.shiftKey ) {
4744 tabbables.first().focus();
4746 } else if ( tabbables.first()[0] === event.target && event.shiftKey ) {
4747 tabbables.last().focus();
4754 module.exports = FocusManager;
4756 },{}],43:[function(require,module,exports){
4758 * wp.media.view.Frame
4760 * A frame is a composite view consisting of one or more regions and one or more
4763 * @see wp.media.controller.State
4764 * @see wp.media.controller.Region
4767 * @augments wp.media.View
4768 * @augments wp.Backbone.View
4769 * @augments Backbone.View
4770 * @mixes wp.media.controller.StateMachine
4772 var Frame = wp.media.View.extend({
4773 initialize: function() {
4774 _.defaults( this.options, {
4777 this._createRegions();
4778 this._createStates();
4779 this._createModes();
4782 _createRegions: function() {
4783 // Clone the regions array.
4784 this.regions = this.regions ? this.regions.slice() : [];
4786 // Initialize regions.
4787 _.each( this.regions, function( region ) {
4788 this[ region ] = new wp.media.controller.Region({
4791 selector: '.media-frame-' + region
4796 * Create the frame's states.
4798 * @see wp.media.controller.State
4799 * @see wp.media.controller.StateMachine
4801 * @fires wp.media.controller.State#ready
4803 _createStates: function() {
4804 // Create the default `states` collection.
4805 this.states = new Backbone.Collection( null, {
4806 model: wp.media.controller.State
4809 // Ensure states have a reference to the frame.
4810 this.states.on( 'add', function( model ) {
4812 model.trigger('ready');
4815 if ( this.options.states ) {
4816 this.states.add( this.options.states );
4821 * A frame can be in a mode or multiple modes at one time.
4823 * For example, the manage media frame can be in the `Bulk Select` or `Edit` mode.
4825 _createModes: function() {
4826 // Store active "modes" that the frame is in. Unrelated to region modes.
4827 this.activeModes = new Backbone.Collection();
4828 this.activeModes.on( 'add remove reset', _.bind( this.triggerModeEvents, this ) );
4830 _.each( this.options.mode, function( mode ) {
4831 this.activateMode( mode );
4835 * Reset all states on the frame to their defaults.
4837 * @returns {wp.media.view.Frame} Returns itself to allow chaining
4840 this.states.invoke( 'trigger', 'reset' );
4844 * Map activeMode collection events to the frame.
4846 triggerModeEvents: function( model, collection, options ) {
4847 var collectionEvent,
4850 remove: 'deactivate'
4853 // Probably a better way to do this.
4854 _.each( options, function( value, key ) {
4856 collectionEvent = key;
4860 if ( ! _.has( modeEventMap, collectionEvent ) ) {
4864 eventToTrigger = model.get('id') + ':' + modeEventMap[collectionEvent];
4865 this.trigger( eventToTrigger );
4868 * Activate a mode on the frame.
4870 * @param string mode Mode ID.
4871 * @returns {this} Returns itself to allow chaining.
4873 activateMode: function( mode ) {
4874 // Bail if the mode is already active.
4875 if ( this.isModeActive( mode ) ) {
4878 this.activeModes.add( [ { id: mode } ] );
4879 // Add a CSS class to the frame so elements can be styled for the mode.
4880 this.$el.addClass( 'mode-' + mode );
4885 * Deactivate a mode on the frame.
4887 * @param string mode Mode ID.
4888 * @returns {this} Returns itself to allow chaining.
4890 deactivateMode: function( mode ) {
4891 // Bail if the mode isn't active.
4892 if ( ! this.isModeActive( mode ) ) {
4895 this.activeModes.remove( this.activeModes.where( { id: mode } ) );
4896 this.$el.removeClass( 'mode-' + mode );
4898 * Frame mode deactivation event.
4900 * @event this#{mode}:deactivate
4902 this.trigger( mode + ':deactivate' );
4907 * Check if a mode is enabled on the frame.
4909 * @param string mode Mode ID.
4912 isModeActive: function( mode ) {
4913 return Boolean( this.activeModes.where( { id: mode } ).length );
4917 // Make the `Frame` a `StateMachine`.
4918 _.extend( Frame.prototype, wp.media.controller.StateMachine.prototype );
4920 module.exports = Frame;
4922 },{}],44:[function(require,module,exports){
4924 * wp.media.view.MediaFrame.ImageDetails
4926 * A media frame for manipulating an image that's already been inserted
4930 * @augments wp.media.view.MediaFrame.Select
4931 * @augments wp.media.view.MediaFrame
4932 * @augments wp.media.view.Frame
4933 * @augments wp.media.View
4934 * @augments wp.Backbone.View
4935 * @augments Backbone.View
4936 * @mixes wp.media.controller.StateMachine
4938 var Select = wp.media.view.MediaFrame.Select,
4939 l10n = wp.media.view.l10n,
4942 ImageDetails = Select.extend({
4946 menu: 'image-details',
4947 content: 'image-details',
4948 toolbar: 'image-details',
4950 title: l10n.imageDetailsTitle,
4954 initialize: function( options ) {
4955 this.image = new wp.media.model.PostImage( options.metadata );
4956 this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } );
4957 Select.prototype.initialize.apply( this, arguments );
4960 bindHandlers: function() {
4961 Select.prototype.bindHandlers.apply( this, arguments );
4962 this.on( 'menu:create:image-details', this.createMenu, this );
4963 this.on( 'content:create:image-details', this.imageDetailsContent, this );
4964 this.on( 'content:render:edit-image', this.editImageContent, this );
4965 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this );
4966 // override the select toolbar
4967 this.on( 'toolbar:render:replace', this.renderReplaceImageToolbar, this );
4970 createStates: function() {
4972 new wp.media.controller.ImageDetails({
4976 new wp.media.controller.ReplaceImage({
4977 id: 'replace-image',
4978 library: wp.media.query( { type: 'image' } ),
4981 title: l10n.imageReplaceTitle,
4984 displaySettings: true
4986 new wp.media.controller.EditImage( {
4988 selection: this.options.selection
4993 imageDetailsContent: function( options ) {
4994 options.view = new wp.media.view.ImageDetails({
4996 model: this.state().image,
4997 attachment: this.state().image.attachment
5001 editImageContent: function() {
5002 var state = this.state(),
5003 model = state.get('image'),
5010 view = new wp.media.view.EditImage( { model: model, controller: this } ).render();
5012 this.content.set( view );
5014 // after bringing in the frame, load the actual editor via an ajax call
5019 renderImageDetailsToolbar: function() {
5020 this.toolbar.set( new wp.media.view.Toolbar({
5029 var controller = this.controller,
5030 state = controller.state();
5034 // not sure if we want to use wp.media.string.image which will create a shortcode or
5035 // perhaps wp.html.string to at least to build the <img />
5036 state.trigger( 'update', controller.image.toJSON() );
5038 // Restore and reset the default state.
5039 controller.setState( controller.options.state );
5047 renderReplaceImageToolbar: function() {
5049 lastState = frame.lastState(),
5050 previous = lastState && lastState.id;
5052 this.toolbar.set( new wp.media.view.Toolbar({
5060 frame.setState( previous );
5073 var controller = this.controller,
5074 state = controller.state(),
5075 selection = state.get( 'selection' ),
5076 attachment = selection.single();
5080 controller.image.changeAttachment( attachment, state.display( attachment ) );
5082 // not sure if we want to use wp.media.string.image which will create a shortcode or
5083 // perhaps wp.html.string to at least to build the <img />
5084 state.trigger( 'replace', controller.image.toJSON() );
5086 // Restore and reset the default state.
5087 controller.setState( controller.options.state );
5097 module.exports = ImageDetails;
5099 },{}],45:[function(require,module,exports){
5101 * wp.media.view.MediaFrame.Post
5103 * The frame for manipulating media on the Edit Post page.
5106 * @augments wp.media.view.MediaFrame.Select
5107 * @augments wp.media.view.MediaFrame
5108 * @augments wp.media.view.Frame
5109 * @augments wp.media.View
5110 * @augments wp.Backbone.View
5111 * @augments Backbone.View
5112 * @mixes wp.media.controller.StateMachine
5114 var Select = wp.media.view.MediaFrame.Select,
5115 Library = wp.media.controller.Library,
5116 l10n = wp.media.view.l10n,
5119 Post = Select.extend({
5120 initialize: function() {
5123 count: wp.media.view.settings.attachmentCounts.audio,
5127 count: wp.media.view.settings.attachmentCounts.video,
5128 state: 'video-playlist'
5132 _.defaults( this.options, {
5139 // Call 'initialize' directly on the parent class.
5140 Select.prototype.initialize.apply( this, arguments );
5141 this.createIframeStates();
5146 * Create the default states.
5148 createStates: function() {
5149 var options = this.options;
5155 title: l10n.insertMediaTitle,
5157 toolbar: 'main-insert',
5159 library: wp.media.query( options.library ),
5160 multiple: options.multiple ? 'reset' : false,
5163 // If the user isn't allowed to edit fields,
5164 // can they still edit it locally?
5165 allowLocalEdits: true,
5167 // Show the attachment display settings.
5168 displaySettings: true,
5169 // Update user settings when users adjust the
5170 // attachment display settings.
5171 displayUserSettings: true
5176 title: l10n.createGalleryTitle,
5178 toolbar: 'main-gallery',
5179 filterable: 'uploaded',
5183 library: wp.media.query( _.defaults({
5185 }, options.library ) )
5189 new wp.media.controller.Embed( { metadata: options.metadata } ),
5191 new wp.media.controller.EditImage( { model: options.editImage } ),
5194 new wp.media.controller.GalleryEdit({
5195 library: options.selection,
5196 editing: options.editing,
5200 new wp.media.controller.GalleryAdd(),
5204 title: l10n.createPlaylistTitle,
5206 toolbar: 'main-playlist',
5207 filterable: 'uploaded',
5211 library: wp.media.query( _.defaults({
5213 }, options.library ) )
5217 new wp.media.controller.CollectionEdit({
5219 collectionType: 'playlist',
5220 title: l10n.editPlaylistTitle,
5221 SettingsView: wp.media.view.Settings.Playlist,
5222 library: options.selection,
5223 editing: options.editing,
5225 dragInfoText: l10n.playlistDragInfo,
5229 new wp.media.controller.CollectionAdd({
5231 collectionType: 'playlist',
5232 title: l10n.addToPlaylistTitle
5236 id: 'video-playlist',
5237 title: l10n.createVideoPlaylistTitle,
5239 toolbar: 'main-video-playlist',
5240 filterable: 'uploaded',
5244 library: wp.media.query( _.defaults({
5246 }, options.library ) )
5249 new wp.media.controller.CollectionEdit({
5251 collectionType: 'playlist',
5252 title: l10n.editVideoPlaylistTitle,
5253 SettingsView: wp.media.view.Settings.Playlist,
5254 library: options.selection,
5255 editing: options.editing,
5256 menu: 'video-playlist',
5257 dragInfoText: l10n.videoPlaylistDragInfo,
5261 new wp.media.controller.CollectionAdd({
5263 collectionType: 'playlist',
5264 title: l10n.addToVideoPlaylistTitle
5268 if ( wp.media.view.settings.post.featuredImageId ) {
5269 this.states.add( new wp.media.controller.FeaturedImage() );
5273 bindHandlers: function() {
5274 var handlers, checkCounts;
5276 Select.prototype.bindHandlers.apply( this, arguments );
5278 this.on( 'activate', this.activate, this );
5280 // Only bother checking media type counts if one of the counts is zero
5281 checkCounts = _.find( this.counts, function( type ) {
5282 return type.count === 0;
5285 if ( typeof checkCounts !== 'undefined' ) {
5286 this.listenTo( wp.media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
5289 this.on( 'menu:create:gallery', this.createMenu, this );
5290 this.on( 'menu:create:playlist', this.createMenu, this );
5291 this.on( 'menu:create:video-playlist', this.createMenu, this );
5292 this.on( 'toolbar:create:main-insert', this.createToolbar, this );
5293 this.on( 'toolbar:create:main-gallery', this.createToolbar, this );
5294 this.on( 'toolbar:create:main-playlist', this.createToolbar, this );
5295 this.on( 'toolbar:create:main-video-playlist', this.createToolbar, this );
5296 this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
5297 this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
5301 'default': 'mainMenu',
5302 'gallery': 'galleryMenu',
5303 'playlist': 'playlistMenu',
5304 'video-playlist': 'videoPlaylistMenu'
5308 'embed': 'embedContent',
5309 'edit-image': 'editImageContent',
5310 'edit-selection': 'editSelectionContent'
5314 'main-insert': 'mainInsertToolbar',
5315 'main-gallery': 'mainGalleryToolbar',
5316 'gallery-edit': 'galleryEditToolbar',
5317 'gallery-add': 'galleryAddToolbar',
5318 'main-playlist': 'mainPlaylistToolbar',
5319 'playlist-edit': 'playlistEditToolbar',
5320 'playlist-add': 'playlistAddToolbar',
5321 'main-video-playlist': 'mainVideoPlaylistToolbar',
5322 'video-playlist-edit': 'videoPlaylistEditToolbar',
5323 'video-playlist-add': 'videoPlaylistAddToolbar'
5327 _.each( handlers, function( regionHandlers, region ) {
5328 _.each( regionHandlers, function( callback, handler ) {
5329 this.on( region + ':render:' + handler, this[ callback ], this );
5334 activate: function() {
5335 // Hide menu items for states tied to particular media types if there are no items
5336 _.each( this.counts, function( type ) {
5337 if ( type.count < 1 ) {
5338 this.menuItemVisibility( type.state, 'hide' );
5343 mediaTypeCounts: function( model, attr ) {
5344 if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
5345 this.counts[ attr ].count++;
5346 this.menuItemVisibility( this.counts[ attr ].state, 'show' );
5352 * @param {wp.Backbone.View} view
5354 mainMenu: function( view ) {
5356 'library-separator': new wp.media.View({
5357 className: 'separator',
5363 menuItemVisibility: function( state, visibility ) {
5364 var menu = this.menu.get();
5365 if ( visibility === 'hide' ) {
5367 } else if ( visibility === 'show' ) {
5372 * @param {wp.Backbone.View} view
5374 galleryMenu: function( view ) {
5375 var lastState = this.lastState(),
5376 previous = lastState && lastState.id,
5381 text: l10n.cancelGalleryTitle,
5385 frame.setState( previous );
5390 // Keep focus inside media modal
5391 // after canceling a gallery
5392 this.controller.modal.focusManager.focus();
5395 separateCancel: new wp.media.View({
5396 className: 'separator',
5402 playlistMenu: function( view ) {
5403 var lastState = this.lastState(),
5404 previous = lastState && lastState.id,
5409 text: l10n.cancelPlaylistTitle,
5413 frame.setState( previous );
5419 separateCancel: new wp.media.View({
5420 className: 'separator',
5426 videoPlaylistMenu: function( view ) {
5427 var lastState = this.lastState(),
5428 previous = lastState && lastState.id,
5433 text: l10n.cancelVideoPlaylistTitle,
5437 frame.setState( previous );
5443 separateCancel: new wp.media.View({
5444 className: 'separator',
5451 embedContent: function() {
5452 var view = new wp.media.view.Embed({
5457 this.content.set( view );
5459 if ( ! wp.media.isTouchDevice ) {
5464 editSelectionContent: function() {
5465 var state = this.state(),
5466 selection = state.get('selection'),
5469 view = new wp.media.view.AttachmentsBrowser({
5471 collection: selection,
5472 selection: selection,
5479 AttachmentView: wp.media.view.Attachments.EditSelection
5482 view.toolbar.set( 'backToLibrary', {
5483 text: l10n.returnToLibrary,
5487 this.controller.content.mode('browse');
5491 // Browse our library of attachments.
5492 this.content.set( view );
5494 // Trigger the controller to set focus
5495 this.trigger( 'edit:selection', this );
5498 editImageContent: function() {
5499 var image = this.state().get('image'),
5500 view = new wp.media.view.EditImage( { model: image, controller: this } ).render();
5502 this.content.set( view );
5504 // after creating the wrapper view, load the actual editor via an ajax call
5512 * @param {wp.Backbone.View} view
5514 selectionStatusToolbar: function( view ) {
5515 var editable = this.state().get('editable');
5517 view.set( 'selection', new wp.media.view.Selection({
5519 collection: this.state().get('selection'),
5522 // If the selection is editable, pass the callback to
5523 // switch the content mode.
5524 editable: editable && function() {
5525 this.controller.content.mode('edit-selection');
5531 * @param {wp.Backbone.View} view
5533 mainInsertToolbar: function( view ) {
5534 var controller = this;
5536 this.selectionStatusToolbar( view );
5538 view.set( 'insert', {
5541 text: l10n.insertIntoPost,
5542 requires: { selection: true },
5545 * @fires wp.media.controller.State#insert
5548 var state = controller.state(),
5549 selection = state.get('selection');
5552 state.trigger( 'insert', selection ).reset();
5558 * @param {wp.Backbone.View} view
5560 mainGalleryToolbar: function( view ) {
5561 var controller = this;
5563 this.selectionStatusToolbar( view );
5565 view.set( 'gallery', {
5567 text: l10n.createNewGallery,
5569 requires: { selection: true },
5572 var selection = controller.state().get('selection'),
5573 edit = controller.state('gallery-edit'),
5574 models = selection.where({ type: 'image' });
5576 edit.set( 'library', new wp.media.model.Selection( models, {
5577 props: selection.props.toJSON(),
5581 this.controller.setState('gallery-edit');
5583 // Keep focus inside media modal
5584 // after jumping to gallery view
5585 this.controller.modal.focusManager.focus();
5590 mainPlaylistToolbar: function( view ) {
5591 var controller = this;
5593 this.selectionStatusToolbar( view );
5595 view.set( 'playlist', {
5597 text: l10n.createNewPlaylist,
5599 requires: { selection: true },
5602 var selection = controller.state().get('selection'),
5603 edit = controller.state('playlist-edit'),
5604 models = selection.where({ type: 'audio' });
5606 edit.set( 'library', new wp.media.model.Selection( models, {
5607 props: selection.props.toJSON(),
5611 this.controller.setState('playlist-edit');
5613 // Keep focus inside media modal
5614 // after jumping to playlist view
5615 this.controller.modal.focusManager.focus();
5620 mainVideoPlaylistToolbar: function( view ) {
5621 var controller = this;
5623 this.selectionStatusToolbar( view );
5625 view.set( 'video-playlist', {
5627 text: l10n.createNewVideoPlaylist,
5629 requires: { selection: true },
5632 var selection = controller.state().get('selection'),
5633 edit = controller.state('video-playlist-edit'),
5634 models = selection.where({ type: 'video' });
5636 edit.set( 'library', new wp.media.model.Selection( models, {
5637 props: selection.props.toJSON(),
5641 this.controller.setState('video-playlist-edit');
5643 // Keep focus inside media modal
5644 // after jumping to video playlist view
5645 this.controller.modal.focusManager.focus();
5650 featuredImageToolbar: function( toolbar ) {
5651 this.createSelectToolbar( toolbar, {
5652 text: l10n.setFeaturedImage,
5653 state: this.options.state
5657 mainEmbedToolbar: function( toolbar ) {
5658 toolbar.view = new wp.media.view.Toolbar.Embed({
5663 galleryEditToolbar: function() {
5664 var editing = this.state().get('editing');
5665 this.toolbar.set( new wp.media.view.Toolbar({
5670 text: editing ? l10n.updateGallery : l10n.insertGallery,
5672 requires: { library: true },
5675 * @fires wp.media.controller.State#update
5678 var controller = this.controller,
5679 state = controller.state();
5682 state.trigger( 'update', state.get('library') );
5684 // Restore and reset the default state.
5685 controller.setState( controller.options.state );
5693 galleryAddToolbar: function() {
5694 this.toolbar.set( new wp.media.view.Toolbar({
5699 text: l10n.addToGallery,
5701 requires: { selection: true },
5704 * @fires wp.media.controller.State#reset
5707 var controller = this.controller,
5708 state = controller.state(),
5709 edit = controller.state('gallery-edit');
5711 edit.get('library').add( state.get('selection').models );
5712 state.trigger('reset');
5713 controller.setState('gallery-edit');
5720 playlistEditToolbar: function() {
5721 var editing = this.state().get('editing');
5722 this.toolbar.set( new wp.media.view.Toolbar({
5727 text: editing ? l10n.updatePlaylist : l10n.insertPlaylist,
5729 requires: { library: true },
5732 * @fires wp.media.controller.State#update
5735 var controller = this.controller,
5736 state = controller.state();
5739 state.trigger( 'update', state.get('library') );
5741 // Restore and reset the default state.
5742 controller.setState( controller.options.state );
5750 playlistAddToolbar: function() {
5751 this.toolbar.set( new wp.media.view.Toolbar({
5756 text: l10n.addToPlaylist,
5758 requires: { selection: true },
5761 * @fires wp.media.controller.State#reset
5764 var controller = this.controller,
5765 state = controller.state(),
5766 edit = controller.state('playlist-edit');
5768 edit.get('library').add( state.get('selection').models );
5769 state.trigger('reset');
5770 controller.setState('playlist-edit');
5777 videoPlaylistEditToolbar: function() {
5778 var editing = this.state().get('editing');
5779 this.toolbar.set( new wp.media.view.Toolbar({
5784 text: editing ? l10n.updateVideoPlaylist : l10n.insertVideoPlaylist,
5786 requires: { library: true },
5789 var controller = this.controller,
5790 state = controller.state(),
5791 library = state.get('library');
5793 library.type = 'video';
5796 state.trigger( 'update', library );
5798 // Restore and reset the default state.
5799 controller.setState( controller.options.state );
5807 videoPlaylistAddToolbar: function() {
5808 this.toolbar.set( new wp.media.view.Toolbar({
5813 text: l10n.addToVideoPlaylist,
5815 requires: { selection: true },
5818 var controller = this.controller,
5819 state = controller.state(),
5820 edit = controller.state('video-playlist-edit');
5822 edit.get('library').add( state.get('selection').models );
5823 state.trigger('reset');
5824 controller.setState('video-playlist-edit');
5832 module.exports = Post;
5834 },{}],46:[function(require,module,exports){
5836 * wp.media.view.MediaFrame.Select
5838 * A frame for selecting an item or items from the media library.
5841 * @augments wp.media.view.MediaFrame
5842 * @augments wp.media.view.Frame
5843 * @augments wp.media.View
5844 * @augments wp.Backbone.View
5845 * @augments Backbone.View
5846 * @mixes wp.media.controller.StateMachine
5849 var MediaFrame = wp.media.view.MediaFrame,
5850 l10n = wp.media.view.l10n,
5853 Select = MediaFrame.extend({
5854 initialize: function() {
5855 // Call 'initialize' directly on the parent class.
5856 MediaFrame.prototype.initialize.apply( this, arguments );
5858 _.defaults( this.options, {
5865 this.createSelection();
5866 this.createStates();
5867 this.bindHandlers();
5871 * Attach a selection collection to the frame.
5873 * A selection is a collection of attachments used for a specific purpose
5874 * by a media frame. e.g. Selecting an attachment (or many) to insert into
5877 * @see media.model.Selection
5879 createSelection: function() {
5880 var selection = this.options.selection;
5882 if ( ! (selection instanceof wp.media.model.Selection) ) {
5883 this.options.selection = new wp.media.model.Selection( selection, {
5884 multiple: this.options.multiple
5889 attachments: new wp.media.model.Attachments(),
5895 * Create the default states on the frame.
5897 createStates: function() {
5898 var options = this.options;
5900 if ( this.options.states ) {
5904 // Add the default states.
5907 new wp.media.controller.Library({
5908 library: wp.media.query( options.library ),
5909 multiple: options.multiple,
5910 title: options.title,
5917 * Bind region mode event callbacks.
5919 * @see media.controller.Region.render
5921 bindHandlers: function() {
5922 this.on( 'router:create:browse', this.createRouter, this );
5923 this.on( 'router:render:browse', this.browseRouter, this );
5924 this.on( 'content:create:browse', this.browseContent, this );
5925 this.on( 'content:render:upload', this.uploadContent, this );
5926 this.on( 'toolbar:create:select', this.createSelectToolbar, this );
5930 * Render callback for the router region in the `browse` mode.
5932 * @param {wp.media.view.Router} routerView
5934 browseRouter: function( routerView ) {
5937 text: l10n.uploadFilesTitle,
5941 text: l10n.mediaLibraryTitle,
5948 * Render callback for the content region in the `browse` mode.
5950 * @param {wp.media.controller.Region} contentRegion
5952 browseContent: function( contentRegion ) {
5953 var state = this.state();
5955 this.$el.removeClass('hide-toolbar');
5957 // Browse our library of attachments.
5958 contentRegion.view = new wp.media.view.AttachmentsBrowser({
5960 collection: state.get('library'),
5961 selection: state.get('selection'),
5963 sortable: state.get('sortable'),
5964 search: state.get('searchable'),
5965 filters: state.get('filterable'),
5966 date: state.get('date'),
5967 display: state.has('display') ? state.get('display') : state.get('displaySettings'),
5968 dragInfo: state.get('dragInfo'),
5970 idealColumnWidth: state.get('idealColumnWidth'),
5971 suggestedWidth: state.get('suggestedWidth'),
5972 suggestedHeight: state.get('suggestedHeight'),
5974 AttachmentView: state.get('AttachmentView')
5979 * Render callback for the content region in the `upload` mode.
5981 uploadContent: function() {
5982 this.$el.removeClass( 'hide-toolbar' );
5983 this.content.set( new wp.media.view.UploaderInline({
5991 * @param {Object} toolbar
5992 * @param {Object} [options={}]
5993 * @this wp.media.controller.Region
5995 createSelectToolbar: function( toolbar, options ) {
5996 options = options || this.options.button || {};
5997 options.controller = this;
5999 toolbar.view = new wp.media.view.Toolbar.Select( options );
6003 module.exports = Select;
6005 },{}],47:[function(require,module,exports){
6007 * wp.media.view.Iframe
6010 * @augments wp.media.View
6011 * @augments wp.Backbone.View
6012 * @augments Backbone.View
6014 var Iframe = wp.media.View.extend({
6015 className: 'media-iframe',
6017 * @returns {wp.media.view.Iframe} Returns itself to allow chaining
6019 render: function() {
6020 this.views.detach();
6021 this.$el.html( '<iframe src="' + this.controller.state().get('src') + '" />' );
6022 this.views.render();
6027 module.exports = Iframe;
6029 },{}],48:[function(require,module,exports){
6031 * wp.media.view.ImageDetails
6034 * @augments wp.media.view.Settings.AttachmentDisplay
6035 * @augments wp.media.view.Settings
6036 * @augments wp.media.View
6037 * @augments wp.Backbone.View
6038 * @augments Backbone.View
6040 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
6044 ImageDetails = AttachmentDisplay.extend({
6045 className: 'image-details',
6046 template: wp.template('image-details'),
6047 events: _.defaults( AttachmentDisplay.prototype.events, {
6048 'click .edit-attachment': 'editAttachment',
6049 'click .replace-attachment': 'replaceAttachment',
6050 'click .advanced-toggle': 'onToggleAdvanced',
6051 'change [data-setting="customWidth"]': 'onCustomSize',
6052 'change [data-setting="customHeight"]': 'onCustomSize',
6053 'keyup [data-setting="customWidth"]': 'onCustomSize',
6054 'keyup [data-setting="customHeight"]': 'onCustomSize'
6056 initialize: function() {
6057 // used in AttachmentDisplay.prototype.updateLinkTo
6058 this.options.attachment = this.model.attachment;
6059 this.listenTo( this.model, 'change:url', this.updateUrl );
6060 this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
6061 this.listenTo( this.model, 'change:size', this.toggleCustomSize );
6063 AttachmentDisplay.prototype.initialize.apply( this, arguments );
6066 prepare: function() {
6067 var attachment = false;
6069 if ( this.model.attachment ) {
6070 attachment = this.model.attachment.toJSON();
6073 model: this.model.toJSON(),
6074 attachment: attachment
6078 render: function() {
6079 var args = arguments;
6081 if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
6083 .done( _.bind( function() {
6084 AttachmentDisplay.prototype.render.apply( this, args );
6087 .fail( _.bind( function() {
6088 this.model.attachment = false;
6089 AttachmentDisplay.prototype.render.apply( this, args );
6093 AttachmentDisplay.prototype.render.apply( this, arguments );
6100 postRender: function() {
6101 setTimeout( _.bind( this.resetFocus, this ), 10 );
6102 this.toggleLinkSettings();
6103 if ( window.getUserSetting( 'advImgDetails' ) === 'show' ) {
6104 this.toggleAdvanced( true );
6106 this.trigger( 'post-render' );
6109 resetFocus: function() {
6110 this.$( '.link-to-custom' ).blur();
6111 this.$( '.embed-media-settings' ).scrollTop( 0 );
6114 updateUrl: function() {
6115 this.$( '.image img' ).attr( 'src', this.model.get( 'url' ) );
6116 this.$( '.url' ).val( this.model.get( 'url' ) );
6119 toggleLinkSettings: function() {
6120 if ( this.model.get( 'link' ) === 'none' ) {
6121 this.$( '.link-settings' ).addClass('hidden');
6123 this.$( '.link-settings' ).removeClass('hidden');
6127 toggleCustomSize: function() {
6128 if ( this.model.get( 'size' ) !== 'custom' ) {
6129 this.$( '.custom-size' ).addClass('hidden');
6131 this.$( '.custom-size' ).removeClass('hidden');
6135 onCustomSize: function( event ) {
6136 var dimension = $( event.target ).data('setting'),
6137 num = $( event.target ).val(),
6140 // Ignore bogus input
6141 if ( ! /^\d+/.test( num ) || parseInt( num, 10 ) < 1 ) {
6142 event.preventDefault();
6146 if ( dimension === 'customWidth' ) {
6147 value = Math.round( 1 / this.model.get( 'aspectRatio' ) * num );
6148 this.model.set( 'customHeight', value, { silent: true } );
6149 this.$( '[data-setting="customHeight"]' ).val( value );
6151 value = Math.round( this.model.get( 'aspectRatio' ) * num );
6152 this.model.set( 'customWidth', value, { silent: true } );
6153 this.$( '[data-setting="customWidth"]' ).val( value );
6157 onToggleAdvanced: function( event ) {
6158 event.preventDefault();
6159 this.toggleAdvanced();
6162 toggleAdvanced: function( show ) {
6163 var $advanced = this.$el.find( '.advanced-section' ),
6166 if ( $advanced.hasClass('advanced-visible') || show === false ) {
6167 $advanced.removeClass('advanced-visible');
6168 $advanced.find('.advanced-settings').addClass('hidden');
6171 $advanced.addClass('advanced-visible');
6172 $advanced.find('.advanced-settings').removeClass('hidden');
6176 window.setUserSetting( 'advImgDetails', mode );
6179 editAttachment: function( event ) {
6180 var editState = this.controller.states.get( 'edit-image' );
6182 if ( window.imageEdit && editState ) {
6183 event.preventDefault();
6184 editState.set( 'image', this.model.attachment );
6185 this.controller.setState( 'edit-image' );
6189 replaceAttachment: function( event ) {
6190 event.preventDefault();
6191 this.controller.setState( 'replace-image' );
6195 module.exports = ImageDetails;
6197 },{}],49:[function(require,module,exports){
6199 * wp.media.view.Label
6202 * @augments wp.media.View
6203 * @augments wp.Backbone.View
6204 * @augments Backbone.View
6206 var Label = wp.media.View.extend({
6208 className: 'screen-reader-text',
6210 initialize: function() {
6211 this.value = this.options.value;
6214 render: function() {
6215 this.$el.html( this.value );
6221 module.exports = Label;
6223 },{}],50:[function(require,module,exports){
6225 * wp.media.view.MediaFrame
6227 * The frame used to create the media modal.
6230 * @augments wp.media.view.Frame
6231 * @augments wp.media.View
6232 * @augments wp.Backbone.View
6233 * @augments Backbone.View
6234 * @mixes wp.media.controller.StateMachine
6236 var Frame = wp.media.view.Frame,
6240 MediaFrame = Frame.extend({
6241 className: 'media-frame',
6242 template: wp.template('media-frame'),
6243 regions: ['menu','title','content','toolbar','router'],
6246 'click div.media-frame-title h1': 'toggleMenu'
6250 * @global wp.Uploader
6252 initialize: function() {
6253 Frame.prototype.initialize.apply( this, arguments );
6255 _.defaults( this.options, {
6261 // Ensure core UI is enabled.
6262 this.$el.addClass('wp-core-ui');
6264 // Initialize modal container view.
6265 if ( this.options.modal ) {
6266 this.modal = new wp.media.view.Modal({
6268 title: this.options.title
6271 this.modal.content( this );
6274 // Force the uploader off if the upload limit has been exceeded or
6275 // if the browser isn't supported.
6276 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
6277 this.options.uploader = false;
6280 // Initialize window-wide uploader.
6281 if ( this.options.uploader ) {
6282 this.uploader = new wp.media.view.UploaderWindow({
6285 dropzone: this.modal ? this.modal.$el : this.$el,
6289 this.views.set( '.media-frame-uploader', this.uploader );
6292 this.on( 'attach', _.bind( this.views.ready, this.views ), this );
6294 // Bind default title creation.
6295 this.on( 'title:create:default', this.createTitle, this );
6296 this.title.mode('default');
6298 this.on( 'title:render', function( view ) {
6299 view.$el.append( '<span class="dashicons dashicons-arrow-down"></span>' );
6302 // Bind default menu.
6303 this.on( 'menu:create:default', this.createMenu, this );
6306 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6308 render: function() {
6309 // Activate the default state if no active state exists.
6310 if ( ! this.state() && this.options.state ) {
6311 this.setState( this.options.state );
6314 * call 'render' directly on the parent class
6316 return Frame.prototype.render.apply( this, arguments );
6319 * @param {Object} title
6320 * @this wp.media.controller.Region
6322 createTitle: function( title ) {
6323 title.view = new wp.media.View({
6329 * @param {Object} menu
6330 * @this wp.media.controller.Region
6332 createMenu: function( menu ) {
6333 menu.view = new wp.media.view.Menu({
6338 toggleMenu: function() {
6339 this.$el.find( '.media-menu' ).toggleClass( 'visible' );
6343 * @param {Object} toolbar
6344 * @this wp.media.controller.Region
6346 createToolbar: function( toolbar ) {
6347 toolbar.view = new wp.media.view.Toolbar({
6352 * @param {Object} router
6353 * @this wp.media.controller.Region
6355 createRouter: function( router ) {
6356 router.view = new wp.media.view.Router({
6361 * @param {Object} options
6363 createIframeStates: function( options ) {
6364 var settings = wp.media.view.settings,
6365 tabs = settings.tabs,
6366 tabUrl = settings.tabUrl,
6369 if ( ! tabs || ! tabUrl ) {
6373 // Add the post ID to the tab URL if it exists.
6374 $postId = $('#post_ID');
6375 if ( $postId.length ) {
6376 tabUrl += '&post_id=' + $postId.val();
6379 // Generate the tab states.
6380 _.each( tabs, function( title, id ) {
6381 this.state( 'iframe:' + id ).set( _.defaults({
6383 src: tabUrl + '&tab=' + id,
6390 this.on( 'content:create:iframe', this.iframeContent, this );
6391 this.on( 'content:deactivate:iframe', this.iframeContentCleanup, this );
6392 this.on( 'menu:render:default', this.iframeMenu, this );
6393 this.on( 'open', this.hijackThickbox, this );
6394 this.on( 'close', this.restoreThickbox, this );
6398 * @param {Object} content
6399 * @this wp.media.controller.Region
6401 iframeContent: function( content ) {
6402 this.$el.addClass('hide-toolbar');
6403 content.view = new wp.media.view.Iframe({
6408 iframeContentCleanup: function() {
6409 this.$el.removeClass('hide-toolbar');
6412 iframeMenu: function( view ) {
6419 _.each( wp.media.view.settings.tabs, function( title, id ) {
6420 views[ 'iframe:' + id ] = {
6421 text: this.state( 'iframe:' + id ).get('title'),
6429 hijackThickbox: function() {
6432 if ( ! window.tb_remove || this._tb_remove ) {
6436 this._tb_remove = window.tb_remove;
6437 window.tb_remove = function() {
6440 frame.setState( frame.options.state );
6441 frame._tb_remove.call( window );
6445 restoreThickbox: function() {
6446 if ( ! this._tb_remove ) {
6450 window.tb_remove = this._tb_remove;
6451 delete this._tb_remove;
6455 // Map some of the modal's methods to the frame.
6456 _.each(['open','close','attach','detach','escape'], function( method ) {
6458 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6460 MediaFrame.prototype[ method ] = function() {
6462 this.modal[ method ].apply( this.modal, arguments );
6468 module.exports = MediaFrame;
6470 },{}],51:[function(require,module,exports){
6472 * wp.media.view.MenuItem
6475 * @augments wp.media.View
6476 * @augments wp.Backbone.View
6477 * @augments Backbone.View
6482 MenuItem = wp.media.View.extend({
6484 className: 'media-menu-item',
6494 * @param {Object} event
6496 _click: function( event ) {
6497 var clickOverride = this.options.click;
6500 event.preventDefault();
6503 if ( clickOverride ) {
6504 clickOverride.call( this );
6509 // When selecting a tab along the left side,
6510 // focus should be transferred into the main panel
6511 if ( ! wp.media.isTouchDevice ) {
6512 $('.media-frame-content input').first().focus();
6517 var state = this.options.state;
6520 this.controller.setState( state );
6521 this.views.parent.$el.removeClass( 'visible' ); // TODO: or hide on any click, see below
6525 * @returns {wp.media.view.MenuItem} returns itself to allow chaining
6527 render: function() {
6528 var options = this.options;
6530 if ( options.text ) {
6531 this.$el.text( options.text );
6532 } else if ( options.html ) {
6533 this.$el.html( options.html );
6540 module.exports = MenuItem;
6542 },{}],52:[function(require,module,exports){
6544 * wp.media.view.Menu
6547 * @augments wp.media.view.PriorityList
6548 * @augments wp.media.View
6549 * @augments wp.Backbone.View
6550 * @augments Backbone.View
6552 var MenuItem = wp.media.view.MenuItem,
6553 PriorityList = wp.media.view.PriorityList,
6556 Menu = PriorityList.extend({
6558 className: 'media-menu',
6563 /* TODO: alternatively hide on any click anywhere
6569 this.$el.removeClass( 'visible' );
6574 * @param {Object} options
6575 * @param {string} id
6576 * @returns {wp.media.View}
6578 toView: function( options, id ) {
6579 options = options || {};
6580 options[ this.property ] = options[ this.property ] || id;
6581 return new this.ItemView( options ).render();
6586 * call 'ready' directly on the parent class
6588 PriorityList.prototype.ready.apply( this, arguments );
6594 * call 'set' directly on the parent class
6596 PriorityList.prototype.set.apply( this, arguments );
6602 * call 'unset' directly on the parent class
6604 PriorityList.prototype.unset.apply( this, arguments );
6608 visibility: function() {
6609 var region = this.region,
6610 view = this.controller[ region ].get(),
6611 views = this.views.get(),
6612 hide = ! views || views.length < 2;
6614 if ( this === view ) {
6615 this.controller.$el.toggleClass( 'hide-' + region, hide );
6619 * @param {string} id
6621 select: function( id ) {
6622 var view = this.get( id );
6629 view.$el.addClass('active');
6632 deselect: function() {
6633 this.$el.children().removeClass('active');
6636 hide: function( id ) {
6637 var view = this.get( id );
6643 view.$el.addClass('hidden');
6646 show: function( id ) {
6647 var view = this.get( id );
6653 view.$el.removeClass('hidden');
6657 module.exports = Menu;
6659 },{}],53:[function(require,module,exports){
6661 * wp.media.view.Modal
6663 * A modal view, which the media modal uses as its default container.
6666 * @augments wp.media.View
6667 * @augments wp.Backbone.View
6668 * @augments Backbone.View
6673 Modal = wp.media.View.extend({
6675 template: wp.template('media-modal'),
6682 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler',
6683 'keydown': 'keydown'
6686 initialize: function() {
6687 _.defaults( this.options, {
6688 container: document.body,
6694 this.focusManager = new wp.media.view.FocusManager({
6701 prepare: function() {
6703 title: this.options.title
6708 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6710 attach: function() {
6711 if ( this.views.attached ) {
6715 if ( ! this.views.rendered ) {
6719 this.$el.appendTo( this.options.container );
6721 // Manually mark the view as attached and trigger ready.
6722 this.views.attached = true;
6725 return this.propagate('attach');
6729 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6731 detach: function() {
6732 if ( this.$el.is(':visible') ) {
6737 this.views.attached = false;
6738 return this.propagate('detach');
6742 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6746 options = this.options,
6749 if ( $el.is(':visible') ) {
6753 if ( ! this.views.attached ) {
6757 // If the `freeze` option is set, record the window's scroll position.
6758 if ( options.freeze ) {
6760 scrollTop: $( window ).scrollTop()
6764 // Disable page scrolling.
6765 $( 'body' ).addClass( 'modal-open' );
6769 // Try to close the onscreen keyboard
6770 if ( 'ontouchend' in document ) {
6771 if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor ) && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
6772 mceEditor.iframeElement.focus();
6773 mceEditor.iframeElement.blur();
6775 setTimeout( function() {
6776 mceEditor.iframeElement.blur();
6783 return this.propagate('open');
6787 * @param {Object} options
6788 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6790 close: function( options ) {
6791 var freeze = this._freeze;
6793 if ( ! this.views.attached || ! this.$el.is(':visible') ) {
6797 // Enable page scrolling.
6798 $( 'body' ).removeClass( 'modal-open' );
6800 // Hide modal and remove restricted media modal tab focus once it's closed
6801 this.$el.hide().undelegate( 'keydown' );
6803 // Put focus back in useful location once modal is closed
6804 $('#wpbody-content').focus();
6806 this.propagate('close');
6808 // If the `freeze` option is set, restore the container's scroll position.
6810 $( window ).scrollTop( freeze.scrollTop );
6813 if ( options && options.escape ) {
6814 this.propagate('escape');
6820 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6822 escape: function() {
6823 return this.close({ escape: true });
6826 * @param {Object} event
6828 escapeHandler: function( event ) {
6829 event.preventDefault();
6834 * @param {Array|Object} content Views to register to '.media-modal-content'
6835 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6837 content: function( content ) {
6838 this.views.set( '.media-modal-content', content );
6843 * Triggers a modal event and if the `propagate` option is set,
6844 * forwards events to the modal's controller.
6846 * @param {string} id
6847 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6849 propagate: function( id ) {
6852 if ( this.options.propagate ) {
6853 this.controller.trigger( id );
6859 * @param {Object} event
6861 keydown: function( event ) {
6862 // Close the modal when escape is pressed.
6863 if ( 27 === event.which && this.$el.is(':visible') ) {
6865 event.stopImmediatePropagation();
6870 module.exports = Modal;
6872 },{}],54:[function(require,module,exports){
6874 * wp.media.view.PriorityList
6877 * @augments wp.media.View
6878 * @augments wp.Backbone.View
6879 * @augments Backbone.View
6881 var PriorityList = wp.media.View.extend({
6884 initialize: function() {
6887 this.set( _.extend( {}, this._views, this.options.views ), { silent: true });
6888 delete this.options.views;
6890 if ( ! this.options.silent ) {
6895 * @param {string} id
6896 * @param {wp.media.View|Object} view
6897 * @param {Object} options
6898 * @returns {wp.media.view.PriorityList} Returns itself to allow chaining
6900 set: function( id, view, options ) {
6901 var priority, views, index;
6903 options = options || {};
6905 // Accept an object with an `id` : `view` mapping.
6906 if ( _.isObject( id ) ) {
6907 _.each( id, function( view, id ) {
6908 this.set( id, view );
6913 if ( ! (view instanceof Backbone.View) ) {
6914 view = this.toView( view, id, options );
6916 view.controller = view.controller || this.controller;
6920 priority = view.options.priority || 10;
6921 views = this.views.get() || [];
6923 _.find( views, function( existing, i ) {
6924 if ( existing.options.priority > priority ) {
6930 this._views[ id ] = view;
6931 this.views.add( view, {
6932 at: _.isNumber( index ) ? index : views.length || 0
6938 * @param {string} id
6939 * @returns {wp.media.View}
6941 get: function( id ) {
6942 return this._views[ id ];
6945 * @param {string} id
6946 * @returns {wp.media.view.PriorityList}
6948 unset: function( id ) {
6949 var view = this.get( id );
6955 delete this._views[ id ];
6959 * @param {Object} options
6960 * @returns {wp.media.View}
6962 toView: function( options ) {
6963 return new wp.media.View( options );
6967 module.exports = PriorityList;
6969 },{}],55:[function(require,module,exports){
6971 * wp.media.view.RouterItem
6974 * @augments wp.media.view.MenuItem
6975 * @augments wp.media.View
6976 * @augments wp.Backbone.View
6977 * @augments Backbone.View
6979 var RouterItem = wp.media.view.MenuItem.extend({
6981 * On click handler to activate the content region's corresponding mode.
6984 var contentMode = this.options.contentMode;
6985 if ( contentMode ) {
6986 this.controller.content.mode( contentMode );
6991 module.exports = RouterItem;
6993 },{}],56:[function(require,module,exports){
6995 * wp.media.view.Router
6998 * @augments wp.media.view.Menu
6999 * @augments wp.media.view.PriorityList
7000 * @augments wp.media.View
7001 * @augments wp.Backbone.View
7002 * @augments Backbone.View
7004 var Menu = wp.media.view.Menu,
7007 Router = Menu.extend({
7009 className: 'media-router',
7010 property: 'contentMode',
7011 ItemView: wp.media.view.RouterItem,
7014 initialize: function() {
7015 this.controller.on( 'content:render', this.update, this );
7016 // Call 'initialize' directly on the parent class.
7017 Menu.prototype.initialize.apply( this, arguments );
7020 update: function() {
7021 var mode = this.controller.content.mode();
7023 this.select( mode );
7028 module.exports = Router;
7030 },{}],57:[function(require,module,exports){
7032 * wp.media.view.Search
7035 * @augments wp.media.View
7036 * @augments wp.Backbone.View
7037 * @augments Backbone.View
7039 var l10n = wp.media.view.l10n,
7042 Search = wp.media.View.extend({
7044 className: 'search',
7045 id: 'media-search-input',
7049 placeholder: l10n.search
7060 * @returns {wp.media.view.Search} Returns itself to allow chaining
7062 render: function() {
7063 this.el.value = this.model.escape('search');
7067 search: function( event ) {
7068 if ( event.target.value ) {
7069 this.model.set( 'search', event.target.value );
7071 this.model.unset('search');
7076 module.exports = Search;
7078 },{}],58:[function(require,module,exports){
7080 * wp.media.view.Selection
7083 * @augments wp.media.View
7084 * @augments wp.Backbone.View
7085 * @augments Backbone.View
7087 var l10n = wp.media.view.l10n,
7090 Selection = wp.media.View.extend({
7092 className: 'media-selection',
7093 template: wp.template('media-selection'),
7096 'click .edit-selection': 'edit',
7097 'click .clear-selection': 'clear'
7100 initialize: function() {
7101 _.defaults( this.options, {
7107 * @member {wp.media.view.Attachments.Selection}
7109 this.attachments = new wp.media.view.Attachments.Selection({
7110 controller: this.controller,
7111 collection: this.collection,
7112 selection: this.collection,
7113 model: new Backbone.Model()
7116 this.views.set( '.selection-view', this.attachments );
7117 this.collection.on( 'add remove reset', this.refresh, this );
7118 this.controller.on( 'content:activate', this.refresh, this );
7125 refresh: function() {
7126 // If the selection hasn't been rendered, bail.
7127 if ( ! this.$el.children().length ) {
7131 var collection = this.collection,
7132 editing = 'edit-selection' === this.controller.content.mode();
7134 // If nothing is selected, display nothing.
7135 this.$el.toggleClass( 'empty', ! collection.length );
7136 this.$el.toggleClass( 'one', 1 === collection.length );
7137 this.$el.toggleClass( 'editing', editing );
7139 this.$('.count').text( l10n.selected.replace('%d', collection.length) );
7142 edit: function( event ) {
7143 event.preventDefault();
7144 if ( this.options.editable ) {
7145 this.options.editable.call( this, this.collection );
7149 clear: function( event ) {
7150 event.preventDefault();
7151 this.collection.reset();
7153 // Keep focus inside media modal
7154 // after clear link is selected
7155 this.controller.modal.focusManager.focus();
7159 module.exports = Selection;
7161 },{}],59:[function(require,module,exports){
7163 * wp.media.view.Settings
7166 * @augments wp.media.View
7167 * @augments wp.Backbone.View
7168 * @augments Backbone.View
7170 var View = wp.media.View,
7174 Settings = View.extend({
7176 'click button': 'updateHandler',
7177 'change input': 'updateHandler',
7178 'change select': 'updateHandler',
7179 'change textarea': 'updateHandler'
7182 initialize: function() {
7183 this.model = this.model || new Backbone.Model();
7184 this.listenTo( this.model, 'change', this.updateChanges );
7187 prepare: function() {
7189 model: this.model.toJSON()
7193 * @returns {wp.media.view.Settings} Returns itself to allow chaining
7195 render: function() {
7196 View.prototype.render.apply( this, arguments );
7197 // Select the correct values.
7198 _( this.model.attributes ).chain().keys().each( this.update, this );
7202 * @param {string} key
7204 update: function( key ) {
7205 var value = this.model.get( key ),
7206 $setting = this.$('[data-setting="' + key + '"]'),
7209 // Bail if we didn't find a matching setting.
7210 if ( ! $setting.length ) {
7214 // Attempt to determine how the setting is rendered and update
7215 // the selected value.
7217 // Handle dropdowns.
7218 if ( $setting.is('select') ) {
7219 $value = $setting.find('[value="' + value + '"]');
7221 if ( $value.length ) {
7222 $setting.find('option').prop( 'selected', false );
7223 $value.prop( 'selected', true );
7225 // If we can't find the desired value, record what *is* selected.
7226 this.model.set( key, $setting.find(':selected').val() );
7229 // Handle button groups.
7230 } else if ( $setting.hasClass('button-group') ) {
7231 $buttons = $setting.find('button').removeClass('active');
7232 $buttons.filter( '[value="' + value + '"]' ).addClass('active');
7234 // Handle text inputs and textareas.
7235 } else if ( $setting.is('input[type="text"], textarea') ) {
7236 if ( ! $setting.is(':focus') ) {
7237 $setting.val( value );
7239 // Handle checkboxes.
7240 } else if ( $setting.is('input[type="checkbox"]') ) {
7241 $setting.prop( 'checked', !! value && 'false' !== value );
7245 * @param {Object} event
7247 updateHandler: function( event ) {
7248 var $setting = $( event.target ).closest('[data-setting]'),
7249 value = event.target.value,
7252 event.preventDefault();
7254 if ( ! $setting.length ) {
7258 // Use the correct value for checkboxes.
7259 if ( $setting.is('input[type="checkbox"]') ) {
7260 value = $setting[0].checked;
7263 // Update the corresponding setting.
7264 this.model.set( $setting.data('setting'), value );
7266 // If the setting has a corresponding user setting,
7267 // update that as well.
7268 if ( userSetting = $setting.data('userSetting') ) {
7269 window.setUserSetting( userSetting, value );
7273 updateChanges: function( model ) {
7274 if ( model.hasChanged() ) {
7275 _( model.changed ).chain().keys().each( this.update, this );
7280 module.exports = Settings;
7282 },{}],60:[function(require,module,exports){
7284 * wp.media.view.Settings.AttachmentDisplay
7287 * @augments wp.media.view.Settings
7288 * @augments wp.media.View
7289 * @augments wp.Backbone.View
7290 * @augments Backbone.View
7292 var Settings = wp.media.view.Settings,
7295 AttachmentDisplay = Settings.extend({
7296 className: 'attachment-display-settings',
7297 template: wp.template('attachment-display-settings'),
7299 initialize: function() {
7300 var attachment = this.options.attachment;
7302 _.defaults( this.options, {
7305 // Call 'initialize' directly on the parent class.
7306 Settings.prototype.initialize.apply( this, arguments );
7307 this.listenTo( this.model, 'change:link', this.updateLinkTo );
7310 attachment.on( 'change:uploading', this.render, this );
7314 dispose: function() {
7315 var attachment = this.options.attachment;
7317 attachment.off( null, null, this );
7320 * call 'dispose' directly on the parent class
7322 Settings.prototype.dispose.apply( this, arguments );
7325 * @returns {wp.media.view.AttachmentDisplay} Returns itself to allow chaining
7327 render: function() {
7328 var attachment = this.options.attachment;
7330 _.extend( this.options, {
7331 sizes: attachment.get('sizes'),
7332 type: attachment.get('type')
7336 * call 'render' directly on the parent class
7338 Settings.prototype.render.call( this );
7339 this.updateLinkTo();
7343 updateLinkTo: function() {
7344 var linkTo = this.model.get('link'),
7345 $input = this.$('.link-to-custom'),
7346 attachment = this.options.attachment;
7348 if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
7349 $input.addClass( 'hidden' );
7354 if ( 'post' === linkTo ) {
7355 $input.val( attachment.get('link') );
7356 } else if ( 'file' === linkTo ) {
7357 $input.val( attachment.get('url') );
7358 } else if ( ! this.model.get('linkUrl') ) {
7359 $input.val('http://');
7362 $input.prop( 'readonly', 'custom' !== linkTo );
7365 $input.removeClass( 'hidden' );
7367 // If the input is visible, focus and select its contents.
7368 if ( ! wp.media.isTouchDevice && $input.is(':visible') ) {
7369 $input.focus()[0].select();
7374 module.exports = AttachmentDisplay;
7376 },{}],61:[function(require,module,exports){
7378 * wp.media.view.Settings.Gallery
7381 * @augments wp.media.view.Settings
7382 * @augments wp.media.View
7383 * @augments wp.Backbone.View
7384 * @augments Backbone.View
7386 var Gallery = wp.media.view.Settings.extend({
7387 className: 'collection-settings gallery-settings',
7388 template: wp.template('gallery-settings')
7391 module.exports = Gallery;
7393 },{}],62:[function(require,module,exports){
7395 * wp.media.view.Settings.Playlist
7398 * @augments wp.media.view.Settings
7399 * @augments wp.media.View
7400 * @augments wp.Backbone.View
7401 * @augments Backbone.View
7403 var Playlist = wp.media.view.Settings.extend({
7404 className: 'collection-settings playlist-settings',
7405 template: wp.template('playlist-settings')
7408 module.exports = Playlist;
7410 },{}],63:[function(require,module,exports){
7412 * wp.media.view.Sidebar
7415 * @augments wp.media.view.PriorityList
7416 * @augments wp.media.View
7417 * @augments wp.Backbone.View
7418 * @augments Backbone.View
7420 var Sidebar = wp.media.view.PriorityList.extend({
7421 className: 'media-sidebar'
7424 module.exports = Sidebar;
7426 },{}],64:[function(require,module,exports){
7428 * wp.media.view.SiteIconCropper
7430 * Uses the imgAreaSelect plugin to allow a user to crop a Site Icon.
7432 * Takes imgAreaSelect options from
7433 * wp.customize.SiteIconControl.calculateImageSelectOptions.
7436 * @augments wp.media.view.Cropper
7437 * @augments wp.media.View
7438 * @augments wp.Backbone.View
7439 * @augments Backbone.View
7441 var View = wp.media.view,
7444 SiteIconCropper = View.Cropper.extend({
7445 className: 'crop-content site-icon',
7447 ready: function () {
7448 View.Cropper.prototype.ready.apply( this, arguments );
7450 this.$( '.crop-image' ).on( 'load', _.bind( this.addSidebar, this ) );
7453 addSidebar: function() {
7454 this.sidebar = new wp.media.view.Sidebar({
7455 controller: this.controller
7458 this.sidebar.set( 'preview', new wp.media.view.SiteIconPreview({
7459 controller: this.controller,
7460 attachment: this.options.attachment
7463 this.controller.cropperView.views.add( this.sidebar );
7467 module.exports = SiteIconCropper;
7469 },{}],65:[function(require,module,exports){
7471 * wp.media.view.SiteIconPreview
7473 * Shows a preview of the Site Icon as a favicon and app icon while cropping.
7476 * @augments wp.media.View
7477 * @augments wp.Backbone.View
7478 * @augments Backbone.View
7480 var View = wp.media.View,
7484 SiteIconPreview = View.extend({
7485 className: 'site-icon-preview',
7486 template: wp.template( 'site-icon-preview' ),
7489 this.controller.imgSelect.setOptions({
7490 onInit: this.updatePreview,
7491 onSelectChange: this.updatePreview
7495 prepare: function() {
7497 url: this.options.attachment.get( 'url' )
7501 updatePreview: function( img, coords ) {
7502 var rx = 64 / coords.width,
7503 ry = 64 / coords.height,
7504 preview_rx = 16 / coords.width,
7505 preview_ry = 16 / coords.height;
7507 $( '#preview-app-icon' ).css({
7508 width: Math.round(rx * this.imageWidth ) + 'px',
7509 height: Math.round(ry * this.imageHeight ) + 'px',
7510 marginLeft: '-' + Math.round(rx * coords.x1) + 'px',
7511 marginTop: '-' + Math.round(ry * coords.y1) + 'px'
7514 $( '#preview-favicon' ).css({
7515 width: Math.round( preview_rx * this.imageWidth ) + 'px',
7516 height: Math.round( preview_ry * this.imageHeight ) + 'px',
7517 marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px',
7518 marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px'
7523 module.exports = SiteIconPreview;
7525 },{}],66:[function(require,module,exports){
7527 * wp.media.view.Spinner
7530 * @augments wp.media.View
7531 * @augments wp.Backbone.View
7532 * @augments Backbone.View
7534 var Spinner = wp.media.View.extend({
7536 className: 'spinner',
7537 spinnerTimeout: false,
7541 if ( ! this.spinnerTimeout ) {
7542 this.spinnerTimeout = _.delay(function( $el ) {
7543 $el.addClass( 'is-active' );
7544 }, this.delay, this.$el );
7551 this.$el.removeClass( 'is-active' );
7552 this.spinnerTimeout = clearTimeout( this.spinnerTimeout );
7558 module.exports = Spinner;
7560 },{}],67:[function(require,module,exports){
7562 * wp.media.view.Toolbar
7564 * A toolbar which consists of a primary and a secondary section. Each sections
7565 * can be filled with views.
7568 * @augments wp.media.View
7569 * @augments wp.Backbone.View
7570 * @augments Backbone.View
7572 var View = wp.media.View,
7575 Toolbar = View.extend({
7577 className: 'media-toolbar',
7579 initialize: function() {
7580 var state = this.controller.state(),
7581 selection = this.selection = state.get('selection'),
7582 library = this.library = state.get('library');
7586 // The toolbar is composed of two `PriorityList` views.
7587 this.primary = new wp.media.view.PriorityList();
7588 this.secondary = new wp.media.view.PriorityList();
7589 this.primary.$el.addClass('media-toolbar-primary search-form');
7590 this.secondary.$el.addClass('media-toolbar-secondary');
7592 this.views.set([ this.secondary, this.primary ]);
7594 if ( this.options.items ) {
7595 this.set( this.options.items, { silent: true });
7598 if ( ! this.options.silent ) {
7603 selection.on( 'add remove reset', this.refresh, this );
7607 library.on( 'add remove reset', this.refresh, this );
7611 * @returns {wp.media.view.Toolbar} Returns itsef to allow chaining
7613 dispose: function() {
7614 if ( this.selection ) {
7615 this.selection.off( null, null, this );
7618 if ( this.library ) {
7619 this.library.off( null, null, this );
7622 * call 'dispose' directly on the parent class
7624 return View.prototype.dispose.apply( this, arguments );
7632 * @param {string} id
7633 * @param {Backbone.View|Object} view
7634 * @param {Object} [options={}]
7635 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7637 set: function( id, view, options ) {
7639 options = options || {};
7641 // Accept an object with an `id` : `view` mapping.
7642 if ( _.isObject( id ) ) {
7643 _.each( id, function( view, id ) {
7644 this.set( id, view, { silent: true });
7648 if ( ! ( view instanceof Backbone.View ) ) {
7649 view.classes = [ 'media-button-' + id ].concat( view.classes || [] );
7650 view = new wp.media.view.Button( view ).render();
7653 view.controller = view.controller || this.controller;
7655 this._views[ id ] = view;
7657 list = view.options.priority < 0 ? 'secondary' : 'primary';
7658 this[ list ].set( id, view, options );
7661 if ( ! options.silent ) {
7668 * @param {string} id
7669 * @returns {wp.media.view.Button}
7671 get: function( id ) {
7672 return this._views[ id ];
7675 * @param {string} id
7676 * @param {Object} options
7677 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7679 unset: function( id, options ) {
7680 delete this._views[ id ];
7681 this.primary.unset( id, options );
7682 this.secondary.unset( id, options );
7684 if ( ! options || ! options.silent ) {
7690 refresh: function() {
7691 var state = this.controller.state(),
7692 library = state.get('library'),
7693 selection = state.get('selection');
7695 _.each( this._views, function( button ) {
7696 if ( ! button.model || ! button.options || ! button.options.requires ) {
7700 var requires = button.options.requires,
7703 // Prevent insertion of attachments if any of them are still uploading
7704 disabled = _.some( selection.models, function( attachment ) {
7705 return attachment.get('uploading') === true;
7708 if ( requires.selection && selection && ! selection.length ) {
7710 } else if ( requires.library && library && ! library.length ) {
7713 button.model.set( 'disabled', disabled );
7718 module.exports = Toolbar;
7720 },{}],68:[function(require,module,exports){
7722 * wp.media.view.Toolbar.Embed
7725 * @augments wp.media.view.Toolbar.Select
7726 * @augments wp.media.view.Toolbar
7727 * @augments wp.media.View
7728 * @augments wp.Backbone.View
7729 * @augments Backbone.View
7731 var Select = wp.media.view.Toolbar.Select,
7732 l10n = wp.media.view.l10n,
7735 Embed = Select.extend({
7736 initialize: function() {
7737 _.defaults( this.options, {
7738 text: l10n.insertIntoPost,
7741 // Call 'initialize' directly on the parent class.
7742 Select.prototype.initialize.apply( this, arguments );
7745 refresh: function() {
7746 var url = this.controller.state().props.get('url');
7747 this.get('select').model.set( 'disabled', ! url || url === 'http://' );
7749 * call 'refresh' directly on the parent class
7751 Select.prototype.refresh.apply( this, arguments );
7755 module.exports = Embed;
7757 },{}],69:[function(require,module,exports){
7759 * wp.media.view.Toolbar.Select
7762 * @augments wp.media.view.Toolbar
7763 * @augments wp.media.View
7764 * @augments wp.Backbone.View
7765 * @augments Backbone.View
7767 var Toolbar = wp.media.view.Toolbar,
7768 l10n = wp.media.view.l10n,
7771 Select = Toolbar.extend({
7772 initialize: function() {
7773 var options = this.options;
7775 _.bindAll( this, 'clickSelect' );
7777 _.defaults( options, {
7784 // Does the button rely on the selection?
7790 options.items = _.defaults( options.items || {}, {
7795 click: this.clickSelect,
7796 requires: options.requires
7799 // Call 'initialize' directly on the parent class.
7800 Toolbar.prototype.initialize.apply( this, arguments );
7803 clickSelect: function() {
7804 var options = this.options,
7805 controller = this.controller;
7807 if ( options.close ) {
7811 if ( options.event ) {
7812 controller.state().trigger( options.event );
7815 if ( options.state ) {
7816 controller.setState( options.state );
7819 if ( options.reset ) {
7825 module.exports = Select;
7827 },{}],70:[function(require,module,exports){
7829 * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap)
7830 * and relays drag'n'dropped files to a media workflow.
7832 * wp.media.view.EditorUploader
7835 * @augments wp.media.View
7836 * @augments wp.Backbone.View
7837 * @augments Backbone.View
7839 var View = wp.media.View,
7840 l10n = wp.media.view.l10n,
7844 EditorUploader = View.extend({
7846 className: 'uploader-editor',
7847 template: wp.template( 'uploader-editor' ),
7850 overContainer: false,
7851 overDropzone: false,
7855 * Bind drag'n'drop events to callbacks.
7857 initialize: function() {
7858 this.initialized = false;
7860 // Bail if not enabled or UA does not support drag'n'drop or File API.
7861 if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) {
7865 this.$document = $(document);
7866 this.dropzones = [];
7869 this.$document.on( 'drop', '.uploader-editor', _.bind( this.drop, this ) );
7870 this.$document.on( 'dragover', '.uploader-editor', _.bind( this.dropzoneDragover, this ) );
7871 this.$document.on( 'dragleave', '.uploader-editor', _.bind( this.dropzoneDragleave, this ) );
7872 this.$document.on( 'click', '.uploader-editor', _.bind( this.click, this ) );
7874 this.$document.on( 'dragover', _.bind( this.containerDragover, this ) );
7875 this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
7877 this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
7878 this.localDrag = event.type === 'dragstart';
7880 if ( event.type === 'drop' ) {
7881 this.containerDragleave();
7885 this.initialized = true;
7890 * Check browser support for drag'n'drop.
7894 browserSupport: function() {
7895 var supports = false, div = document.createElement('div');
7897 supports = ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div );
7898 supports = supports && !! ( window.File && window.FileList && window.FileReader );
7902 isDraggingFile: function( event ) {
7903 if ( this.draggingFile !== null ) {
7904 return this.draggingFile;
7907 if ( _.isUndefined( event.originalEvent ) || _.isUndefined( event.originalEvent.dataTransfer ) ) {
7911 this.draggingFile = _.indexOf( event.originalEvent.dataTransfer.types, 'Files' ) > -1 &&
7912 _.indexOf( event.originalEvent.dataTransfer.types, 'text/plain' ) === -1;
7914 return this.draggingFile;
7917 refresh: function( e ) {
7919 for ( dropzone_id in this.dropzones ) {
7920 // Hide the dropzones only if dragging has left the screen.
7921 this.dropzones[ dropzone_id ].toggle( this.overContainer || this.overDropzone );
7924 if ( ! _.isUndefined( e ) ) {
7925 $( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone );
7928 if ( ! this.overContainer && ! this.overDropzone ) {
7929 this.draggingFile = null;
7935 render: function() {
7936 if ( ! this.initialized ) {
7940 View.prototype.render.apply( this, arguments );
7941 $( '.wp-editor-wrap' ).each( _.bind( this.attach, this ) );
7945 attach: function( index, editor ) {
7946 // Attach a dropzone to an editor.
7947 var dropzone = this.$el.clone();
7948 this.dropzones.push( dropzone );
7949 $( editor ).append( dropzone );
7954 * When a file is dropped on the editor uploader, open up an editor media workflow
7955 * and upload the file immediately.
7957 * @param {jQuery.Event} event The 'drop' event.
7959 drop: function( event ) {
7960 var $wrap, uploadView;
7962 this.containerDragleave( event );
7963 this.dropzoneDragleave( event );
7965 this.files = event.originalEvent.dataTransfer.files;
7966 if ( this.files.length < 1 ) {
7970 // Set the active editor to the drop target.
7971 $wrap = $( event.target ).parents( '.wp-editor-wrap' );
7972 if ( $wrap.length > 0 && $wrap[0].id ) {
7973 window.wpActiveEditor = $wrap[0].id.slice( 3, -5 );
7976 if ( ! this.workflow ) {
7977 this.workflow = wp.media.editor.open( window.wpActiveEditor, {
7980 title: l10n.addMedia,
7984 uploadView = this.workflow.uploader;
7986 if ( uploadView.uploader && uploadView.uploader.ready ) {
7987 this.addFiles.apply( this );
7989 this.workflow.on( 'uploader:ready', this.addFiles, this );
7992 this.workflow.state().reset();
7993 this.addFiles.apply( this );
7994 this.workflow.open();
8001 * Add the files to the uploader.
8003 addFiles: function() {
8004 if ( this.files.length ) {
8005 this.workflow.uploader.uploader.uploader.addFile( _.toArray( this.files ) );
8011 containerDragover: function( event ) {
8012 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
8016 this.overContainer = true;
8020 containerDragleave: function() {
8021 this.overContainer = false;
8023 // Throttle dragleave because it's called when bouncing from some elements to others.
8024 _.delay( _.bind( this.refresh, this ), 50 );
8027 dropzoneDragover: function( event ) {
8028 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
8032 this.overDropzone = true;
8033 this.refresh( event );
8037 dropzoneDragleave: function( e ) {
8038 this.overDropzone = false;
8039 _.delay( _.bind( this.refresh, this, e ), 50 );
8042 click: function( e ) {
8043 // In the rare case where the dropzone gets stuck, hide it on click.
8044 this.containerDragleave( e );
8045 this.dropzoneDragleave( e );
8046 this.localDrag = false;
8050 module.exports = EditorUploader;
8052 },{}],71:[function(require,module,exports){
8054 * wp.media.view.UploaderInline
8056 * The inline uploader that shows up in the 'Upload Files' tab.
8059 * @augments wp.media.View
8060 * @augments wp.Backbone.View
8061 * @augments Backbone.View
8063 var View = wp.media.View,
8066 UploaderInline = View.extend({
8068 className: 'uploader-inline',
8069 template: wp.template('uploader-inline'),
8072 'click .close': 'hide'
8075 initialize: function() {
8076 _.defaults( this.options, {
8082 if ( ! this.options.$browser && this.controller.uploader ) {
8083 this.options.$browser = this.controller.uploader.$browser;
8086 if ( _.isUndefined( this.options.postId ) ) {
8087 this.options.postId = wp.media.view.settings.post.id;
8090 if ( this.options.status ) {
8091 this.views.set( '.upload-inline-status', new wp.media.view.UploaderStatus({
8092 controller: this.controller
8097 prepare: function() {
8098 var suggestedWidth = this.controller.state().get('suggestedWidth'),
8099 suggestedHeight = this.controller.state().get('suggestedHeight'),
8102 data.message = this.options.message;
8103 data.canClose = this.options.canClose;
8105 if ( suggestedWidth && suggestedHeight ) {
8106 data.suggestedWidth = suggestedWidth;
8107 data.suggestedHeight = suggestedHeight;
8113 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8115 dispose: function() {
8116 if ( this.disposing ) {
8118 * call 'dispose' directly on the parent class
8120 return View.prototype.dispose.apply( this, arguments );
8123 // Run remove on `dispose`, so we can be sure to refresh the
8124 // uploader with a view-less DOM. Track whether we're disposing
8125 // so we don't trigger an infinite loop.
8126 this.disposing = true;
8127 return this.remove();
8130 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8132 remove: function() {
8134 * call 'remove' directly on the parent class
8136 var result = View.prototype.remove.apply( this, arguments );
8138 _.defer( _.bind( this.refresh, this ) );
8142 refresh: function() {
8143 var uploader = this.controller.uploader;
8150 * @returns {wp.media.view.UploaderInline}
8153 var $browser = this.options.$browser,
8156 if ( this.controller.uploader ) {
8157 $placeholder = this.$('.browser');
8159 // Check if we've already replaced the placeholder.
8160 if ( $placeholder[0] === $browser[0] ) {
8164 $browser.detach().text( $placeholder.text() );
8165 $browser[0].className = $placeholder[0].className;
8166 $placeholder.replaceWith( $browser.show() );
8173 this.$el.removeClass( 'hidden' );
8176 this.$el.addClass( 'hidden' );
8181 module.exports = UploaderInline;
8183 },{}],72:[function(require,module,exports){
8185 * wp.media.view.UploaderStatusError
8188 * @augments wp.media.View
8189 * @augments wp.Backbone.View
8190 * @augments Backbone.View
8192 var UploaderStatusError = wp.media.View.extend({
8193 className: 'upload-error',
8194 template: wp.template('uploader-status-error')
8197 module.exports = UploaderStatusError;
8199 },{}],73:[function(require,module,exports){
8201 * wp.media.view.UploaderStatus
8203 * An uploader status for on-going uploads.
8206 * @augments wp.media.View
8207 * @augments wp.Backbone.View
8208 * @augments Backbone.View
8210 var View = wp.media.View,
8213 UploaderStatus = View.extend({
8214 className: 'media-uploader-status',
8215 template: wp.template('uploader-status'),
8218 'click .upload-dismiss-errors': 'dismiss'
8221 initialize: function() {
8222 this.queue = wp.Uploader.queue;
8223 this.queue.on( 'add remove reset', this.visibility, this );
8224 this.queue.on( 'add remove reset change:percent', this.progress, this );
8225 this.queue.on( 'add remove reset change:uploading', this.info, this );
8227 this.errors = wp.Uploader.errors;
8228 this.errors.reset();
8229 this.errors.on( 'add remove reset', this.visibility, this );
8230 this.errors.on( 'add', this.error, this );
8233 * @global wp.Uploader
8234 * @returns {wp.media.view.UploaderStatus}
8236 dispose: function() {
8237 wp.Uploader.queue.off( null, null, this );
8239 * call 'dispose' directly on the parent class
8241 View.prototype.dispose.apply( this, arguments );
8245 visibility: function() {
8246 this.$el.toggleClass( 'uploading', !! this.queue.length );
8247 this.$el.toggleClass( 'errors', !! this.errors.length );
8248 this.$el.toggle( !! this.queue.length || !! this.errors.length );
8253 '$bar': '.media-progress-bar div',
8254 '$index': '.upload-index',
8255 '$total': '.upload-total',
8256 '$filename': '.upload-filename'
8257 }, function( selector, key ) {
8258 this[ key ] = this.$( selector );
8266 progress: function() {
8267 var queue = this.queue,
8270 if ( ! $bar || ! queue.length ) {
8274 $bar.width( ( queue.reduce( function( memo, attachment ) {
8275 if ( ! attachment.get('uploading') ) {
8279 var percent = attachment.get('percent');
8280 return memo + ( _.isNumber( percent ) ? percent : 100 );
8281 }, 0 ) / queue.length ) + '%' );
8285 var queue = this.queue,
8288 if ( ! queue.length ) {
8292 active = this.queue.find( function( attachment, i ) {
8294 return attachment.get('uploading');
8297 this.$index.text( index + 1 );
8298 this.$total.text( queue.length );
8299 this.$filename.html( active ? this.filename( active.get('filename') ) : '' );
8302 * @param {string} filename
8305 filename: function( filename ) {
8306 return _.escape( filename );
8309 * @param {Backbone.Model} error
8311 error: function( error ) {
8312 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
8313 filename: this.filename( error.get('file').name ),
8314 message: error.get('message')
8319 * @global wp.Uploader
8321 * @param {Object} event
8323 dismiss: function( event ) {
8324 var errors = this.views.get('.upload-errors');
8326 event.preventDefault();
8329 _.invoke( errors, 'remove' );
8331 wp.Uploader.errors.reset();
8335 module.exports = UploaderStatus;
8337 },{}],74:[function(require,module,exports){
8339 * wp.media.view.UploaderWindow
8341 * An uploader window that allows for dragging and dropping media.
8344 * @augments wp.media.View
8345 * @augments wp.Backbone.View
8346 * @augments Backbone.View
8348 * @param {object} [options] Options hash passed to the view.
8349 * @param {object} [options.uploader] Uploader properties.
8350 * @param {jQuery} [options.uploader.browser]
8351 * @param {jQuery} [options.uploader.dropzone] jQuery collection of the dropzone.
8352 * @param {object} [options.uploader.params]
8357 UploaderWindow = wp.media.View.extend({
8359 className: 'uploader-window',
8360 template: wp.template('uploader-window'),
8362 initialize: function() {
8365 this.$browser = $('<a href="#" class="browser" />').hide().appendTo('body');
8367 uploader = this.options.uploader = _.defaults( this.options.uploader || {}, {
8369 browser: this.$browser,
8373 // Ensure the dropzone is a jQuery collection.
8374 if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) {
8375 uploader.dropzone = $( uploader.dropzone );
8378 this.controller.on( 'activate', this.refresh, this );
8380 this.controller.on( 'detach', function() {
8381 this.$browser.remove();
8385 refresh: function() {
8386 if ( this.uploader ) {
8387 this.uploader.refresh();
8392 var postId = wp.media.view.settings.post.id,
8395 // If the uploader already exists, bail.
8396 if ( this.uploader ) {
8401 this.options.uploader.params.post_id = postId;
8403 this.uploader = new wp.Uploader( this.options.uploader );
8405 dropzone = this.uploader.dropzone;
8406 dropzone.on( 'dropzone:enter', _.bind( this.show, this ) );
8407 dropzone.on( 'dropzone:leave', _.bind( this.hide, this ) );
8409 $( this.uploader ).on( 'uploader:ready', _.bind( this._ready, this ) );
8412 _ready: function() {
8413 this.controller.trigger( 'uploader:ready' );
8417 var $el = this.$el.show();
8419 // Ensure that the animation is triggered by waiting until
8420 // the transparent element is painted into the DOM.
8421 _.defer( function() {
8422 $el.css({ opacity: 1 });
8427 var $el = this.$el.css({ opacity: 0 });
8429 wp.media.transition( $el ).done( function() {
8430 // Transition end events are subject to race conditions.
8431 // Make sure that the value is set as intended.
8432 if ( '0' === $el.css('opacity') ) {
8437 // https://core.trac.wordpress.org/ticket/27341
8438 _.delay( function() {
8439 if ( '0' === $el.css('opacity') && $el.is(':visible') ) {
8446 module.exports = UploaderWindow;
8448 },{}],75:[function(require,module,exports){
8452 * The base view class for media.
8454 * Undelegating events, removing events from the model, and
8455 * removing events from the controller mirror the code for
8456 * `Backbone.View.dispose` in Backbone 0.9.8 development.
8458 * This behavior has since been removed, and should not be used
8459 * outside of the media manager.
8462 * @augments wp.Backbone.View
8463 * @augments Backbone.View
8465 var View = wp.Backbone.View.extend({
8466 constructor: function( options ) {
8467 if ( options && options.controller ) {
8468 this.controller = options.controller;
8470 wp.Backbone.View.apply( this, arguments );
8473 * @todo The internal comment mentions this might have been a stop-gap
8474 * before Backbone 0.9.8 came out. Figure out if Backbone core takes
8475 * care of this in Backbone.View now.
8477 * @returns {wp.media.View} Returns itself to allow chaining
8479 dispose: function() {
8480 // Undelegating events, removing events from the model, and
8481 // removing events from the controller mirror the code for
8482 // `Backbone.View.dispose` in Backbone 0.9.8 development.
8483 this.undelegateEvents();
8485 if ( this.model && this.model.off ) {
8486 this.model.off( null, null, this );
8489 if ( this.collection && this.collection.off ) {
8490 this.collection.off( null, null, this );
8493 // Unbind controller events.
8494 if ( this.controller && this.controller.off ) {
8495 this.controller.off( null, null, this );
8501 * @returns {wp.media.View} Returns itself to allow chaining
8503 remove: function() {
8506 * call 'remove' directly on the parent class
8508 return wp.Backbone.View.prototype.remove.apply( this, arguments );
8512 module.exports = View;