2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/widgets/media-image-widget.js
|
|
|
|
*/
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/* eslint consistent-this: [ "error", "control" ] */
|
|
|
|
(function( component, $ ) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ImageWidgetModel, ImageWidgetControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Image widget model.
|
|
|
|
*
|
|
|
|
* See WP_Widget_Media_Image::enqueue_admin_scripts() for amending prototype from PHP exports.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.mediaWidgets.modelConstructors.media_image
|
|
|
|
* @augments wp.mediaWidgets.MediaWidgetModel
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
ImageWidgetModel = component.MediaWidgetModel.extend({});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Image widget control.
|
|
|
|
*
|
|
|
|
* See WP_Widget_Media_Image::enqueue_admin_scripts() for amending prototype from PHP exports.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.mediaWidgets.controlConstructors.media_audio
|
|
|
|
* @augments wp.mediaWidgets.MediaWidgetControl
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
ImageWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_image.prototype */{
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
2017-09-25 08:28:45 +02:00
|
|
|
/**
|
|
|
|
* View events.
|
|
|
|
*
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
events: _.extend( {}, component.MediaWidgetControl.prototype.events, {
|
|
|
|
'click .media-widget-preview.populated': 'editMedia'
|
|
|
|
} ),
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/**
|
|
|
|
* Render preview.
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
renderPreview: function renderPreview() {
|
2017-08-14 19:56:42 +02:00
|
|
|
var control = this, previewContainer, previewTemplate, fieldsContainer, fieldsTemplate, linkInput;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
if ( ! control.model.get( 'attachment_id' ) && ! control.model.get( 'url' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
previewContainer = control.$el.find( '.media-widget-preview' );
|
|
|
|
previewTemplate = wp.template( 'wp-media-widget-image-preview' );
|
2017-08-14 19:56:42 +02:00
|
|
|
previewContainer.html( previewTemplate( control.previewTemplateProps.toJSON() ) );
|
2017-09-25 08:28:45 +02:00
|
|
|
previewContainer.addClass( 'populated' );
|
2017-08-14 19:56:42 +02:00
|
|
|
|
|
|
|
linkInput = control.$el.find( '.link' );
|
|
|
|
if ( ! linkInput.is( document.activeElement ) ) {
|
|
|
|
fieldsContainer = control.$el.find( '.media-widget-fields' );
|
|
|
|
fieldsTemplate = wp.template( 'wp-media-widget-image-fields' );
|
|
|
|
fieldsContainer.html( fieldsTemplate( control.previewTemplateProps.toJSON() ) );
|
|
|
|
}
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the media image-edit frame to modify the selected item.
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
editMedia: function editMedia() {
|
|
|
|
var control = this, mediaFrame, updateCallback, defaultSync, metadata;
|
|
|
|
|
|
|
|
metadata = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
|
|
|
|
|
|
|
// Needed or else none will not be selected if linkUrl is not also empty.
|
|
|
|
if ( 'none' === metadata.link ) {
|
|
|
|
metadata.linkUrl = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the media frame.
|
|
|
|
mediaFrame = wp.media({
|
|
|
|
frame: 'image',
|
|
|
|
state: 'image-details',
|
|
|
|
metadata: metadata
|
|
|
|
});
|
|
|
|
mediaFrame.$el.addClass( 'media-widget' );
|
|
|
|
|
|
|
|
updateCallback = function() {
|
2017-08-14 19:56:42 +02:00
|
|
|
var mediaProps, linkType;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
// Update cached attachment object to avoid having to re-fetch. This also triggers re-rendering of preview.
|
|
|
|
mediaProps = mediaFrame.state().attributes.image.toJSON();
|
2017-08-14 19:56:42 +02:00
|
|
|
linkType = mediaProps.link;
|
|
|
|
mediaProps.link = mediaProps.linkUrl;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
control.selectedAttachment.set( mediaProps );
|
2017-08-14 19:56:42 +02:00
|
|
|
control.displaySettings.set( 'link', linkType );
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
control.model.set( _.extend(
|
|
|
|
control.mapMediaToModelProps( mediaProps ),
|
|
|
|
{ error: false }
|
|
|
|
) );
|
|
|
|
};
|
|
|
|
|
|
|
|
mediaFrame.state( 'image-details' ).on( 'update', updateCallback );
|
|
|
|
mediaFrame.state( 'replace-image' ).on( 'replace', updateCallback );
|
|
|
|
|
|
|
|
// Disable syncing of attachment changes back to server. See <https://core.trac.wordpress.org/ticket/40403>.
|
|
|
|
defaultSync = wp.media.model.Attachment.prototype.sync;
|
|
|
|
wp.media.model.Attachment.prototype.sync = function rejectedSync() {
|
|
|
|
return $.Deferred().rejectWith( this ).promise();
|
|
|
|
};
|
|
|
|
mediaFrame.on( 'close', function onClose() {
|
|
|
|
mediaFrame.detach();
|
|
|
|
wp.media.model.Attachment.prototype.sync = defaultSync;
|
|
|
|
});
|
|
|
|
|
|
|
|
mediaFrame.open();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get props which are merged on top of the model when an embed is chosen (as opposed to an attachment).
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Object} Reset/override props.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
getEmbedResetProps: function getEmbedResetProps() {
|
|
|
|
return _.extend(
|
|
|
|
component.MediaWidgetControl.prototype.getEmbedResetProps.call( this ),
|
|
|
|
{
|
|
|
|
size: 'full',
|
|
|
|
width: 0,
|
|
|
|
height: 0
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-05-15 20:42:44 +02:00
|
|
|
/**
|
|
|
|
* Get the instance props from the media selection frame.
|
|
|
|
*
|
|
|
|
* Prevent the image_title attribute from being initially set when adding an image from the media library.
|
|
|
|
*
|
|
|
|
* @param {wp.media.view.MediaFrame.Select} mediaFrame - Select frame.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Object} Props.
|
2017-05-15 20:42:44 +02:00
|
|
|
*/
|
|
|
|
getModelPropsFromMediaFrame: function getModelPropsFromMediaFrame( mediaFrame ) {
|
|
|
|
var control = this;
|
|
|
|
return _.omit(
|
|
|
|
component.MediaWidgetControl.prototype.getModelPropsFromMediaFrame.call( control, mediaFrame ),
|
|
|
|
'image_title'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/**
|
|
|
|
* Map model props to preview template props.
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Object} Preview template props.
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
|
|
|
mapModelToPreviewTemplateProps: function mapModelToPreviewTemplateProps() {
|
2017-08-14 19:56:42 +02:00
|
|
|
var control = this, previewTemplateProps, url;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
url = control.model.get( 'url' );
|
2017-08-14 19:56:42 +02:00
|
|
|
previewTemplateProps = component.MediaWidgetControl.prototype.mapModelToPreviewTemplateProps.call( control );
|
|
|
|
previewTemplateProps.currentFilename = url ? url.replace( /\?.*$/, '' ).replace( /^.+\//, '' ) : '';
|
|
|
|
previewTemplateProps.link_url = control.model.get( 'link_url' );
|
|
|
|
return previewTemplateProps;
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Exports.
|
|
|
|
component.controlConstructors.media_image = ImageWidgetControl;
|
|
|
|
component.modelConstructors.media_image = ImageWidgetModel;
|
|
|
|
|
|
|
|
})( wp.mediaWidgets, jQuery );
|