/HotelSpaWP/wp-includes/js/media-views.js
https://bitbucket.org/Trulsh/personal-bootstrap-projects · JavaScript · 8542 lines · 5137 code · 1223 blank · 2182 comment · 606 complexity · b44bc57736b0f9071a8d5b4e1a1c38c0 MD5 · raw file
Large files are truncated click here to view the full file
- (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){
- /**
- * wp.media.controller.CollectionAdd
- *
- * A state for adding attachments to a collection (e.g. video playlist).
- *
- * @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').
- */
- var Selection = wp.media.model.Selection,
- Library = wp.media.controller.Library,
- CollectionAdd;
- CollectionAdd = Library.extend({
- 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;
- },{}],2:[function(require,module,exports){
- /**
- * 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.
- *
- * @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').
- */
- var Library = wp.media.controller.Library,
- l10n = wp.media.view.l10n,
- $ = jQuery,
- CollectionEdit;
- CollectionEdit = Library.extend({
- 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: $( '<div class="instructions">' + dragInfoText + '</div>' )[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;
- },{}],3:[function(require,module,exports){
- /**
- * wp.media.controller.Cropper
- *
- * A state for cropping an image.
- *
- * @class
- * @augments wp.media.controller.State
- * @augments Backbone.Model
- */
- var l10n = wp.media.view.l10n,
- Cropper;
- Cropper = wp.media.controller.State.extend({
- 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: {}
- },
- 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));
- },
- deactivate: function() {
- this.frame.toolbar.mode('browse');
- },
- 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);
- },
- removeCropper: function() {
- this.imgSelect.cancelSelection();
- this.imgSelect.setOptions({remove: true});
- this.imgSelect.update();
- this.cropperView.remove();
- },
- 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) );
- },
- 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;
- },{}],4:[function(require,module,exports){
- /**
- * wp.media.controller.CustomizeImageCropper
- *
- * A state for cropping an image.
- *
- * @class
- * @augments wp.media.controller.Cropper
- * @augments wp.media.controller.State
- * @augments Backbone.Model
- */
- var Controller = wp.media.controller,
- CustomizeImageCropper;
- CustomizeImageCropper = Controller.Cropper.extend({
- 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;
- },{}],5:[function(require,module,exports){
- /**
- * wp.media.controller.EditImage
- *
- * A state for editing (cropping, etc.) an image.
- *
- * @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.
- */
- var l10n = wp.media.view.l10n,
- EditImage;
- EditImage = wp.media.controller.State.extend({
- defaults: {
- id: 'edit-image',
- title: l10n.editImage,
- menu: false,
- toolbar: 'edit-image',
- content: 'edit-image',
- url: ''
- },
- /**
- * @since 3.9.0
- */
- activate: function() {
- this.frame.on( 'toolbar:render:edit-image', _.bind( this.toolbar, this ) );
- },
- /**
- * @since 3.9.0
- */
- deactivate: function() {
- this.frame.off( 'toolbar:render:edit-image' );
- },
- /**
- * @since 3.9.0
- */
- 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;
- },{}],6:[function(require,module,exports){
- /**
- * wp.media.controller.Embed
- *
- * A state for embedding media from a URL.
- *
- * @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.
- */
- var l10n = wp.media.view.l10n,
- $ = Backbone.$,
- Embed;
- Embed = wp.media.controller.State.extend({
- 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;
- },{}],7:[function(require,module,exports){
- /**
- * wp.media.controller.FeaturedImage
- *
- * A state for selecting a featured image for a post.
- *
- * @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.
- */
- var Attachment = wp.media.model.Attachment,
- Library = wp.media.controller.Library,
- l10n = wp.media.view.l10n,
- FeaturedImage;
- FeaturedImage = Library.extend({
- 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.updateSelection();
- 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;
- },{}],8:[function(require,module,exports){
- /**
- * wp.media.controller.GalleryAdd
- *
- * A state for selecting more images to add to a gallery.
- *
- * @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=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 {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.
- */
- var Selection = wp.media.model.Selection,
- Library = wp.media.controller.Library,
- l10n = wp.media.view.l10n,
- GalleryAdd;
- GalleryAdd = Library.extend({
- defaults: _.defaults({
- id: 'gallery-library',
- title: l10n.addToGalleryTitle,
- multiple: 'add',
- filterable: 'uploaded',
- menu: 'gallery',
- toolbar: 'gallery-add',
- priority: 100,
- syncSelection: false
- }, Library.prototype.defaults ),
- /**
- * @since 3.5.0
- */
- initialize: function() {
- // If a library wasn't supplied, create a library of images.
- if ( ! this.get('library') ) {
- this.set( 'library', wp.media.query({ type: 'image' }) );
- }
- Library.prototype.initialize.apply( this, arguments );
- },
- /**
- * @since 3.5.0
- */
- 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 );
- }
- // 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.editLibrary = edit;
- Library.prototype.activate.apply( this, arguments );
- }
- });
- module.exports = GalleryAdd;
- },{}],9:[function(require,module,exports){
- /**
- * wp.media.controller.GalleryEdit
- *
- * A state for editing a gallery's images and settings.
- *
- * @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=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 {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.AttachmentView] The single `Attachment` view to be used in the `Attachments`.
- * If none supplied, defaults to wp.media.view.Attachment.EditLibrary.
- */
- var Library = wp.media.controller.Library,
- l10n = wp.media.view.l10n,
- GalleryEdit;
- GalleryEdit = Library.extend({
- 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
- },
- /**
- * @since 3.5.0
- */
- 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 );
- },
- /**
- * @since 3.5.0
- */
- 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 );
- },
- /**
- * @since 3.5.0
- */
- 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 );
- },
- /**
- * @since 3.5.0
- *
- * @param browser
- */
- 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;
- },{}],10:[function(require,module,exports){
- /**
- * wp.media.controller.ImageDetails
- *
- * A state for editing the attachment display settings of an image that's been
- * inserted into the editor.
- *
- * @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.
- */
- var State = wp.media.controller.State,
- Library = wp.media.controller.Library,
- l10n = wp.media.view.l10n,
- ImageDetails;
- ImageDetails = State.extend({
- 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;
- },{}],11:[function(require,module,exports){
- /**
- * wp.media.controller.Library
- *
- * A state for choosing an attachment or group of attachments from the media library.
- *
- * @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.
- */
- var l10n = wp.media.view.l10n,
- getUserSetting = window.getUserSetting,
- setUserSetting = window.setUserSetting,
- Library;
- Library = wp.media.controller.State.extend({
- 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
- * @returns {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
- * @returns {Object}
- */
- defaultDisplaySettings: function( attachment ) {
- var settings = _.clone( this._defaultDisplaySettings );
- if ( settings.canEmbed = this.canEmbed( attachment ) ) {
- 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
- * @returns {Boolean}
- */
- isImageAttachment: function( attachment ) {
- // If uploading, we know the filename but not the mime type.
- if ( attachment.get('uploading') ) {
- return /\.(jpe?g|png|gif)$/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
- * @returns {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') ) {
- return;
- }
- var mode = this.frame.content.mode(),
- view = this.frame.router.get();
- if ( view && view.get( mode ) ) {
- setUserSetting( 'libraryContent', mode );…