Header Images: Add suggested dimensions to the media workflow.
This updates [28030] to the latest patch. props gcorne. see #21785. Built from https://develop.svn.wordpress.org/trunk@28031 git-svn-id: http://core.svn.wordpress.org/trunk@27861 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6b41f728d4
commit
c870767d98
|
@ -424,24 +424,25 @@
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
this.frame = wp.media({
|
this.frame = wp.media({
|
||||||
title: l10n.chooseImage,
|
|
||||||
library: {
|
|
||||||
type: 'image'
|
|
||||||
},
|
|
||||||
button: {
|
button: {
|
||||||
text: l10n.selectAndCrop,
|
text: l10n.selectAndCrop,
|
||||||
close: false
|
close: false
|
||||||
},
|
},
|
||||||
multiple: false,
|
states: [
|
||||||
crop: {
|
new wp.media.controller.Library({
|
||||||
suggestedWidth: _wpCustomizeHeader.data.width,
|
title: l10n.chooseImage,
|
||||||
suggestedHeight: _wpCustomizeHeader.data.height,
|
library: wp.media.query({ type: 'image' }),
|
||||||
imgSelectOptions: this.calculateImageSelectOptions
|
multiple: false,
|
||||||
}
|
priority: 20,
|
||||||
|
suggestedWidth: _wpCustomizeHeader.data.width,
|
||||||
|
suggestedHeight: _wpCustomizeHeader.data.height
|
||||||
|
}),
|
||||||
|
new wp.media.controller.Cropper({
|
||||||
|
imgSelectOptions: this.calculateImageSelectOptions
|
||||||
|
})
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
this.frame.states.add([new wp.media.controller.Cropper()]);
|
|
||||||
|
|
||||||
this.frame.on('select', this.onSelect, this);
|
this.frame.on('select', this.onSelect, this);
|
||||||
this.frame.on('cropped', this.onCropped, this);
|
this.frame.on('cropped', this.onCropped, this);
|
||||||
this.frame.on('skippedcrop', this.onSkippedCrop, this);
|
this.frame.on('skippedcrop', this.onSkippedCrop, this);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1843,6 +1843,9 @@
|
||||||
display: state.get('displaySettings'),
|
display: state.get('displaySettings'),
|
||||||
dragInfo: state.get('dragInfo'),
|
dragInfo: state.get('dragInfo'),
|
||||||
|
|
||||||
|
suggestedWidth: state.get('suggestedWidth'),
|
||||||
|
suggestedHeight: state.get('suggestedHeight'),
|
||||||
|
|
||||||
AttachmentView: state.get('AttachmentView')
|
AttachmentView: state.get('AttachmentView')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -3314,12 +3317,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
prepare: function() {
|
prepare: function() {
|
||||||
var cropOptions = this.controller.options.crop;
|
var suggestedWidth = this.controller.state().get('suggestedWidth'),
|
||||||
if ( cropOptions ) {
|
suggestedHeight = this.controller.state().get('suggestedHeight');
|
||||||
|
|
||||||
|
if ( suggestedWidth && suggestedHeight ) {
|
||||||
return {
|
return {
|
||||||
suggestedWidth: cropOptions.suggestedWidth,
|
suggestedWidth: suggestedWidth,
|
||||||
suggestedHeight: cropOptions.suggestedHeight
|
suggestedHeight: suggestedHeight
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -5164,8 +5169,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
createToolbar: function() {
|
createToolbar: function() {
|
||||||
var filters, FiltersConstructor,
|
var filters, FiltersConstructor;
|
||||||
frameOptions = this.controller.options;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {wp.media.view.Toolbar}
|
* @member {wp.media.view.Toolbar}
|
||||||
|
@ -5210,9 +5214,9 @@
|
||||||
}) );
|
}) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frameOptions.crop ) {
|
if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
|
||||||
this.toolbar.set( 'suggestedDimensions', new media.View({
|
this.toolbar.set( 'suggestedDimensions', new media.View({
|
||||||
el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + frameOptions.crop.suggestedWidth + ' × ' + frameOptions.crop.suggestedHeight + '</div>' )[0],
|
el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + this.options.suggestedWidth + ' × ' + this.options.suggestedHeight + '</div>' )[0],
|
||||||
priority: -40
|
priority: -40
|
||||||
}) );
|
}) );
|
||||||
}
|
}
|
||||||
|
@ -6248,7 +6252,7 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onImageLoad: function() {
|
onImageLoad: function() {
|
||||||
var imgOptions = this.controller.frame.options.crop.imgSelectOptions;
|
var imgOptions = this.controller.get('imgSelectOptions');
|
||||||
if (typeof imgOptions === 'function') {
|
if (typeof imgOptions === 'function') {
|
||||||
imgOptions = imgOptions(this.options.attachment, this.controller);
|
imgOptions = imgOptions(this.options.attachment, this.controller);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue