Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: image-edit.js
/**
[0] Fix | Delete
* The functions necessary for editing images.
[1] Fix | Delete
*
[2] Fix | Delete
* @since 2.9.0
[3] Fix | Delete
* @output wp-admin/js/image-edit.js
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/* global ajaxurl, confirm */
[7] Fix | Delete
[8] Fix | Delete
(function($) {
[9] Fix | Delete
var __ = wp.i18n.__;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Contains all the methods to initialise and control the image editor.
[13] Fix | Delete
*
[14] Fix | Delete
* @namespace imageEdit
[15] Fix | Delete
*/
[16] Fix | Delete
var imageEdit = window.imageEdit = {
[17] Fix | Delete
iasapi : {},
[18] Fix | Delete
hold : {},
[19] Fix | Delete
postid : '',
[20] Fix | Delete
_view : false,
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Handle crop tool clicks.
[24] Fix | Delete
*/
[25] Fix | Delete
handleCropToolClick: function( postid, nonce, cropButton ) {
[26] Fix | Delete
var img = $( '#image-preview-' + postid ),
[27] Fix | Delete
selection = this.iasapi.getSelection();
[28] Fix | Delete
[29] Fix | Delete
// Ensure selection is available, otherwise reset to full image.
[30] Fix | Delete
if ( isNaN( selection.x1 ) ) {
[31] Fix | Delete
this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': img.innerWidth(), 'y2': img.innerHeight(), 'width': img.innerWidth(), 'height': img.innerHeight() } );
[32] Fix | Delete
selection = this.iasapi.getSelection();
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
// If we don't already have a selection, select the entire image.
[36] Fix | Delete
if ( 0 === selection.x1 && 0 === selection.y1 && 0 === selection.x2 && 0 === selection.y2 ) {
[37] Fix | Delete
this.iasapi.setSelection( 0, 0, img.innerWidth(), img.innerHeight(), true );
[38] Fix | Delete
this.iasapi.setOptions( { show: true } );
[39] Fix | Delete
this.iasapi.update();
[40] Fix | Delete
} else {
[41] Fix | Delete
[42] Fix | Delete
// Otherwise, perform the crop.
[43] Fix | Delete
imageEdit.crop( postid, nonce , cropButton );
[44] Fix | Delete
}
[45] Fix | Delete
},
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Converts a value to an integer.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 2.9.0
[51] Fix | Delete
*
[52] Fix | Delete
* @memberof imageEdit
[53] Fix | Delete
*
[54] Fix | Delete
* @param {number} f The float value that should be converted.
[55] Fix | Delete
*
[56] Fix | Delete
* @return {number} The integer representation from the float value.
[57] Fix | Delete
*/
[58] Fix | Delete
intval : function(f) {
[59] Fix | Delete
/*
[60] Fix | Delete
* Bitwise OR operator: one of the obscure ways to truncate floating point figures,
[61] Fix | Delete
* worth reminding JavaScript doesn't have a distinct "integer" type.
[62] Fix | Delete
*/
[63] Fix | Delete
return f | 0;
[64] Fix | Delete
},
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Adds the disabled attribute and class to a single form element or a field set.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 2.9.0
[70] Fix | Delete
*
[71] Fix | Delete
* @memberof imageEdit
[72] Fix | Delete
*
[73] Fix | Delete
* @param {jQuery} el The element that should be modified.
[74] Fix | Delete
* @param {boolean|number} s The state for the element. If set to true
[75] Fix | Delete
* the element is disabled,
[76] Fix | Delete
* otherwise the element is enabled.
[77] Fix | Delete
* The function is sometimes called with a 0 or 1
[78] Fix | Delete
* instead of true or false.
[79] Fix | Delete
*
[80] Fix | Delete
* @return {void}
[81] Fix | Delete
*/
[82] Fix | Delete
setDisabled : function( el, s ) {
[83] Fix | Delete
/*
[84] Fix | Delete
* `el` can be a single form element or a fieldset. Before #28864, the disabled state on
[85] Fix | Delete
* some text fields was handled targeting $('input', el). Now we need to handle the
[86] Fix | Delete
* disabled state on buttons too so we can just target `el` regardless if it's a single
[87] Fix | Delete
* element or a fieldset because when a fieldset is disabled, its descendants are disabled too.
[88] Fix | Delete
*/
[89] Fix | Delete
if ( s ) {
[90] Fix | Delete
el.removeClass( 'disabled' ).prop( 'disabled', false );
[91] Fix | Delete
} else {
[92] Fix | Delete
el.addClass( 'disabled' ).prop( 'disabled', true );
[93] Fix | Delete
}
[94] Fix | Delete
},
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Initializes the image editor.
[98] Fix | Delete
*
[99] Fix | Delete
* @since 2.9.0
[100] Fix | Delete
*
[101] Fix | Delete
* @memberof imageEdit
[102] Fix | Delete
*
[103] Fix | Delete
* @param {number} postid The post ID.
[104] Fix | Delete
*
[105] Fix | Delete
* @return {void}
[106] Fix | Delete
*/
[107] Fix | Delete
init : function(postid) {
[108] Fix | Delete
var t = this, old = $('#image-editor-' + t.postid),
[109] Fix | Delete
x = t.intval( $('#imgedit-x-' + postid).val() ),
[110] Fix | Delete
y = t.intval( $('#imgedit-y-' + postid).val() );
[111] Fix | Delete
[112] Fix | Delete
if ( t.postid !== postid && old.length ) {
[113] Fix | Delete
t.close(t.postid);
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
t.hold.w = t.hold.ow = x;
[117] Fix | Delete
t.hold.h = t.hold.oh = y;
[118] Fix | Delete
t.hold.xy_ratio = x / y;
[119] Fix | Delete
t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
[120] Fix | Delete
t.postid = postid;
[121] Fix | Delete
$('#imgedit-response-' + postid).empty();
[122] Fix | Delete
[123] Fix | Delete
$('#imgedit-panel-' + postid).on( 'keypress', 'input[type="text"]', function(e) {
[124] Fix | Delete
var k = e.keyCode;
[125] Fix | Delete
[126] Fix | Delete
// Key codes 37 through 40 are the arrow keys.
[127] Fix | Delete
if ( 36 < k && k < 41 ) {
[128] Fix | Delete
$(this).trigger( 'blur' );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
// The key code 13 is the Enter key.
[132] Fix | Delete
if ( 13 === k ) {
[133] Fix | Delete
e.preventDefault();
[134] Fix | Delete
e.stopPropagation();
[135] Fix | Delete
return false;
[136] Fix | Delete
}
[137] Fix | Delete
});
[138] Fix | Delete
[139] Fix | Delete
$( document ).on( 'image-editor-ui-ready', this.focusManager );
[140] Fix | Delete
},
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Toggles the wait/load icon in the editor.
[144] Fix | Delete
*
[145] Fix | Delete
* @since 2.9.0
[146] Fix | Delete
* @since 5.5.0 Added the triggerUIReady parameter.
[147] Fix | Delete
*
[148] Fix | Delete
* @memberof imageEdit
[149] Fix | Delete
*
[150] Fix | Delete
* @param {number} postid The post ID.
[151] Fix | Delete
* @param {number} toggle Is 0 or 1, fades the icon in when 1 and out when 0.
[152] Fix | Delete
* @param {boolean} triggerUIReady Whether to trigger a custom event when the UI is ready. Default false.
[153] Fix | Delete
*
[154] Fix | Delete
* @return {void}
[155] Fix | Delete
*/
[156] Fix | Delete
toggleEditor: function( postid, toggle, triggerUIReady ) {
[157] Fix | Delete
var wait = $('#imgedit-wait-' + postid);
[158] Fix | Delete
[159] Fix | Delete
if ( toggle ) {
[160] Fix | Delete
wait.fadeIn( 'fast' );
[161] Fix | Delete
} else {
[162] Fix | Delete
wait.fadeOut( 'fast', function() {
[163] Fix | Delete
if ( triggerUIReady ) {
[164] Fix | Delete
$( document ).trigger( 'image-editor-ui-ready' );
[165] Fix | Delete
}
[166] Fix | Delete
} );
[167] Fix | Delete
}
[168] Fix | Delete
},
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Shows or hides the image edit help box.
[172] Fix | Delete
*
[173] Fix | Delete
* @since 2.9.0
[174] Fix | Delete
*
[175] Fix | Delete
* @memberof imageEdit
[176] Fix | Delete
*
[177] Fix | Delete
* @param {HTMLElement} el The element to create the help window in.
[178] Fix | Delete
*
[179] Fix | Delete
* @return {boolean} Always returns false.
[180] Fix | Delete
*/
[181] Fix | Delete
toggleHelp : function(el) {
[182] Fix | Delete
var $el = $( el );
[183] Fix | Delete
$el
[184] Fix | Delete
.attr( 'aria-expanded', 'false' === $el.attr( 'aria-expanded' ) ? 'true' : 'false' )
[185] Fix | Delete
.parents( '.imgedit-group-top' ).toggleClass( 'imgedit-help-toggled' ).find( '.imgedit-help' ).slideToggle( 'fast' );
[186] Fix | Delete
[187] Fix | Delete
return false;
[188] Fix | Delete
},
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Gets the value from the image edit target.
[192] Fix | Delete
*
[193] Fix | Delete
* The image edit target contains the image sizes where the (possible) changes
[194] Fix | Delete
* have to be applied to.
[195] Fix | Delete
*
[196] Fix | Delete
* @since 2.9.0
[197] Fix | Delete
*
[198] Fix | Delete
* @memberof imageEdit
[199] Fix | Delete
*
[200] Fix | Delete
* @param {number} postid The post ID.
[201] Fix | Delete
*
[202] Fix | Delete
* @return {string} The value from the imagedit-save-target input field when available,
[203] Fix | Delete
* or 'full' when not available.
[204] Fix | Delete
*/
[205] Fix | Delete
getTarget : function(postid) {
[206] Fix | Delete
return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full';
[207] Fix | Delete
},
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Recalculates the height or width and keeps the original aspect ratio.
[211] Fix | Delete
*
[212] Fix | Delete
* If the original image size is exceeded a red exclamation mark is shown.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 2.9.0
[215] Fix | Delete
*
[216] Fix | Delete
* @memberof imageEdit
[217] Fix | Delete
*
[218] Fix | Delete
* @param {number} postid The current post ID.
[219] Fix | Delete
* @param {number} x Is 0 when it applies the y-axis
[220] Fix | Delete
* and 1 when applicable for the x-axis.
[221] Fix | Delete
* @param {jQuery} el Element.
[222] Fix | Delete
*
[223] Fix | Delete
* @return {void}
[224] Fix | Delete
*/
[225] Fix | Delete
scaleChanged : function( postid, x, el ) {
[226] Fix | Delete
var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid),
[227] Fix | Delete
warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = '';
[228] Fix | Delete
[229] Fix | Delete
if ( false === this.validateNumeric( el ) ) {
[230] Fix | Delete
return;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
if ( x ) {
[234] Fix | Delete
h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : '';
[235] Fix | Delete
h.val( h1 );
[236] Fix | Delete
} else {
[237] Fix | Delete
w1 = ( h.val() !== '' ) ? Math.round( h.val() * this.hold.xy_ratio ) : '';
[238] Fix | Delete
w.val( w1 );
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) {
[242] Fix | Delete
warn.css('visibility', 'visible');
[243] Fix | Delete
} else {
[244] Fix | Delete
warn.css('visibility', 'hidden');
[245] Fix | Delete
}
[246] Fix | Delete
},
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Gets the selected aspect ratio.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 2.9.0
[252] Fix | Delete
*
[253] Fix | Delete
* @memberof imageEdit
[254] Fix | Delete
*
[255] Fix | Delete
* @param {number} postid The post ID.
[256] Fix | Delete
*
[257] Fix | Delete
* @return {string} The aspect ratio.
[258] Fix | Delete
*/
[259] Fix | Delete
getSelRatio : function(postid) {
[260] Fix | Delete
var x = this.hold.w, y = this.hold.h,
[261] Fix | Delete
X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
[262] Fix | Delete
Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
[263] Fix | Delete
[264] Fix | Delete
if ( X && Y ) {
[265] Fix | Delete
return X + ':' + Y;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if ( x && y ) {
[269] Fix | Delete
return x + ':' + y;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
return '1:1';
[273] Fix | Delete
},
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Removes the last action from the image edit history.
[277] Fix | Delete
* The history consist of (edit) actions performed on the image.
[278] Fix | Delete
*
[279] Fix | Delete
* @since 2.9.0
[280] Fix | Delete
*
[281] Fix | Delete
* @memberof imageEdit
[282] Fix | Delete
*
[283] Fix | Delete
* @param {number} postid The post ID.
[284] Fix | Delete
* @param {number} setSize 0 or 1, when 1 the image resets to its original size.
[285] Fix | Delete
*
[286] Fix | Delete
* @return {string} JSON string containing the history or an empty string if no history exists.
[287] Fix | Delete
*/
[288] Fix | Delete
filterHistory : function(postid, setSize) {
[289] Fix | Delete
// Apply undo state to history.
[290] Fix | Delete
var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
[291] Fix | Delete
[292] Fix | Delete
if ( history !== '' ) {
[293] Fix | Delete
// Read the JSON string with the image edit history.
[294] Fix | Delete
history = JSON.parse(history);
[295] Fix | Delete
pop = this.intval( $('#imgedit-undone-' + postid).val() );
[296] Fix | Delete
if ( pop > 0 ) {
[297] Fix | Delete
while ( pop > 0 ) {
[298] Fix | Delete
history.pop();
[299] Fix | Delete
pop--;
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
// Reset size to its original state.
[304] Fix | Delete
if ( setSize ) {
[305] Fix | Delete
if ( !history.length ) {
[306] Fix | Delete
this.hold.w = this.hold.ow;
[307] Fix | Delete
this.hold.h = this.hold.oh;
[308] Fix | Delete
return '';
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
// Restore original 'o'.
[312] Fix | Delete
o = history[history.length - 1];
[313] Fix | Delete
[314] Fix | Delete
// c = 'crop', r = 'rotate', f = 'flip'.
[315] Fix | Delete
o = o.c || o.r || o.f || false;
[316] Fix | Delete
[317] Fix | Delete
if ( o ) {
[318] Fix | Delete
// fw = Full image width.
[319] Fix | Delete
this.hold.w = o.fw;
[320] Fix | Delete
// fh = Full image height.
[321] Fix | Delete
this.hold.h = o.fh;
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
// Filter the last step/action from the history.
[326] Fix | Delete
for ( n in history ) {
[327] Fix | Delete
i = history[n];
[328] Fix | Delete
if ( i.hasOwnProperty('c') ) {
[329] Fix | Delete
op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } };
[330] Fix | Delete
} else if ( i.hasOwnProperty('r') ) {
[331] Fix | Delete
op[n] = { 'r': i.r.r };
[332] Fix | Delete
} else if ( i.hasOwnProperty('f') ) {
[333] Fix | Delete
op[n] = { 'f': i.f.f };
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
return JSON.stringify(op);
[337] Fix | Delete
}
[338] Fix | Delete
return '';
[339] Fix | Delete
},
[340] Fix | Delete
/**
[341] Fix | Delete
* Binds the necessary events to the image.
[342] Fix | Delete
*
[343] Fix | Delete
* When the image source is reloaded the image will be reloaded.
[344] Fix | Delete
*
[345] Fix | Delete
* @since 2.9.0
[346] Fix | Delete
*
[347] Fix | Delete
* @memberof imageEdit
[348] Fix | Delete
*
[349] Fix | Delete
* @param {number} postid The post ID.
[350] Fix | Delete
* @param {string} nonce The nonce to verify the request.
[351] Fix | Delete
* @param {function} callback Function to execute when the image is loaded.
[352] Fix | Delete
*
[353] Fix | Delete
* @return {void}
[354] Fix | Delete
*/
[355] Fix | Delete
refreshEditor : function(postid, nonce, callback) {
[356] Fix | Delete
var t = this, data, img;
[357] Fix | Delete
[358] Fix | Delete
t.toggleEditor(postid, 1);
[359] Fix | Delete
data = {
[360] Fix | Delete
'action': 'imgedit-preview',
[361] Fix | Delete
'_ajax_nonce': nonce,
[362] Fix | Delete
'postid': postid,
[363] Fix | Delete
'history': t.filterHistory(postid, 1),
[364] Fix | Delete
'rand': t.intval(Math.random() * 1000000)
[365] Fix | Delete
};
[366] Fix | Delete
[367] Fix | Delete
img = $( '<img id="image-preview-' + postid + '" alt="" />' )
[368] Fix | Delete
.on( 'load', { history: data.history }, function( event ) {
[369] Fix | Delete
var max1, max2,
[370] Fix | Delete
parent = $( '#imgedit-crop-' + postid ),
[371] Fix | Delete
t = imageEdit,
[372] Fix | Delete
historyObj;
[373] Fix | Delete
[374] Fix | Delete
// Checks if there already is some image-edit history.
[375] Fix | Delete
if ( '' !== event.data.history ) {
[376] Fix | Delete
historyObj = JSON.parse( event.data.history );
[377] Fix | Delete
// If last executed action in history is a crop action.
[378] Fix | Delete
if ( historyObj[historyObj.length - 1].hasOwnProperty( 'c' ) ) {
[379] Fix | Delete
/*
[380] Fix | Delete
* A crop action has completed and the crop button gets disabled
[381] Fix | Delete
* ensure the undo button is enabled.
[382] Fix | Delete
*/
[383] Fix | Delete
t.setDisabled( $( '#image-undo-' + postid) , true );
[384] Fix | Delete
// Move focus to the undo button to avoid a focus loss.
[385] Fix | Delete
$( '#image-undo-' + postid ).trigger( 'focus' );
[386] Fix | Delete
}
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
parent.empty().append(img);
[390] Fix | Delete
[391] Fix | Delete
// w, h are the new full size dimensions.
[392] Fix | Delete
max1 = Math.max( t.hold.w, t.hold.h );
[393] Fix | Delete
max2 = Math.max( $(img).width(), $(img).height() );
[394] Fix | Delete
t.hold.sizer = max1 > max2 ? max2 / max1 : 1;
[395] Fix | Delete
[396] Fix | Delete
t.initCrop(postid, img, parent);
[397] Fix | Delete
[398] Fix | Delete
if ( (typeof callback !== 'undefined') && callback !== null ) {
[399] Fix | Delete
callback();
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === '0' ) {
[403] Fix | Delete
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', false);
[404] Fix | Delete
} else {
[405] Fix | Delete
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
t.toggleEditor(postid, 0);
[409] Fix | Delete
})
[410] Fix | Delete
.on( 'error', function() {
[411] Fix | Delete
var errorMessage = __( 'Could not load the preview image. Please reload the page and try again.' );
[412] Fix | Delete
[413] Fix | Delete
$( '#imgedit-crop-' + postid )
[414] Fix | Delete
.empty()
[415] Fix | Delete
.append( '<div class="notice notice-error" tabindex="-1" role="alert"><p>' + errorMessage + '</p></div>' );
[416] Fix | Delete
[417] Fix | Delete
t.toggleEditor( postid, 0, true );
[418] Fix | Delete
wp.a11y.speak( errorMessage, 'assertive' );
[419] Fix | Delete
} )
[420] Fix | Delete
.attr('src', ajaxurl + '?' + $.param(data));
[421] Fix | Delete
},
[422] Fix | Delete
/**
[423] Fix | Delete
* Performs an image edit action.
[424] Fix | Delete
*
[425] Fix | Delete
* @since 2.9.0
[426] Fix | Delete
*
[427] Fix | Delete
* @memberof imageEdit
[428] Fix | Delete
*
[429] Fix | Delete
* @param {number} postid The post ID.
[430] Fix | Delete
* @param {string} nonce The nonce to verify the request.
[431] Fix | Delete
* @param {string} action The action to perform on the image.
[432] Fix | Delete
* The possible actions are: "scale" and "restore".
[433] Fix | Delete
*
[434] Fix | Delete
* @return {boolean|void} Executes a post request that refreshes the page
[435] Fix | Delete
* when the action is performed.
[436] Fix | Delete
* Returns false if a invalid action is given,
[437] Fix | Delete
* or when the action cannot be performed.
[438] Fix | Delete
*/
[439] Fix | Delete
action : function(postid, nonce, action) {
[440] Fix | Delete
var t = this, data, w, h, fw, fh;
[441] Fix | Delete
[442] Fix | Delete
if ( t.notsaved(postid) ) {
[443] Fix | Delete
return false;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
data = {
[447] Fix | Delete
'action': 'image-editor',
[448] Fix | Delete
'_ajax_nonce': nonce,
[449] Fix | Delete
'postid': postid
[450] Fix | Delete
};
[451] Fix | Delete
[452] Fix | Delete
if ( 'scale' === action ) {
[453] Fix | Delete
w = $('#imgedit-scale-width-' + postid),
[454] Fix | Delete
h = $('#imgedit-scale-height-' + postid),
[455] Fix | Delete
fw = t.intval(w.val()),
[456] Fix | Delete
fh = t.intval(h.val());
[457] Fix | Delete
[458] Fix | Delete
if ( fw < 1 ) {
[459] Fix | Delete
w.trigger( 'focus' );
[460] Fix | Delete
return false;
[461] Fix | Delete
} else if ( fh < 1 ) {
[462] Fix | Delete
h.trigger( 'focus' );
[463] Fix | Delete
return false;
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
if ( fw === t.hold.ow || fh === t.hold.oh ) {
[467] Fix | Delete
return false;
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
data['do'] = 'scale';
[471] Fix | Delete
data.fwidth = fw;
[472] Fix | Delete
data.fheight = fh;
[473] Fix | Delete
} else if ( 'restore' === action ) {
[474] Fix | Delete
data['do'] = 'restore';
[475] Fix | Delete
} else {
[476] Fix | Delete
return false;
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
t.toggleEditor(postid, 1);
[480] Fix | Delete
$.post( ajaxurl, data, function( response ) {
[481] Fix | Delete
$( '#image-editor-' + postid ).empty().append( response.data.html );
[482] Fix | Delete
t.toggleEditor( postid, 0, true );
[483] Fix | Delete
// Refresh the attachment model so that changes propagate.
[484] Fix | Delete
if ( t._view ) {
[485] Fix | Delete
t._view.refresh();
[486] Fix | Delete
}
[487] Fix | Delete
} ).done( function( response ) {
[488] Fix | Delete
// Whether the executed action was `scale` or `restore`, the response does have a message.
[489] Fix | Delete
if ( response && response.data.message.msg ) {
[490] Fix | Delete
wp.a11y.speak( response.data.message.msg );
[491] Fix | Delete
return;
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
if ( response && response.data.message.error ) {
[495] Fix | Delete
wp.a11y.speak( response.data.message.error );
[496] Fix | Delete
}
[497] Fix | Delete
} );
[498] Fix | Delete
},
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function