' + imageEditL10n.error + '
');
t.toggleEditor(postid, 0);
})
.attr('src', ajaxurl + '?' + $.param(data));
},
/**
* Performs an image edit action.
*
* @memberof imageEdit
* @since 2.9.0
*
* @param {number} postid The post id.
* @param {string} nonce The nonce to verify the request.
* @param {string} action The action to perform on the image.
* The possible actions are: "scale" and "restore".
*
* @returns {boolean|void} Executes a post request that refreshes the page
* when the action is performed.
* Returns false if a invalid action is given,
* or when the action cannot be performed.
*/
action : function(postid, nonce, action) {
var t = this, data, w, h, fw, fh;
if ( t.notsaved(postid) ) {
return false;
}
data = {
'action': 'image-editor',
'_ajax_nonce': nonce,
'postid': postid
};
if ( 'scale' === action ) {
w = $('#imgedit-scale-width-' + postid),
h = $('#imgedit-scale-height-' + postid),
fw = t.intval(w.val()),
fh = t.intval(h.val());
if ( fw < 1 ) {
w.focus();
return false;
} else if ( fh < 1 ) {
h.focus();
return false;
}
if ( fw === t.hold.ow || fh === t.hold.oh ) {
return false;
}
data['do'] = 'scale';
data.fwidth = fw;
data.fheight = fh;
} else if ( 'restore' === action ) {
data['do'] = 'restore';
} else {
return false;
}
t.toggleEditor(postid, 1);
$.post(ajaxurl, data, function(r) {
$('#image-editor-' + postid).empty().append(r);
t.toggleEditor(postid, 0);
// refresh the attachment model so that changes propagate
if ( t._view ) {
t._view.refresh();
}
});
},
/**
* Stores the changes that are made to the image.
*
* @memberof imageEdit
* @since 2.9.0
*
* @param {number} postid The post id to get the image from the database.
* @param {string} nonce The nonce to verify the request.
*
* @returns {boolean|void} If the actions are successfully saved a response message is shown.
* Returns false if there is no image editing history,
* thus there are not edit-actions performed on the image.
*/
save : function(postid, nonce) {
var data,
target = this.getTarget(postid),
history = this.filterHistory(postid, 0),
self = this;
if ( '' === history ) {
return false;
}
this.toggleEditor(postid, 1);
data = {
'action': 'image-editor',
'_ajax_nonce': nonce,
'postid': postid,
'history': history,
'target': target,
'context': $('#image-edit-context').length ? $('#image-edit-context').val() : null,
'do': 'save'
};
// Post the image edit data to the backend.
$.post(ajaxurl, data, function(r) {
// Read the response.
var ret = JSON.parse(r);
// If a response is returned, close the editor and show an error.
if ( ret.error ) {
$('#imgedit-response-' + postid).html('