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.
287 // Default doCrop Ajax arguments to allow the Customizer (for example) to inject state.
291 activate: function() {
292 this.frame.on( 'content:create:crop', this.createCropContent, this );
293 this.frame.on( 'close', this.removeCropper, this );
294 this.set('selection', new Backbone.Collection(this.frame._selection.single));
297 deactivate: function() {
298 this.frame.toolbar.mode('browse');
301 createCropContent: function() {
302 this.cropperView = new wp.media.view.Cropper({
304 attachment: this.get('selection').first()
306 this.cropperView.on('image-loaded', this.createCropToolbar, this);
307 this.frame.content.set(this.cropperView);
310 removeCropper: function() {
311 this.imgSelect.cancelSelection();
312 this.imgSelect.setOptions({remove: true});
313 this.imgSelect.update();
314 this.cropperView.remove();
316 createCropToolbar: function() {
317 var canSkipCrop, toolbarOptions;
319 canSkipCrop = this.get('canSkipCrop') || false;
322 controller: this.frame,
326 text: l10n.cropImage,
328 requires: { library: false, selection: false },
331 var controller = this.controller,
334 selection = controller.state().get('selection').first();
335 selection.set({cropDetails: controller.state().imgSelect.getSelection()});
337 this.$el.text(l10n.cropping);
338 this.$el.attr('disabled', true);
340 controller.state().doCrop( selection ).done( function( croppedImage ) {
341 controller.trigger('cropped', croppedImage );
343 }).fail( function() {
344 controller.trigger('content:error:crop');
352 _.extend( toolbarOptions.items, {
355 text: l10n.skipCropping,
357 requires: { library: false, selection: false },
359 var selection = this.controller.state().get('selection').first();
360 this.controller.state().cropperView.remove();
361 this.controller.trigger('skippedcrop', selection);
362 this.controller.close();
368 this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
371 doCrop: function( attachment ) {
372 return wp.ajax.post( 'custom-header-crop', _.extend(
374 this.defaults.doCropArgs,
376 nonce: attachment.get( 'nonces' ).edit,
377 id: attachment.get( 'id' ),
378 cropDetails: attachment.get( 'cropDetails' )
384 module.exports = Cropper;
386 },{}],4:[function(require,module,exports){
388 * wp.media.controller.CustomizeImageCropper
390 * A state for cropping an image.
393 * @augments wp.media.controller.Cropper
394 * @augments wp.media.controller.State
395 * @augments Backbone.Model
397 var Controller = wp.media.controller,
398 CustomizeImageCropper;
400 CustomizeImageCropper = Controller.Cropper.extend({
401 doCrop: function( attachment ) {
402 var cropDetails = attachment.get( 'cropDetails' ),
403 control = this.get( 'control' ),
404 ratio = cropDetails.width / cropDetails.height;
406 // Use crop measurements when flexible in both directions.
407 if ( control.params.flex_width && control.params.flex_height ) {
408 cropDetails.dst_width = cropDetails.width;
409 cropDetails.dst_height = cropDetails.height;
411 // Constrain flexible side based on image ratio and size of the fixed side.
413 cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width;
414 cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height;
417 return wp.ajax.post( 'crop-image', {
419 nonce: attachment.get( 'nonces' ).edit,
420 id: attachment.get( 'id' ),
422 cropDetails: cropDetails
427 module.exports = CustomizeImageCropper;
429 },{}],5:[function(require,module,exports){
431 * wp.media.controller.EditImage
433 * A state for editing (cropping, etc.) an image.
436 * @augments wp.media.controller.State
437 * @augments Backbone.Model
439 * @param {object} attributes The attributes hash passed to the state.
440 * @param {wp.media.model.Attachment} attributes.model The attachment.
441 * @param {string} [attributes.id=edit-image] Unique identifier.
442 * @param {string} [attributes.title=Edit Image] Title for the state. Displays in the media menu and the frame's title region.
443 * @param {string} [attributes.content=edit-image] Initial mode for the content region.
444 * @param {string} [attributes.toolbar=edit-image] Initial mode for the toolbar region.
445 * @param {string} [attributes.menu=false] Initial mode for the menu region.
446 * @param {string} [attributes.url] Unused. @todo Consider removal.
448 var l10n = wp.media.view.l10n,
451 EditImage = wp.media.controller.State.extend({
454 title: l10n.editImage,
456 toolbar: 'edit-image',
457 content: 'edit-image',
464 activate: function() {
465 this.frame.on( 'toolbar:render:edit-image', _.bind( this.toolbar, this ) );
471 deactivate: function() {
472 this.frame.off( 'toolbar:render:edit-image' );
478 toolbar: function() {
479 var frame = this.frame,
480 lastState = frame.lastState(),
481 previous = lastState && lastState.id;
483 frame.toolbar.set( new wp.media.view.Toolbar({
492 frame.setState( previous );
503 module.exports = EditImage;
505 },{}],6:[function(require,module,exports){
507 * wp.media.controller.Embed
509 * A state for embedding media from a URL.
512 * @augments wp.media.controller.State
513 * @augments Backbone.Model
515 * @param {object} attributes The attributes hash passed to the state.
516 * @param {string} [attributes.id=embed] Unique identifier.
517 * @param {string} [attributes.title=Insert From URL] Title for the state. Displays in the media menu and the frame's title region.
518 * @param {string} [attributes.content=embed] Initial mode for the content region.
519 * @param {string} [attributes.menu=default] Initial mode for the menu region.
520 * @param {string} [attributes.toolbar=main-embed] Initial mode for the toolbar region.
521 * @param {string} [attributes.menu=false] Initial mode for the menu region.
522 * @param {int} [attributes.priority=120] The priority for the state link in the media menu.
523 * @param {string} [attributes.type=link] The type of embed. Currently only link is supported.
524 * @param {string} [attributes.url] The embed URL.
525 * @param {object} [attributes.metadata={}] Properties of the embed, which will override attributes.url if set.
527 var l10n = wp.media.view.l10n,
531 Embed = wp.media.controller.State.extend({
534 title: l10n.insertFromUrlTitle,
537 toolbar: 'main-embed',
544 // The amount of time used when debouncing the scan.
547 initialize: function(options) {
548 this.metadata = options.metadata;
549 this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
550 this.props = new Backbone.Model( this.metadata || { url: '' });
551 this.props.on( 'change:url', this.debouncedScan, this );
552 this.props.on( 'change:url', this.refresh, this );
553 this.on( 'scan', this.scanImage, this );
557 * Trigger a scan of the embedded URL's content for metadata required to embed.
559 * @fires wp.media.controller.Embed#scan
569 // Scan is triggered with the list of `attributes` to set on the
570 // state, useful for the 'type' attribute and 'scanners' attribute,
571 // an array of promise objects for asynchronous scan operations.
572 if ( this.props.get('url') ) {
573 this.trigger( 'scan', attributes );
576 if ( attributes.scanners.length ) {
577 scanners = attributes.scanners = $.when.apply( $, attributes.scanners );
578 scanners.always( function() {
579 if ( embed.get('scanners') === scanners ) {
580 embed.set( 'loading', false );
584 attributes.scanners = null;
587 attributes.loading = !! attributes.scanners;
588 this.set( attributes );
591 * Try scanning the embed as an image to discover its dimensions.
593 * @param {Object} attributes
595 scanImage: function( attributes ) {
596 var frame = this.frame,
598 url = this.props.get('url'),
600 deferred = $.Deferred();
602 attributes.scanners.push( deferred.promise() );
604 // Try to load the image and find its width/height.
605 image.onload = function() {
608 if ( state !== frame.state() || url !== state.props.get('url') ) {
622 image.onerror = deferred.reject;
626 refresh: function() {
627 this.frame.toolbar.get().refresh();
631 this.props.clear().set({ url: '' });
639 module.exports = Embed;
641 },{}],7:[function(require,module,exports){
643 * wp.media.controller.FeaturedImage
645 * A state for selecting a featured image for a post.
648 * @augments wp.media.controller.Library
649 * @augments wp.media.controller.State
650 * @augments Backbone.Model
652 * @param {object} [attributes] The attributes hash passed to the state.
653 * @param {string} [attributes.id=featured-image] Unique identifier.
654 * @param {string} [attributes.title=Set Featured Image] Title for the state. Displays in the media menu and the frame's title region.
655 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
656 * If one is not supplied, a collection of all images will be created.
657 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
658 * @param {string} [attributes.content=upload] Initial mode for the content region.
659 * Overridden by persistent user setting if 'contentUserSetting' is true.
660 * @param {string} [attributes.menu=default] Initial mode for the menu region.
661 * @param {string} [attributes.router=browse] Initial mode for the router region.
662 * @param {string} [attributes.toolbar=featured-image] Initial mode for the toolbar region.
663 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
664 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
665 * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
666 * Accepts 'all', 'uploaded', or 'unattached'.
667 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
668 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
669 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
670 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
671 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
673 var Attachment = wp.media.model.Attachment,
674 Library = wp.media.controller.Library,
675 l10n = wp.media.view.l10n,
678 FeaturedImage = Library.extend({
679 defaults: _.defaults({
680 id: 'featured-image',
681 title: l10n.setFeaturedImageTitle,
683 filterable: 'uploaded',
684 toolbar: 'featured-image',
687 }, Library.prototype.defaults ),
692 initialize: function() {
693 var library, comparator;
695 // If we haven't been provided a `library`, create a `Selection`.
696 if ( ! this.get('library') ) {
697 this.set( 'library', wp.media.query({ type: 'image' }) );
700 Library.prototype.initialize.apply( this, arguments );
702 library = this.get('library');
703 comparator = library.comparator;
705 // Overload the library's comparator to push items that are not in
706 // the mirrored query to the front of the aggregate collection.
707 library.comparator = function( a, b ) {
708 var aInQuery = !! this.mirroring.get( a.cid ),
709 bInQuery = !! this.mirroring.get( b.cid );
711 if ( ! aInQuery && bInQuery ) {
713 } else if ( aInQuery && ! bInQuery ) {
716 return comparator.apply( this, arguments );
720 // Add all items in the selection to the library, so any featured
721 // images that are not initially loaded still appear.
722 library.observe( this.get('selection') );
728 activate: function() {
729 this.updateSelection();
730 this.frame.on( 'open', this.updateSelection, this );
732 Library.prototype.activate.apply( this, arguments );
738 deactivate: function() {
739 this.frame.off( 'open', this.updateSelection, this );
741 Library.prototype.deactivate.apply( this, arguments );
747 updateSelection: function() {
748 var selection = this.get('selection'),
749 id = wp.media.view.settings.post.featuredImageId,
752 if ( '' !== id && -1 !== id ) {
753 attachment = Attachment.get( id );
757 selection.reset( attachment ? [ attachment ] : [] );
761 module.exports = FeaturedImage;
763 },{}],8:[function(require,module,exports){
765 * wp.media.controller.GalleryAdd
767 * A state for selecting more images to add to a gallery.
770 * @augments wp.media.controller.Library
771 * @augments wp.media.controller.State
772 * @augments Backbone.Model
774 * @param {object} [attributes] The attributes hash passed to the state.
775 * @param {string} [attributes.id=gallery-library] Unique identifier.
776 * @param {string} [attributes.title=Add to Gallery] Title for the state. Displays in the frame's title region.
777 * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
778 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
779 * If one is not supplied, a collection of all images will be created.
780 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
781 * Accepts 'all', 'uploaded', or 'unattached'.
782 * @param {string} [attributes.menu=gallery] Initial mode for the menu region.
783 * @param {string} [attributes.content=upload] Initial mode for the content region.
784 * Overridden by persistent user setting if 'contentUserSetting' is true.
785 * @param {string} [attributes.router=browse] Initial mode for the router region.
786 * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
787 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
788 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
789 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
790 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
791 * @param {int} [attributes.priority=100] The priority for the state link in the media menu.
792 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
793 * Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
795 var Selection = wp.media.model.Selection,
796 Library = wp.media.controller.Library,
797 l10n = wp.media.view.l10n,
800 GalleryAdd = Library.extend({
801 defaults: _.defaults({
802 id: 'gallery-library',
803 title: l10n.addToGalleryTitle,
805 filterable: 'uploaded',
807 toolbar: 'gallery-add',
810 }, Library.prototype.defaults ),
815 initialize: function() {
816 // If a library wasn't supplied, create a library of images.
817 if ( ! this.get('library') ) {
818 this.set( 'library', wp.media.query({ type: 'image' }) );
821 Library.prototype.initialize.apply( this, arguments );
827 activate: function() {
828 var library = this.get('library'),
829 edit = this.frame.state('gallery-edit').get('library');
831 if ( this.editLibrary && this.editLibrary !== edit ) {
832 library.unobserve( this.editLibrary );
835 // Accepts attachments that exist in the original library and
836 // that do not exist in gallery's library.
837 library.validator = function( attachment ) {
838 return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments );
841 // Reset the library to ensure that all attachments are re-added
842 // to the collection. Do so silently, as calling `observe` will
843 // trigger the `reset` event.
844 library.reset( library.mirroring.models, { silent: true });
845 library.observe( edit );
846 this.editLibrary = edit;
848 Library.prototype.activate.apply( this, arguments );
852 module.exports = GalleryAdd;
854 },{}],9:[function(require,module,exports){
856 * wp.media.controller.GalleryEdit
858 * A state for editing a gallery's images and settings.
861 * @augments wp.media.controller.Library
862 * @augments wp.media.controller.State
863 * @augments Backbone.Model
865 * @param {object} [attributes] The attributes hash passed to the state.
866 * @param {string} [attributes.id=gallery-edit] Unique identifier.
867 * @param {string} [attributes.title=Edit Gallery] Title for the state. Displays in the frame's title region.
868 * @param {wp.media.model.Attachments} [attributes.library] The collection of attachments in the gallery.
869 * If one is not supplied, an empty media.model.Selection collection is created.
870 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
871 * @param {boolean} [attributes.searchable=false] Whether the library is searchable.
872 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
873 * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar.
874 * @param {string|false} [attributes.content=browse] Initial mode for the content region.
875 * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
876 * @param {boolean} [attributes.describe=true] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
877 * @param {boolean} [attributes.displaySettings=true] Whether to show the attachment display settings interface.
878 * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable.
879 * @param {int} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments.
880 * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance.
881 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
882 * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
883 * Defaults to false for this state, because the library passed in *is* the selection.
884 * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
885 * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
887 var Library = wp.media.controller.Library,
888 l10n = wp.media.view.l10n,
891 GalleryEdit = Library.extend({
894 title: l10n.editGalleryTitle,
901 toolbar: 'gallery-edit',
903 displaySettings: true,
905 idealColumnWidth: 170,
914 initialize: function() {
915 // If we haven't been provided a `library`, create a `Selection`.
916 if ( ! this.get('library') ) {
917 this.set( 'library', new wp.media.model.Selection() );
920 // The single `Attachment` view to be used in the `Attachments` view.
921 if ( ! this.get('AttachmentView') ) {
922 this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary );
925 Library.prototype.initialize.apply( this, arguments );
931 activate: function() {
932 var library = this.get('library');
934 // Limit the library to images only.
935 library.props.set( 'type', 'image' );
937 // Watch for uploaded attachments.
938 this.get('library').observe( wp.Uploader.queue );
940 this.frame.on( 'content:render:browse', this.gallerySettings, this );
942 Library.prototype.activate.apply( this, arguments );
948 deactivate: function() {
949 // Stop watching for uploaded attachments.
950 this.get('library').unobserve( wp.Uploader.queue );
952 this.frame.off( 'content:render:browse', this.gallerySettings, this );
954 Library.prototype.deactivate.apply( this, arguments );
962 gallerySettings: function( browser ) {
963 if ( ! this.get('displaySettings') ) {
967 var library = this.get('library');
969 if ( ! library || ! browser ) {
973 library.gallery = library.gallery || new Backbone.Model();
975 browser.sidebar.set({
976 gallery: new wp.media.view.Settings.Gallery({
978 model: library.gallery,
983 browser.toolbar.set( 'reverse', {
984 text: l10n.reverseOrder,
988 library.reset( library.toArray().reverse() );
994 module.exports = GalleryEdit;
996 },{}],10:[function(require,module,exports){
998 * wp.media.controller.ImageDetails
1000 * A state for editing the attachment display settings of an image that's been
1001 * inserted into the editor.
1004 * @augments wp.media.controller.State
1005 * @augments Backbone.Model
1007 * @param {object} [attributes] The attributes hash passed to the state.
1008 * @param {string} [attributes.id=image-details] Unique identifier.
1009 * @param {string} [attributes.title=Image Details] Title for the state. Displays in the frame's title region.
1010 * @param {wp.media.model.Attachment} attributes.image The image's model.
1011 * @param {string|false} [attributes.content=image-details] Initial mode for the content region.
1012 * @param {string|false} [attributes.menu=false] Initial mode for the menu region.
1013 * @param {string|false} [attributes.router=false] Initial mode for the router region.
1014 * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region.
1015 * @param {boolean} [attributes.editing=false] Unused.
1016 * @param {int} [attributes.priority=60] Unused.
1018 * @todo This state inherits some defaults from media.controller.Library.prototype.defaults,
1019 * however this may not do anything.
1021 var State = wp.media.controller.State,
1022 Library = wp.media.controller.Library,
1023 l10n = wp.media.view.l10n,
1026 ImageDetails = State.extend({
1027 defaults: _.defaults({
1028 id: 'image-details',
1029 title: l10n.imageDetailsTitle,
1030 content: 'image-details',
1033 toolbar: 'image-details',
1036 }, Library.prototype.defaults ),
1041 * @param options Attributes
1043 initialize: function( options ) {
1044 this.image = options.image;
1045 State.prototype.initialize.apply( this, arguments );
1051 activate: function() {
1052 this.frame.modal.$el.addClass('image-details');
1056 module.exports = ImageDetails;
1058 },{}],11:[function(require,module,exports){
1060 * wp.media.controller.Library
1062 * A state for choosing an attachment or group of attachments from the media library.
1065 * @augments wp.media.controller.State
1066 * @augments Backbone.Model
1067 * @mixes media.selectionSync
1069 * @param {object} [attributes] The attributes hash passed to the state.
1070 * @param {string} [attributes.id=library] Unique identifier.
1071 * @param {string} [attributes.title=Media library] Title for the state. Displays in the media menu and the frame's title region.
1072 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
1073 * If one is not supplied, a collection of all attachments will be created.
1074 * @param {wp.media.model.Selection|object} [attributes.selection] A collection to contain attachment selections within the state.
1075 * If the 'selection' attribute is a plain JS object,
1076 * a Selection will be created using its values as the selection instance's `props` model.
1077 * Otherwise, it will copy the library's `props` model.
1078 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
1079 * @param {string} [attributes.content=upload] Initial mode for the content region.
1080 * Overridden by persistent user setting if 'contentUserSetting' is true.
1081 * @param {string} [attributes.menu=default] Initial mode for the menu region.
1082 * @param {string} [attributes.router=browse] Initial mode for the router region.
1083 * @param {string} [attributes.toolbar=select] Initial mode for the toolbar region.
1084 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
1085 * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown.
1086 * Accepts 'all', 'uploaded', or 'unattached'.
1087 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
1088 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
1089 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
1090 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
1091 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
1093 var l10n = wp.media.view.l10n,
1094 getUserSetting = window.getUserSetting,
1095 setUserSetting = window.setUserSetting,
1098 Library = wp.media.controller.State.extend({
1101 title: l10n.mediaLibraryTitle,
1112 contentUserSetting: true,
1117 * If a library isn't provided, query all media items.
1118 * If a selection instance isn't provided, create one.
1122 initialize: function() {
1123 var selection = this.get('selection'),
1126 if ( ! this.get('library') ) {
1127 this.set( 'library', wp.media.query() );
1130 if ( ! ( selection instanceof wp.media.model.Selection ) ) {
1134 props = this.get('library').props.toJSON();
1135 props = _.omit( props, 'orderby', 'query' );
1138 this.set( 'selection', new wp.media.model.Selection( null, {
1139 multiple: this.get('multiple'),
1144 this.resetDisplays();
1150 activate: function() {
1151 this.syncSelection();
1153 wp.Uploader.queue.on( 'add', this.uploading, this );
1155 this.get('selection').on( 'add remove reset', this.refreshContent, this );
1157 if ( this.get( 'router' ) && this.get('contentUserSetting') ) {
1158 this.frame.on( 'content:activate', this.saveContentMode, this );
1159 this.set( 'content', getUserSetting( 'libraryContent', this.get('content') ) );
1166 deactivate: function() {
1167 this.recordSelection();
1169 this.frame.off( 'content:activate', this.saveContentMode, this );
1171 // Unbind all event handlers that use this state as the context
1172 // from the selection.
1173 this.get('selection').off( null, null, this );
1175 wp.Uploader.queue.off( null, null, this );
1179 * Reset the library to its initial state.
1184 this.get('selection').reset();
1185 this.resetDisplays();
1186 this.refreshContent();
1190 * Reset the attachment display settings defaults to the site options.
1192 * If site options don't define them, fall back to a persistent user setting.
1196 resetDisplays: function() {
1197 var defaultProps = wp.media.view.settings.defaultProps;
1198 this._displays = [];
1199 this._defaultDisplaySettings = {
1200 align: getUserSetting( 'align', defaultProps.align ) || 'none',
1201 size: getUserSetting( 'imgsize', defaultProps.size ) || 'medium',
1202 link: getUserSetting( 'urlbutton', defaultProps.link ) || 'none'
1207 * Create a model to represent display settings (alignment, etc.) for an attachment.
1211 * @param {wp.media.model.Attachment} attachment
1212 * @returns {Backbone.Model}
1214 display: function( attachment ) {
1215 var displays = this._displays;
1217 if ( ! displays[ attachment.cid ] ) {
1218 displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) );
1220 return displays[ attachment.cid ];
1224 * Given an attachment, create attachment display settings properties.
1228 * @param {wp.media.model.Attachment} attachment
1231 defaultDisplaySettings: function( attachment ) {
1232 var settings = _.clone( this._defaultDisplaySettings );
1234 if ( settings.canEmbed = this.canEmbed( attachment ) ) {
1235 settings.link = 'embed';
1236 } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) {
1237 settings.link = 'file';
1244 * Whether an attachment is image.
1248 * @param {wp.media.model.Attachment} attachment
1249 * @returns {Boolean}
1251 isImageAttachment: function( attachment ) {
1252 // If uploading, we know the filename but not the mime type.
1253 if ( attachment.get('uploading') ) {
1254 return /\.(jpe?g|png|gif)$/i.test( attachment.get('filename') );
1257 return attachment.get('type') === 'image';
1261 * Whether an attachment can be embedded (audio or video).
1265 * @param {wp.media.model.Attachment} attachment
1266 * @returns {Boolean}
1268 canEmbed: function( attachment ) {
1269 // If uploading, we know the filename but not the mime type.
1270 if ( ! attachment.get('uploading') ) {
1271 var type = attachment.get('type');
1272 if ( type !== 'audio' && type !== 'video' ) {
1277 return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
1282 * If the state is active, no items are selected, and the current
1283 * content mode is not an option in the state's router (provided
1284 * the state has a router), reset the content mode to the default.
1288 refreshContent: function() {
1289 var selection = this.get('selection'),
1291 router = frame.router.get(),
1292 mode = frame.content.mode();
1294 if ( this.active && ! selection.length && router && ! router.get( mode ) ) {
1295 this.frame.content.render( this.get('content') );
1300 * Callback handler when an attachment is uploaded.
1302 * Switch to the Media Library if uploaded from the 'Upload Files' tab.
1304 * Adds any uploading attachments to the selection.
1306 * If the state only supports one attachment to be selected and multiple
1307 * attachments are uploaded, the last attachment in the upload queue will
1312 * @param {wp.media.model.Attachment} attachment
1314 uploading: function( attachment ) {
1315 var content = this.frame.content;
1317 if ( 'upload' === content.mode() ) {
1318 this.frame.content.mode('browse');
1321 if ( this.get( 'autoSelect' ) ) {
1322 this.get('selection').add( attachment );
1323 this.frame.trigger( 'library:selection:add' );
1328 * Persist the mode of the content region as a user setting.
1332 saveContentMode: function() {
1333 if ( 'browse' !== this.get('router') ) {
1337 var mode = this.frame.content.mode(),
1338 view = this.frame.router.get();
1340 if ( view && view.get( mode ) ) {
1341 setUserSetting( 'libraryContent', mode );
1346 // Make selectionSync available on any Media Library state.
1347 _.extend( Library.prototype, wp.media.selectionSync );
1349 module.exports = Library;
1351 },{}],12:[function(require,module,exports){
1353 * wp.media.controller.MediaLibrary
1356 * @augments wp.media.controller.Library
1357 * @augments wp.media.controller.State
1358 * @augments Backbone.Model
1360 var Library = wp.media.controller.Library,
1363 MediaLibrary = Library.extend({
1364 defaults: _.defaults({
1365 // Attachments browser defaults. @see media.view.AttachmentsBrowser
1366 filterable: 'uploaded',
1368 displaySettings: false,
1370 syncSelection: false
1371 }, Library.prototype.defaults ),
1378 initialize: function( options ) {
1379 this.media = options.media;
1380 this.type = options.type;
1381 this.set( 'library', wp.media.query({ type: this.type }) );
1383 Library.prototype.initialize.apply( this, arguments );
1389 activate: function() {
1390 // @todo this should use this.frame.
1391 if ( wp.media.frame.lastMime ) {
1392 this.set( 'library', wp.media.query({ type: wp.media.frame.lastMime }) );
1393 delete wp.media.frame.lastMime;
1395 Library.prototype.activate.apply( this, arguments );
1399 module.exports = MediaLibrary;
1401 },{}],13:[function(require,module,exports){
1403 * wp.media.controller.Region
1405 * A region is a persistent application layout area.
1407 * A region assumes one mode at any time, and can be switched to another.
1409 * When mode changes, events are triggered on the region's parent view.
1410 * The parent view will listen to specific events and fill the region with an
1411 * appropriate view depending on mode. For example, a frame listens for the
1412 * 'browse' mode t be activated on the 'content' view and then fills the region
1413 * with an AttachmentsBrowser view.
1417 * @param {object} options Options hash for the region.
1418 * @param {string} options.id Unique identifier for the region.
1419 * @param {Backbone.View} options.view A parent view the region exists within.
1420 * @param {string} options.selector jQuery selector for the region within the parent view.
1422 var Region = function( options ) {
1423 _.extend( this, _.pick( options || {}, 'id', 'view', 'selector' ) );
1426 // Use Backbone's self-propagating `extend` inheritance method.
1427 Region.extend = Backbone.Model.extend;
1429 _.extend( Region.prototype, {
1435 * @param {string} mode
1437 * @fires this.view#{this.id}:activate:{this._mode}
1438 * @fires this.view#{this.id}:activate
1439 * @fires this.view#{this.id}:deactivate:{this._mode}
1440 * @fires this.view#{this.id}:deactivate
1442 * @returns {wp.media.controller.Region} Returns itself to allow chaining.
1444 mode: function( mode ) {
1448 // Bail if we're trying to change to the current mode.
1449 if ( mode === this._mode ) {
1454 * Region mode deactivation event.
1456 * @event this.view#{this.id}:deactivate:{this._mode}
1457 * @event this.view#{this.id}:deactivate
1459 this.trigger('deactivate');
1462 this.render( mode );
1465 * Region mode activation event.
1467 * @event this.view#{this.id}:activate:{this._mode}
1468 * @event this.view#{this.id}:activate
1470 this.trigger('activate');
1478 * @param {string} mode
1480 * @fires this.view#{this.id}:create:{this._mode}
1481 * @fires this.view#{this.id}:create
1482 * @fires this.view#{this.id}:render:{this._mode}
1483 * @fires this.view#{this.id}:render
1485 * @returns {wp.media.controller.Region} Returns itself to allow chaining
1487 render: function( mode ) {
1488 // If the mode isn't active, activate it.
1489 if ( mode && mode !== this._mode ) {
1490 return this.mode( mode );
1493 var set = { view: null },
1497 * Create region view event.
1499 * Region view creation takes place in an event callback on the frame.
1501 * @event this.view#{this.id}:create:{this._mode}
1502 * @event this.view#{this.id}:create
1504 this.trigger( 'create', set );
1508 * Render region view event.
1510 * Region view creation takes place in an event callback on the frame.
1512 * @event this.view#{this.id}:create:{this._mode}
1513 * @event this.view#{this.id}:create
1515 this.trigger( 'render', view );
1523 * Get the region's view.
1527 * @returns {wp.media.View}
1530 return this.view.views.first( this.selector );
1534 * Set the region's view as a subview of the frame.
1538 * @param {Array|Object} views
1539 * @param {Object} [options={}]
1540 * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining
1542 set: function( views, options ) {
1544 options.add = false;
1546 return this.view.views.set( this.selector, views, options );
1550 * Trigger regional view events on the frame.
1554 * @param {string} event
1555 * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining.
1557 trigger: function( event ) {
1560 if ( ! this._mode ) {
1564 args = _.toArray( arguments );
1565 base = this.id + ':' + event;
1567 // Trigger `{this.id}:{event}:{this._mode}` event on the frame.
1568 args[0] = base + ':' + this._mode;
1569 this.view.trigger.apply( this.view, args );
1571 // Trigger `{this.id}:{event}` event on the frame.
1573 this.view.trigger.apply( this.view, args );
1578 module.exports = Region;
1580 },{}],14:[function(require,module,exports){
1582 * wp.media.controller.ReplaceImage
1584 * A state for replacing an image.
1587 * @augments wp.media.controller.Library
1588 * @augments wp.media.controller.State
1589 * @augments Backbone.Model
1591 * @param {object} [attributes] The attributes hash passed to the state.
1592 * @param {string} [attributes.id=replace-image] Unique identifier.
1593 * @param {string} [attributes.title=Replace Image] Title for the state. Displays in the media menu and the frame's title region.
1594 * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
1595 * If one is not supplied, a collection of all images will be created.
1596 * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled.
1597 * @param {string} [attributes.content=upload] Initial mode for the content region.
1598 * Overridden by persistent user setting if 'contentUserSetting' is true.
1599 * @param {string} [attributes.menu=default] Initial mode for the menu region.
1600 * @param {string} [attributes.router=browse] Initial mode for the router region.
1601 * @param {string} [attributes.toolbar=replace] Initial mode for the toolbar region.
1602 * @param {int} [attributes.priority=60] The priority for the state link in the media menu.
1603 * @param {boolean} [attributes.searchable=true] Whether the library is searchable.
1604 * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
1605 * Accepts 'all', 'uploaded', or 'unattached'.
1606 * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
1607 * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
1608 * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery.
1609 * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
1610 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state.
1612 var Library = wp.media.controller.Library,
1613 l10n = wp.media.view.l10n,
1616 ReplaceImage = Library.extend({
1617 defaults: _.defaults({
1618 id: 'replace-image',
1619 title: l10n.replaceImageTitle,
1621 filterable: 'uploaded',
1626 }, Library.prototype.defaults ),
1633 initialize: function( options ) {
1634 var library, comparator;
1636 this.image = options.image;
1637 // If we haven't been provided a `library`, create a `Selection`.
1638 if ( ! this.get('library') ) {
1639 this.set( 'library', wp.media.query({ type: 'image' }) );
1642 Library.prototype.initialize.apply( this, arguments );
1644 library = this.get('library');
1645 comparator = library.comparator;
1647 // Overload the library's comparator to push items that are not in
1648 // the mirrored query to the front of the aggregate collection.
1649 library.comparator = function( a, b ) {
1650 var aInQuery = !! this.mirroring.get( a.cid ),
1651 bInQuery = !! this.mirroring.get( b.cid );
1653 if ( ! aInQuery && bInQuery ) {
1655 } else if ( aInQuery && ! bInQuery ) {
1658 return comparator.apply( this, arguments );
1662 // Add all items in the selection to the library, so any featured
1663 // images that are not initially loaded still appear.
1664 library.observe( this.get('selection') );
1670 activate: function() {
1671 this.updateSelection();
1672 Library.prototype.activate.apply( this, arguments );
1678 updateSelection: function() {
1679 var selection = this.get('selection'),
1680 attachment = this.image.attachment;
1682 selection.reset( attachment ? [ attachment ] : [] );
1686 module.exports = ReplaceImage;
1688 },{}],15:[function(require,module,exports){
1690 * wp.media.controller.SiteIconCropper
1692 * A state for cropping a Site Icon.
1695 * @augments wp.media.controller.Cropper
1696 * @augments wp.media.controller.State
1697 * @augments Backbone.Model
1699 var Controller = wp.media.controller,
1702 SiteIconCropper = Controller.Cropper.extend({
1703 activate: function() {
1704 this.frame.on( 'content:create:crop', this.createCropContent, this );
1705 this.frame.on( 'close', this.removeCropper, this );
1706 this.set('selection', new Backbone.Collection(this.frame._selection.single));
1709 createCropContent: function() {
1710 this.cropperView = new wp.media.view.SiteIconCropper({
1712 attachment: this.get('selection').first()
1714 this.cropperView.on('image-loaded', this.createCropToolbar, this);
1715 this.frame.content.set(this.cropperView);
1719 doCrop: function( attachment ) {
1720 var cropDetails = attachment.get( 'cropDetails' ),
1721 control = this.get( 'control' );
1723 cropDetails.dst_width = control.params.width;
1724 cropDetails.dst_height = control.params.height;
1726 return wp.ajax.post( 'crop-image', {
1727 nonce: attachment.get( 'nonces' ).edit,
1728 id: attachment.get( 'id' ),
1729 context: 'site-icon',
1730 cropDetails: cropDetails
1735 module.exports = SiteIconCropper;
1737 },{}],16:[function(require,module,exports){
1739 * wp.media.controller.StateMachine
1741 * A state machine keeps track of state. It is in one state at a time,
1742 * and can change from one state to another.
1744 * States are stored as models in a Backbone collection.
1749 * @augments Backbone.Model
1751 * @mixes Backbone.Events
1753 * @param {Array} states
1755 var StateMachine = function( states ) {
1756 // @todo This is dead code. The states collection gets created in media.view.Frame._createStates.
1757 this.states = new Backbone.Collection( states );
1760 // Use Backbone's self-propagating `extend` inheritance method.
1761 StateMachine.extend = Backbone.Model.extend;
1763 _.extend( StateMachine.prototype, Backbone.Events, {
1767 * If no `id` is provided, returns the active state.
1769 * Implicitly creates states.
1771 * Ensure that the `states` collection exists so the `StateMachine`
1772 * can be used as a mixin.
1776 * @param {string} id
1777 * @returns {wp.media.controller.State} Returns a State model
1778 * from the StateMachine collection
1780 state: function( id ) {
1781 this.states = this.states || new Backbone.Collection();
1783 // Default to the active state.
1784 id = id || this._state;
1786 if ( id && ! this.states.get( id ) ) {
1787 this.states.add({ id: id });
1789 return this.states.get( id );
1793 * Sets the active state.
1795 * Bail if we're trying to select the current state, if we haven't
1796 * created the `states` collection, or are trying to select a state
1797 * that does not exist.
1801 * @param {string} id
1803 * @fires wp.media.controller.State#deactivate
1804 * @fires wp.media.controller.State#activate
1806 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining
1808 setState: function( id ) {
1809 var previous = this.state();
1811 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) {
1816 previous.trigger('deactivate');
1817 this._lastState = previous.id;
1821 this.state().trigger('activate');
1827 * Returns the previous active state.
1829 * Call the `state()` method with no parameters to retrieve the current
1834 * @returns {wp.media.controller.State} Returns a State model
1835 * from the StateMachine collection
1837 lastState: function() {
1838 if ( this._lastState ) {
1839 return this.state( this._lastState );
1844 // Map all event binding and triggering on a StateMachine to its `states` collection.
1845 _.each([ 'on', 'off', 'trigger' ], function( method ) {
1847 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining.
1849 StateMachine.prototype[ method ] = function() {
1850 // Ensure that the `states` collection exists so the `StateMachine`
1851 // can be used as a mixin.
1852 this.states = this.states || new Backbone.Collection();
1853 // Forward the method to the `states` collection.
1854 this.states[ method ].apply( this.states, arguments );
1859 module.exports = StateMachine;
1861 },{}],17:[function(require,module,exports){
1863 * wp.media.controller.State
1865 * A state is a step in a workflow that when set will trigger the controllers
1866 * for the regions to be updated as specified in the frame.
1868 * A state has an event-driven lifecycle:
1870 * 'ready' triggers when a state is added to a state machine's collection.
1871 * 'activate' triggers when a state is activated by a state machine.
1872 * 'deactivate' triggers when a state is deactivated by a state machine.
1873 * 'reset' is not triggered automatically. It should be invoked by the
1874 * proper controller to reset the state to its default.
1877 * @augments Backbone.Model
1879 var State = Backbone.Model.extend({
1885 constructor: function() {
1886 this.on( 'activate', this._preActivate, this );
1887 this.on( 'activate', this.activate, this );
1888 this.on( 'activate', this._postActivate, this );
1889 this.on( 'deactivate', this._deactivate, this );
1890 this.on( 'deactivate', this.deactivate, this );
1891 this.on( 'reset', this.reset, this );
1892 this.on( 'ready', this._ready, this );
1893 this.on( 'ready', this.ready, this );
1895 * Call parent constructor with passed arguments
1897 Backbone.Model.apply( this, arguments );
1898 this.on( 'change:menu', this._updateMenu, this );
1901 * Ready event callback.
1906 ready: function() {},
1909 * Activate event callback.
1914 activate: function() {},
1917 * Deactivate event callback.
1922 deactivate: function() {},
1925 * Reset event callback.
1930 reset: function() {},
1936 _ready: function() {
1944 _preActivate: function() {
1952 _postActivate: function() {
1953 this.on( 'change:menu', this._menu, this );
1954 this.on( 'change:titleMode', this._title, this );
1955 this.on( 'change:content', this._content, this );
1956 this.on( 'change:toolbar', this._toolbar, this );
1958 this.frame.on( 'title:render:default', this._renderTitle, this );
1971 _deactivate: function() {
1972 this.active = false;
1974 this.frame.off( 'title:render:default', this._renderTitle, this );
1976 this.off( 'change:menu', this._menu, this );
1977 this.off( 'change:titleMode', this._title, this );
1978 this.off( 'change:content', this._content, this );
1979 this.off( 'change:toolbar', this._toolbar, this );
1986 _title: function() {
1987 this.frame.title.render( this.get('titleMode') || 'default' );
1994 _renderTitle: function( view ) {
1995 view.$el.text( this.get('title') || '' );
2002 _router: function() {
2003 var router = this.frame.router,
2004 mode = this.get('router'),
2007 this.frame.$el.toggleClass( 'hide-router', ! mode );
2012 this.frame.router.render( mode );
2014 view = router.get();
2015 if ( view && view.select ) {
2016 view.select( this.frame.content.mode() );
2025 var menu = this.frame.menu,
2026 mode = this.get('menu'),
2029 this.frame.$el.toggleClass( 'hide-menu', ! mode );
2037 if ( view && view.select ) {
2038 view.select( this.id );
2046 _updateMenu: function() {
2047 var previous = this.previous('menu'),
2048 menu = this.get('menu');
2051 this.frame.off( 'menu:render:' + previous, this._renderMenu, this );
2055 this.frame.on( 'menu:render:' + menu, this._renderMenu, this );
2060 * Create a view in the media menu for the state.
2065 * @param {media.view.Menu} view The menu view.
2067 _renderMenu: function( view ) {
2068 var menuItem = this.get('menuItem'),
2069 title = this.get('title'),
2070 priority = this.get('priority');
2072 if ( ! menuItem && title ) {
2073 menuItem = { text: title };
2076 menuItem.priority = priority;
2084 view.set( this.id, menuItem );
2088 _.each(['toolbar','content'], function( region ) {
2092 State.prototype[ '_' + region ] = function() {
2093 var mode = this.get( region );
2095 this.frame[ region ].render( mode );
2100 module.exports = State;
2102 },{}],18:[function(require,module,exports){
2104 * wp.media.selectionSync
2106 * Sync an attachments selection in a state with another state.
2108 * Allows for selecting multiple images in the Insert Media workflow, and then
2109 * switching to the Insert Gallery workflow while preserving the attachments selection.
2113 var selectionSync = {
2117 syncSelection: function() {
2118 var selection = this.get('selection'),
2119 manager = this.frame._selection;
2121 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2125 // If the selection supports multiple items, validate the stored
2126 // attachments based on the new selection's conditions. Record
2127 // the attachments that are not included; we'll maintain a
2128 // reference to those. Other attachments are considered in flux.
2129 if ( selection.multiple ) {
2130 selection.reset( [], { silent: true });
2131 selection.validateAll( manager.attachments );
2132 manager.difference = _.difference( manager.attachments.models, selection.models );
2135 // Sync the selection's single item with the master.
2136 selection.single( manager.single );
2140 * Record the currently active attachments, which is a combination
2141 * of the selection's attachments and the set of selected
2142 * attachments that this specific selection considered invalid.
2143 * Reset the difference and record the single attachment.
2147 recordSelection: function() {
2148 var selection = this.get('selection'),
2149 manager = this.frame._selection;
2151 if ( ! this.get('syncSelection') || ! manager || ! selection ) {
2155 if ( selection.multiple ) {
2156 manager.attachments.reset( selection.toArray().concat( manager.difference ) );
2157 manager.difference = [];
2159 manager.attachments.add( selection.toArray() );
2162 manager.single = selection._single;
2166 module.exports = selectionSync;
2168 },{}],19:[function(require,module,exports){
2169 var media = wp.media,
2173 media.isTouchDevice = ( 'ontouchend' in document );
2175 // Link any localized strings.
2176 l10n = media.view.l10n = window._wpMediaViewsL10n || {};
2178 // Link any settings.
2179 media.view.settings = l10n.settings || {};
2180 delete l10n.settings;
2182 // Copy the `post` setting over to the model settings.
2183 media.model.settings.post = media.view.settings.post;
2185 // Check if the browser supports CSS 3.0 transitions
2186 $.support.transition = (function(){
2187 var style = document.documentElement.style,
2189 WebkitTransition: 'webkitTransitionEnd',
2190 MozTransition: 'transitionend',
2191 OTransition: 'oTransitionEnd otransitionend',
2192 transition: 'transitionend'
2195 transition = _.find( _.keys( transitions ), function( transition ) {
2196 return ! _.isUndefined( style[ transition ] );
2199 return transition && {
2200 end: transitions[ transition ]
2205 * A shared event bus used to provide events into
2206 * the media workflows that 3rd-party devs can use to hook
2209 media.events = _.extend( {}, Backbone.Events );
2212 * Makes it easier to bind events using transitions.
2214 * @param {string} selector
2215 * @param {Number} sensitivity
2216 * @returns {Promise}
2218 media.transition = function( selector, sensitivity ) {
2219 var deferred = $.Deferred();
2221 sensitivity = sensitivity || 2000;
2223 if ( $.support.transition ) {
2224 if ( ! (selector instanceof $) ) {
2225 selector = $( selector );
2228 // Resolve the deferred when the first element finishes animating.
2229 selector.first().one( $.support.transition.end, deferred.resolve );
2231 // Just in case the event doesn't trigger, fire a callback.
2232 _.delay( deferred.resolve, sensitivity );
2234 // Otherwise, execute on the spot.
2239 return deferred.promise();
2242 media.controller.Region = require( './controllers/region.js' );
2243 media.controller.StateMachine = require( './controllers/state-machine.js' );
2244 media.controller.State = require( './controllers/state.js' );
2246 media.selectionSync = require( './utils/selection-sync.js' );
2247 media.controller.Library = require( './controllers/library.js' );
2248 media.controller.ImageDetails = require( './controllers/image-details.js' );
2249 media.controller.GalleryEdit = require( './controllers/gallery-edit.js' );
2250 media.controller.GalleryAdd = require( './controllers/gallery-add.js' );
2251 media.controller.CollectionEdit = require( './controllers/collection-edit.js' );
2252 media.controller.CollectionAdd = require( './controllers/collection-add.js' );
2253 media.controller.FeaturedImage = require( './controllers/featured-image.js' );
2254 media.controller.ReplaceImage = require( './controllers/replace-image.js' );
2255 media.controller.EditImage = require( './controllers/edit-image.js' );
2256 media.controller.MediaLibrary = require( './controllers/media-library.js' );
2257 media.controller.Embed = require( './controllers/embed.js' );
2258 media.controller.Cropper = require( './controllers/cropper.js' );
2259 media.controller.CustomizeImageCropper = require( './controllers/customize-image-cropper.js' );
2260 media.controller.SiteIconCropper = require( './controllers/site-icon-cropper.js' );
2262 media.View = require( './views/view.js' );
2263 media.view.Frame = require( './views/frame.js' );
2264 media.view.MediaFrame = require( './views/media-frame.js' );
2265 media.view.MediaFrame.Select = require( './views/frame/select.js' );
2266 media.view.MediaFrame.Post = require( './views/frame/post.js' );
2267 media.view.MediaFrame.ImageDetails = require( './views/frame/image-details.js' );
2268 media.view.Modal = require( './views/modal.js' );
2269 media.view.FocusManager = require( './views/focus-manager.js' );
2270 media.view.UploaderWindow = require( './views/uploader/window.js' );
2271 media.view.EditorUploader = require( './views/uploader/editor.js' );
2272 media.view.UploaderInline = require( './views/uploader/inline.js' );
2273 media.view.UploaderStatus = require( './views/uploader/status.js' );
2274 media.view.UploaderStatusError = require( './views/uploader/status-error.js' );
2275 media.view.Toolbar = require( './views/toolbar.js' );
2276 media.view.Toolbar.Select = require( './views/toolbar/select.js' );
2277 media.view.Toolbar.Embed = require( './views/toolbar/embed.js' );
2278 media.view.Button = require( './views/button.js' );
2279 media.view.ButtonGroup = require( './views/button-group.js' );
2280 media.view.PriorityList = require( './views/priority-list.js' );
2281 media.view.MenuItem = require( './views/menu-item.js' );
2282 media.view.Menu = require( './views/menu.js' );
2283 media.view.RouterItem = require( './views/router-item.js' );
2284 media.view.Router = require( './views/router.js' );
2285 media.view.Sidebar = require( './views/sidebar.js' );
2286 media.view.Attachment = require( './views/attachment.js' );
2287 media.view.Attachment.Library = require( './views/attachment/library.js' );
2288 media.view.Attachment.EditLibrary = require( './views/attachment/edit-library.js' );
2289 media.view.Attachments = require( './views/attachments.js' );
2290 media.view.Search = require( './views/search.js' );
2291 media.view.AttachmentFilters = require( './views/attachment-filters.js' );
2292 media.view.DateFilter = require( './views/attachment-filters/date.js' );
2293 media.view.AttachmentFilters.Uploaded = require( './views/attachment-filters/uploaded.js' );
2294 media.view.AttachmentFilters.All = require( './views/attachment-filters/all.js' );
2295 media.view.AttachmentsBrowser = require( './views/attachments/browser.js' );
2296 media.view.Selection = require( './views/selection.js' );
2297 media.view.Attachment.Selection = require( './views/attachment/selection.js' );
2298 media.view.Attachments.Selection = require( './views/attachments/selection.js' );
2299 media.view.Attachment.EditSelection = require( './views/attachment/edit-selection.js' );
2300 media.view.Settings = require( './views/settings.js' );
2301 media.view.Settings.AttachmentDisplay = require( './views/settings/attachment-display.js' );
2302 media.view.Settings.Gallery = require( './views/settings/gallery.js' );
2303 media.view.Settings.Playlist = require( './views/settings/playlist.js' );
2304 media.view.Attachment.Details = require( './views/attachment/details.js' );
2305 media.view.AttachmentCompat = require( './views/attachment-compat.js' );
2306 media.view.Iframe = require( './views/iframe.js' );
2307 media.view.Embed = require( './views/embed.js' );
2308 media.view.Label = require( './views/label.js' );
2309 media.view.EmbedUrl = require( './views/embed/url.js' );
2310 media.view.EmbedLink = require( './views/embed/link.js' );
2311 media.view.EmbedImage = require( './views/embed/image.js' );
2312 media.view.ImageDetails = require( './views/image-details.js' );
2313 media.view.Cropper = require( './views/cropper.js' );
2314 media.view.SiteIconCropper = require( './views/site-icon-cropper.js' );
2315 media.view.SiteIconPreview = require( './views/site-icon-preview.js' );
2316 media.view.EditImage = require( './views/edit-image.js' );
2317 media.view.Spinner = require( './views/spinner.js' );
2319 },{"./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){
2321 * wp.media.view.AttachmentCompat
2323 * A view to display fields added via the `attachment_fields_to_edit` filter.
2326 * @augments wp.media.View
2327 * @augments wp.Backbone.View
2328 * @augments Backbone.View
2330 var View = wp.media.View,
2333 AttachmentCompat = View.extend({
2335 className: 'compat-item',
2338 'submit': 'preventDefault',
2339 'change input': 'save',
2340 'change select': 'save',
2341 'change textarea': 'save'
2344 initialize: function() {
2345 this.listenTo( this.model, 'change:compat', this.render );
2348 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2350 dispose: function() {
2351 if ( this.$(':focus').length ) {
2355 * call 'dispose' directly on the parent class
2357 return View.prototype.dispose.apply( this, arguments );
2360 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
2362 render: function() {
2363 var compat = this.model.get('compat');
2364 if ( ! compat || ! compat.item ) {
2368 this.views.detach();
2369 this.$el.html( compat.item );
2370 this.views.render();
2374 * @param {Object} event
2376 preventDefault: function( event ) {
2377 event.preventDefault();
2380 * @param {Object} event
2382 save: function( event ) {
2386 event.preventDefault();
2389 _.each( this.$el.serializeArray(), function( pair ) {
2390 data[ pair.name ] = pair.value;
2393 this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
2394 this.model.saveCompat( data ).always( _.bind( this.postSave, this ) );
2397 postSave: function() {
2398 this.controller.trigger( 'attachment:compat:ready', ['ready'] );
2402 module.exports = AttachmentCompat;
2404 },{}],21:[function(require,module,exports){
2406 * wp.media.view.AttachmentFilters
2409 * @augments wp.media.View
2410 * @augments wp.Backbone.View
2411 * @augments Backbone.View
2416 AttachmentFilters = wp.media.View.extend({
2418 className: 'attachment-filters',
2419 id: 'media-attachment-filters',
2427 initialize: function() {
2428 this.createFilters();
2429 _.extend( this.filters, this.options.filters );
2431 // Build `<option>` elements.
2432 this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
2434 el: $( '<option></option>' ).val( value ).html( filter.text )[0],
2435 priority: filter.priority || 50
2437 }, this ).sortBy('priority').pluck('el').value() );
2439 this.listenTo( this.model, 'change', this.select );
2446 createFilters: function() {
2451 * When the selected filter changes, update the Attachment Query properties to match.
2453 change: function() {
2454 var filter = this.filters[ this.el.value ];
2456 this.model.set( filter.props );
2460 select: function() {
2461 var model = this.model,
2463 props = model.toJSON();
2465 _.find( this.filters, function( filter, id ) {
2466 var equal = _.all( filter.props, function( prop, key ) {
2467 return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] );
2475 this.$el.val( value );
2479 module.exports = AttachmentFilters;
2481 },{}],22:[function(require,module,exports){
2483 * wp.media.view.AttachmentFilters.All
2486 * @augments wp.media.view.AttachmentFilters
2487 * @augments wp.media.View
2488 * @augments wp.Backbone.View
2489 * @augments Backbone.View
2491 var l10n = wp.media.view.l10n,
2494 All = wp.media.view.AttachmentFilters.extend({
2495 createFilters: function() {
2498 _.each( wp.media.view.settings.mimeTypes || {}, function( text, key ) {
2512 text: l10n.allMediaItems,
2523 if ( wp.media.view.settings.post.id ) {
2524 filters.uploaded = {
2525 text: l10n.uploadedToThisPost,
2529 uploadedTo: wp.media.view.settings.post.id,
2530 orderby: 'menuOrder',
2537 filters.unattached = {
2538 text: l10n.unattached,
2543 orderby: 'menuOrder',
2549 if ( wp.media.view.settings.mediaTrash &&
2550 this.controller.isModeActive( 'grid' ) ) {
2565 this.filters = filters;
2569 module.exports = All;
2571 },{}],23:[function(require,module,exports){
2573 * A filter dropdown for month/dates.
2576 * @augments wp.media.view.AttachmentFilters
2577 * @augments wp.media.View
2578 * @augments wp.Backbone.View
2579 * @augments Backbone.View
2581 var l10n = wp.media.view.l10n,
2584 DateFilter = wp.media.view.AttachmentFilters.extend({
2585 id: 'media-attachment-date-filters',
2587 createFilters: function() {
2589 _.each( wp.media.view.settings.months || {}, function( value, index ) {
2590 filters[ index ] = {
2594 monthnum: value.month
2599 text: l10n.allDates,
2606 this.filters = filters;
2610 module.exports = DateFilter;
2612 },{}],24:[function(require,module,exports){
2614 * wp.media.view.AttachmentFilters.Uploaded
2617 * @augments wp.media.view.AttachmentFilters
2618 * @augments wp.media.View
2619 * @augments wp.Backbone.View
2620 * @augments Backbone.View
2622 var l10n = wp.media.view.l10n,
2625 Uploaded = wp.media.view.AttachmentFilters.extend({
2626 createFilters: function() {
2627 var type = this.model.get('type'),
2628 types = wp.media.view.settings.mimeTypes,
2631 if ( types && type ) {
2632 text = types[ type ];
2637 text: text || l10n.allMediaItems,
2647 text: l10n.uploadedToThisPost,
2649 uploadedTo: wp.media.view.settings.post.id,
2650 orderby: 'menuOrder',
2657 text: l10n.unattached,
2660 orderby: 'menuOrder',
2669 module.exports = Uploaded;
2671 },{}],25:[function(require,module,exports){
2673 * wp.media.view.Attachment
2676 * @augments wp.media.View
2677 * @augments wp.Backbone.View
2678 * @augments Backbone.View
2680 var View = wp.media.View,
2684 Attachment = View.extend({
2686 className: 'attachment',
2687 template: wp.template('attachment'),
2689 attributes: function() {
2693 'aria-label': this.model.get( 'title' ),
2694 'aria-checked': false,
2695 'data-id': this.model.get( 'id' )
2700 'click .js--select-attachment': 'toggleSelectionHandler',
2701 'change [data-setting]': 'updateSetting',
2702 'change [data-setting] input': 'updateSetting',
2703 'change [data-setting] select': 'updateSetting',
2704 'change [data-setting] textarea': 'updateSetting',
2705 'click .attachment-close': 'removeFromLibrary',
2706 'click .check': 'checkClickHandler',
2707 'keydown': 'toggleSelectionHandler'
2712 initialize: function() {
2713 var selection = this.options.selection,
2714 options = _.defaults( this.options, {
2715 rerenderOnModelChange: true
2718 if ( options.rerenderOnModelChange ) {
2719 this.listenTo( this.model, 'change', this.render );
2721 this.listenTo( this.model, 'change:percent', this.progress );
2723 this.listenTo( this.model, 'change:title', this._syncTitle );
2724 this.listenTo( this.model, 'change:caption', this._syncCaption );
2725 this.listenTo( this.model, 'change:artist', this._syncArtist );
2726 this.listenTo( this.model, 'change:album', this._syncAlbum );
2728 // Update the selection.
2729 this.listenTo( this.model, 'add', this.select );
2730 this.listenTo( this.model, 'remove', this.deselect );
2732 selection.on( 'reset', this.updateSelect, this );
2733 // Update the model's details view.
2734 this.listenTo( this.model, 'selection:single selection:unsingle', this.details );
2735 this.details( this.model, this.controller.state().get('selection') );
2738 this.listenTo( this.controller, 'attachment:compat:waiting attachment:compat:ready', this.updateSave );
2741 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2743 dispose: function() {
2744 var selection = this.options.selection;
2746 // Make sure all settings are saved before removing the view.
2750 selection.off( null, null, this );
2753 * call 'dispose' directly on the parent class
2755 View.prototype.dispose.apply( this, arguments );
2759 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
2761 render: function() {
2762 var options = _.defaults( this.model.toJSON(), {
2763 orientation: 'landscape',
2779 options.buttons = this.buttons;
2780 options.describe = this.controller.state().get('describe');
2782 if ( 'image' === options.type ) {
2783 options.size = this.imageSize();
2787 if ( options.nonces ) {
2788 options.can.remove = !! options.nonces['delete'];
2789 options.can.save = !! options.nonces.update;
2792 if ( this.controller.state().get('allowLocalEdits') ) {
2793 options.allowLocalEdits = true;
2796 if ( options.uploading && ! options.percent ) {
2797 options.percent = 0;
2800 this.views.detach();
2801 this.$el.html( this.template( options ) );
2803 this.$el.toggleClass( 'uploading', options.uploading );
2805 if ( options.uploading ) {
2806 this.$bar = this.$('.media-progress-bar div');
2811 // Check if the model is selected.
2812 this.updateSelect();
2814 // Update the save status.
2817 this.views.render();
2822 progress: function() {
2823 if ( this.$bar && this.$bar.length ) {
2824 this.$bar.width( this.model.get('percent') + '%' );
2829 * @param {Object} event
2831 toggleSelectionHandler: function( event ) {
2834 // Don't do anything inside inputs and on the attachment check and remove buttons.
2835 if ( 'INPUT' === event.target.nodeName || 'BUTTON' === event.target.nodeName ) {
2839 // Catch arrow events
2840 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
2841 this.controller.trigger( 'attachment:keydown:arrow', event );
2845 // Catch enter and space events
2846 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
2850 event.preventDefault();
2852 // In the grid view, bubble up an edit:attachment event to the controller.
2853 if ( this.controller.isModeActive( 'grid' ) ) {
2854 if ( this.controller.isModeActive( 'edit' ) ) {
2855 // Pass the current target to restore focus when closing
2856 this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
2860 if ( this.controller.isModeActive( 'select' ) ) {
2865 if ( event.shiftKey ) {
2867 } else if ( event.ctrlKey || event.metaKey ) {
2871 this.toggleSelection({
2875 this.controller.trigger( 'selection:toggle' );
2878 * @param {Object} options
2880 toggleSelection: function( options ) {
2881 var collection = this.collection,
2882 selection = this.options.selection,
2884 method = options && options.method,
2885 single, models, singleIndex, modelIndex;
2887 if ( ! selection ) {
2891 single = selection.single();
2892 method = _.isUndefined( method ) ? selection.multiple : method;
2894 // If the `method` is set to `between`, select all models that
2895 // exist between the current and the selected model.
2896 if ( 'between' === method && single && selection.multiple ) {
2897 // If the models are the same, short-circuit.
2898 if ( single === model ) {
2902 singleIndex = collection.indexOf( single );
2903 modelIndex = collection.indexOf( this.model );
2905 if ( singleIndex < modelIndex ) {
2906 models = collection.models.slice( singleIndex, modelIndex + 1 );
2908 models = collection.models.slice( modelIndex, singleIndex + 1 );
2911 selection.add( models );
2912 selection.single( model );
2915 // If the `method` is set to `toggle`, just flip the selection
2916 // status, regardless of whether the model is the single model.
2917 } else if ( 'toggle' === method ) {
2918 selection[ this.selected() ? 'remove' : 'add' ]( model );
2919 selection.single( model );
2921 } else if ( 'add' === method ) {
2922 selection.add( model );
2923 selection.single( model );
2927 // Fixes bug that loses focus when selecting a featured image
2932 if ( method !== 'add' ) {
2936 if ( this.selected() ) {
2937 // If the model is the single model, remove it.
2938 // If it is not the same as the single model,
2939 // it now becomes the single model.
2940 selection[ single === model ? 'remove' : 'single' ]( model );
2942 // If the model is not selected, run the `method` on the
2943 // selection. By default, we `reset` the selection, but the
2944 // `method` can be set to `add` the model to the selection.
2945 selection[ method ]( model );
2946 selection.single( model );
2950 updateSelect: function() {
2951 this[ this.selected() ? 'select' : 'deselect' ]();
2954 * @returns {unresolved|Boolean}
2956 selected: function() {
2957 var selection = this.options.selection;
2959 return !! selection.get( this.model.cid );
2963 * @param {Backbone.Model} model
2964 * @param {Backbone.Collection} collection
2966 select: function( model, collection ) {
2967 var selection = this.options.selection,
2968 controller = this.controller;
2970 // Check if a selection exists and if it's the collection provided.
2971 // If they're not the same collection, bail; we're in another
2972 // selection's event loop.
2973 if ( ! selection || ( collection && collection !== selection ) ) {
2977 // Bail if the model is already selected.
2978 if ( this.$el.hasClass( 'selected' ) ) {
2982 // Add 'selected' class to model, set aria-checked to true.
2983 this.$el.addClass( 'selected' ).attr( 'aria-checked', true );
2984 // Make the checkbox tabable, except in media grid (bulk select mode).
2985 if ( ! ( controller.isModeActive( 'grid' ) && controller.isModeActive( 'select' ) ) ) {
2986 this.$( '.check' ).attr( 'tabindex', '0' );
2990 * @param {Backbone.Model} model
2991 * @param {Backbone.Collection} collection
2993 deselect: function( model, collection ) {
2994 var selection = this.options.selection;
2996 // Check if a selection exists and if it's the collection provided.
2997 // If they're not the same collection, bail; we're in another
2998 // selection's event loop.
2999 if ( ! selection || ( collection && collection !== selection ) ) {
3002 this.$el.removeClass( 'selected' ).attr( 'aria-checked', false )
3003 .find( '.check' ).attr( 'tabindex', '-1' );
3006 * @param {Backbone.Model} model
3007 * @param {Backbone.Collection} collection
3009 details: function( model, collection ) {
3010 var selection = this.options.selection,
3013 if ( selection !== collection ) {
3017 details = selection.single();
3018 this.$el.toggleClass( 'details', details === this.model );
3021 * @param {string} size
3024 imageSize: function( size ) {
3025 var sizes = this.model.get('sizes'), matched = false;
3027 size = size || 'medium';
3029 // Use the provided image size if possible.
3031 if ( sizes[ size ] ) {
3032 matched = sizes[ size ];
3033 } else if ( sizes.large ) {
3034 matched = sizes.large;
3035 } else if ( sizes.thumbnail ) {
3036 matched = sizes.thumbnail;
3037 } else if ( sizes.full ) {
3038 matched = sizes.full;
3042 return _.clone( matched );
3047 url: this.model.get('url'),
3048 width: this.model.get('width'),
3049 height: this.model.get('height'),
3050 orientation: this.model.get('orientation')
3054 * @param {Object} event
3056 updateSetting: function( event ) {
3057 var $setting = $( event.target ).closest('[data-setting]'),
3060 if ( ! $setting.length ) {
3064 setting = $setting.data('setting');
3065 value = event.target.value;
3067 if ( this.model.get( setting ) !== value ) {
3068 this.save( setting, value );
3073 * Pass all the arguments to the model's save method.
3075 * Records the aggregate status of all save requests and updates the
3076 * view's classes accordingly.
3080 save = this._save = this._save || { status: 'ready' },
3081 request = this.model.save.apply( this.model, arguments ),
3082 requests = save.requests ? $.when( request, save.requests ) : request;
3084 // If we're waiting to remove 'Saved.', stop.
3085 if ( save.savedTimer ) {
3086 clearTimeout( save.savedTimer );
3089 this.updateSave('waiting');
3090 save.requests = requests;
3091 requests.always( function() {
3092 // If we've performed another request since this one, bail.
3093 if ( save.requests !== requests ) {
3097 view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' );
3098 save.savedTimer = setTimeout( function() {
3099 view.updateSave('ready');
3100 delete save.savedTimer;
3105 * @param {string} status
3106 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3108 updateSave: function( status ) {
3109 var save = this._save = this._save || { status: 'ready' };
3111 if ( status && status !== save.status ) {
3112 this.$el.removeClass( 'save-' + save.status );
3113 save.status = status;
3116 this.$el.addClass( 'save-' + save.status );
3120 updateAll: function() {
3121 var $settings = this.$('[data-setting]'),
3125 changed = _.chain( $settings ).map( function( el ) {
3126 var $input = $('input, textarea, select, [value]', el ),
3129 if ( ! $input.length ) {
3133 setting = $(el).data('setting');
3134 value = $input.val();
3136 // Record the value if it changed.
3137 if ( model.get( setting ) !== value ) {
3138 return [ setting, value ];
3140 }).compact().object().value();
3142 if ( ! _.isEmpty( changed ) ) {
3143 model.save( changed );
3147 * @param {Object} event
3149 removeFromLibrary: function( event ) {
3150 // Catch enter and space events
3151 if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
3155 // Stop propagation so the model isn't selected.
3156 event.stopPropagation();
3158 this.collection.remove( this.model );
3162 * Add the model if it isn't in the selection, if it is in the selection,
3165 * @param {[type]} event [description]
3166 * @return {[type]} [description]
3168 checkClickHandler: function ( event ) {
3169 var selection = this.options.selection;
3170 if ( ! selection ) {
3173 event.stopPropagation();
3174 if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
3175 selection.remove( this.model );
3176 // Move focus back to the attachment tile (from the check).
3179 selection.add( this.model );
3184 // Ensure settings remain in sync between attachment views.
3186 caption: '_syncCaption',
3187 title: '_syncTitle',
3188 artist: '_syncArtist',
3190 }, function( method, setting ) {
3192 * @param {Backbone.Model} model
3193 * @param {string} value
3194 * @returns {wp.media.view.Attachment} Returns itself to allow chaining
3196 Attachment.prototype[ method ] = function( model, value ) {
3197 var $setting = this.$('[data-setting="' + setting + '"]');
3199 if ( ! $setting.length ) {
3203 // If the updated value is in sync with the value in the DOM, there
3204 // is no need to re-render. If we're currently editing the value,
3205 // it will automatically be in sync, suppressing the re-render for
3206 // the view we're editing, while updating any others.
3207 if ( value === $setting.find('input, textarea, select, [value]').val() ) {
3211 return this.render();
3215 module.exports = Attachment;
3217 },{}],26:[function(require,module,exports){
3219 * wp.media.view.Attachment.Details
3222 * @augments wp.media.view.Attachment
3223 * @augments wp.media.View
3224 * @augments wp.Backbone.View
3225 * @augments Backbone.View
3227 var Attachment = wp.media.view.Attachment,
3228 l10n = wp.media.view.l10n,
3231 Details = Attachment.extend({
3233 className: 'attachment-details',
3234 template: wp.template('attachment-details'),
3236 attributes: function() {
3239 'data-id': this.model.get( 'id' )
3244 'change [data-setting]': 'updateSetting',
3245 'change [data-setting] input': 'updateSetting',
3246 'change [data-setting] select': 'updateSetting',
3247 'change [data-setting] textarea': 'updateSetting',
3248 'click .delete-attachment': 'deleteAttachment',
3249 'click .trash-attachment': 'trashAttachment',
3250 'click .untrash-attachment': 'untrashAttachment',
3251 'click .edit-attachment': 'editAttachment',
3252 'keydown': 'toggleSelectionHandler'
3255 initialize: function() {
3256 this.options = _.defaults( this.options, {
3257 rerenderOnModelChange: false
3260 this.on( 'ready', this.initialFocus );
3261 // Call 'initialize' directly on the parent class.
3262 Attachment.prototype.initialize.apply( this, arguments );
3265 initialFocus: function() {
3266 if ( ! wp.media.isTouchDevice ) {
3268 Previously focused the first ':input' (the readonly URL text field).
3269 Since the first ':input' is now a button (delete/trash): when pressing
3270 spacebar on an attachment, Firefox fires deleteAttachment/trashAttachment
3271 as soon as focus is moved. Explicitly target the first text field for now.
3272 @todo change initial focus logic, also for accessibility.
3274 this.$( 'input[type="text"]' ).eq( 0 ).focus();
3278 * @param {Object} event
3280 deleteAttachment: function( event ) {
3281 event.preventDefault();
3283 if ( window.confirm( l10n.warnDelete ) ) {
3284 this.model.destroy();
3285 // Keep focus inside media modal
3286 // after image is deleted
3287 this.controller.modal.focusManager.focus();
3291 * @param {Object} event
3293 trashAttachment: function( event ) {
3294 var library = this.controller.library;
3295 event.preventDefault();
3297 if ( wp.media.view.settings.mediaTrash &&
3298 'edit-metadata' === this.controller.content.mode() ) {
3300 this.model.set( 'status', 'trash' );
3301 this.model.save().done( function() {
3302 library._requery( true );
3305 this.model.destroy();
3309 * @param {Object} event
3311 untrashAttachment: function( event ) {
3312 var library = this.controller.library;
3313 event.preventDefault();
3315 this.model.set( 'status', 'inherit' );
3316 this.model.save().done( function() {
3317 library._requery( true );
3321 * @param {Object} event
3323 editAttachment: function( event ) {
3324 var editState = this.controller.states.get( 'edit-image' );
3325 if ( window.imageEdit && editState ) {
3326 event.preventDefault();
3328 editState.set( 'image', this.model );
3329 this.controller.setState( 'edit-image' );
3331 this.$el.addClass('needs-refresh');
3335 * When reverse tabbing(shift+tab) out of the right details panel, deliver
3336 * the focus to the item in the list that was being edited.
3338 * @param {Object} event
3340 toggleSelectionHandler: function( event ) {
3341 if ( 'keydown' === event.type && 9 === event.keyCode && event.shiftKey && event.target === this.$( ':tabbable' ).get( 0 ) ) {
3342 this.controller.trigger( 'attachment:details:shift-tab', event );
3346 if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
3347 this.controller.trigger( 'attachment:keydown:arrow', event );
3353 module.exports = Details;
3355 },{}],27:[function(require,module,exports){
3357 * wp.media.view.Attachment.EditLibrary
3360 * @augments wp.media.view.Attachment
3361 * @augments wp.media.View
3362 * @augments wp.Backbone.View
3363 * @augments Backbone.View
3365 var EditLibrary = wp.media.view.Attachment.extend({
3371 module.exports = EditLibrary;
3373 },{}],28:[function(require,module,exports){
3375 * wp.media.view.Attachments.EditSelection
3378 * @augments wp.media.view.Attachment.Selection
3379 * @augments wp.media.view.Attachment
3380 * @augments wp.media.View
3381 * @augments wp.Backbone.View
3382 * @augments Backbone.View
3384 var EditSelection = wp.media.view.Attachment.Selection.extend({
3390 module.exports = EditSelection;
3392 },{}],29:[function(require,module,exports){
3394 * wp.media.view.Attachment.Library
3397 * @augments wp.media.view.Attachment
3398 * @augments wp.media.View
3399 * @augments wp.Backbone.View
3400 * @augments Backbone.View
3402 var Library = wp.media.view.Attachment.extend({
3408 module.exports = Library;
3410 },{}],30:[function(require,module,exports){
3412 * wp.media.view.Attachment.Selection
3415 * @augments wp.media.view.Attachment
3416 * @augments wp.media.View
3417 * @augments wp.Backbone.View
3418 * @augments Backbone.View
3420 var Selection = wp.media.view.Attachment.extend({
3421 className: 'attachment selection',
3423 // On click, just select the model, instead of removing the model from
3425 toggleSelection: function() {
3426 this.options.selection.single( this.model );
3430 module.exports = Selection;
3432 },{}],31:[function(require,module,exports){
3434 * wp.media.view.Attachments
3437 * @augments wp.media.View
3438 * @augments wp.Backbone.View
3439 * @augments Backbone.View
3441 var View = wp.media.View,
3445 Attachments = View.extend({
3447 className: 'attachments',
3453 initialize: function() {
3454 this.el.id = _.uniqueId('__attachments-view-');
3456 _.defaults( this.options, {
3457 refreshSensitivity: wp.media.isTouchDevice ? 300 : 200,
3458 refreshThreshold: 3,
3459 AttachmentView: wp.media.view.Attachment,
3462 idealColumnWidth: $( window ).width() < 640 ? 135 : 150
3465 this._viewsByCid = {};
3466 this.$window = $( window );
3467 this.resizeEvent = 'resize.media-modal-columns';
3469 this.collection.on( 'add', function( attachment ) {
3470 this.views.add( this.createAttachmentView( attachment ), {
3471 at: this.collection.indexOf( attachment )
3475 this.collection.on( 'remove', function( attachment ) {
3476 var view = this._viewsByCid[ attachment.cid ];
3477 delete this._viewsByCid[ attachment.cid ];
3484 this.collection.on( 'reset', this.render, this );
3486 this.listenTo( this.controller, 'library:selection:add', this.attachmentFocus );
3488 // Throttle the scroll handler and bind this.
3489 this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
3491 this.options.scrollElement = this.options.scrollElement || this.el;
3492 $( this.options.scrollElement ).on( 'scroll', this.scroll );
3494 this.initSortable();
3496 _.bindAll( this, 'setColumns' );
3498 if ( this.options.resize ) {
3499 this.on( 'ready', this.bindEvents );
3500 this.controller.on( 'open', this.setColumns );
3502 // Call this.setColumns() after this view has been rendered in the DOM so
3503 // attachments get proper width applied.
3504 _.defer( this.setColumns, this );
3508 bindEvents: function() {
3509 this.$window.off( this.resizeEvent ).on( this.resizeEvent, _.debounce( this.setColumns, 50 ) );
3512 attachmentFocus: function() {
3513 this.$( 'li:first' ).focus();
3516 restoreFocus: function() {
3517 this.$( 'li.selected:first' ).focus();
3520 arrowEvent: function( event ) {
3521 var attachments = this.$el.children( 'li' ),
3522 perRow = this.columns,
3523 index = attachments.filter( ':focus' ).index(),
3524 row = ( index + 1 ) <= perRow ? 1 : Math.ceil( ( index + 1 ) / perRow );
3526 if ( index === -1 ) {
3531 if ( 37 === event.keyCode ) {
3532 if ( 0 === index ) {
3535 attachments.eq( index - 1 ).focus();
3539 if ( 38 === event.keyCode ) {
3543 attachments.eq( index - perRow ).focus();
3547 if ( 39 === event.keyCode ) {
3548 if ( attachments.length === index ) {
3551 attachments.eq( index + 1 ).focus();
3555 if ( 40 === event.keyCode ) {
3556 if ( Math.ceil( attachments.length / perRow ) === row ) {
3559 attachments.eq( index + perRow ).focus();
3563 dispose: function() {
3564 this.collection.props.off( null, null, this );
3565 if ( this.options.resize ) {
3566 this.$window.off( this.resizeEvent );
3570 * call 'dispose' directly on the parent class
3572 View.prototype.dispose.apply( this, arguments );
3575 setColumns: function() {
3576 var prev = this.columns,
3577 width = this.$el.width();
3580 this.columns = Math.min( Math.round( width / this.options.idealColumnWidth ), 12 ) || 1;
3582 if ( ! prev || prev !== this.columns ) {
3583 this.$el.closest( '.media-frame-content' ).attr( 'data-columns', this.columns );
3588 initSortable: function() {
3589 var collection = this.collection;
3591 if ( ! this.options.sortable || ! $.fn.sortable ) {
3595 this.$el.sortable( _.extend({
3596 // If the `collection` has a `comparator`, disable sorting.
3597 disabled: !! collection.comparator,
3599 // Change the position of the attachment as soon as the
3600 // mouse pointer overlaps a thumbnail.
3601 tolerance: 'pointer',
3603 // Record the initial `index` of the dragged model.
3604 start: function( event, ui ) {
3605 ui.item.data('sortableIndexStart', ui.item.index());
3608 // Update the model's index in the collection.
3609 // Do so silently, as the view is already accurate.
3610 update: function( event, ui ) {
3611 var model = collection.at( ui.item.data('sortableIndexStart') ),
3612 comparator = collection.comparator;
3614 // Temporarily disable the comparator to prevent `add`
3616 delete collection.comparator;
3618 // Silently shift the model to its new index.
3619 collection.remove( model, {
3622 collection.add( model, {
3627 // Restore the comparator.
3628 collection.comparator = comparator;
3630 // Fire the `reset` event to ensure other collections sync.
3631 collection.trigger( 'reset', collection );
3633 // If the collection is sorted by menu order,
3634 // update the menu order.
3635 collection.saveMenuOrder();
3637 }, this.options.sortable ) );
3639 // If the `orderby` property is changed on the `collection`,
3640 // check to see if we have a `comparator`. If so, disable sorting.
3641 collection.props.on( 'change:orderby', function() {
3642 this.$el.sortable( 'option', 'disabled', !! collection.comparator );
3645 this.collection.props.on( 'change:orderby', this.refreshSortable, this );
3646 this.refreshSortable();
3649 refreshSortable: function() {
3650 if ( ! this.options.sortable || ! $.fn.sortable ) {
3654 // If the `collection` has a `comparator`, disable sorting.
3655 var collection = this.collection,
3656 orderby = collection.props.get('orderby'),
3657 enabled = 'menuOrder' === orderby || ! collection.comparator;
3659 this.$el.sortable( 'option', 'disabled', ! enabled );
3663 * @param {wp.media.model.Attachment} attachment
3664 * @returns {wp.media.View}
3666 createAttachmentView: function( attachment ) {
3667 var view = new this.options.AttachmentView({
3668 controller: this.controller,
3670 collection: this.collection,
3671 selection: this.options.selection
3674 return this._viewsByCid[ attachment.cid ] = view;
3677 prepare: function() {
3678 // Create all of the Attachment views, and replace
3679 // the list in a single DOM operation.
3680 if ( this.collection.length ) {
3681 this.views.set( this.collection.map( this.createAttachmentView, this ) );
3683 // If there are no elements, clear the views and load some.
3686 this.collection.more().done( this.scroll );
3691 // Trigger the scroll event to check if we're within the
3692 // threshold to query for additional attachments.
3696 scroll: function() {
3698 el = this.options.scrollElement,
3699 scrollTop = el.scrollTop,
3702 // The scroll event occurs on the document, but the element
3703 // that should be checked is the document body.
3704 if ( el === document ) {
3706 scrollTop = $(document).scrollTop();
3709 if ( ! $(el).is(':visible') || ! this.collection.hasMore() ) {
3713 toolbar = this.views.parent.toolbar;
3715 // Show the spinner only if we are close to the bottom.
3716 if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 ) {
3717 toolbar.get('spinner').show();
3720 if ( el.scrollHeight < scrollTop + ( el.clientHeight * this.options.refreshThreshold ) ) {
3721 this.collection.more().done(function() {
3723 toolbar.get('spinner').hide();
3729 module.exports = Attachments;
3731 },{}],32:[function(require,module,exports){
3733 * wp.media.view.AttachmentsBrowser
3736 * @augments wp.media.View
3737 * @augments wp.Backbone.View
3738 * @augments Backbone.View
3740 * @param {object} [options] The options hash passed to the view.
3741 * @param {boolean|string} [options.filters=false] Which filters to show in the browser's toolbar.
3742 * Accepts 'uploaded' and 'all'.
3743 * @param {boolean} [options.search=true] Whether to show the search interface in the
3744 * browser's toolbar.
3745 * @param {boolean} [options.date=true] Whether to show the date filter in the
3746 * browser's toolbar.
3747 * @param {boolean} [options.display=false] Whether to show the attachments display settings
3748 * view in the sidebar.
3749 * @param {boolean|string} [options.sidebar=true] Whether to create a sidebar for the browser.
3750 * Accepts true, false, and 'errors'.
3752 var View = wp.media.View,
3753 mediaTrash = wp.media.view.settings.mediaTrash,
3754 l10n = wp.media.view.l10n,
3758 AttachmentsBrowser = View.extend({
3760 className: 'attachments-browser',
3762 initialize: function() {
3763 _.defaults( this.options, {
3769 AttachmentView: wp.media.view.Attachment.Library
3772 this.controller.on( 'toggle:upload:attachment', this.toggleUploader, this );
3773 this.controller.on( 'edit:selection', this.editSelection );
3774 this.createToolbar();
3775 this.createUploader();
3776 this.createAttachments();
3777 if ( this.options.sidebar ) {
3778 this.createSidebar();
3780 this.updateContent();
3782 if ( ! this.options.sidebar || 'errors' === this.options.sidebar ) {
3783 this.$el.addClass( 'hide-sidebar' );
3785 if ( 'errors' === this.options.sidebar ) {
3786 this.$el.addClass( 'sidebar-for-errors' );
3790 this.collection.on( 'add remove reset', this.updateContent, this );
3793 editSelection: function( modal ) {
3794 modal.$( '.media-button-backToLibrary' ).focus();
3798 * @returns {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining
3800 dispose: function() {
3801 this.options.selection.off( null, null, this );
3802 View.prototype.dispose.apply( this, arguments );
3806 createToolbar: function() {
3807 var LibraryViewSwitcher, Filters, toolbarOptions;
3810 controller: this.controller
3813 if ( this.controller.isModeActive( 'grid' ) ) {
3814 toolbarOptions.className = 'media-toolbar wp-filter';
3818 * @member {wp.media.view.Toolbar}
3820 this.toolbar = new wp.media.view.Toolbar( toolbarOptions );
3822 this.views.add( this.toolbar );
3824 this.toolbar.set( 'spinner', new wp.media.view.Spinner({
3828 if ( -1 !== $.inArray( this.options.filters, [ 'uploaded', 'all' ] ) ) {
3829 // "Filters" will return a <select>, need to render
3830 // screen reader text before
3831 this.toolbar.set( 'filtersLabel', new wp.media.view.Label({
3832 value: l10n.filterByType,
3834 'for': 'media-attachment-filters'
3839 if ( 'uploaded' === this.options.filters ) {
3840 this.toolbar.set( 'filters', new wp.media.view.AttachmentFilters.Uploaded({
3841 controller: this.controller,
3842 model: this.collection.props,
3846 Filters = new wp.media.view.AttachmentFilters.All({
3847 controller: this.controller,
3848 model: this.collection.props,
3852 this.toolbar.set( 'filters', Filters.render() );
3856 // Feels odd to bring the global media library switcher into the Attachment
3857 // browser view. Is this a use case for doAction( 'add:toolbar-items:attachments-browser', this.toolbar );
3858 // which the controller can tap into and add this view?
3859 if ( this.controller.isModeActive( 'grid' ) ) {
3860 LibraryViewSwitcher = View.extend({
3861 className: 'view-switch media-grid-view-switch',
3862 template: wp.template( 'media-library-view-switcher')
3865 this.toolbar.set( 'libraryViewSwitcher', new LibraryViewSwitcher({
3866 controller: this.controller,
3870 // DateFilter is a <select>, screen reader text needs to be rendered before
3871 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3872 value: l10n.filterByDate,
3874 'for': 'media-attachment-date-filters'
3878 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3879 controller: this.controller,
3880 model: this.collection.props,
3884 // BulkSelection is a <div> with subviews, including screen reader text
3885 this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({
3886 text: l10n.bulkSelect,
3887 controller: this.controller,
3891 this.toolbar.set( 'deleteSelectedButton', new wp.media.view.DeleteSelectedButton({
3895 text: mediaTrash ? l10n.trashSelected : l10n.deleteSelected,
3896 controller: this.controller,
3899 var changed = [], removed = [],
3900 selection = this.controller.state().get( 'selection' ),
3901 library = this.controller.state().get( 'library' );
3903 if ( ! selection.length ) {
3907 if ( ! mediaTrash && ! window.confirm( l10n.warnBulkDelete ) ) {
3912 'trash' !== selection.at( 0 ).get( 'status' ) &&
3913 ! window.confirm( l10n.warnBulkTrash ) ) {
3918 selection.each( function( model ) {
3919 if ( ! model.get( 'nonces' )['delete'] ) {
3920 removed.push( model );
3924 if ( mediaTrash && 'trash' === model.get( 'status' ) ) {
3925 model.set( 'status', 'inherit' );
3926 changed.push( model.save() );
3927 removed.push( model );
3928 } else if ( mediaTrash ) {
3929 model.set( 'status', 'trash' );
3930 changed.push( model.save() );
3931 removed.push( model );
3933 model.destroy({wait: true});
3937 if ( changed.length ) {
3938 selection.remove( removed );
3940 $.when.apply( null, changed ).then( _.bind( function() {
3941 library._requery( true );
3942 this.controller.trigger( 'selection:action:done' );
3945 this.controller.trigger( 'selection:action:done' );
3951 this.toolbar.set( 'deleteSelectedPermanentlyButton', new wp.media.view.DeleteSelectedPermanentlyButton({
3955 text: l10n.deleteSelected,
3956 controller: this.controller,
3959 var removed = [], selection = this.controller.state().get( 'selection' );
3961 if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
3965 selection.each( function( model ) {
3966 if ( ! model.get( 'nonces' )['delete'] ) {
3967 removed.push( model );
3974 selection.remove( removed );
3975 this.controller.trigger( 'selection:action:done' );
3980 } else if ( this.options.date ) {
3981 // DateFilter is a <select>, screen reader text needs to be rendered before
3982 this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
3983 value: l10n.filterByDate,
3985 'for': 'media-attachment-date-filters'
3989 this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
3990 controller: this.controller,
3991 model: this.collection.props,
3996 if ( this.options.search ) {
3997 // Search is an input, screen reader text needs to be rendered before
3998 this.toolbar.set( 'searchLabel', new wp.media.view.Label({
3999 value: l10n.searchMediaLabel,
4001 'for': 'media-search-input'
4005 this.toolbar.set( 'search', new wp.media.view.Search({
4006 controller: this.controller,
4007 model: this.collection.props,
4012 if ( this.options.dragInfo ) {
4013 this.toolbar.set( 'dragInfo', new View({
4014 el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0],
4019 if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
4020 this.toolbar.set( 'suggestedDimensions', new View({
4021 el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + this.options.suggestedWidth + ' × ' + this.options.suggestedHeight + '</div>' )[0],
4027 updateContent: function() {
4031 if ( this.controller.isModeActive( 'grid' ) ) {
4032 noItemsView = view.attachmentsNoResults;
4034 noItemsView = view.uploader;
4037 if ( ! this.collection.length ) {
4038 this.toolbar.get( 'spinner' ).show();
4039 this.dfd = this.collection.more().done( function() {
4040 if ( ! view.collection.length ) {
4041 noItemsView.$el.removeClass( 'hidden' );
4043 noItemsView.$el.addClass( 'hidden' );
4045 view.toolbar.get( 'spinner' ).hide();
4048 noItemsView.$el.addClass( 'hidden' );
4049 view.toolbar.get( 'spinner' ).hide();
4053 createUploader: function() {
4054 this.uploader = new wp.media.view.UploaderInline({
4055 controller: this.controller,
4057 message: this.controller.isModeActive( 'grid' ) ? '' : l10n.noItemsFound,
4058 canClose: this.controller.isModeActive( 'grid' )
4061 this.uploader.hide();
4062 this.views.add( this.uploader );
4065 toggleUploader: function() {
4066 if ( this.uploader.$el.hasClass( 'hidden' ) ) {
4067 this.uploader.show();
4069 this.uploader.hide();
4073 createAttachments: function() {
4074 this.attachments = new wp.media.view.Attachments({
4075 controller: this.controller,
4076 collection: this.collection,
4077 selection: this.options.selection,
4079 sortable: this.options.sortable,
4080 scrollElement: this.options.scrollElement,
4081 idealColumnWidth: this.options.idealColumnWidth,
4083 // The single `Attachment` view to be used in the `Attachments` view.
4084 AttachmentView: this.options.AttachmentView
4087 // Add keydown listener to the instance of the Attachments view
4088 this.controller.on( 'attachment:keydown:arrow', _.bind( this.attachments.arrowEvent, this.attachments ) );
4089 this.controller.on( 'attachment:details:shift-tab', _.bind( this.attachments.restoreFocus, this.attachments ) );
4091 this.views.add( this.attachments );
4094 if ( this.controller.isModeActive( 'grid' ) ) {
4095 this.attachmentsNoResults = new View({
4096 controller: this.controller,
4100 this.attachmentsNoResults.$el.addClass( 'hidden no-media' );
4101 this.attachmentsNoResults.$el.html( l10n.noMedia );
4103 this.views.add( this.attachmentsNoResults );
4107 createSidebar: function() {
4108 var options = this.options,
4109 selection = options.selection,
4110 sidebar = this.sidebar = new wp.media.view.Sidebar({
4111 controller: this.controller
4114 this.views.add( sidebar );
4116 if ( this.controller.uploader ) {
4117 sidebar.set( 'uploads', new wp.media.view.UploaderStatus({
4118 controller: this.controller,
4123 selection.on( 'selection:single', this.createSingle, this );
4124 selection.on( 'selection:unsingle', this.disposeSingle, this );
4126 if ( selection.single() ) {
4127 this.createSingle();
4131 createSingle: function() {
4132 var sidebar = this.sidebar,
4133 single = this.options.selection.single();
4135 sidebar.set( 'details', new wp.media.view.Attachment.Details({
4136 controller: this.controller,
4141 sidebar.set( 'compat', new wp.media.view.AttachmentCompat({
4142 controller: this.controller,
4147 if ( this.options.display ) {
4148 sidebar.set( 'display', new wp.media.view.Settings.AttachmentDisplay({
4149 controller: this.controller,
4150 model: this.model.display( single ),
4153 userSettings: this.model.get('displayUserSettings')
4157 // Show the sidebar on mobile
4158 if ( this.model.id === 'insert' ) {
4159 sidebar.$el.addClass( 'visible' );
4163 disposeSingle: function() {
4164 var sidebar = this.sidebar;
4165 sidebar.unset('details');
4166 sidebar.unset('compat');
4167 sidebar.unset('display');
4168 // Hide the sidebar on mobile
4169 sidebar.$el.removeClass( 'visible' );
4173 module.exports = AttachmentsBrowser;
4175 },{}],33:[function(require,module,exports){
4177 * wp.media.view.Attachments.Selection
4180 * @augments wp.media.view.Attachments
4181 * @augments wp.media.View
4182 * @augments wp.Backbone.View
4183 * @augments Backbone.View
4185 var Attachments = wp.media.view.Attachments,
4188 Selection = Attachments.extend({
4190 initialize: function() {
4191 _.defaults( this.options, {
4195 // The single `Attachment` view to be used in the `Attachments` view.
4196 AttachmentView: wp.media.view.Attachment.Selection
4198 // Call 'initialize' directly on the parent class.
4199 return Attachments.prototype.initialize.apply( this, arguments );
4203 module.exports = Selection;
4205 },{}],34:[function(require,module,exports){
4207 * wp.media.view.ButtonGroup
4210 * @augments wp.media.View
4211 * @augments wp.Backbone.View
4212 * @augments Backbone.View
4217 ButtonGroup = wp.media.View.extend({
4219 className: 'button-group button-large media-button-group',
4221 initialize: function() {
4223 * @member {wp.media.view.Button[]}
4225 this.buttons = _.map( this.options.buttons || [], function( button ) {
4226 if ( button instanceof Backbone.View ) {
4229 return new wp.media.view.Button( button ).render();
4233 delete this.options.buttons;
4235 if ( this.options.classes ) {
4236 this.$el.addClass( this.options.classes );
4241 * @returns {wp.media.view.ButtonGroup}
4243 render: function() {
4244 this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() );
4249 module.exports = ButtonGroup;
4251 },{}],35:[function(require,module,exports){
4253 * wp.media.view.Button
4256 * @augments wp.media.View
4257 * @augments wp.Backbone.View
4258 * @augments Backbone.View
4260 var Button = wp.media.View.extend({
4262 className: 'media-button',
4263 attributes: { type: 'button' },
4276 initialize: function() {
4278 * Create a model with the provided `defaults`.
4280 * @member {Backbone.Model}
4282 this.model = new Backbone.Model( this.defaults );
4284 // If any of the `options` have a key from `defaults`, apply its
4285 // value to the `model` and remove it from the `options object.
4286 _.each( this.defaults, function( def, key ) {
4287 var value = this.options[ key ];
4288 if ( _.isUndefined( value ) ) {
4292 this.model.set( key, value );
4293 delete this.options[ key ];
4296 this.listenTo( this.model, 'change', this.render );
4299 * @returns {wp.media.view.Button} Returns itself to allow chaining
4301 render: function() {
4302 var classes = [ 'button', this.className ],
4303 model = this.model.toJSON();
4305 if ( model.style ) {
4306 classes.push( 'button-' + model.style );
4310 classes.push( 'button-' + model.size );
4313 classes = _.uniq( classes.concat( this.options.classes ) );
4314 this.el.className = classes.join(' ');
4316 this.$el.attr( 'disabled', model.disabled );
4317 this.$el.text( this.model.get('text') );
4322 * @param {Object} event
4324 click: function( event ) {
4325 if ( '#' === this.attributes.href ) {
4326 event.preventDefault();
4329 if ( this.options.click && ! this.model.get('disabled') ) {
4330 this.options.click.apply( this, arguments );
4335 module.exports = Button;
4337 },{}],36:[function(require,module,exports){
4339 * wp.media.view.Cropper
4341 * Uses the imgAreaSelect plugin to allow a user to crop an image.
4343 * Takes imgAreaSelect options from
4344 * wp.customize.HeaderControl.calculateImageSelectOptions via
4345 * wp.customize.HeaderControl.openMM.
4348 * @augments wp.media.View
4349 * @augments wp.Backbone.View
4350 * @augments Backbone.View
4352 var View = wp.media.View,
4353 UploaderStatus = wp.media.view.UploaderStatus,
4354 l10n = wp.media.view.l10n,
4358 Cropper = View.extend({
4359 className: 'crop-content',
4360 template: wp.template('crop-content'),
4361 initialize: function() {
4362 _.bindAll(this, 'onImageLoad');
4365 this.controller.frame.on('content:error:crop', this.onError, this);
4366 this.$image = this.$el.find('.crop-image');
4367 this.$image.on('load', this.onImageLoad);
4368 $(window).on('resize.cropper', _.debounce(this.onImageLoad, 250));
4370 remove: function() {
4371 $(window).off('resize.cropper');
4374 View.prototype.remove.apply(this, arguments);
4376 prepare: function() {
4378 title: l10n.cropYourImage,
4379 url: this.options.attachment.get('url')
4382 onImageLoad: function() {
4383 var imgOptions = this.controller.get('imgSelectOptions');
4384 if (typeof imgOptions === 'function') {
4385 imgOptions = imgOptions(this.options.attachment, this.controller);
4388 imgOptions = _.extend(imgOptions, {parent: this.$el});
4389 this.trigger('image-loaded');
4390 this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
4392 onError: function() {
4393 var filename = this.options.attachment.get('filename');
4395 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
4396 filename: UploaderStatus.prototype.filename(filename),
4397 message: window._wpMediaViewsL10n.cropError
4402 module.exports = Cropper;
4404 },{}],37:[function(require,module,exports){
4406 * wp.media.view.EditImage
4409 * @augments wp.media.View
4410 * @augments wp.Backbone.View
4411 * @augments Backbone.View
4413 var View = wp.media.View,
4416 EditImage = View.extend({
4417 className: 'image-editor',
4418 template: wp.template('image-editor'),
4420 initialize: function( options ) {
4421 this.editor = window.imageEdit;
4422 this.controller = options.controller;
4423 View.prototype.initialize.apply( this, arguments );
4426 prepare: function() {
4427 return this.model.toJSON();
4430 loadEditor: function() {
4431 var dfd = this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this );
4432 dfd.done( _.bind( this.focus, this ) );
4436 this.$( '.imgedit-submit .button' ).eq( 0 ).focus();
4440 var lastState = this.controller.lastState();
4441 this.controller.setState( lastState );
4444 refresh: function() {
4449 var lastState = this.controller.lastState();
4451 this.model.fetch().done( _.bind( function() {
4452 this.controller.setState( lastState );
4458 module.exports = EditImage;
4460 },{}],38:[function(require,module,exports){
4462 * wp.media.view.Embed
4465 * @augments wp.media.View
4466 * @augments wp.Backbone.View
4467 * @augments Backbone.View
4469 var Embed = wp.media.View.extend({
4470 className: 'media-embed',
4472 initialize: function() {
4474 * @member {wp.media.view.EmbedUrl}
4476 this.url = new wp.media.view.EmbedUrl({
4477 controller: this.controller,
4478 model: this.model.props
4481 this.views.set([ this.url ]);
4483 this.listenTo( this.model, 'change:type', this.refresh );
4484 this.listenTo( this.model, 'change:loading', this.loading );
4488 * @param {Object} view
4490 settings: function( view ) {
4491 if ( this._settings ) {
4492 this._settings.remove();
4494 this._settings = view;
4495 this.views.add( view );
4498 refresh: function() {
4499 var type = this.model.get('type'),
4502 if ( 'image' === type ) {
4503 constructor = wp.media.view.EmbedImage;
4504 } else if ( 'link' === type ) {
4505 constructor = wp.media.view.EmbedLink;
4510 this.settings( new constructor({
4511 controller: this.controller,
4512 model: this.model.props,
4517 loading: function() {
4518 this.$el.toggleClass( 'embed-loading', this.model.get('loading') );
4522 module.exports = Embed;
4524 },{}],39:[function(require,module,exports){
4526 * wp.media.view.EmbedImage
4529 * @augments wp.media.view.Settings.AttachmentDisplay
4530 * @augments wp.media.view.Settings
4531 * @augments wp.media.View
4532 * @augments wp.Backbone.View
4533 * @augments Backbone.View
4535 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
4538 EmbedImage = AttachmentDisplay.extend({
4539 className: 'embed-media-settings',
4540 template: wp.template('embed-image-settings'),
4542 initialize: function() {
4544 * Call `initialize` directly on parent class with passed arguments
4546 AttachmentDisplay.prototype.initialize.apply( this, arguments );
4547 this.listenTo( this.model, 'change:url', this.updateImage );
4550 updateImage: function() {
4551 this.$('img').attr( 'src', this.model.get('url') );
4555 module.exports = EmbedImage;
4557 },{}],40:[function(require,module,exports){
4559 * wp.media.view.EmbedLink
4562 * @augments wp.media.view.Settings
4563 * @augments wp.media.View
4564 * @augments wp.Backbone.View
4565 * @augments Backbone.View
4570 EmbedLink = wp.media.view.Settings.extend({
4571 className: 'embed-link-settings',
4572 template: wp.template('embed-link-settings'),
4574 initialize: function() {
4575 this.listenTo( this.model, 'change:url', this.updateoEmbed );
4578 updateoEmbed: _.debounce( function() {
4579 var url = this.model.get( 'url' );
4581 // clear out previous results
4582 this.$('.embed-container').hide().find('.embed-preview').empty();
4583 this.$( '.setting' ).hide();
4585 // only proceed with embed if the field contains more than 11 characters
4586 // Example: http://a.io is 11 chars
4587 if ( url && ( url.length < 11 || ! url.match(/^http(s)?:\/\//) ) ) {
4592 }, wp.media.controller.Embed.sensitivity ),
4597 // check if they haven't typed in 500 ms
4598 if ( $('#embed-url-field').val() !== this.model.get('url') ) {
4602 if ( this.dfd && 'pending' === this.dfd.state() ) {
4606 embed = new wp.shortcode({
4608 attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
4609 content: this.model.get('url')
4614 url: wp.ajax.settings.url,
4617 action: 'parse-embed',
4618 post_ID: wp.media.view.settings.post.id,
4619 shortcode: embed.string()
4622 .done( this.renderoEmbed )
4623 .fail( this.renderFail );
4626 renderFail: function ( response, status ) {
4627 if ( 'abort' === status ) {
4630 this.$( '.link-text' ).show();
4633 renderoEmbed: function( response ) {
4634 var html = ( response && response.data && response.data.body ) || '';
4637 this.$('.embed-container').show().find('.embed-preview').html( html );
4644 module.exports = EmbedLink;
4646 },{}],41:[function(require,module,exports){
4648 * wp.media.view.EmbedUrl
4651 * @augments wp.media.View
4652 * @augments wp.Backbone.View
4653 * @augments Backbone.View
4655 var View = wp.media.View,
4659 EmbedUrl = View.extend({
4661 className: 'embed-url',
4669 initialize: function() {
4670 this.$input = $('<input id="embed-url-field" type="url" />').val( this.model.get('url') );
4671 this.input = this.$input[0];
4673 this.spinner = $('<span class="spinner" />')[0];
4674 this.$el.append([ this.input, this.spinner ]);
4676 this.listenTo( this.model, 'change:url', this.render );
4678 if ( this.model.get( 'url' ) ) {
4679 _.delay( _.bind( function () {
4680 this.model.trigger( 'change:url' );
4685 * @returns {wp.media.view.EmbedUrl} Returns itself to allow chaining
4687 render: function() {
4688 var $input = this.$input;
4690 if ( $input.is(':focus') ) {
4694 this.input.value = this.model.get('url') || 'http://';
4696 * Call `render` directly on parent class with passed arguments
4698 View.prototype.render.apply( this, arguments );
4703 if ( ! wp.media.isTouchDevice ) {
4708 url: function( event ) {
4709 this.model.set( 'url', event.target.value );
4713 * If the input is visible, focus and select its contents.
4716 var $input = this.$input;
4717 if ( $input.is(':visible') ) {
4718 $input.focus()[0].select();
4723 module.exports = EmbedUrl;
4725 },{}],42:[function(require,module,exports){
4727 * wp.media.view.FocusManager
4730 * @augments wp.media.View
4731 * @augments wp.Backbone.View
4732 * @augments Backbone.View
4734 var FocusManager = wp.media.View.extend({
4737 'keydown': 'constrainTabbing'
4740 focus: function() { // Reset focus on first left menu item
4741 this.$('.media-menu-item').first().focus();
4744 * @param {Object} event
4746 constrainTabbing: function( event ) {
4749 // Look for the tab key.
4750 if ( 9 !== event.keyCode ) {
4754 // Skip the file input added by Plupload.
4755 tabbables = this.$( ':tabbable' ).not( '.moxie-shim input[type="file"]' );
4757 // Keep tab focus within media modal while it's open
4758 if ( tabbables.last()[0] === event.target && ! event.shiftKey ) {
4759 tabbables.first().focus();
4761 } else if ( tabbables.first()[0] === event.target && event.shiftKey ) {
4762 tabbables.last().focus();
4769 module.exports = FocusManager;
4771 },{}],43:[function(require,module,exports){
4773 * wp.media.view.Frame
4775 * A frame is a composite view consisting of one or more regions and one or more
4778 * @see wp.media.controller.State
4779 * @see wp.media.controller.Region
4782 * @augments wp.media.View
4783 * @augments wp.Backbone.View
4784 * @augments Backbone.View
4785 * @mixes wp.media.controller.StateMachine
4787 var Frame = wp.media.View.extend({
4788 initialize: function() {
4789 _.defaults( this.options, {
4792 this._createRegions();
4793 this._createStates();
4794 this._createModes();
4797 _createRegions: function() {
4798 // Clone the regions array.
4799 this.regions = this.regions ? this.regions.slice() : [];
4801 // Initialize regions.
4802 _.each( this.regions, function( region ) {
4803 this[ region ] = new wp.media.controller.Region({
4806 selector: '.media-frame-' + region
4811 * Create the frame's states.
4813 * @see wp.media.controller.State
4814 * @see wp.media.controller.StateMachine
4816 * @fires wp.media.controller.State#ready
4818 _createStates: function() {
4819 // Create the default `states` collection.
4820 this.states = new Backbone.Collection( null, {
4821 model: wp.media.controller.State
4824 // Ensure states have a reference to the frame.
4825 this.states.on( 'add', function( model ) {
4827 model.trigger('ready');
4830 if ( this.options.states ) {
4831 this.states.add( this.options.states );
4836 * A frame can be in a mode or multiple modes at one time.
4838 * For example, the manage media frame can be in the `Bulk Select` or `Edit` mode.
4840 _createModes: function() {
4841 // Store active "modes" that the frame is in. Unrelated to region modes.
4842 this.activeModes = new Backbone.Collection();
4843 this.activeModes.on( 'add remove reset', _.bind( this.triggerModeEvents, this ) );
4845 _.each( this.options.mode, function( mode ) {
4846 this.activateMode( mode );
4850 * Reset all states on the frame to their defaults.
4852 * @returns {wp.media.view.Frame} Returns itself to allow chaining
4855 this.states.invoke( 'trigger', 'reset' );
4859 * Map activeMode collection events to the frame.
4861 triggerModeEvents: function( model, collection, options ) {
4862 var collectionEvent,
4865 remove: 'deactivate'
4868 // Probably a better way to do this.
4869 _.each( options, function( value, key ) {
4871 collectionEvent = key;
4875 if ( ! _.has( modeEventMap, collectionEvent ) ) {
4879 eventToTrigger = model.get('id') + ':' + modeEventMap[collectionEvent];
4880 this.trigger( eventToTrigger );
4883 * Activate a mode on the frame.
4885 * @param string mode Mode ID.
4886 * @returns {this} Returns itself to allow chaining.
4888 activateMode: function( mode ) {
4889 // Bail if the mode is already active.
4890 if ( this.isModeActive( mode ) ) {
4893 this.activeModes.add( [ { id: mode } ] );
4894 // Add a CSS class to the frame so elements can be styled for the mode.
4895 this.$el.addClass( 'mode-' + mode );
4900 * Deactivate a mode on the frame.
4902 * @param string mode Mode ID.
4903 * @returns {this} Returns itself to allow chaining.
4905 deactivateMode: function( mode ) {
4906 // Bail if the mode isn't active.
4907 if ( ! this.isModeActive( mode ) ) {
4910 this.activeModes.remove( this.activeModes.where( { id: mode } ) );
4911 this.$el.removeClass( 'mode-' + mode );
4913 * Frame mode deactivation event.
4915 * @event this#{mode}:deactivate
4917 this.trigger( mode + ':deactivate' );
4922 * Check if a mode is enabled on the frame.
4924 * @param string mode Mode ID.
4927 isModeActive: function( mode ) {
4928 return Boolean( this.activeModes.where( { id: mode } ).length );
4932 // Make the `Frame` a `StateMachine`.
4933 _.extend( Frame.prototype, wp.media.controller.StateMachine.prototype );
4935 module.exports = Frame;
4937 },{}],44:[function(require,module,exports){
4939 * wp.media.view.MediaFrame.ImageDetails
4941 * A media frame for manipulating an image that's already been inserted
4945 * @augments wp.media.view.MediaFrame.Select
4946 * @augments wp.media.view.MediaFrame
4947 * @augments wp.media.view.Frame
4948 * @augments wp.media.View
4949 * @augments wp.Backbone.View
4950 * @augments Backbone.View
4951 * @mixes wp.media.controller.StateMachine
4953 var Select = wp.media.view.MediaFrame.Select,
4954 l10n = wp.media.view.l10n,
4957 ImageDetails = Select.extend({
4961 menu: 'image-details',
4962 content: 'image-details',
4963 toolbar: 'image-details',
4965 title: l10n.imageDetailsTitle,
4969 initialize: function( options ) {
4970 this.image = new wp.media.model.PostImage( options.metadata );
4971 this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } );
4972 Select.prototype.initialize.apply( this, arguments );
4975 bindHandlers: function() {
4976 Select.prototype.bindHandlers.apply( this, arguments );
4977 this.on( 'menu:create:image-details', this.createMenu, this );
4978 this.on( 'content:create:image-details', this.imageDetailsContent, this );
4979 this.on( 'content:render:edit-image', this.editImageContent, this );
4980 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this );
4981 // override the select toolbar
4982 this.on( 'toolbar:render:replace', this.renderReplaceImageToolbar, this );
4985 createStates: function() {
4987 new wp.media.controller.ImageDetails({
4991 new wp.media.controller.ReplaceImage({
4992 id: 'replace-image',
4993 library: wp.media.query( { type: 'image' } ),
4996 title: l10n.imageReplaceTitle,
4999 displaySettings: true
5001 new wp.media.controller.EditImage( {
5003 selection: this.options.selection
5008 imageDetailsContent: function( options ) {
5009 options.view = new wp.media.view.ImageDetails({
5011 model: this.state().image,
5012 attachment: this.state().image.attachment
5016 editImageContent: function() {
5017 var state = this.state(),
5018 model = state.get('image'),
5025 view = new wp.media.view.EditImage( { model: model, controller: this } ).render();
5027 this.content.set( view );
5029 // after bringing in the frame, load the actual editor via an ajax call
5034 renderImageDetailsToolbar: function() {
5035 this.toolbar.set( new wp.media.view.Toolbar({
5044 var controller = this.controller,
5045 state = controller.state();
5049 // not sure if we want to use wp.media.string.image which will create a shortcode or
5050 // perhaps wp.html.string to at least to build the <img />
5051 state.trigger( 'update', controller.image.toJSON() );
5053 // Restore and reset the default state.
5054 controller.setState( controller.options.state );
5062 renderReplaceImageToolbar: function() {
5064 lastState = frame.lastState(),
5065 previous = lastState && lastState.id;
5067 this.toolbar.set( new wp.media.view.Toolbar({
5075 frame.setState( previous );
5088 var controller = this.controller,
5089 state = controller.state(),
5090 selection = state.get( 'selection' ),
5091 attachment = selection.single();
5095 controller.image.changeAttachment( attachment, state.display( attachment ) );
5097 // not sure if we want to use wp.media.string.image which will create a shortcode or
5098 // perhaps wp.html.string to at least to build the <img />
5099 state.trigger( 'replace', controller.image.toJSON() );
5101 // Restore and reset the default state.
5102 controller.setState( controller.options.state );
5112 module.exports = ImageDetails;
5114 },{}],45:[function(require,module,exports){
5116 * wp.media.view.MediaFrame.Post
5118 * The frame for manipulating media on the Edit Post page.
5121 * @augments wp.media.view.MediaFrame.Select
5122 * @augments wp.media.view.MediaFrame
5123 * @augments wp.media.view.Frame
5124 * @augments wp.media.View
5125 * @augments wp.Backbone.View
5126 * @augments Backbone.View
5127 * @mixes wp.media.controller.StateMachine
5129 var Select = wp.media.view.MediaFrame.Select,
5130 Library = wp.media.controller.Library,
5131 l10n = wp.media.view.l10n,
5134 Post = Select.extend({
5135 initialize: function() {
5138 count: wp.media.view.settings.attachmentCounts.audio,
5142 count: wp.media.view.settings.attachmentCounts.video,
5143 state: 'video-playlist'
5147 _.defaults( this.options, {
5154 // Call 'initialize' directly on the parent class.
5155 Select.prototype.initialize.apply( this, arguments );
5156 this.createIframeStates();
5161 * Create the default states.
5163 createStates: function() {
5164 var options = this.options;
5170 title: l10n.insertMediaTitle,
5172 toolbar: 'main-insert',
5174 library: wp.media.query( options.library ),
5175 multiple: options.multiple ? 'reset' : false,
5178 // If the user isn't allowed to edit fields,
5179 // can they still edit it locally?
5180 allowLocalEdits: true,
5182 // Show the attachment display settings.
5183 displaySettings: true,
5184 // Update user settings when users adjust the
5185 // attachment display settings.
5186 displayUserSettings: true
5191 title: l10n.createGalleryTitle,
5193 toolbar: 'main-gallery',
5194 filterable: 'uploaded',
5198 library: wp.media.query( _.defaults({
5200 }, options.library ) )
5204 new wp.media.controller.Embed( { metadata: options.metadata } ),
5206 new wp.media.controller.EditImage( { model: options.editImage } ),
5209 new wp.media.controller.GalleryEdit({
5210 library: options.selection,
5211 editing: options.editing,
5215 new wp.media.controller.GalleryAdd(),
5219 title: l10n.createPlaylistTitle,
5221 toolbar: 'main-playlist',
5222 filterable: 'uploaded',
5226 library: wp.media.query( _.defaults({
5228 }, options.library ) )
5232 new wp.media.controller.CollectionEdit({
5234 collectionType: 'playlist',
5235 title: l10n.editPlaylistTitle,
5236 SettingsView: wp.media.view.Settings.Playlist,
5237 library: options.selection,
5238 editing: options.editing,
5240 dragInfoText: l10n.playlistDragInfo,
5244 new wp.media.controller.CollectionAdd({
5246 collectionType: 'playlist',
5247 title: l10n.addToPlaylistTitle
5251 id: 'video-playlist',
5252 title: l10n.createVideoPlaylistTitle,
5254 toolbar: 'main-video-playlist',
5255 filterable: 'uploaded',
5259 library: wp.media.query( _.defaults({
5261 }, options.library ) )
5264 new wp.media.controller.CollectionEdit({
5266 collectionType: 'playlist',
5267 title: l10n.editVideoPlaylistTitle,
5268 SettingsView: wp.media.view.Settings.Playlist,
5269 library: options.selection,
5270 editing: options.editing,
5271 menu: 'video-playlist',
5272 dragInfoText: l10n.videoPlaylistDragInfo,
5276 new wp.media.controller.CollectionAdd({
5278 collectionType: 'playlist',
5279 title: l10n.addToVideoPlaylistTitle
5283 if ( wp.media.view.settings.post.featuredImageId ) {
5284 this.states.add( new wp.media.controller.FeaturedImage() );
5288 bindHandlers: function() {
5289 var handlers, checkCounts;
5291 Select.prototype.bindHandlers.apply( this, arguments );
5293 this.on( 'activate', this.activate, this );
5295 // Only bother checking media type counts if one of the counts is zero
5296 checkCounts = _.find( this.counts, function( type ) {
5297 return type.count === 0;
5300 if ( typeof checkCounts !== 'undefined' ) {
5301 this.listenTo( wp.media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
5304 this.on( 'menu:create:gallery', this.createMenu, this );
5305 this.on( 'menu:create:playlist', this.createMenu, this );
5306 this.on( 'menu:create:video-playlist', this.createMenu, this );
5307 this.on( 'toolbar:create:main-insert', this.createToolbar, this );
5308 this.on( 'toolbar:create:main-gallery', this.createToolbar, this );
5309 this.on( 'toolbar:create:main-playlist', this.createToolbar, this );
5310 this.on( 'toolbar:create:main-video-playlist', this.createToolbar, this );
5311 this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
5312 this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
5316 'default': 'mainMenu',
5317 'gallery': 'galleryMenu',
5318 'playlist': 'playlistMenu',
5319 'video-playlist': 'videoPlaylistMenu'
5323 'embed': 'embedContent',
5324 'edit-image': 'editImageContent',
5325 'edit-selection': 'editSelectionContent'
5329 'main-insert': 'mainInsertToolbar',
5330 'main-gallery': 'mainGalleryToolbar',
5331 'gallery-edit': 'galleryEditToolbar',
5332 'gallery-add': 'galleryAddToolbar',
5333 'main-playlist': 'mainPlaylistToolbar',
5334 'playlist-edit': 'playlistEditToolbar',
5335 'playlist-add': 'playlistAddToolbar',
5336 'main-video-playlist': 'mainVideoPlaylistToolbar',
5337 'video-playlist-edit': 'videoPlaylistEditToolbar',
5338 'video-playlist-add': 'videoPlaylistAddToolbar'
5342 _.each( handlers, function( regionHandlers, region ) {
5343 _.each( regionHandlers, function( callback, handler ) {
5344 this.on( region + ':render:' + handler, this[ callback ], this );
5349 activate: function() {
5350 // Hide menu items for states tied to particular media types if there are no items
5351 _.each( this.counts, function( type ) {
5352 if ( type.count < 1 ) {
5353 this.menuItemVisibility( type.state, 'hide' );
5358 mediaTypeCounts: function( model, attr ) {
5359 if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
5360 this.counts[ attr ].count++;
5361 this.menuItemVisibility( this.counts[ attr ].state, 'show' );
5367 * @param {wp.Backbone.View} view
5369 mainMenu: function( view ) {
5371 'library-separator': new wp.media.View({
5372 className: 'separator',
5378 menuItemVisibility: function( state, visibility ) {
5379 var menu = this.menu.get();
5380 if ( visibility === 'hide' ) {
5382 } else if ( visibility === 'show' ) {
5387 * @param {wp.Backbone.View} view
5389 galleryMenu: function( view ) {
5390 var lastState = this.lastState(),
5391 previous = lastState && lastState.id,
5396 text: l10n.cancelGalleryTitle,
5400 frame.setState( previous );
5405 // Keep focus inside media modal
5406 // after canceling a gallery
5407 this.controller.modal.focusManager.focus();
5410 separateCancel: new wp.media.View({
5411 className: 'separator',
5417 playlistMenu: function( view ) {
5418 var lastState = this.lastState(),
5419 previous = lastState && lastState.id,
5424 text: l10n.cancelPlaylistTitle,
5428 frame.setState( previous );
5434 separateCancel: new wp.media.View({
5435 className: 'separator',
5441 videoPlaylistMenu: function( view ) {
5442 var lastState = this.lastState(),
5443 previous = lastState && lastState.id,
5448 text: l10n.cancelVideoPlaylistTitle,
5452 frame.setState( previous );
5458 separateCancel: new wp.media.View({
5459 className: 'separator',
5466 embedContent: function() {
5467 var view = new wp.media.view.Embed({
5472 this.content.set( view );
5474 if ( ! wp.media.isTouchDevice ) {
5479 editSelectionContent: function() {
5480 var state = this.state(),
5481 selection = state.get('selection'),
5484 view = new wp.media.view.AttachmentsBrowser({
5486 collection: selection,
5487 selection: selection,
5494 AttachmentView: wp.media.view.Attachments.EditSelection
5497 view.toolbar.set( 'backToLibrary', {
5498 text: l10n.returnToLibrary,
5502 this.controller.content.mode('browse');
5506 // Browse our library of attachments.
5507 this.content.set( view );
5509 // Trigger the controller to set focus
5510 this.trigger( 'edit:selection', this );
5513 editImageContent: function() {
5514 var image = this.state().get('image'),
5515 view = new wp.media.view.EditImage( { model: image, controller: this } ).render();
5517 this.content.set( view );
5519 // after creating the wrapper view, load the actual editor via an ajax call
5527 * @param {wp.Backbone.View} view
5529 selectionStatusToolbar: function( view ) {
5530 var editable = this.state().get('editable');
5532 view.set( 'selection', new wp.media.view.Selection({
5534 collection: this.state().get('selection'),
5537 // If the selection is editable, pass the callback to
5538 // switch the content mode.
5539 editable: editable && function() {
5540 this.controller.content.mode('edit-selection');
5546 * @param {wp.Backbone.View} view
5548 mainInsertToolbar: function( view ) {
5549 var controller = this;
5551 this.selectionStatusToolbar( view );
5553 view.set( 'insert', {
5556 text: l10n.insertIntoPost,
5557 requires: { selection: true },
5560 * @fires wp.media.controller.State#insert
5563 var state = controller.state(),
5564 selection = state.get('selection');
5567 state.trigger( 'insert', selection ).reset();
5573 * @param {wp.Backbone.View} view
5575 mainGalleryToolbar: function( view ) {
5576 var controller = this;
5578 this.selectionStatusToolbar( view );
5580 view.set( 'gallery', {
5582 text: l10n.createNewGallery,
5584 requires: { selection: true },
5587 var selection = controller.state().get('selection'),
5588 edit = controller.state('gallery-edit'),
5589 models = selection.where({ type: 'image' });
5591 edit.set( 'library', new wp.media.model.Selection( models, {
5592 props: selection.props.toJSON(),
5596 this.controller.setState('gallery-edit');
5598 // Keep focus inside media modal
5599 // after jumping to gallery view
5600 this.controller.modal.focusManager.focus();
5605 mainPlaylistToolbar: function( view ) {
5606 var controller = this;
5608 this.selectionStatusToolbar( view );
5610 view.set( 'playlist', {
5612 text: l10n.createNewPlaylist,
5614 requires: { selection: true },
5617 var selection = controller.state().get('selection'),
5618 edit = controller.state('playlist-edit'),
5619 models = selection.where({ type: 'audio' });
5621 edit.set( 'library', new wp.media.model.Selection( models, {
5622 props: selection.props.toJSON(),
5626 this.controller.setState('playlist-edit');
5628 // Keep focus inside media modal
5629 // after jumping to playlist view
5630 this.controller.modal.focusManager.focus();
5635 mainVideoPlaylistToolbar: function( view ) {
5636 var controller = this;
5638 this.selectionStatusToolbar( view );
5640 view.set( 'video-playlist', {
5642 text: l10n.createNewVideoPlaylist,
5644 requires: { selection: true },
5647 var selection = controller.state().get('selection'),
5648 edit = controller.state('video-playlist-edit'),
5649 models = selection.where({ type: 'video' });
5651 edit.set( 'library', new wp.media.model.Selection( models, {
5652 props: selection.props.toJSON(),
5656 this.controller.setState('video-playlist-edit');
5658 // Keep focus inside media modal
5659 // after jumping to video playlist view
5660 this.controller.modal.focusManager.focus();
5665 featuredImageToolbar: function( toolbar ) {
5666 this.createSelectToolbar( toolbar, {
5667 text: l10n.setFeaturedImage,
5668 state: this.options.state
5672 mainEmbedToolbar: function( toolbar ) {
5673 toolbar.view = new wp.media.view.Toolbar.Embed({
5678 galleryEditToolbar: function() {
5679 var editing = this.state().get('editing');
5680 this.toolbar.set( new wp.media.view.Toolbar({
5685 text: editing ? l10n.updateGallery : l10n.insertGallery,
5687 requires: { library: true },
5690 * @fires wp.media.controller.State#update
5693 var controller = this.controller,
5694 state = controller.state();
5697 state.trigger( 'update', state.get('library') );
5699 // Restore and reset the default state.
5700 controller.setState( controller.options.state );
5708 galleryAddToolbar: function() {
5709 this.toolbar.set( new wp.media.view.Toolbar({
5714 text: l10n.addToGallery,
5716 requires: { selection: true },
5719 * @fires wp.media.controller.State#reset
5722 var controller = this.controller,
5723 state = controller.state(),
5724 edit = controller.state('gallery-edit');
5726 edit.get('library').add( state.get('selection').models );
5727 state.trigger('reset');
5728 controller.setState('gallery-edit');
5735 playlistEditToolbar: function() {
5736 var editing = this.state().get('editing');
5737 this.toolbar.set( new wp.media.view.Toolbar({
5742 text: editing ? l10n.updatePlaylist : l10n.insertPlaylist,
5744 requires: { library: true },
5747 * @fires wp.media.controller.State#update
5750 var controller = this.controller,
5751 state = controller.state();
5754 state.trigger( 'update', state.get('library') );
5756 // Restore and reset the default state.
5757 controller.setState( controller.options.state );
5765 playlistAddToolbar: function() {
5766 this.toolbar.set( new wp.media.view.Toolbar({
5771 text: l10n.addToPlaylist,
5773 requires: { selection: true },
5776 * @fires wp.media.controller.State#reset
5779 var controller = this.controller,
5780 state = controller.state(),
5781 edit = controller.state('playlist-edit');
5783 edit.get('library').add( state.get('selection').models );
5784 state.trigger('reset');
5785 controller.setState('playlist-edit');
5792 videoPlaylistEditToolbar: function() {
5793 var editing = this.state().get('editing');
5794 this.toolbar.set( new wp.media.view.Toolbar({
5799 text: editing ? l10n.updateVideoPlaylist : l10n.insertVideoPlaylist,
5801 requires: { library: true },
5804 var controller = this.controller,
5805 state = controller.state(),
5806 library = state.get('library');
5808 library.type = 'video';
5811 state.trigger( 'update', library );
5813 // Restore and reset the default state.
5814 controller.setState( controller.options.state );
5822 videoPlaylistAddToolbar: function() {
5823 this.toolbar.set( new wp.media.view.Toolbar({
5828 text: l10n.addToVideoPlaylist,
5830 requires: { selection: true },
5833 var controller = this.controller,
5834 state = controller.state(),
5835 edit = controller.state('video-playlist-edit');
5837 edit.get('library').add( state.get('selection').models );
5838 state.trigger('reset');
5839 controller.setState('video-playlist-edit');
5847 module.exports = Post;
5849 },{}],46:[function(require,module,exports){
5851 * wp.media.view.MediaFrame.Select
5853 * A frame for selecting an item or items from the media library.
5856 * @augments wp.media.view.MediaFrame
5857 * @augments wp.media.view.Frame
5858 * @augments wp.media.View
5859 * @augments wp.Backbone.View
5860 * @augments Backbone.View
5861 * @mixes wp.media.controller.StateMachine
5864 var MediaFrame = wp.media.view.MediaFrame,
5865 l10n = wp.media.view.l10n,
5868 Select = MediaFrame.extend({
5869 initialize: function() {
5870 // Call 'initialize' directly on the parent class.
5871 MediaFrame.prototype.initialize.apply( this, arguments );
5873 _.defaults( this.options, {
5880 this.createSelection();
5881 this.createStates();
5882 this.bindHandlers();
5886 * Attach a selection collection to the frame.
5888 * A selection is a collection of attachments used for a specific purpose
5889 * by a media frame. e.g. Selecting an attachment (or many) to insert into
5892 * @see media.model.Selection
5894 createSelection: function() {
5895 var selection = this.options.selection;
5897 if ( ! (selection instanceof wp.media.model.Selection) ) {
5898 this.options.selection = new wp.media.model.Selection( selection, {
5899 multiple: this.options.multiple
5904 attachments: new wp.media.model.Attachments(),
5910 * Create the default states on the frame.
5912 createStates: function() {
5913 var options = this.options;
5915 if ( this.options.states ) {
5919 // Add the default states.
5922 new wp.media.controller.Library({
5923 library: wp.media.query( options.library ),
5924 multiple: options.multiple,
5925 title: options.title,
5932 * Bind region mode event callbacks.
5934 * @see media.controller.Region.render
5936 bindHandlers: function() {
5937 this.on( 'router:create:browse', this.createRouter, this );
5938 this.on( 'router:render:browse', this.browseRouter, this );
5939 this.on( 'content:create:browse', this.browseContent, this );
5940 this.on( 'content:render:upload', this.uploadContent, this );
5941 this.on( 'toolbar:create:select', this.createSelectToolbar, this );
5945 * Render callback for the router region in the `browse` mode.
5947 * @param {wp.media.view.Router} routerView
5949 browseRouter: function( routerView ) {
5952 text: l10n.uploadFilesTitle,
5956 text: l10n.mediaLibraryTitle,
5963 * Render callback for the content region in the `browse` mode.
5965 * @param {wp.media.controller.Region} contentRegion
5967 browseContent: function( contentRegion ) {
5968 var state = this.state();
5970 this.$el.removeClass('hide-toolbar');
5972 // Browse our library of attachments.
5973 contentRegion.view = new wp.media.view.AttachmentsBrowser({
5975 collection: state.get('library'),
5976 selection: state.get('selection'),
5978 sortable: state.get('sortable'),
5979 search: state.get('searchable'),
5980 filters: state.get('filterable'),
5981 date: state.get('date'),
5982 display: state.has('display') ? state.get('display') : state.get('displaySettings'),
5983 dragInfo: state.get('dragInfo'),
5985 idealColumnWidth: state.get('idealColumnWidth'),
5986 suggestedWidth: state.get('suggestedWidth'),
5987 suggestedHeight: state.get('suggestedHeight'),
5989 AttachmentView: state.get('AttachmentView')
5994 * Render callback for the content region in the `upload` mode.
5996 uploadContent: function() {
5997 this.$el.removeClass( 'hide-toolbar' );
5998 this.content.set( new wp.media.view.UploaderInline({
6006 * @param {Object} toolbar
6007 * @param {Object} [options={}]
6008 * @this wp.media.controller.Region
6010 createSelectToolbar: function( toolbar, options ) {
6011 options = options || this.options.button || {};
6012 options.controller = this;
6014 toolbar.view = new wp.media.view.Toolbar.Select( options );
6018 module.exports = Select;
6020 },{}],47:[function(require,module,exports){
6022 * wp.media.view.Iframe
6025 * @augments wp.media.View
6026 * @augments wp.Backbone.View
6027 * @augments Backbone.View
6029 var Iframe = wp.media.View.extend({
6030 className: 'media-iframe',
6032 * @returns {wp.media.view.Iframe} Returns itself to allow chaining
6034 render: function() {
6035 this.views.detach();
6036 this.$el.html( '<iframe src="' + this.controller.state().get('src') + '" />' );
6037 this.views.render();
6042 module.exports = Iframe;
6044 },{}],48:[function(require,module,exports){
6046 * wp.media.view.ImageDetails
6049 * @augments wp.media.view.Settings.AttachmentDisplay
6050 * @augments wp.media.view.Settings
6051 * @augments wp.media.View
6052 * @augments wp.Backbone.View
6053 * @augments Backbone.View
6055 var AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay,
6059 ImageDetails = AttachmentDisplay.extend({
6060 className: 'image-details',
6061 template: wp.template('image-details'),
6062 events: _.defaults( AttachmentDisplay.prototype.events, {
6063 'click .edit-attachment': 'editAttachment',
6064 'click .replace-attachment': 'replaceAttachment',
6065 'click .advanced-toggle': 'onToggleAdvanced',
6066 'change [data-setting="customWidth"]': 'onCustomSize',
6067 'change [data-setting="customHeight"]': 'onCustomSize',
6068 'keyup [data-setting="customWidth"]': 'onCustomSize',
6069 'keyup [data-setting="customHeight"]': 'onCustomSize'
6071 initialize: function() {
6072 // used in AttachmentDisplay.prototype.updateLinkTo
6073 this.options.attachment = this.model.attachment;
6074 this.listenTo( this.model, 'change:url', this.updateUrl );
6075 this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
6076 this.listenTo( this.model, 'change:size', this.toggleCustomSize );
6078 AttachmentDisplay.prototype.initialize.apply( this, arguments );
6081 prepare: function() {
6082 var attachment = false;
6084 if ( this.model.attachment ) {
6085 attachment = this.model.attachment.toJSON();
6088 model: this.model.toJSON(),
6089 attachment: attachment
6093 render: function() {
6094 var args = arguments;
6096 if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
6098 .done( _.bind( function() {
6099 AttachmentDisplay.prototype.render.apply( this, args );
6102 .fail( _.bind( function() {
6103 this.model.attachment = false;
6104 AttachmentDisplay.prototype.render.apply( this, args );
6108 AttachmentDisplay.prototype.render.apply( this, arguments );
6115 postRender: function() {
6116 setTimeout( _.bind( this.resetFocus, this ), 10 );
6117 this.toggleLinkSettings();
6118 if ( window.getUserSetting( 'advImgDetails' ) === 'show' ) {
6119 this.toggleAdvanced( true );
6121 this.trigger( 'post-render' );
6124 resetFocus: function() {
6125 this.$( '.link-to-custom' ).blur();
6126 this.$( '.embed-media-settings' ).scrollTop( 0 );
6129 updateUrl: function() {
6130 this.$( '.image img' ).attr( 'src', this.model.get( 'url' ) );
6131 this.$( '.url' ).val( this.model.get( 'url' ) );
6134 toggleLinkSettings: function() {
6135 if ( this.model.get( 'link' ) === 'none' ) {
6136 this.$( '.link-settings' ).addClass('hidden');
6138 this.$( '.link-settings' ).removeClass('hidden');
6142 toggleCustomSize: function() {
6143 if ( this.model.get( 'size' ) !== 'custom' ) {
6144 this.$( '.custom-size' ).addClass('hidden');
6146 this.$( '.custom-size' ).removeClass('hidden');
6150 onCustomSize: function( event ) {
6151 var dimension = $( event.target ).data('setting'),
6152 num = $( event.target ).val(),
6155 // Ignore bogus input
6156 if ( ! /^\d+/.test( num ) || parseInt( num, 10 ) < 1 ) {
6157 event.preventDefault();
6161 if ( dimension === 'customWidth' ) {
6162 value = Math.round( 1 / this.model.get( 'aspectRatio' ) * num );
6163 this.model.set( 'customHeight', value, { silent: true } );
6164 this.$( '[data-setting="customHeight"]' ).val( value );
6166 value = Math.round( this.model.get( 'aspectRatio' ) * num );
6167 this.model.set( 'customWidth', value, { silent: true } );
6168 this.$( '[data-setting="customWidth"]' ).val( value );
6172 onToggleAdvanced: function( event ) {
6173 event.preventDefault();
6174 this.toggleAdvanced();
6177 toggleAdvanced: function( show ) {
6178 var $advanced = this.$el.find( '.advanced-section' ),
6181 if ( $advanced.hasClass('advanced-visible') || show === false ) {
6182 $advanced.removeClass('advanced-visible');
6183 $advanced.find('.advanced-settings').addClass('hidden');
6186 $advanced.addClass('advanced-visible');
6187 $advanced.find('.advanced-settings').removeClass('hidden');
6191 window.setUserSetting( 'advImgDetails', mode );
6194 editAttachment: function( event ) {
6195 var editState = this.controller.states.get( 'edit-image' );
6197 if ( window.imageEdit && editState ) {
6198 event.preventDefault();
6199 editState.set( 'image', this.model.attachment );
6200 this.controller.setState( 'edit-image' );
6204 replaceAttachment: function( event ) {
6205 event.preventDefault();
6206 this.controller.setState( 'replace-image' );
6210 module.exports = ImageDetails;
6212 },{}],49:[function(require,module,exports){
6214 * wp.media.view.Label
6217 * @augments wp.media.View
6218 * @augments wp.Backbone.View
6219 * @augments Backbone.View
6221 var Label = wp.media.View.extend({
6223 className: 'screen-reader-text',
6225 initialize: function() {
6226 this.value = this.options.value;
6229 render: function() {
6230 this.$el.html( this.value );
6236 module.exports = Label;
6238 },{}],50:[function(require,module,exports){
6240 * wp.media.view.MediaFrame
6242 * The frame used to create the media modal.
6245 * @augments wp.media.view.Frame
6246 * @augments wp.media.View
6247 * @augments wp.Backbone.View
6248 * @augments Backbone.View
6249 * @mixes wp.media.controller.StateMachine
6251 var Frame = wp.media.view.Frame,
6255 MediaFrame = Frame.extend({
6256 className: 'media-frame',
6257 template: wp.template('media-frame'),
6258 regions: ['menu','title','content','toolbar','router'],
6261 'click div.media-frame-title h1': 'toggleMenu'
6265 * @global wp.Uploader
6267 initialize: function() {
6268 Frame.prototype.initialize.apply( this, arguments );
6270 _.defaults( this.options, {
6276 // Ensure core UI is enabled.
6277 this.$el.addClass('wp-core-ui');
6279 // Initialize modal container view.
6280 if ( this.options.modal ) {
6281 this.modal = new wp.media.view.Modal({
6283 title: this.options.title
6286 this.modal.content( this );
6289 // Force the uploader off if the upload limit has been exceeded or
6290 // if the browser isn't supported.
6291 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
6292 this.options.uploader = false;
6295 // Initialize window-wide uploader.
6296 if ( this.options.uploader ) {
6297 this.uploader = new wp.media.view.UploaderWindow({
6300 dropzone: this.modal ? this.modal.$el : this.$el,
6304 this.views.set( '.media-frame-uploader', this.uploader );
6307 this.on( 'attach', _.bind( this.views.ready, this.views ), this );
6309 // Bind default title creation.
6310 this.on( 'title:create:default', this.createTitle, this );
6311 this.title.mode('default');
6313 this.on( 'title:render', function( view ) {
6314 view.$el.append( '<span class="dashicons dashicons-arrow-down"></span>' );
6317 // Bind default menu.
6318 this.on( 'menu:create:default', this.createMenu, this );
6321 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6323 render: function() {
6324 // Activate the default state if no active state exists.
6325 if ( ! this.state() && this.options.state ) {
6326 this.setState( this.options.state );
6329 * call 'render' directly on the parent class
6331 return Frame.prototype.render.apply( this, arguments );
6334 * @param {Object} title
6335 * @this wp.media.controller.Region
6337 createTitle: function( title ) {
6338 title.view = new wp.media.View({
6344 * @param {Object} menu
6345 * @this wp.media.controller.Region
6347 createMenu: function( menu ) {
6348 menu.view = new wp.media.view.Menu({
6353 toggleMenu: function() {
6354 this.$el.find( '.media-menu' ).toggleClass( 'visible' );
6358 * @param {Object} toolbar
6359 * @this wp.media.controller.Region
6361 createToolbar: function( toolbar ) {
6362 toolbar.view = new wp.media.view.Toolbar({
6367 * @param {Object} router
6368 * @this wp.media.controller.Region
6370 createRouter: function( router ) {
6371 router.view = new wp.media.view.Router({
6376 * @param {Object} options
6378 createIframeStates: function( options ) {
6379 var settings = wp.media.view.settings,
6380 tabs = settings.tabs,
6381 tabUrl = settings.tabUrl,
6384 if ( ! tabs || ! tabUrl ) {
6388 // Add the post ID to the tab URL if it exists.
6389 $postId = $('#post_ID');
6390 if ( $postId.length ) {
6391 tabUrl += '&post_id=' + $postId.val();
6394 // Generate the tab states.
6395 _.each( tabs, function( title, id ) {
6396 this.state( 'iframe:' + id ).set( _.defaults({
6398 src: tabUrl + '&tab=' + id,
6405 this.on( 'content:create:iframe', this.iframeContent, this );
6406 this.on( 'content:deactivate:iframe', this.iframeContentCleanup, this );
6407 this.on( 'menu:render:default', this.iframeMenu, this );
6408 this.on( 'open', this.hijackThickbox, this );
6409 this.on( 'close', this.restoreThickbox, this );
6413 * @param {Object} content
6414 * @this wp.media.controller.Region
6416 iframeContent: function( content ) {
6417 this.$el.addClass('hide-toolbar');
6418 content.view = new wp.media.view.Iframe({
6423 iframeContentCleanup: function() {
6424 this.$el.removeClass('hide-toolbar');
6427 iframeMenu: function( view ) {
6434 _.each( wp.media.view.settings.tabs, function( title, id ) {
6435 views[ 'iframe:' + id ] = {
6436 text: this.state( 'iframe:' + id ).get('title'),
6444 hijackThickbox: function() {
6447 if ( ! window.tb_remove || this._tb_remove ) {
6451 this._tb_remove = window.tb_remove;
6452 window.tb_remove = function() {
6455 frame.setState( frame.options.state );
6456 frame._tb_remove.call( window );
6460 restoreThickbox: function() {
6461 if ( ! this._tb_remove ) {
6465 window.tb_remove = this._tb_remove;
6466 delete this._tb_remove;
6470 // Map some of the modal's methods to the frame.
6471 _.each(['open','close','attach','detach','escape'], function( method ) {
6473 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining
6475 MediaFrame.prototype[ method ] = function() {
6477 this.modal[ method ].apply( this.modal, arguments );
6483 module.exports = MediaFrame;
6485 },{}],51:[function(require,module,exports){
6487 * wp.media.view.MenuItem
6490 * @augments wp.media.View
6491 * @augments wp.Backbone.View
6492 * @augments Backbone.View
6497 MenuItem = wp.media.View.extend({
6499 className: 'media-menu-item',
6509 * @param {Object} event
6511 _click: function( event ) {
6512 var clickOverride = this.options.click;
6515 event.preventDefault();
6518 if ( clickOverride ) {
6519 clickOverride.call( this );
6524 // When selecting a tab along the left side,
6525 // focus should be transferred into the main panel
6526 if ( ! wp.media.isTouchDevice ) {
6527 $('.media-frame-content input').first().focus();
6532 var state = this.options.state;
6535 this.controller.setState( state );
6536 this.views.parent.$el.removeClass( 'visible' ); // TODO: or hide on any click, see below
6540 * @returns {wp.media.view.MenuItem} returns itself to allow chaining
6542 render: function() {
6543 var options = this.options;
6545 if ( options.text ) {
6546 this.$el.text( options.text );
6547 } else if ( options.html ) {
6548 this.$el.html( options.html );
6555 module.exports = MenuItem;
6557 },{}],52:[function(require,module,exports){
6559 * wp.media.view.Menu
6562 * @augments wp.media.view.PriorityList
6563 * @augments wp.media.View
6564 * @augments wp.Backbone.View
6565 * @augments Backbone.View
6567 var MenuItem = wp.media.view.MenuItem,
6568 PriorityList = wp.media.view.PriorityList,
6571 Menu = PriorityList.extend({
6573 className: 'media-menu',
6578 /* TODO: alternatively hide on any click anywhere
6584 this.$el.removeClass( 'visible' );
6589 * @param {Object} options
6590 * @param {string} id
6591 * @returns {wp.media.View}
6593 toView: function( options, id ) {
6594 options = options || {};
6595 options[ this.property ] = options[ this.property ] || id;
6596 return new this.ItemView( options ).render();
6601 * call 'ready' directly on the parent class
6603 PriorityList.prototype.ready.apply( this, arguments );
6609 * call 'set' directly on the parent class
6611 PriorityList.prototype.set.apply( this, arguments );
6617 * call 'unset' directly on the parent class
6619 PriorityList.prototype.unset.apply( this, arguments );
6623 visibility: function() {
6624 var region = this.region,
6625 view = this.controller[ region ].get(),
6626 views = this.views.get(),
6627 hide = ! views || views.length < 2;
6629 if ( this === view ) {
6630 this.controller.$el.toggleClass( 'hide-' + region, hide );
6634 * @param {string} id
6636 select: function( id ) {
6637 var view = this.get( id );
6644 view.$el.addClass('active');
6647 deselect: function() {
6648 this.$el.children().removeClass('active');
6651 hide: function( id ) {
6652 var view = this.get( id );
6658 view.$el.addClass('hidden');
6661 show: function( id ) {
6662 var view = this.get( id );
6668 view.$el.removeClass('hidden');
6672 module.exports = Menu;
6674 },{}],53:[function(require,module,exports){
6676 * wp.media.view.Modal
6678 * A modal view, which the media modal uses as its default container.
6681 * @augments wp.media.View
6682 * @augments wp.Backbone.View
6683 * @augments Backbone.View
6688 Modal = wp.media.View.extend({
6690 template: wp.template('media-modal'),
6697 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler',
6698 'keydown': 'keydown'
6701 clickedOpenerEl: null,
6703 initialize: function() {
6704 _.defaults( this.options, {
6705 container: document.body,
6711 this.focusManager = new wp.media.view.FocusManager({
6718 prepare: function() {
6720 title: this.options.title
6725 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6727 attach: function() {
6728 if ( this.views.attached ) {
6732 if ( ! this.views.rendered ) {
6736 this.$el.appendTo( this.options.container );
6738 // Manually mark the view as attached and trigger ready.
6739 this.views.attached = true;
6742 return this.propagate('attach');
6746 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6748 detach: function() {
6749 if ( this.$el.is(':visible') ) {
6754 this.views.attached = false;
6755 return this.propagate('detach');
6759 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6763 options = this.options,
6766 if ( $el.is(':visible') ) {
6770 this.clickedOpenerEl = document.activeElement;
6772 if ( ! this.views.attached ) {
6776 // If the `freeze` option is set, record the window's scroll position.
6777 if ( options.freeze ) {
6779 scrollTop: $( window ).scrollTop()
6783 // Disable page scrolling.
6784 $( 'body' ).addClass( 'modal-open' );
6788 // Try to close the onscreen keyboard
6789 if ( 'ontouchend' in document ) {
6790 if ( ( mceEditor = window.tinymce && window.tinymce.activeEditor ) && ! mceEditor.isHidden() && mceEditor.iframeElement ) {
6791 mceEditor.iframeElement.focus();
6792 mceEditor.iframeElement.blur();
6794 setTimeout( function() {
6795 mceEditor.iframeElement.blur();
6802 return this.propagate('open');
6806 * @param {Object} options
6807 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6809 close: function( options ) {
6810 var freeze = this._freeze;
6812 if ( ! this.views.attached || ! this.$el.is(':visible') ) {
6816 // Enable page scrolling.
6817 $( 'body' ).removeClass( 'modal-open' );
6819 // Hide modal and remove restricted media modal tab focus once it's closed
6820 this.$el.hide().undelegate( 'keydown' );
6822 // Put focus back in useful location once modal is closed.
6823 if ( null !== this.clickedOpenerEl ) {
6824 this.clickedOpenerEl.focus();
6826 $( '#wpbody-content' ).focus();
6829 this.propagate('close');
6831 // If the `freeze` option is set, restore the container's scroll position.
6833 $( window ).scrollTop( freeze.scrollTop );
6836 if ( options && options.escape ) {
6837 this.propagate('escape');
6843 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6845 escape: function() {
6846 return this.close({ escape: true });
6849 * @param {Object} event
6851 escapeHandler: function( event ) {
6852 event.preventDefault();
6857 * @param {Array|Object} content Views to register to '.media-modal-content'
6858 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6860 content: function( content ) {
6861 this.views.set( '.media-modal-content', content );
6866 * Triggers a modal event and if the `propagate` option is set,
6867 * forwards events to the modal's controller.
6869 * @param {string} id
6870 * @returns {wp.media.view.Modal} Returns itself to allow chaining
6872 propagate: function( id ) {
6875 if ( this.options.propagate ) {
6876 this.controller.trigger( id );
6882 * @param {Object} event
6884 keydown: function( event ) {
6885 // Close the modal when escape is pressed.
6886 if ( 27 === event.which && this.$el.is(':visible') ) {
6888 event.stopImmediatePropagation();
6893 module.exports = Modal;
6895 },{}],54:[function(require,module,exports){
6897 * wp.media.view.PriorityList
6900 * @augments wp.media.View
6901 * @augments wp.Backbone.View
6902 * @augments Backbone.View
6904 var PriorityList = wp.media.View.extend({
6907 initialize: function() {
6910 this.set( _.extend( {}, this._views, this.options.views ), { silent: true });
6911 delete this.options.views;
6913 if ( ! this.options.silent ) {
6918 * @param {string} id
6919 * @param {wp.media.View|Object} view
6920 * @param {Object} options
6921 * @returns {wp.media.view.PriorityList} Returns itself to allow chaining
6923 set: function( id, view, options ) {
6924 var priority, views, index;
6926 options = options || {};
6928 // Accept an object with an `id` : `view` mapping.
6929 if ( _.isObject( id ) ) {
6930 _.each( id, function( view, id ) {
6931 this.set( id, view );
6936 if ( ! (view instanceof Backbone.View) ) {
6937 view = this.toView( view, id, options );
6939 view.controller = view.controller || this.controller;
6943 priority = view.options.priority || 10;
6944 views = this.views.get() || [];
6946 _.find( views, function( existing, i ) {
6947 if ( existing.options.priority > priority ) {
6953 this._views[ id ] = view;
6954 this.views.add( view, {
6955 at: _.isNumber( index ) ? index : views.length || 0
6961 * @param {string} id
6962 * @returns {wp.media.View}
6964 get: function( id ) {
6965 return this._views[ id ];
6968 * @param {string} id
6969 * @returns {wp.media.view.PriorityList}
6971 unset: function( id ) {
6972 var view = this.get( id );
6978 delete this._views[ id ];
6982 * @param {Object} options
6983 * @returns {wp.media.View}
6985 toView: function( options ) {
6986 return new wp.media.View( options );
6990 module.exports = PriorityList;
6992 },{}],55:[function(require,module,exports){
6994 * wp.media.view.RouterItem
6997 * @augments wp.media.view.MenuItem
6998 * @augments wp.media.View
6999 * @augments wp.Backbone.View
7000 * @augments Backbone.View
7002 var RouterItem = wp.media.view.MenuItem.extend({
7004 * On click handler to activate the content region's corresponding mode.
7007 var contentMode = this.options.contentMode;
7008 if ( contentMode ) {
7009 this.controller.content.mode( contentMode );
7014 module.exports = RouterItem;
7016 },{}],56:[function(require,module,exports){
7018 * wp.media.view.Router
7021 * @augments wp.media.view.Menu
7022 * @augments wp.media.view.PriorityList
7023 * @augments wp.media.View
7024 * @augments wp.Backbone.View
7025 * @augments Backbone.View
7027 var Menu = wp.media.view.Menu,
7030 Router = Menu.extend({
7032 className: 'media-router',
7033 property: 'contentMode',
7034 ItemView: wp.media.view.RouterItem,
7037 initialize: function() {
7038 this.controller.on( 'content:render', this.update, this );
7039 // Call 'initialize' directly on the parent class.
7040 Menu.prototype.initialize.apply( this, arguments );
7043 update: function() {
7044 var mode = this.controller.content.mode();
7046 this.select( mode );
7051 module.exports = Router;
7053 },{}],57:[function(require,module,exports){
7055 * wp.media.view.Search
7058 * @augments wp.media.View
7059 * @augments wp.Backbone.View
7060 * @augments Backbone.View
7062 var l10n = wp.media.view.l10n,
7065 Search = wp.media.View.extend({
7067 className: 'search',
7068 id: 'media-search-input',
7072 placeholder: l10n.searchMediaPlaceholder
7083 * @returns {wp.media.view.Search} Returns itself to allow chaining
7085 render: function() {
7086 this.el.value = this.model.escape('search');
7090 search: function( event ) {
7091 if ( event.target.value ) {
7092 this.model.set( 'search', event.target.value );
7094 this.model.unset('search');
7099 module.exports = Search;
7101 },{}],58:[function(require,module,exports){
7103 * wp.media.view.Selection
7106 * @augments wp.media.View
7107 * @augments wp.Backbone.View
7108 * @augments Backbone.View
7110 var l10n = wp.media.view.l10n,
7113 Selection = wp.media.View.extend({
7115 className: 'media-selection',
7116 template: wp.template('media-selection'),
7119 'click .edit-selection': 'edit',
7120 'click .clear-selection': 'clear'
7123 initialize: function() {
7124 _.defaults( this.options, {
7130 * @member {wp.media.view.Attachments.Selection}
7132 this.attachments = new wp.media.view.Attachments.Selection({
7133 controller: this.controller,
7134 collection: this.collection,
7135 selection: this.collection,
7136 model: new Backbone.Model()
7139 this.views.set( '.selection-view', this.attachments );
7140 this.collection.on( 'add remove reset', this.refresh, this );
7141 this.controller.on( 'content:activate', this.refresh, this );
7148 refresh: function() {
7149 // If the selection hasn't been rendered, bail.
7150 if ( ! this.$el.children().length ) {
7154 var collection = this.collection,
7155 editing = 'edit-selection' === this.controller.content.mode();
7157 // If nothing is selected, display nothing.
7158 this.$el.toggleClass( 'empty', ! collection.length );
7159 this.$el.toggleClass( 'one', 1 === collection.length );
7160 this.$el.toggleClass( 'editing', editing );
7162 this.$('.count').text( l10n.selected.replace('%d', collection.length) );
7165 edit: function( event ) {
7166 event.preventDefault();
7167 if ( this.options.editable ) {
7168 this.options.editable.call( this, this.collection );
7172 clear: function( event ) {
7173 event.preventDefault();
7174 this.collection.reset();
7176 // Keep focus inside media modal
7177 // after clear link is selected
7178 this.controller.modal.focusManager.focus();
7182 module.exports = Selection;
7184 },{}],59:[function(require,module,exports){
7186 * wp.media.view.Settings
7189 * @augments wp.media.View
7190 * @augments wp.Backbone.View
7191 * @augments Backbone.View
7193 var View = wp.media.View,
7197 Settings = View.extend({
7199 'click button': 'updateHandler',
7200 'change input': 'updateHandler',
7201 'change select': 'updateHandler',
7202 'change textarea': 'updateHandler'
7205 initialize: function() {
7206 this.model = this.model || new Backbone.Model();
7207 this.listenTo( this.model, 'change', this.updateChanges );
7210 prepare: function() {
7212 model: this.model.toJSON()
7216 * @returns {wp.media.view.Settings} Returns itself to allow chaining
7218 render: function() {
7219 View.prototype.render.apply( this, arguments );
7220 // Select the correct values.
7221 _( this.model.attributes ).chain().keys().each( this.update, this );
7225 * @param {string} key
7227 update: function( key ) {
7228 var value = this.model.get( key ),
7229 $setting = this.$('[data-setting="' + key + '"]'),
7232 // Bail if we didn't find a matching setting.
7233 if ( ! $setting.length ) {
7237 // Attempt to determine how the setting is rendered and update
7238 // the selected value.
7240 // Handle dropdowns.
7241 if ( $setting.is('select') ) {
7242 $value = $setting.find('[value="' + value + '"]');
7244 if ( $value.length ) {
7245 $setting.find('option').prop( 'selected', false );
7246 $value.prop( 'selected', true );
7248 // If we can't find the desired value, record what *is* selected.
7249 this.model.set( key, $setting.find(':selected').val() );
7252 // Handle button groups.
7253 } else if ( $setting.hasClass('button-group') ) {
7254 $buttons = $setting.find('button').removeClass('active');
7255 $buttons.filter( '[value="' + value + '"]' ).addClass('active');
7257 // Handle text inputs and textareas.
7258 } else if ( $setting.is('input[type="text"], textarea') ) {
7259 if ( ! $setting.is(':focus') ) {
7260 $setting.val( value );
7262 // Handle checkboxes.
7263 } else if ( $setting.is('input[type="checkbox"]') ) {
7264 $setting.prop( 'checked', !! value && 'false' !== value );
7268 * @param {Object} event
7270 updateHandler: function( event ) {
7271 var $setting = $( event.target ).closest('[data-setting]'),
7272 value = event.target.value,
7275 event.preventDefault();
7277 if ( ! $setting.length ) {
7281 // Use the correct value for checkboxes.
7282 if ( $setting.is('input[type="checkbox"]') ) {
7283 value = $setting[0].checked;
7286 // Update the corresponding setting.
7287 this.model.set( $setting.data('setting'), value );
7289 // If the setting has a corresponding user setting,
7290 // update that as well.
7291 if ( userSetting = $setting.data('userSetting') ) {
7292 window.setUserSetting( userSetting, value );
7296 updateChanges: function( model ) {
7297 if ( model.hasChanged() ) {
7298 _( model.changed ).chain().keys().each( this.update, this );
7303 module.exports = Settings;
7305 },{}],60:[function(require,module,exports){
7307 * wp.media.view.Settings.AttachmentDisplay
7310 * @augments wp.media.view.Settings
7311 * @augments wp.media.View
7312 * @augments wp.Backbone.View
7313 * @augments Backbone.View
7315 var Settings = wp.media.view.Settings,
7318 AttachmentDisplay = Settings.extend({
7319 className: 'attachment-display-settings',
7320 template: wp.template('attachment-display-settings'),
7322 initialize: function() {
7323 var attachment = this.options.attachment;
7325 _.defaults( this.options, {
7328 // Call 'initialize' directly on the parent class.
7329 Settings.prototype.initialize.apply( this, arguments );
7330 this.listenTo( this.model, 'change:link', this.updateLinkTo );
7333 attachment.on( 'change:uploading', this.render, this );
7337 dispose: function() {
7338 var attachment = this.options.attachment;
7340 attachment.off( null, null, this );
7343 * call 'dispose' directly on the parent class
7345 Settings.prototype.dispose.apply( this, arguments );
7348 * @returns {wp.media.view.AttachmentDisplay} Returns itself to allow chaining
7350 render: function() {
7351 var attachment = this.options.attachment;
7353 _.extend( this.options, {
7354 sizes: attachment.get('sizes'),
7355 type: attachment.get('type')
7359 * call 'render' directly on the parent class
7361 Settings.prototype.render.call( this );
7362 this.updateLinkTo();
7366 updateLinkTo: function() {
7367 var linkTo = this.model.get('link'),
7368 $input = this.$('.link-to-custom'),
7369 attachment = this.options.attachment;
7371 if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
7372 $input.addClass( 'hidden' );
7377 if ( 'post' === linkTo ) {
7378 $input.val( attachment.get('link') );
7379 } else if ( 'file' === linkTo ) {
7380 $input.val( attachment.get('url') );
7381 } else if ( ! this.model.get('linkUrl') ) {
7382 $input.val('http://');
7385 $input.prop( 'readonly', 'custom' !== linkTo );
7388 $input.removeClass( 'hidden' );
7390 // If the input is visible, focus and select its contents.
7391 if ( ! wp.media.isTouchDevice && $input.is(':visible') ) {
7392 $input.focus()[0].select();
7397 module.exports = AttachmentDisplay;
7399 },{}],61:[function(require,module,exports){
7401 * wp.media.view.Settings.Gallery
7404 * @augments wp.media.view.Settings
7405 * @augments wp.media.View
7406 * @augments wp.Backbone.View
7407 * @augments Backbone.View
7409 var Gallery = wp.media.view.Settings.extend({
7410 className: 'collection-settings gallery-settings',
7411 template: wp.template('gallery-settings')
7414 module.exports = Gallery;
7416 },{}],62:[function(require,module,exports){
7418 * wp.media.view.Settings.Playlist
7421 * @augments wp.media.view.Settings
7422 * @augments wp.media.View
7423 * @augments wp.Backbone.View
7424 * @augments Backbone.View
7426 var Playlist = wp.media.view.Settings.extend({
7427 className: 'collection-settings playlist-settings',
7428 template: wp.template('playlist-settings')
7431 module.exports = Playlist;
7433 },{}],63:[function(require,module,exports){
7435 * wp.media.view.Sidebar
7438 * @augments wp.media.view.PriorityList
7439 * @augments wp.media.View
7440 * @augments wp.Backbone.View
7441 * @augments Backbone.View
7443 var Sidebar = wp.media.view.PriorityList.extend({
7444 className: 'media-sidebar'
7447 module.exports = Sidebar;
7449 },{}],64:[function(require,module,exports){
7451 * wp.media.view.SiteIconCropper
7453 * Uses the imgAreaSelect plugin to allow a user to crop a Site Icon.
7455 * Takes imgAreaSelect options from
7456 * wp.customize.SiteIconControl.calculateImageSelectOptions.
7459 * @augments wp.media.view.Cropper
7460 * @augments wp.media.View
7461 * @augments wp.Backbone.View
7462 * @augments Backbone.View
7464 var View = wp.media.view,
7467 SiteIconCropper = View.Cropper.extend({
7468 className: 'crop-content site-icon',
7470 ready: function () {
7471 View.Cropper.prototype.ready.apply( this, arguments );
7473 this.$( '.crop-image' ).on( 'load', _.bind( this.addSidebar, this ) );
7476 addSidebar: function() {
7477 this.sidebar = new wp.media.view.Sidebar({
7478 controller: this.controller
7481 this.sidebar.set( 'preview', new wp.media.view.SiteIconPreview({
7482 controller: this.controller,
7483 attachment: this.options.attachment
7486 this.controller.cropperView.views.add( this.sidebar );
7490 module.exports = SiteIconCropper;
7492 },{}],65:[function(require,module,exports){
7494 * wp.media.view.SiteIconPreview
7496 * Shows a preview of the Site Icon as a favicon and app icon while cropping.
7499 * @augments wp.media.View
7500 * @augments wp.Backbone.View
7501 * @augments Backbone.View
7503 var View = wp.media.View,
7507 SiteIconPreview = View.extend({
7508 className: 'site-icon-preview',
7509 template: wp.template( 'site-icon-preview' ),
7512 this.controller.imgSelect.setOptions({
7513 onInit: this.updatePreview,
7514 onSelectChange: this.updatePreview
7518 prepare: function() {
7520 url: this.options.attachment.get( 'url' )
7524 updatePreview: function( img, coords ) {
7525 var rx = 64 / coords.width,
7526 ry = 64 / coords.height,
7527 preview_rx = 16 / coords.width,
7528 preview_ry = 16 / coords.height;
7530 $( '#preview-app-icon' ).css({
7531 width: Math.round(rx * this.imageWidth ) + 'px',
7532 height: Math.round(ry * this.imageHeight ) + 'px',
7533 marginLeft: '-' + Math.round(rx * coords.x1) + 'px',
7534 marginTop: '-' + Math.round(ry * coords.y1) + 'px'
7537 $( '#preview-favicon' ).css({
7538 width: Math.round( preview_rx * this.imageWidth ) + 'px',
7539 height: Math.round( preview_ry * this.imageHeight ) + 'px',
7540 marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px',
7541 marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px'
7546 module.exports = SiteIconPreview;
7548 },{}],66:[function(require,module,exports){
7550 * wp.media.view.Spinner
7553 * @augments wp.media.View
7554 * @augments wp.Backbone.View
7555 * @augments Backbone.View
7557 var Spinner = wp.media.View.extend({
7559 className: 'spinner',
7560 spinnerTimeout: false,
7564 if ( ! this.spinnerTimeout ) {
7565 this.spinnerTimeout = _.delay(function( $el ) {
7566 $el.addClass( 'is-active' );
7567 }, this.delay, this.$el );
7574 this.$el.removeClass( 'is-active' );
7575 this.spinnerTimeout = clearTimeout( this.spinnerTimeout );
7581 module.exports = Spinner;
7583 },{}],67:[function(require,module,exports){
7585 * wp.media.view.Toolbar
7587 * A toolbar which consists of a primary and a secondary section. Each sections
7588 * can be filled with views.
7591 * @augments wp.media.View
7592 * @augments wp.Backbone.View
7593 * @augments Backbone.View
7595 var View = wp.media.View,
7598 Toolbar = View.extend({
7600 className: 'media-toolbar',
7602 initialize: function() {
7603 var state = this.controller.state(),
7604 selection = this.selection = state.get('selection'),
7605 library = this.library = state.get('library');
7609 // The toolbar is composed of two `PriorityList` views.
7610 this.primary = new wp.media.view.PriorityList();
7611 this.secondary = new wp.media.view.PriorityList();
7612 this.primary.$el.addClass('media-toolbar-primary search-form');
7613 this.secondary.$el.addClass('media-toolbar-secondary');
7615 this.views.set([ this.secondary, this.primary ]);
7617 if ( this.options.items ) {
7618 this.set( this.options.items, { silent: true });
7621 if ( ! this.options.silent ) {
7626 selection.on( 'add remove reset', this.refresh, this );
7630 library.on( 'add remove reset', this.refresh, this );
7634 * @returns {wp.media.view.Toolbar} Returns itsef to allow chaining
7636 dispose: function() {
7637 if ( this.selection ) {
7638 this.selection.off( null, null, this );
7641 if ( this.library ) {
7642 this.library.off( null, null, this );
7645 * call 'dispose' directly on the parent class
7647 return View.prototype.dispose.apply( this, arguments );
7655 * @param {string} id
7656 * @param {Backbone.View|Object} view
7657 * @param {Object} [options={}]
7658 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7660 set: function( id, view, options ) {
7662 options = options || {};
7664 // Accept an object with an `id` : `view` mapping.
7665 if ( _.isObject( id ) ) {
7666 _.each( id, function( view, id ) {
7667 this.set( id, view, { silent: true });
7671 if ( ! ( view instanceof Backbone.View ) ) {
7672 view.classes = [ 'media-button-' + id ].concat( view.classes || [] );
7673 view = new wp.media.view.Button( view ).render();
7676 view.controller = view.controller || this.controller;
7678 this._views[ id ] = view;
7680 list = view.options.priority < 0 ? 'secondary' : 'primary';
7681 this[ list ].set( id, view, options );
7684 if ( ! options.silent ) {
7691 * @param {string} id
7692 * @returns {wp.media.view.Button}
7694 get: function( id ) {
7695 return this._views[ id ];
7698 * @param {string} id
7699 * @param {Object} options
7700 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining
7702 unset: function( id, options ) {
7703 delete this._views[ id ];
7704 this.primary.unset( id, options );
7705 this.secondary.unset( id, options );
7707 if ( ! options || ! options.silent ) {
7713 refresh: function() {
7714 var state = this.controller.state(),
7715 library = state.get('library'),
7716 selection = state.get('selection');
7718 _.each( this._views, function( button ) {
7719 if ( ! button.model || ! button.options || ! button.options.requires ) {
7723 var requires = button.options.requires,
7726 // Prevent insertion of attachments if any of them are still uploading
7727 disabled = _.some( selection.models, function( attachment ) {
7728 return attachment.get('uploading') === true;
7731 if ( requires.selection && selection && ! selection.length ) {
7733 } else if ( requires.library && library && ! library.length ) {
7736 button.model.set( 'disabled', disabled );
7741 module.exports = Toolbar;
7743 },{}],68:[function(require,module,exports){
7745 * wp.media.view.Toolbar.Embed
7748 * @augments wp.media.view.Toolbar.Select
7749 * @augments wp.media.view.Toolbar
7750 * @augments wp.media.View
7751 * @augments wp.Backbone.View
7752 * @augments Backbone.View
7754 var Select = wp.media.view.Toolbar.Select,
7755 l10n = wp.media.view.l10n,
7758 Embed = Select.extend({
7759 initialize: function() {
7760 _.defaults( this.options, {
7761 text: l10n.insertIntoPost,
7764 // Call 'initialize' directly on the parent class.
7765 Select.prototype.initialize.apply( this, arguments );
7768 refresh: function() {
7769 var url = this.controller.state().props.get('url');
7770 this.get('select').model.set( 'disabled', ! url || url === 'http://' );
7772 * call 'refresh' directly on the parent class
7774 Select.prototype.refresh.apply( this, arguments );
7778 module.exports = Embed;
7780 },{}],69:[function(require,module,exports){
7782 * wp.media.view.Toolbar.Select
7785 * @augments wp.media.view.Toolbar
7786 * @augments wp.media.View
7787 * @augments wp.Backbone.View
7788 * @augments Backbone.View
7790 var Toolbar = wp.media.view.Toolbar,
7791 l10n = wp.media.view.l10n,
7794 Select = Toolbar.extend({
7795 initialize: function() {
7796 var options = this.options;
7798 _.bindAll( this, 'clickSelect' );
7800 _.defaults( options, {
7807 // Does the button rely on the selection?
7813 options.items = _.defaults( options.items || {}, {
7818 click: this.clickSelect,
7819 requires: options.requires
7822 // Call 'initialize' directly on the parent class.
7823 Toolbar.prototype.initialize.apply( this, arguments );
7826 clickSelect: function() {
7827 var options = this.options,
7828 controller = this.controller;
7830 if ( options.close ) {
7834 if ( options.event ) {
7835 controller.state().trigger( options.event );
7838 if ( options.state ) {
7839 controller.setState( options.state );
7842 if ( options.reset ) {
7848 module.exports = Select;
7850 },{}],70:[function(require,module,exports){
7852 * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap)
7853 * and relays drag'n'dropped files to a media workflow.
7855 * wp.media.view.EditorUploader
7858 * @augments wp.media.View
7859 * @augments wp.Backbone.View
7860 * @augments Backbone.View
7862 var View = wp.media.View,
7863 l10n = wp.media.view.l10n,
7867 EditorUploader = View.extend({
7869 className: 'uploader-editor',
7870 template: wp.template( 'uploader-editor' ),
7873 overContainer: false,
7874 overDropzone: false,
7878 * Bind drag'n'drop events to callbacks.
7880 initialize: function() {
7881 this.initialized = false;
7883 // Bail if not enabled or UA does not support drag'n'drop or File API.
7884 if ( ! window.tinyMCEPreInit || ! window.tinyMCEPreInit.dragDropUpload || ! this.browserSupport() ) {
7888 this.$document = $(document);
7889 this.dropzones = [];
7892 this.$document.on( 'drop', '.uploader-editor', _.bind( this.drop, this ) );
7893 this.$document.on( 'dragover', '.uploader-editor', _.bind( this.dropzoneDragover, this ) );
7894 this.$document.on( 'dragleave', '.uploader-editor', _.bind( this.dropzoneDragleave, this ) );
7895 this.$document.on( 'click', '.uploader-editor', _.bind( this.click, this ) );
7897 this.$document.on( 'dragover', _.bind( this.containerDragover, this ) );
7898 this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
7900 this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
7901 this.localDrag = event.type === 'dragstart';
7903 if ( event.type === 'drop' ) {
7904 this.containerDragleave();
7908 this.initialized = true;
7913 * Check browser support for drag'n'drop.
7917 browserSupport: function() {
7918 var supports = false, div = document.createElement('div');
7920 supports = ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div );
7921 supports = supports && !! ( window.File && window.FileList && window.FileReader );
7925 isDraggingFile: function( event ) {
7926 if ( this.draggingFile !== null ) {
7927 return this.draggingFile;
7930 if ( _.isUndefined( event.originalEvent ) || _.isUndefined( event.originalEvent.dataTransfer ) ) {
7934 this.draggingFile = _.indexOf( event.originalEvent.dataTransfer.types, 'Files' ) > -1 &&
7935 _.indexOf( event.originalEvent.dataTransfer.types, 'text/plain' ) === -1;
7937 return this.draggingFile;
7940 refresh: function( e ) {
7942 for ( dropzone_id in this.dropzones ) {
7943 // Hide the dropzones only if dragging has left the screen.
7944 this.dropzones[ dropzone_id ].toggle( this.overContainer || this.overDropzone );
7947 if ( ! _.isUndefined( e ) ) {
7948 $( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone );
7951 if ( ! this.overContainer && ! this.overDropzone ) {
7952 this.draggingFile = null;
7958 render: function() {
7959 if ( ! this.initialized ) {
7963 View.prototype.render.apply( this, arguments );
7964 $( '.wp-editor-wrap' ).each( _.bind( this.attach, this ) );
7968 attach: function( index, editor ) {
7969 // Attach a dropzone to an editor.
7970 var dropzone = this.$el.clone();
7971 this.dropzones.push( dropzone );
7972 $( editor ).append( dropzone );
7977 * When a file is dropped on the editor uploader, open up an editor media workflow
7978 * and upload the file immediately.
7980 * @param {jQuery.Event} event The 'drop' event.
7982 drop: function( event ) {
7983 var $wrap, uploadView;
7985 this.containerDragleave( event );
7986 this.dropzoneDragleave( event );
7988 this.files = event.originalEvent.dataTransfer.files;
7989 if ( this.files.length < 1 ) {
7993 // Set the active editor to the drop target.
7994 $wrap = $( event.target ).parents( '.wp-editor-wrap' );
7995 if ( $wrap.length > 0 && $wrap[0].id ) {
7996 window.wpActiveEditor = $wrap[0].id.slice( 3, -5 );
7999 if ( ! this.workflow ) {
8000 this.workflow = wp.media.editor.open( window.wpActiveEditor, {
8003 title: l10n.addMedia,
8007 uploadView = this.workflow.uploader;
8009 if ( uploadView.uploader && uploadView.uploader.ready ) {
8010 this.addFiles.apply( this );
8012 this.workflow.on( 'uploader:ready', this.addFiles, this );
8015 this.workflow.state().reset();
8016 this.addFiles.apply( this );
8017 this.workflow.open();
8024 * Add the files to the uploader.
8026 addFiles: function() {
8027 if ( this.files.length ) {
8028 this.workflow.uploader.uploader.uploader.addFile( _.toArray( this.files ) );
8034 containerDragover: function( event ) {
8035 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
8039 this.overContainer = true;
8043 containerDragleave: function() {
8044 this.overContainer = false;
8046 // Throttle dragleave because it's called when bouncing from some elements to others.
8047 _.delay( _.bind( this.refresh, this ), 50 );
8050 dropzoneDragover: function( event ) {
8051 if ( this.localDrag || ! this.isDraggingFile( event ) ) {
8055 this.overDropzone = true;
8056 this.refresh( event );
8060 dropzoneDragleave: function( e ) {
8061 this.overDropzone = false;
8062 _.delay( _.bind( this.refresh, this, e ), 50 );
8065 click: function( e ) {
8066 // In the rare case where the dropzone gets stuck, hide it on click.
8067 this.containerDragleave( e );
8068 this.dropzoneDragleave( e );
8069 this.localDrag = false;
8073 module.exports = EditorUploader;
8075 },{}],71:[function(require,module,exports){
8077 * wp.media.view.UploaderInline
8079 * The inline uploader that shows up in the 'Upload Files' tab.
8082 * @augments wp.media.View
8083 * @augments wp.Backbone.View
8084 * @augments Backbone.View
8086 var View = wp.media.View,
8089 UploaderInline = View.extend({
8091 className: 'uploader-inline',
8092 template: wp.template('uploader-inline'),
8095 'click .close': 'hide'
8098 initialize: function() {
8099 _.defaults( this.options, {
8105 if ( ! this.options.$browser && this.controller.uploader ) {
8106 this.options.$browser = this.controller.uploader.$browser;
8109 if ( _.isUndefined( this.options.postId ) ) {
8110 this.options.postId = wp.media.view.settings.post.id;
8113 if ( this.options.status ) {
8114 this.views.set( '.upload-inline-status', new wp.media.view.UploaderStatus({
8115 controller: this.controller
8120 prepare: function() {
8121 var suggestedWidth = this.controller.state().get('suggestedWidth'),
8122 suggestedHeight = this.controller.state().get('suggestedHeight'),
8125 data.message = this.options.message;
8126 data.canClose = this.options.canClose;
8128 if ( suggestedWidth && suggestedHeight ) {
8129 data.suggestedWidth = suggestedWidth;
8130 data.suggestedHeight = suggestedHeight;
8136 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8138 dispose: function() {
8139 if ( this.disposing ) {
8141 * call 'dispose' directly on the parent class
8143 return View.prototype.dispose.apply( this, arguments );
8146 // Run remove on `dispose`, so we can be sure to refresh the
8147 // uploader with a view-less DOM. Track whether we're disposing
8148 // so we don't trigger an infinite loop.
8149 this.disposing = true;
8150 return this.remove();
8153 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
8155 remove: function() {
8157 * call 'remove' directly on the parent class
8159 var result = View.prototype.remove.apply( this, arguments );
8161 _.defer( _.bind( this.refresh, this ) );
8165 refresh: function() {
8166 var uploader = this.controller.uploader;
8173 * @returns {wp.media.view.UploaderInline}
8176 var $browser = this.options.$browser,
8179 if ( this.controller.uploader ) {
8180 $placeholder = this.$('.browser');
8182 // Check if we've already replaced the placeholder.
8183 if ( $placeholder[0] === $browser[0] ) {
8187 $browser.detach().text( $placeholder.text() );
8188 $browser[0].className = $placeholder[0].className;
8189 $placeholder.replaceWith( $browser.show() );
8196 this.$el.removeClass( 'hidden' );
8199 this.$el.addClass( 'hidden' );
8204 module.exports = UploaderInline;
8206 },{}],72:[function(require,module,exports){
8208 * wp.media.view.UploaderStatusError
8211 * @augments wp.media.View
8212 * @augments wp.Backbone.View
8213 * @augments Backbone.View
8215 var UploaderStatusError = wp.media.View.extend({
8216 className: 'upload-error',
8217 template: wp.template('uploader-status-error')
8220 module.exports = UploaderStatusError;
8222 },{}],73:[function(require,module,exports){
8224 * wp.media.view.UploaderStatus
8226 * An uploader status for on-going uploads.
8229 * @augments wp.media.View
8230 * @augments wp.Backbone.View
8231 * @augments Backbone.View
8233 var View = wp.media.View,
8236 UploaderStatus = View.extend({
8237 className: 'media-uploader-status',
8238 template: wp.template('uploader-status'),
8241 'click .upload-dismiss-errors': 'dismiss'
8244 initialize: function() {
8245 this.queue = wp.Uploader.queue;
8246 this.queue.on( 'add remove reset', this.visibility, this );
8247 this.queue.on( 'add remove reset change:percent', this.progress, this );
8248 this.queue.on( 'add remove reset change:uploading', this.info, this );
8250 this.errors = wp.Uploader.errors;
8251 this.errors.reset();
8252 this.errors.on( 'add remove reset', this.visibility, this );
8253 this.errors.on( 'add', this.error, this );
8256 * @global wp.Uploader
8257 * @returns {wp.media.view.UploaderStatus}
8259 dispose: function() {
8260 wp.Uploader.queue.off( null, null, this );
8262 * call 'dispose' directly on the parent class
8264 View.prototype.dispose.apply( this, arguments );
8268 visibility: function() {
8269 this.$el.toggleClass( 'uploading', !! this.queue.length );
8270 this.$el.toggleClass( 'errors', !! this.errors.length );
8271 this.$el.toggle( !! this.queue.length || !! this.errors.length );
8276 '$bar': '.media-progress-bar div',
8277 '$index': '.upload-index',
8278 '$total': '.upload-total',
8279 '$filename': '.upload-filename'
8280 }, function( selector, key ) {
8281 this[ key ] = this.$( selector );
8289 progress: function() {
8290 var queue = this.queue,
8293 if ( ! $bar || ! queue.length ) {
8297 $bar.width( ( queue.reduce( function( memo, attachment ) {
8298 if ( ! attachment.get('uploading') ) {
8302 var percent = attachment.get('percent');
8303 return memo + ( _.isNumber( percent ) ? percent : 100 );
8304 }, 0 ) / queue.length ) + '%' );
8308 var queue = this.queue,
8311 if ( ! queue.length ) {
8315 active = this.queue.find( function( attachment, i ) {
8317 return attachment.get('uploading');
8320 this.$index.text( index + 1 );
8321 this.$total.text( queue.length );
8322 this.$filename.html( active ? this.filename( active.get('filename') ) : '' );
8325 * @param {string} filename
8328 filename: function( filename ) {
8329 return _.escape( filename );
8332 * @param {Backbone.Model} error
8334 error: function( error ) {
8335 this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
8336 filename: this.filename( error.get('file').name ),
8337 message: error.get('message')
8342 * @global wp.Uploader
8344 * @param {Object} event
8346 dismiss: function( event ) {
8347 var errors = this.views.get('.upload-errors');
8349 event.preventDefault();
8352 _.invoke( errors, 'remove' );
8354 wp.Uploader.errors.reset();
8358 module.exports = UploaderStatus;
8360 },{}],74:[function(require,module,exports){
8362 * wp.media.view.UploaderWindow
8364 * An uploader window that allows for dragging and dropping media.
8367 * @augments wp.media.View
8368 * @augments wp.Backbone.View
8369 * @augments Backbone.View
8371 * @param {object} [options] Options hash passed to the view.
8372 * @param {object} [options.uploader] Uploader properties.
8373 * @param {jQuery} [options.uploader.browser]
8374 * @param {jQuery} [options.uploader.dropzone] jQuery collection of the dropzone.
8375 * @param {object} [options.uploader.params]
8380 UploaderWindow = wp.media.View.extend({
8382 className: 'uploader-window',
8383 template: wp.template('uploader-window'),
8385 initialize: function() {
8388 this.$browser = $('<a href="#" class="browser" />').hide().appendTo('body');
8390 uploader = this.options.uploader = _.defaults( this.options.uploader || {}, {
8392 browser: this.$browser,
8396 // Ensure the dropzone is a jQuery collection.
8397 if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) {
8398 uploader.dropzone = $( uploader.dropzone );
8401 this.controller.on( 'activate', this.refresh, this );
8403 this.controller.on( 'detach', function() {
8404 this.$browser.remove();
8408 refresh: function() {
8409 if ( this.uploader ) {
8410 this.uploader.refresh();
8415 var postId = wp.media.view.settings.post.id,
8418 // If the uploader already exists, bail.
8419 if ( this.uploader ) {
8424 this.options.uploader.params.post_id = postId;
8426 this.uploader = new wp.Uploader( this.options.uploader );
8428 dropzone = this.uploader.dropzone;
8429 dropzone.on( 'dropzone:enter', _.bind( this.show, this ) );
8430 dropzone.on( 'dropzone:leave', _.bind( this.hide, this ) );
8432 $( this.uploader ).on( 'uploader:ready', _.bind( this._ready, this ) );
8435 _ready: function() {
8436 this.controller.trigger( 'uploader:ready' );
8440 var $el = this.$el.show();
8442 // Ensure that the animation is triggered by waiting until
8443 // the transparent element is painted into the DOM.
8444 _.defer( function() {
8445 $el.css({ opacity: 1 });
8450 var $el = this.$el.css({ opacity: 0 });
8452 wp.media.transition( $el ).done( function() {
8453 // Transition end events are subject to race conditions.
8454 // Make sure that the value is set as intended.
8455 if ( '0' === $el.css('opacity') ) {
8460 // https://core.trac.wordpress.org/ticket/27341
8461 _.delay( function() {
8462 if ( '0' === $el.css('opacity') && $el.is(':visible') ) {
8469 module.exports = UploaderWindow;
8471 },{}],75:[function(require,module,exports){
8475 * The base view class for media.
8477 * Undelegating events, removing events from the model, and
8478 * removing events from the controller mirror the code for
8479 * `Backbone.View.dispose` in Backbone 0.9.8 development.
8481 * This behavior has since been removed, and should not be used
8482 * outside of the media manager.
8485 * @augments wp.Backbone.View
8486 * @augments Backbone.View
8488 var View = wp.Backbone.View.extend({
8489 constructor: function( options ) {
8490 if ( options && options.controller ) {
8491 this.controller = options.controller;
8493 wp.Backbone.View.apply( this, arguments );
8496 * @todo The internal comment mentions this might have been a stop-gap
8497 * before Backbone 0.9.8 came out. Figure out if Backbone core takes
8498 * care of this in Backbone.View now.
8500 * @returns {wp.media.View} Returns itself to allow chaining
8502 dispose: function() {
8503 // Undelegating events, removing events from the model, and
8504 // removing events from the controller mirror the code for
8505 // `Backbone.View.dispose` in Backbone 0.9.8 development.
8506 this.undelegateEvents();
8508 if ( this.model && this.model.off ) {
8509 this.model.off( null, null, this );
8512 if ( this.collection && this.collection.off ) {
8513 this.collection.off( null, null, this );
8516 // Unbind controller events.
8517 if ( this.controller && this.controller.off ) {
8518 this.controller.off( null, null, this );
8524 * @returns {wp.media.View} Returns itself to allow chaining
8526 remove: function() {
8529 * call 'remove' directly on the parent class
8531 return wp.Backbone.View.prototype.remove.apply( this, arguments );
8535 module.exports = View;