mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-10 22:58:33 +02:00
* The way that the JS modules for media are currently set up turns the existing global `wp.media` namespace into a read-only API, this is bad. * For the existing module implementation to work with plugins, those looking to override or extend a class would have to modify their own plugin to use `browserify` - we can't expect this to happen * Because the general way that plugins override media classes is via machete (resetting them to something else), we cannot use `require( 'module' )` in the internal code for media modules We CAN continue to use `require( 'fun/js' )` in the manifests for media. Future code/projects should carefully consider what is made to be public API. In 3.5, EVERYTHING was made public, so everything shall remain public. See #31684, #28510. Built from https://develop.svn.wordpress.org/trunk@31935 git-svn-id: http://core.svn.wordpress.org/trunk@31914 1a063a9b-81f0-0310-95a4-ce76da25c4cd
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
/*globals wp, _, jQuery */
|
|
|
|
/**
|
|
* wp.media.view.Cropper
|
|
*
|
|
* Uses the imgAreaSelect plugin to allow a user to crop an image.
|
|
*
|
|
* Takes imgAreaSelect options from
|
|
* wp.customize.HeaderControl.calculateImageSelectOptions via
|
|
* wp.customize.HeaderControl.openMM.
|
|
*
|
|
* @class
|
|
* @augments wp.media.View
|
|
* @augments wp.Backbone.View
|
|
* @augments Backbone.View
|
|
*/
|
|
var View = wp.media.View,
|
|
UploaderStatus = wp.media.view.UploaderStatus,
|
|
l10n = wp.media.view.l10n,
|
|
$ = jQuery,
|
|
Cropper;
|
|
|
|
Cropper = View.extend({
|
|
className: 'crop-content',
|
|
template: wp.template('crop-content'),
|
|
initialize: function() {
|
|
_.bindAll(this, 'onImageLoad');
|
|
},
|
|
ready: function() {
|
|
this.controller.frame.on('content:error:crop', this.onError, this);
|
|
this.$image = this.$el.find('.crop-image');
|
|
this.$image.on('load', this.onImageLoad);
|
|
$(window).on('resize.cropper', _.debounce(this.onImageLoad, 250));
|
|
},
|
|
remove: function() {
|
|
$(window).off('resize.cropper');
|
|
this.$el.remove();
|
|
this.$el.off();
|
|
View.prototype.remove.apply(this, arguments);
|
|
},
|
|
prepare: function() {
|
|
return {
|
|
title: l10n.cropYourImage,
|
|
url: this.options.attachment.get('url')
|
|
};
|
|
},
|
|
onImageLoad: function() {
|
|
var imgOptions = this.controller.get('imgSelectOptions');
|
|
if (typeof imgOptions === 'function') {
|
|
imgOptions = imgOptions(this.options.attachment, this.controller);
|
|
}
|
|
|
|
imgOptions = _.extend(imgOptions, {parent: this.$el});
|
|
this.trigger('image-loaded');
|
|
this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
|
|
},
|
|
onError: function() {
|
|
var filename = this.options.attachment.get('filename');
|
|
|
|
this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({
|
|
filename: UploaderStatus.prototype.filename(filename),
|
|
message: window._wpMediaViewsL10n.cropError
|
|
}), { at: 0 });
|
|
}
|
|
});
|
|
|
|
module.exports = Cropper;
|