芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/cepali.edu.mx/wp-includes/sodium_compat/media-views-20241117075125.js
/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 7145: /***/ ((module) => { var Selection = wp.media.model.Selection, Library = wp.media.controller.Library, CollectionAdd; /** * wp.media.controller.CollectionAdd * * A state for adding attachments to a collection (e.g. video playlist). * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.Library * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=library] Unique identifier. * @param {string} attributes.title Title for the state. Displays in the frame's title region. * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse. * If one is not supplied, a collection of attachments of the specified type will be created. * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown. * Accepts 'all', 'uploaded', or 'unattached'. * @param {string} [attributes.menu=gallery] Initial mode for the menu region. * @param {string} [attributes.content=upload] Initial mode for the content region. * Overridden by persistent user setting if 'contentUserSetting' is true. * @param {string} [attributes.router=browse] Initial mode for the router region. * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region. * @param {boolean} [attributes.searchable=true] Whether the library is searchable. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {int} [attributes.priority=100] The priority for the state link in the media menu. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ CollectionAdd = Library.extend(/** @lends wp.media.controller.CollectionAdd.prototype */{ defaults: _.defaults( { // Selection defaults. @see media.model.Selection multiple: 'add', // Attachments browser defaults. @see media.view.AttachmentsBrowser filterable: 'uploaded', priority: 100, syncSelection: false }, Library.prototype.defaults ), /** * @since 3.9.0 */ initialize: function() { var collectionType = this.get('collectionType'); if ( 'video' === this.get( 'type' ) ) { collectionType = 'video-' + collectionType; } this.set( 'id', collectionType + '-library' ); this.set( 'toolbar', collectionType + '-add' ); this.set( 'menu', collectionType ); // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { this.set( 'library', wp.media.query({ type: this.get('type') }) ); } Library.prototype.initialize.apply( this, arguments ); }, /** * @since 3.9.0 */ activate: function() { var library = this.get('library'), editLibrary = this.get('editLibrary'), edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library'); if ( editLibrary && editLibrary !== edit ) { library.unobserve( editLibrary ); } // Accepts attachments that exist in the original library and // that do not exist in gallery's library. library.validator = function( attachment ) { return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments ); }; /* * Reset the library to ensure that all attachments are re-added * to the collection. Do so silently, as calling `observe` will * trigger the `reset` event. */ library.reset( library.mirroring.models, { silent: true }); library.observe( edit ); this.set('editLibrary', edit); Library.prototype.activate.apply( this, arguments ); } }); module.exports = CollectionAdd; /***/ }), /***/ 8612: /***/ ((module) => { var Library = wp.media.controller.Library, l10n = wp.media.view.l10n, $ = jQuery, CollectionEdit; /** * wp.media.controller.CollectionEdit * * A state for editing a collection, which is used by audio and video playlists, * and can be used for other collections. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.Library * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} [attributes] The attributes hash passed to the state. * @param {string} attributes.title Title for the state. Displays in the media menu and the frame's title region. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to edit. * If one is not supplied, an empty media.model.Selection collection is created. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled. * @param {string} [attributes.content=browse] Initial mode for the content region. * @param {string} attributes.menu Initial mode for the menu region. @todo this needs a better explanation. * @param {boolean} [attributes.searchable=false] Whether the library is searchable. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar. * @param {boolean} [attributes.describe=true] Whether to offer UI to describe the attachments - e.g. captioning images in a gallery. * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable. * @param {boolean} [attributes.dragInfoText] Instructional text about the attachments being sortable. * @param {int} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments. * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance. * @param {int} [attributes.priority=60] The priority for the state link in the media menu. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false for this state, because the library passed in *is* the selection. * @param {view} [attributes.SettingsView] The view to edit the collection instance settings (e.g. Playlist settings with "Show tracklist" checkbox). * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ CollectionEdit = Library.extend(/** @lends wp.media.controller.CollectionEdit.prototype */{ defaults: { multiple: false, sortable: true, date: false, searchable: false, content: 'browse', describe: true, dragInfo: true, idealColumnWidth: 170, editing: false, priority: 60, SettingsView: false, syncSelection: false }, /** * @since 3.9.0 */ initialize: function() { var collectionType = this.get('collectionType'); if ( 'video' === this.get( 'type' ) ) { collectionType = 'video-' + collectionType; } this.set( 'id', collectionType + '-edit' ); this.set( 'toolbar', collectionType + '-edit' ); // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { this.set( 'library', new wp.media.model.Selection() ); } // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) { this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary ); } Library.prototype.initialize.apply( this, arguments ); }, /** * @since 3.9.0 */ activate: function() { var library = this.get('library'); // Limit the library to images only. library.props.set( 'type', this.get( 'type' ) ); // Watch for uploaded attachments. this.get('library').observe( wp.Uploader.queue ); this.frame.on( 'content:render:browse', this.renderSettings, this ); Library.prototype.activate.apply( this, arguments ); }, /** * @since 3.9.0 */ deactivate: function() { // Stop watching for uploaded attachments. this.get('library').unobserve( wp.Uploader.queue ); this.frame.off( 'content:render:browse', this.renderSettings, this ); Library.prototype.deactivate.apply( this, arguments ); }, /** * Render the collection embed settings view in the browser sidebar. * * @todo This is against the pattern elsewhere in media. Typically the frame * is responsible for adding region mode callbacks. Explain. * * @since 3.9.0 * * @param {wp.media.view.attachmentsBrowser} The attachments browser view. */ renderSettings: function( attachmentsBrowserView ) { var library = this.get('library'), collectionType = this.get('collectionType'), dragInfoText = this.get('dragInfoText'), SettingsView = this.get('SettingsView'), obj = {}; if ( ! library || ! attachmentsBrowserView ) { return; } library[ collectionType ] = library[ collectionType ] || new Backbone.Model(); obj[ collectionType ] = new SettingsView({ controller: this, model: library[ collectionType ], priority: 40 }); attachmentsBrowserView.sidebar.set( obj ); if ( dragInfoText ) { attachmentsBrowserView.toolbar.set( 'dragInfo', new wp.media.View({ el: $( '
' + dragInfoText + '
' )[0], priority: -40 }) ); } // Add the 'Reverse order' button to the toolbar. attachmentsBrowserView.toolbar.set( 'reverse', { text: l10n.reverseOrder, priority: 80, click: function() { library.reset( library.toArray().reverse() ); } }); } }); module.exports = CollectionEdit; /***/ }), /***/ 5422: /***/ ((module) => { var l10n = wp.media.view.l10n, Cropper; /** * wp.media.controller.Cropper * * A class for cropping an image when called from the header media customization panel. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.State * @augments Backbone.Model */ Cropper = wp.media.controller.State.extend(/** @lends wp.media.controller.Cropper.prototype */{ defaults: { id: 'cropper', title: l10n.cropImage, // Region mode defaults. toolbar: 'crop', content: 'crop', router: false, canSkipCrop: false, // Default doCrop Ajax arguments to allow the Customizer (for example) to inject state. doCropArgs: {} }, /** * Shows the crop image window when called from the Add new image button. * * @since 4.2.0 * * @return {void} */ activate: function() { this.frame.on( 'content:create:crop', this.createCropContent, this ); this.frame.on( 'close', this.removeCropper, this ); this.set('selection', new Backbone.Collection(this.frame._selection.single)); }, /** * Changes the state of the toolbar window to browse mode. * * @since 4.2.0 * * @return {void} */ deactivate: function() { this.frame.toolbar.mode('browse'); }, /** * Creates the crop image window. * * Initialized when clicking on the Select and Crop button. * * @since 4.2.0 * * @fires crop window * * @return {void} */ createCropContent: function() { this.cropperView = new wp.media.view.Cropper({ controller: this, attachment: this.get('selection').first() }); this.cropperView.on('image-loaded', this.createCropToolbar, this); this.frame.content.set(this.cropperView); }, /** * Removes the image selection and closes the cropping window. * * @since 4.2.0 * * @return {void} */ removeCropper: function() { this.imgSelect.cancelSelection(); this.imgSelect.setOptions({remove: true}); this.imgSelect.update(); this.cropperView.remove(); }, /** * Checks if cropping can be skipped and creates crop toolbar accordingly. * * @since 4.2.0 * * @return {void} */ createCropToolbar: function() { var canSkipCrop, toolbarOptions; canSkipCrop = this.get('canSkipCrop') || false; toolbarOptions = { controller: this.frame, items: { insert: { style: 'primary', text: l10n.cropImage, priority: 80, requires: { library: false, selection: false }, click: function() { var controller = this.controller, selection; selection = controller.state().get('selection').first(); selection.set({cropDetails: controller.state().imgSelect.getSelection()}); this.$el.text(l10n.cropping); this.$el.attr('disabled', true); controller.state().doCrop( selection ).done( function( croppedImage ) { controller.trigger('cropped', croppedImage ); controller.close(); }).fail( function() { controller.trigger('content:error:crop'); }); } } } }; if ( canSkipCrop ) { _.extend( toolbarOptions.items, { skip: { style: 'secondary', text: l10n.skipCropping, priority: 70, requires: { library: false, selection: false }, click: function() { var selection = this.controller.state().get('selection').first(); this.controller.state().cropperView.remove(); this.controller.trigger('skippedcrop', selection); this.controller.close(); } } }); } this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) ); }, /** * Creates an object with the image attachment and crop properties. * * @since 4.2.0 * * @return {$.promise} A jQuery promise with the custom header crop details. */ doCrop: function( attachment ) { return wp.ajax.post( 'custom-header-crop', _.extend( {}, this.defaults.doCropArgs, { nonce: attachment.get( 'nonces' ).edit, id: attachment.get( 'id' ), cropDetails: attachment.get( 'cropDetails' ) } ) ); } }); module.exports = Cropper; /***/ }), /***/ 9660: /***/ ((module) => { var Controller = wp.media.controller, CustomizeImageCropper; /** * A state for cropping an image in the customizer. * * @since 4.3.0 * * @constructs wp.media.controller.CustomizeImageCropper * @memberOf wp.media.controller * @augments wp.media.controller.CustomizeImageCropper.Cropper * @inheritDoc */ CustomizeImageCropper = Controller.Cropper.extend(/** @lends wp.media.controller.CustomizeImageCropper.prototype */{ /** * Posts the crop details to the admin. * * Uses crop measurements when flexible in both directions. * Constrains flexible side based on image ratio and size of the fixed side. * * @since 4.3.0 * * @param {Object} attachment The attachment to crop. * * @return {$.promise} A jQuery promise that represents the crop image request. */ doCrop: function( attachment ) { var cropDetails = attachment.get( 'cropDetails' ), control = this.get( 'control' ), ratio = cropDetails.width / cropDetails.height; // Use crop measurements when flexible in both directions. if ( control.params.flex_width && control.params.flex_height ) { cropDetails.dst_width = cropDetails.width; cropDetails.dst_height = cropDetails.height; // Constrain flexible side based on image ratio and size of the fixed side. } else { cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width; cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height; } return wp.ajax.post( 'crop-image', { wp_customize: 'on', nonce: attachment.get( 'nonces' ).edit, id: attachment.get( 'id' ), context: control.id, cropDetails: cropDetails } ); } }); module.exports = CustomizeImageCropper; /***/ }), /***/ 5663: /***/ ((module) => { var l10n = wp.media.view.l10n, EditImage; /** * wp.media.controller.EditImage * * A state for editing (cropping, etc.) an image. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} attributes The attributes hash passed to the state. * @param {wp.media.model.Attachment} attributes.model The attachment. * @param {string} [attributes.id=edit-image] Unique identifier. * @param {string} [attributes.title=Edit Image] Title for the state. Displays in the media menu and the frame's title region. * @param {string} [attributes.content=edit-image] Initial mode for the content region. * @param {string} [attributes.toolbar=edit-image] Initial mode for the toolbar region. * @param {string} [attributes.menu=false] Initial mode for the menu region. * @param {string} [attributes.url] Unused. @todo Consider removal. */ EditImage = wp.media.controller.State.extend(/** @lends wp.media.controller.EditImage.prototype */{ defaults: { id: 'edit-image', title: l10n.editImage, menu: false, toolbar: 'edit-image', content: 'edit-image', url: '' }, /** * Activates a frame for editing a featured image. * * @since 3.9.0 * * @return {void} */ activate: function() { this.frame.on( 'toolbar:render:edit-image', _.bind( this.toolbar, this ) ); }, /** * Deactivates a frame for editing a featured image. * * @since 3.9.0 * * @return {void} */ deactivate: function() { this.frame.off( 'toolbar:render:edit-image' ); }, /** * Adds a toolbar with a back button. * * When the back button is pressed it checks whether there is a previous state. * In case there is a previous state it sets that previous state otherwise it * closes the frame. * * @since 3.9.0 * * @return {void} */ toolbar: function() { var frame = this.frame, lastState = frame.lastState(), previous = lastState && lastState.id; frame.toolbar.set( new wp.media.view.Toolbar({ controller: frame, items: { back: { style: 'primary', text: l10n.back, priority: 20, click: function() { if ( previous ) { frame.setState( previous ); } else { frame.close(); } } } } }) ); } }); module.exports = EditImage; /***/ }), /***/ 4910: /***/ ((module) => { var l10n = wp.media.view.l10n, $ = Backbone.$, Embed; /** * wp.media.controller.Embed * * A state for embedding media from a URL. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} attributes The attributes hash passed to the state. * @param {string} [attributes.id=embed] Unique identifier. * @param {string} [attributes.title=Insert From URL] Title for the state. Displays in the media menu and the frame's title region. * @param {string} [attributes.content=embed] Initial mode for the content region. * @param {string} [attributes.menu=default] Initial mode for the menu region. * @param {string} [attributes.toolbar=main-embed] Initial mode for the toolbar region. * @param {string} [attributes.menu=false] Initial mode for the menu region. * @param {int} [attributes.priority=120] The priority for the state link in the media menu. * @param {string} [attributes.type=link] The type of embed. Currently only link is supported. * @param {string} [attributes.url] The embed URL. * @param {object} [attributes.metadata={}] Properties of the embed, which will override attributes.url if set. */ Embed = wp.media.controller.State.extend(/** @lends wp.media.controller.Embed.prototype */{ defaults: { id: 'embed', title: l10n.insertFromUrlTitle, content: 'embed', menu: 'default', toolbar: 'main-embed', priority: 120, type: 'link', url: '', metadata: {} }, // The amount of time used when debouncing the scan. sensitivity: 400, initialize: function(options) { this.metadata = options.metadata; this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity ); this.props = new Backbone.Model( this.metadata || { url: '' }); this.props.on( 'change:url', this.debouncedScan, this ); this.props.on( 'change:url', this.refresh, this ); this.on( 'scan', this.scanImage, this ); }, /** * Trigger a scan of the embedded URL's content for metadata required to embed. * * @fires wp.media.controller.Embed#scan */ scan: function() { var scanners, embed = this, attributes = { type: 'link', scanners: [] }; /* * Scan is triggered with the list of `attributes` to set on the * state, useful for the 'type' attribute and 'scanners' attribute, * an array of promise objects for asynchronous scan operations. */ if ( this.props.get('url') ) { this.trigger( 'scan', attributes ); } if ( attributes.scanners.length ) { scanners = attributes.scanners = $.when.apply( $, attributes.scanners ); scanners.always( function() { if ( embed.get('scanners') === scanners ) { embed.set( 'loading', false ); } }); } else { attributes.scanners = null; } attributes.loading = !! attributes.scanners; this.set( attributes ); }, /** * Try scanning the embed as an image to discover its dimensions. * * @param {Object} attributes */ scanImage: function( attributes ) { var frame = this.frame, state = this, url = this.props.get('url'), image = new Image(), deferred = $.Deferred(); attributes.scanners.push( deferred.promise() ); // Try to load the image and find its width/height. image.onload = function() { deferred.resolve(); if ( state !== frame.state() || url !== state.props.get('url') ) { return; } state.set({ type: 'image' }); state.props.set({ width: image.width, height: image.height }); }; image.onerror = deferred.reject; image.src = url; }, refresh: function() { this.frame.toolbar.get().refresh(); }, reset: function() { this.props.clear().set({ url: '' }); if ( this.active ) { this.refresh(); } } }); module.exports = Embed; /***/ }), /***/ 1169: /***/ ((module) => { var Attachment = wp.media.model.Attachment, Library = wp.media.controller.Library, l10n = wp.media.view.l10n, FeaturedImage; /** * wp.media.controller.FeaturedImage * * A state for selecting a featured image for a post. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.Library * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=featured-image] Unique identifier. * @param {string} [attributes.title=Set Featured Image] Title for the state. Displays in the media menu and the frame's title region. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse. * If one is not supplied, a collection of all images will be created. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled. * @param {string} [attributes.content=upload] Initial mode for the content region. * Overridden by persistent user setting if 'contentUserSetting' is true. * @param {string} [attributes.menu=default] Initial mode for the menu region. * @param {string} [attributes.router=browse] Initial mode for the router region. * @param {string} [attributes.toolbar=featured-image] Initial mode for the toolbar region. * @param {int} [attributes.priority=60] The priority for the state link in the media menu. * @param {boolean} [attributes.searchable=true] Whether the library is searchable. * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown. * Accepts 'all', 'uploaded', or 'unattached'. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection. * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. */ FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prototype */{ defaults: _.defaults({ id: 'featured-image', title: l10n.setFeaturedImageTitle, multiple: false, filterable: 'uploaded', toolbar: 'featured-image', priority: 60, syncSelection: true }, Library.prototype.defaults ), /** * @since 3.5.0 */ initialize: function() { var library, comparator; // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { this.set( 'library', wp.media.query({ type: 'image' }) ); } Library.prototype.initialize.apply( this, arguments ); library = this.get('library'); comparator = library.comparator; // Overload the library's comparator to push items that are not in // the mirrored query to the front of the aggregate collection. library.comparator = function( a, b ) { var aInQuery = !! this.mirroring.get( a.cid ), bInQuery = !! this.mirroring.get( b.cid ); if ( ! aInQuery && bInQuery ) { return -1; } else if ( aInQuery && ! bInQuery ) { return 1; } else { return comparator.apply( this, arguments ); } }; // Add all items in the selection to the library, so any featured // images that are not initially loaded still appear. library.observe( this.get('selection') ); }, /** * @since 3.5.0 */ activate: function() { this.frame.on( 'open', this.updateSelection, this ); Library.prototype.activate.apply( this, arguments ); }, /** * @since 3.5.0 */ deactivate: function() { this.frame.off( 'open', this.updateSelection, this ); Library.prototype.deactivate.apply( this, arguments ); }, /** * @since 3.5.0 */ updateSelection: function() { var selection = this.get('selection'), id = wp.media.view.settings.post.featuredImageId, attachment; if ( '' !== id && -1 !== id ) { attachment = Attachment.get( id ); attachment.fetch(); } selection.reset( attachment ? [ attachment ] : [] ); } }); module.exports = FeaturedImage; /***/ }), /***/ 7127: /***/ ((module) => { var Selection = wp.media.model.Selection, Library = wp.media.controller.Library, l10n = wp.media.view.l10n, GalleryAdd; /** * wp.media.controller.GalleryAdd * * A state for selecting more images to add to a gallery. * * @since 3.5.0 * * @class * @augments wp.media.controller.Library * @augments wp.media.controller.State * @augments Backbone.Model * * @memberof wp.media.controller * * @param {Object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=gallery-library] Unique identifier. * @param {string} [attributes.title=Add to Gallery] Title for the state. Displays in the frame's title region. * @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse. * If one is not supplied, a collection of all images will be created. * @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown. * Accepts 'all', 'uploaded', or 'unattached'. * @param {string} [attributes.menu=gallery] Initial mode for the menu region. * @param {string} [attributes.content=upload] Initial mode for the content region. * Overridden by persistent user setting if 'contentUserSetting' is true. * @param {string} [attributes.router=browse] Initial mode for the router region. * @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region. * @param {boolean} [attributes.searchable=true] Whether the library is searchable. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {number} [attributes.priority=100] The priority for the state link in the media menu. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. */ GalleryAdd = Library.extend(/** @lends wp.media.controller.GalleryAdd.prototype */{ defaults: _.defaults({ id: 'gallery-library', title: l10n.addToGalleryTitle, multiple: 'add', filterable: 'uploaded', menu: 'gallery', toolbar: 'gallery-add', priority: 100, syncSelection: false }, Library.prototype.defaults ), /** * Initializes the library. Creates a library of images if a library isn't supplied. * * @since 3.5.0 * * @return {void} */ initialize: function() { if ( ! this.get('library') ) { this.set( 'library', wp.media.query({ type: 'image' }) ); } Library.prototype.initialize.apply( this, arguments ); }, /** * Activates the library. * * Removes all event listeners if in edit mode. Creates a validator to check an attachment. * Resets library and re-enables event listeners. Activates edit mode. Calls the parent's activate method. * * @since 3.5.0 * * @return {void} */ activate: function() { var library = this.get('library'), edit = this.frame.state('gallery-edit').get('library'); if ( this.editLibrary && this.editLibrary !== edit ) { library.unobserve( this.editLibrary ); } /* * Accept attachments that exist in the original library but * that do not exist in gallery's library yet. */ library.validator = function( attachment ) { return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && Selection.prototype.validator.apply( this, arguments ); }; /* * Reset the library to ensure that all attachments are re-added * to the collection. Do so silently, as calling `observe` will * trigger the `reset` event. */ library.reset( library.mirroring.models, { silent: true }); library.observe( edit ); this.editLibrary = edit; Library.prototype.activate.apply( this, arguments ); } }); module.exports = GalleryAdd; /***/ }), /***/ 2038: /***/ ((module) => { var Library = wp.media.controller.Library, l10n = wp.media.view.l10n, GalleryEdit; /** * wp.media.controller.GalleryEdit * * A state for editing a gallery's images and settings. * * @since 3.5.0 * * @class * @augments wp.media.controller.Library * @augments wp.media.controller.State * @augments Backbone.Model * * @memberOf wp.media.controller * * @param {Object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=gallery-edit] Unique identifier. * @param {string} [attributes.title=Edit Gallery] Title for the state. Displays in the frame's title region. * @param {wp.media.model.Attachments} [attributes.library] The collection of attachments in the gallery. * If one is not supplied, an empty media.model.Selection collection is created. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled. * @param {boolean} [attributes.searchable=false] Whether the library is searchable. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.date=true] Whether to show the date filter in the browser's toolbar. * @param {string|false} [attributes.content=browse] Initial mode for the content region. * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region. * @param {boolean} [attributes.describe=true] Whether to offer UI to describe attachments - e.g. captioning images in a gallery. * @param {boolean} [attributes.displaySettings=true] Whether to show the attachment display settings interface. * @param {boolean} [attributes.dragInfo=true] Whether to show instructional text about the attachments being sortable. * @param {number} [attributes.idealColumnWidth=170] The ideal column width in pixels for attachments. * @param {boolean} [attributes.editing=false] Whether the gallery is being created, or editing an existing instance. * @param {number} [attributes.priority=60] The priority for the state link in the media menu. * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false for this state, because the library passed in *is* the selection. * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. */ GalleryEdit = Library.extend(/** @lends wp.media.controller.GalleryEdit.prototype */{ defaults: { id: 'gallery-edit', title: l10n.editGalleryTitle, multiple: false, searchable: false, sortable: true, date: false, display: false, content: 'browse', toolbar: 'gallery-edit', describe: true, displaySettings: true, dragInfo: true, idealColumnWidth: 170, editing: false, priority: 60, syncSelection: false }, /** * Initializes the library. * * Creates a selection if a library isn't supplied and creates an attachment * view if no attachment view is supplied. * * @since 3.5.0 * * @return {void} */ initialize: function() { // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { this.set( 'library', new wp.media.model.Selection() ); } // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) { this.set( 'AttachmentView', wp.media.view.Attachment.EditLibrary ); } Library.prototype.initialize.apply( this, arguments ); }, /** * Activates the library. * * Limits the library to images, watches for uploaded attachments. Watches for * the browse event on the frame and binds it to gallerySettings. * * @since 3.5.0 * * @return {void} */ activate: function() { var library = this.get('library'); // Limit the library to images only. library.props.set( 'type', 'image' ); // Watch for uploaded attachments. this.get('library').observe( wp.Uploader.queue ); this.frame.on( 'content:render:browse', this.gallerySettings, this ); Library.prototype.activate.apply( this, arguments ); }, /** * Deactivates the library. * * Stops watching for uploaded attachments and browse events. * * @since 3.5.0 * * @return {void} */ deactivate: function() { // Stop watching for uploaded attachments. this.get('library').unobserve( wp.Uploader.queue ); this.frame.off( 'content:render:browse', this.gallerySettings, this ); Library.prototype.deactivate.apply( this, arguments ); }, /** * Adds the gallery settings to the sidebar and adds a reverse button to the * toolbar. * * @since 3.5.0 * * @param {wp.media.view.Frame} browser The file browser. * * @return {void} */ gallerySettings: function( browser ) { if ( ! this.get('displaySettings') ) { return; } var library = this.get('library'); if ( ! library || ! browser ) { return; } library.gallery = library.gallery || new Backbone.Model(); browser.sidebar.set({ gallery: new wp.media.view.Settings.Gallery({ controller: this, model: library.gallery, priority: 40 }) }); browser.toolbar.set( 'reverse', { text: l10n.reverseOrder, priority: 80, click: function() { library.reset( library.toArray().reverse() ); } }); } }); module.exports = GalleryEdit; /***/ }), /***/ 705: /***/ ((module) => { var State = wp.media.controller.State, Library = wp.media.controller.Library, l10n = wp.media.view.l10n, ImageDetails; /** * wp.media.controller.ImageDetails * * A state for editing the attachment display settings of an image that's been * inserted into the editor. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.State * @augments Backbone.Model * * @param {object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=image-details] Unique identifier. * @param {string} [attributes.title=Image Details] Title for the state. Displays in the frame's title region. * @param {wp.media.model.Attachment} attributes.image The image's model. * @param {string|false} [attributes.content=image-details] Initial mode for the content region. * @param {string|false} [attributes.menu=false] Initial mode for the menu region. * @param {string|false} [attributes.router=false] Initial mode for the router region. * @param {string|false} [attributes.toolbar=image-details] Initial mode for the toolbar region. * @param {boolean} [attributes.editing=false] Unused. * @param {int} [attributes.priority=60] Unused. * * @todo This state inherits some defaults from media.controller.Library.prototype.defaults, * however this may not do anything. */ ImageDetails = State.extend(/** @lends wp.media.controller.ImageDetails.prototype */{ defaults: _.defaults({ id: 'image-details', title: l10n.imageDetailsTitle, content: 'image-details', menu: false, router: false, toolbar: 'image-details', editing: false, priority: 60 }, Library.prototype.defaults ), /** * @since 3.9.0 * * @param options Attributes */ initialize: function( options ) { this.image = options.image; State.prototype.initialize.apply( this, arguments ); }, /** * @since 3.9.0 */ activate: function() { this.frame.modal.$el.addClass('image-details'); } }); module.exports = ImageDetails; /***/ }), /***/ 472: /***/ ((module) => { var l10n = wp.media.view.l10n, getUserSetting = window.getUserSetting, setUserSetting = window.setUserSetting, Library; /** * wp.media.controller.Library * * A state for choosing an attachment or group of attachments from the media library. * * @memberOf wp.media.controller * * @class * @augments wp.media.controller.State * @augments Backbone.Model * @mixes media.selectionSync * * @param {object} [attributes] The attributes hash passed to the state. * @param {string} [attributes.id=library] Unique identifier. * @param {string} [attributes.title=Media library] Title for the state. Displays in the media menu and the frame's title region. * @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse. * If one is not supplied, a collection of all attachments will be created. * @param {wp.media.model.Selection|object} [attributes.selection] A collection to contain attachment selections within the state. * If the 'selection' attribute is a plain JS object, * a Selection will be created using its values as the selection instance's `props` model. * Otherwise, it will copy the library's `props` model. * @param {boolean} [attributes.multiple=false] Whether multi-select is enabled. * @param {string} [attributes.content=upload] Initial mode for the content region. * Overridden by persistent user setting if 'contentUserSetting' is true. * @param {string} [attributes.menu=default] Initial mode for the menu region. * @param {string} [attributes.router=browse] Initial mode for the router region. * @param {string} [attributes.toolbar=select] Initial mode for the toolbar region. * @param {boolean} [attributes.searchable=true] Whether the library is searchable. * @param {boolean|string} [attributes.filterable=false] Whether the library is filterable, and if so what filters should be shown. * Accepts 'all', 'uploaded', or 'unattached'. * @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection. * @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection. * @param {boolean} [attributes.describe=false] Whether to offer UI to describe attachments - e.g. captioning images in a gallery. * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. */ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Library.prototype */{ defaults: { id: 'library', title: l10n.mediaLibraryTitle, multiple: false, content: 'upload', menu: 'default', router: 'browse', toolbar: 'select', searchable: true, filterable: false, sortable: true, autoSelect: true, describe: false, contentUserSetting: true, syncSelection: true }, /** * If a library isn't provided, query all media items. * If a selection instance isn't provided, create one. * * @since 3.5.0 */ initialize: function() { var selection = this.get('selection'), props; if ( ! this.get('library') ) { this.set( 'library', wp.media.query() ); } if ( ! ( selection instanceof wp.media.model.Selection ) ) { props = selection; if ( ! props ) { props = this.get('library').props.toJSON(); props = _.omit( props, 'orderby', 'query' ); } this.set( 'selection', new wp.media.model.Selection( null, { multiple: this.get('multiple'), props: props }) ); } this.resetDisplays(); }, /** * @since 3.5.0 */ activate: function() { this.syncSelection(); wp.Uploader.queue.on( 'add', this.uploading, this ); this.get('selection').on( 'add remove reset', this.refreshContent, this ); if ( this.get( 'router' ) && this.get('contentUserSetting') ) { this.frame.on( 'content:activate', this.saveContentMode, this ); this.set( 'content', getUserSetting( 'libraryContent', this.get('content') ) ); } }, /** * @since 3.5.0 */ deactivate: function() { this.recordSelection(); this.frame.off( 'content:activate', this.saveContentMode, this ); // Unbind all event handlers that use this state as the context // from the selection. this.get('selection').off( null, null, this ); wp.Uploader.queue.off( null, null, this ); }, /** * Reset the library to its initial state. * * @since 3.5.0 */ reset: function() { this.get('selection').reset(); this.resetDisplays(); this.refreshContent(); }, /** * Reset the attachment display settings defaults to the site options. * * If site options don't define them, fall back to a persistent user setting. * * @since 3.5.0 */ resetDisplays: function() { var defaultProps = wp.media.view.settings.defaultProps; this._displays = []; this._defaultDisplaySettings = { align: getUserSetting( 'align', defaultProps.align ) || 'none', size: getUserSetting( 'imgsize', defaultProps.size ) || 'medium', link: getUserSetting( 'urlbutton', defaultProps.link ) || 'none' }; }, /** * Create a model to represent display settings (alignment, etc.) for an attachment. * * @since 3.5.0 * * @param {wp.media.model.Attachment} attachment * @return {Backbone.Model} */ display: function( attachment ) { var displays = this._displays; if ( ! displays[ attachment.cid ] ) { displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) ); } return displays[ attachment.cid ]; }, /** * Given an attachment, create attachment display settings properties. * * @since 3.6.0 * * @param {wp.media.model.Attachment} attachment * @return {Object} */ defaultDisplaySettings: function( attachment ) { var settings = _.clone( this._defaultDisplaySettings ); settings.canEmbed = this.canEmbed( attachment ); if ( settings.canEmbed ) { settings.link = 'embed'; } else if ( ! this.isImageAttachment( attachment ) && settings.link === 'none' ) { settings.link = 'file'; } return settings; }, /** * Whether an attachment is image. * * @since 4.4.1 * * @param {wp.media.model.Attachment} attachment * @return {boolean} */ isImageAttachment: function( attachment ) { // If uploading, we know the filename but not the mime type. if ( attachment.get('uploading') ) { return /\.(jpe?g|png|gif|webp|avif)$/i.test( attachment.get('filename') ); } return attachment.get('type') === 'image'; }, /** * Whether an attachment can be embedded (audio or video). * * @since 3.6.0 * * @param {wp.media.model.Attachment} attachment * @return {boolean} */ canEmbed: function( attachment ) { // If uploading, we know the filename but not the mime type. if ( ! attachment.get('uploading') ) { var type = attachment.get('type'); if ( type !== 'audio' && type !== 'video' ) { return false; } } return _.contains( wp.media.view.settings.embedExts, attachment.get('filename').split('.').pop() ); }, /** * If the state is active, no items are selected, and the current * content mode is not an option in the state's router (provided * the state has a router), reset the content mode to the default. * * @since 3.5.0 */ refreshContent: function() { var selection = this.get('selection'), frame = this.frame, router = frame.router.get(), mode = frame.content.mode(); if ( this.active && ! selection.length && router && ! router.get( mode ) ) { this.frame.content.render( this.get('content') ); } }, /** * Callback handler when an attachment is uploaded. * * Switch to the Media Library if uploaded from the 'Upload Files' tab. * * Adds any uploading attachments to the selection. * * If the state only supports one attachment to be selected and multiple * attachments are uploaded, the last attachment in the upload queue will * be selected. * * @since 3.5.0 * * @param {wp.media.model.Attachment} attachment */ uploading: function( attachment ) { var content = this.frame.content; if ( 'upload' === content.mode() ) { this.frame.content.mode('browse'); } if ( this.get( 'autoSelect' ) ) { this.get('selection').add( attachment ); this.frame.trigger( 'library:selection:add' ); } }, /** * Persist the mode of the content region as a user setting. * * @since 3.5.0 */ saveContentMode: function() { if ( 'browse' !== this.get('router') ) {