diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js
index 88eb2922e3..f9f3416cb0 100644
--- a/wp-admin/js/image-edit.js
+++ b/wp-admin/js/image-edit.js
@@ -1,7 +1,7 @@
-var imageEdit;
+/* global imageEditL10n, ajaxurl, confirm */
(function($) {
-imageEdit = {
+var imageEdit = window.imageEdit = {
iasapi : {},
hold : {},
postid : '',
@@ -20,28 +20,30 @@ imageEdit = {
}
},
- init : function(postid, nonce) {
+ init : function(postid) {
var t = this, old = $('#image-editor-' + t.postid),
x = t.intval( $('#imgedit-x-' + postid).val() ),
y = t.intval( $('#imgedit-y-' + postid).val() );
- if ( t.postid != postid && old.length )
+ if ( t.postid !== postid && old.length ) {
t.close(t.postid);
+ }
- t.hold['w'] = t.hold['ow'] = x;
- t.hold['h'] = t.hold['oh'] = y;
- t.hold['xy_ratio'] = x / y;
- t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() );
+ t.hold.w = t.hold.ow = x;
+ t.hold.h = t.hold.oh = y;
+ t.hold.xy_ratio = x / y;
+ t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
t.postid = postid;
$('#imgedit-response-' + postid).empty();
$('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) {
var k = e.keyCode;
- if ( 36 < k && k < 41 )
- $(this).blur()
+ if ( 36 < k && k < 41 ) {
+ $(this).blur();
+ }
- if ( 13 == k ) {
+ if ( 13 === k ) {
e.preventDefault();
e.stopPropagation();
return false;
@@ -52,10 +54,11 @@ imageEdit = {
toggleEditor : function(postid, toggle) {
var wait = $('#imgedit-wait-' + postid);
- if ( toggle )
+ if ( toggle ) {
wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast');
- else
+ } else {
wait.fadeOut('fast');
+ }
},
toggleHelp : function(el) {
@@ -72,29 +75,32 @@ imageEdit = {
warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = '';
if ( x ) {
- h1 = (w.val() != '') ? Math.round( w.val() / this.hold['xy_ratio'] ) : '';
+ h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : '';
h.val( h1 );
} else {
- w1 = (h.val() != '') ? Math.round( h.val() * this.hold['xy_ratio'] ) : '';
+ w1 = ( h.val() !== '' ) ? Math.round( h.val() * this.hold.xy_ratio ) : '';
w.val( w1 );
}
- if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) )
+ if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) {
warn.css('visibility', 'visible');
- else
+ } else {
warn.css('visibility', 'hidden');
+ }
},
getSelRatio : function(postid) {
- var x = this.hold['w'], y = this.hold['h'],
+ var x = this.hold.w, y = this.hold.h,
X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
- if ( X && Y )
+ if ( X && Y ) {
return X + ':' + Y;
+ }
- if ( x && y )
+ if ( x && y ) {
return x + ':' + y;
+ }
return '1:1';
},
@@ -103,7 +109,7 @@ imageEdit = {
// apply undo state to history
var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
- if ( history != '' ) {
+ if ( history !== '' ) {
history = JSON.parse(history);
pop = this.intval( $('#imgedit-undone-' + postid).val() );
if ( pop > 0 ) {
@@ -115,8 +121,8 @@ imageEdit = {
if ( setSize ) {
if ( !history.length ) {
- this.hold['w'] = this.hold['ow'];
- this.hold['h'] = this.hold['oh'];
+ this.hold.w = this.hold.ow;
+ this.hold.h = this.hold.oh;
return '';
}
@@ -125,8 +131,8 @@ imageEdit = {
o = o.c || o.r || o.f || false;
if ( o ) {
- this.hold['w'] = o.fw;
- this.hold['h'] = o.fh;
+ this.hold.w = o.fw;
+ this.hold.h = o.fh;
}
}
@@ -167,18 +173,20 @@ imageEdit = {
// w, h are the new full size dims
max1 = Math.max( t.hold.w, t.hold.h );
max2 = Math.max( $(img).width(), $(img).height() );
- t.hold['sizer'] = max1 > max2 ? max2 / max1 : 1;
+ t.hold.sizer = max1 > max2 ? max2 / max1 : 1;
t.initCrop(postid, img, parent);
t.setCropSelection(postid, 0);
- if ( (typeof callback != "unknown") && callback != null )
+ if ( (typeof callback !== 'undefined') && callback !== null ) {
callback();
+ }
- if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 )
+ if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === 0 ) {
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
- else
+ } else {
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
+ }
t.toggleEditor(postid, 0);
})
@@ -192,8 +200,9 @@ imageEdit = {
action : function(postid, nonce, action) {
var t = this, data, w, h, fw, fh;
- if ( t.notsaved(postid) )
+ if ( t.notsaved(postid) ) {
return false;
+ }
data = {
'action': 'image-editor',
@@ -201,7 +210,7 @@ imageEdit = {
'postid': postid
};
- if ( 'scale' == action ) {
+ if ( 'scale' === action ) {
w = $('#imgedit-scale-width-' + postid),
h = $('#imgedit-scale-height-' + postid),
fw = t.intval(w.val()),
@@ -215,13 +224,14 @@ imageEdit = {
return false;
}
- if ( fw == t.hold.ow || fh == t.hold.oh )
+ 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.fwidth = fw;
+ data.fheight = fh;
+ } else if ( 'restore' === action ) {
data['do'] = 'restore';
} else {
return false;
@@ -237,8 +247,9 @@ imageEdit = {
save : function(postid, nonce) {
var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0);
- if ( '' == history )
+ if ( '' === history ) {
return false;
+ }
this.toggleEditor(postid, 1);
data = {
@@ -260,14 +271,17 @@ imageEdit = {
return;
}
- if ( ret.fw && ret.fh )
+ if ( ret.fw && ret.fh ) {
$('#media-dims-' + postid).html( ret.fw + ' × ' + ret.fh );
+ }
- if ( ret.thumbnail )
+ if ( ret.thumbnail ) {
$('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail);
+ }
- if ( ret.msg )
+ if ( ret.msg ) {
$('#imgedit-response-' + postid).html('
');
+ }
imageEdit.close(postid);
});
@@ -316,7 +330,7 @@ imageEdit = {
minWidth: 3,
minHeight: 3,
- onInit: function(img, c) {
+ onInit: function() {
parent.children().mousedown(function(e){
var ratio = false, sel, defRatio;
@@ -332,7 +346,7 @@ imageEdit = {
});
},
- onSelectStart: function(img, c) {
+ onSelectStart: function() {
imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1);
},
@@ -350,7 +364,7 @@ imageEdit = {
setCropSelection : function(postid, c) {
var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
- sizer = this.hold['sizer'];
+ sizer = this.hold.sizer;
min = min.split(':');
c = c || 0;
@@ -377,8 +391,9 @@ imageEdit = {
close : function(postid, warn) {
warn = warn || false;
- if ( warn && this.notsaved(postid) )
+ if ( warn && this.notsaved(postid) ) {
return false;
+ }
this.iasapi = {};
this.hold = {};
@@ -390,12 +405,13 @@ imageEdit = {
notsaved : function(postid) {
var h = $('#imgedit-history-' + postid).val(),
- history = (h != '') ? JSON.parse(h) : new Array(),
+ history = ( h !== '' ) ? JSON.parse(h) : [],
pop = this.intval( $('#imgedit-undone-' + postid).val() );
if ( pop < history.length ) {
- if ( confirm( $('#imgedit-leaving-' + postid).html() ) )
+ if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) {
return false;
+ }
return true;
}
return false;
@@ -403,7 +419,7 @@ imageEdit = {
addStep : function(op, postid, nonce) {
var t = this, elem = $('#imgedit-history-' + postid),
- history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array(),
+ history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [],
undone = $('#imgedit-undone-' + postid),
pop = t.intval(undone.val());
@@ -423,17 +439,19 @@ imageEdit = {
},
rotate : function(angle, postid, nonce, t) {
- if ( $(t).hasClass('disabled') )
+ if ( $(t).hasClass('disabled') ) {
return false;
+ }
- this.addStep({ 'r': { 'r': angle, 'fw': this.hold['h'], 'fh': this.hold['w'] }}, postid, nonce);
+ this.addStep({ 'r': { 'r': angle, 'fw': this.hold.h, 'fh': this.hold.w }}, postid, nonce);
},
flip : function (axis, postid, nonce, t) {
- if ( $(t).hasClass('disabled') )
+ if ( $(t).hasClass('disabled') ) {
return false;
+ }
- this.addStep({ 'f': { 'f': axis, 'fw': this.hold['w'], 'fh': this.hold['h'] }}, postid, nonce);
+ this.addStep({ 'f': { 'f': axis, 'fw': this.hold.w, 'fh': this.hold.h }}, postid, nonce);
},
crop : function (postid, nonce, t) {
@@ -441,13 +459,14 @@ imageEdit = {
w = this.intval( $('#imgedit-sel-width-' + postid).val() ),
h = this.intval( $('#imgedit-sel-height-' + postid).val() );
- if ( $(t).hasClass('disabled') || sel == '' )
+ if ( $(t).hasClass('disabled') || sel === '' ) {
return false;
+ }
sel = JSON.parse(sel);
if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
- sel['fw'] = w;
- sel['fh'] = h;
+ sel.fw = w;
+ sel.fh = h;
this.addStep({ 'c': sel }, postid, nonce);
}
},
@@ -456,13 +475,14 @@ imageEdit = {
var t = this, button = $('#image-undo-' + postid), elem = $('#imgedit-undone-' + postid),
pop = t.intval( elem.val() ) + 1;
- if ( button.hasClass('disabled') )
+ if ( button.hasClass('disabled') ) {
return;
+ }
elem.val(pop);
t.refreshEditor(postid, nonce, function() {
var elem = $('#imgedit-history-' + postid),
- history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array();
+ history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [];
t.setDisabled($('#image-redo-' + postid), true);
t.setDisabled(button, pop < history.length);
@@ -473,8 +493,9 @@ imageEdit = {
var t = this, button = $('#image-redo-' + postid), elem = $('#imgedit-undone-' + postid),
pop = t.intval( elem.val() ) - 1;
- if ( button.hasClass('disabled') )
+ if ( button.hasClass('disabled') ) {
return;
+ }
elem.val(pop);
t.refreshEditor(postid, nonce, function() {
@@ -487,7 +508,7 @@ imageEdit = {
var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid),
x = this.intval( elX.val() ), y = this.intval( elY.val() ),
img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
- sizer = this.hold['sizer'], x1, y1, x2, y2, ias = this.iasapi;
+ sizer = this.hold.sizer, x1, y1, x2, y2, ias = this.iasapi;
if ( x < 1 ) {
elX.val('');
@@ -527,15 +548,17 @@ imageEdit = {
var s;
num = Math.round(num);
- if ( this.hold.sizer > 0.6 )
+ if ( this.hold.sizer > 0.6 ) {
return num;
+ }
s = num.toString().slice(-1);
- if ( '1' == s )
+ if ( '1' === s ) {
return num - 1;
- else if ( '9' == s )
+ } else if ( '9' === s ) {
return num + 1;
+ }
return num;
},
@@ -556,14 +579,15 @@ imageEdit = {
});
if ( sel = this.iasapi.getSelection(true) ) {
- r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) );
+ r = Math.ceil( sel.y1 + ( ( sel.x2 - sel.x1 ) / ( x / y ) ) );
if ( r > h ) {
r = h;
- if ( n )
+ if ( n ) {
$('#imgedit-crop-height-' + postid).val('');
- else
+ } else {
$('#imgedit-crop-width-' + postid).val('');
+ }
}
this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r );
@@ -571,5 +595,5 @@ imageEdit = {
}
}
}
-}
+};
})(jQuery);
diff --git a/wp-admin/js/image-edit.min.js b/wp-admin/js/image-edit.min.js
index 61d1744517..451cbc5fbf 100644
--- a/wp-admin/js/image-edit.min.js
+++ b/wp-admin/js/image-edit.min.js
@@ -1 +1 @@
-var imageEdit;!function(a){imageEdit={iasapi:{},hold:{},postid:"",intval:function(a){return 0|a},setDisabled:function(b,c){c?(b.removeClass("disabled"),a("input",b).removeAttr("disabled")):(b.addClass("disabled"),a("input",b).prop("disabled",!0))},init:function(b){var c=this,d=a("#image-editor-"+c.postid),e=c.intval(a("#imgedit-x-"+b).val()),f=c.intval(a("#imgedit-y-"+b).val());c.postid!=b&&d.length&&c.close(c.postid),c.hold.w=c.hold.ow=e,c.hold.h=c.hold.oh=f,c.hold.xy_ratio=e/f,c.hold.sizer=parseFloat(a("#imgedit-sizer-"+b).val()),c.postid=b,a("#imgedit-response-"+b).empty(),a('input[type="text"]',"#imgedit-panel-"+b).keypress(function(b){var c=b.keyCode;return c>36&&41>c&&a(this).blur(),13==c?(b.preventDefault(),b.stopPropagation(),!1):void 0})},toggleEditor:function(b,c){var d=a("#imgedit-wait-"+b);c?d.height(a("#imgedit-panel-"+b).height()).fadeIn("fast"):d.fadeOut("fast")},toggleHelp:function(b){return a(b).siblings(".imgedit-help").slideToggle("fast"),!1},getTarget:function(b){return a('input[name="imgedit-target-'+b+'"]:checked',"#imgedit-save-target-"+b).val()||"full"},scaleChanged:function(b,c){var d=a("#imgedit-scale-width-"+b),e=a("#imgedit-scale-height-"+b),f=a("#imgedit-scale-warn-"+b),g="",h="";c?(h=""!=d.val()?Math.round(d.val()/this.hold.xy_ratio):"",e.val(h)):(g=""!=e.val()?Math.round(e.val()*this.hold.xy_ratio):"",d.val(g)),h&&h>this.hold.oh||g&&g>this.hold.ow?f.css("visibility","visible"):f.css("visibility","hidden")},getSelRatio:function(b){var c=this.hold.w,d=this.hold.h,e=this.intval(a("#imgedit-crop-width-"+b).val()),f=this.intval(a("#imgedit-crop-height-"+b).val());return e&&f?e+":"+f:c&&d?c+":"+d:"1:1"},filterHistory:function(b,c){var d,e,f,g,h=a("#imgedit-history-"+b).val(),i=[];if(""!=h){if(h=JSON.parse(h),d=this.intval(a("#imgedit-undone-"+b).val()),d>0)for(;d>0;)h.pop(),d--;if(c){if(!h.length)return this.hold.w=this.hold.ow,this.hold.h=this.hold.oh,"";f=h[h.length-1],f=f.c||f.r||f.f||!1,f&&(this.hold.w=f.fw,this.hold.h=f.fh)}for(e in h)g=h[e],g.hasOwnProperty("c")?i[e]={c:{x:g.c.x,y:g.c.y,w:g.c.w,h:g.c.h}}:g.hasOwnProperty("r")?i[e]={r:g.r.r}:g.hasOwnProperty("f")&&(i[e]={f:g.f.f});return JSON.stringify(i)}return""},refreshEditor:function(b,c,d){var e,f,g=this;g.toggleEditor(b,1),e={action:"imgedit-preview",_ajax_nonce:c,postid:b,history:g.filterHistory(b,1),rand:g.intval(1e6*Math.random())},f=a('').on("load",function(){var c,e,g=a("#imgedit-crop-"+b),h=imageEdit;g.empty().append(f),c=Math.max(h.hold.w,h.hold.h),e=Math.max(a(f).width(),a(f).height()),h.hold.sizer=c>e?e/c:1,h.initCrop(b,f,g),h.setCropSelection(b,0),"unknown"!=typeof d&&null!=d&&d(),a("#imgedit-history-"+b).val()&&0==a("#imgedit-undone-"+b).val()?a("input.imgedit-submit-btn","#imgedit-panel-"+b).removeAttr("disabled"):a("input.imgedit-submit-btn","#imgedit-panel-"+b).prop("disabled",!0),h.toggleEditor(b,0)}).on("error",function(){a("#imgedit-crop-"+b).empty().append('"),g.toggleEditor(b,0)}).attr("src",ajaxurl+"?"+a.param(e))},action:function(b,c,d){var e,f,g,h,i,j=this;if(j.notsaved(b))return!1;if(e={action:"image-editor",_ajax_nonce:c,postid:b},"scale"==d){if(f=a("#imgedit-scale-width-"+b),g=a("#imgedit-scale-height-"+b),h=j.intval(f.val()),i=j.intval(g.val()),1>h)return f.focus(),!1;if(1>i)return g.focus(),!1;if(h==j.hold.ow||i==j.hold.oh)return!1;e["do"]="scale",e.fwidth=h,e.fheight=i}else{if("restore"!=d)return!1;e["do"]="restore"}j.toggleEditor(b,1),a.post(ajaxurl,e,function(c){a("#image-editor-"+b).empty().append(c),j.toggleEditor(b,0)})},save:function(b,c){var d,e=this.getTarget(b),f=this.filterHistory(b,0);return""==f?!1:(this.toggleEditor(b,1),d={action:"image-editor",_ajax_nonce:c,postid:b,history:f,target:e,context:a("#image-edit-context").length?a("#image-edit-context").val():null,"do":"save"},a.post(ajaxurl,d,function(c){var d=JSON.parse(c);return d.error?(a("#imgedit-response-"+b).html(''+d.error+"
"),imageEdit.close(b),void 0):(d.fw&&d.fh&&a("#media-dims-"+b).html(d.fw+" × "+d.fh),d.thumbnail&&a(".thumbnail","#thumbnail-head-"+b).attr("src",""+d.thumbnail),d.msg&&a("#imgedit-response-"+b).html('
"),imageEdit.close(b),void 0)}),void 0)},open:function(b,c){var d,e=a("#image-editor-"+b),f=a("#media-head-"+b),g=a("#imgedit-open-btn-"+b),h=g.siblings(".spinner");g.prop("disabled",!0),h.show(),d={action:"image-editor",_ajax_nonce:c,postid:b,"do":"open"},e.load(ajaxurl,d,function(){e.fadeIn("fast"),f.fadeOut("fast",function(){g.removeAttr("disabled"),h.hide()})})},imgLoaded:function(b){var c=a("#image-preview-"+b),d=a("#imgedit-crop-"+b);this.initCrop(b,c,d),this.setCropSelection(b,0),this.toggleEditor(b,0)},initCrop:function(b,c,d){var e=this,f=a("#imgedit-sel-width-"+b),g=a("#imgedit-sel-height-"+b);e.iasapi=a(c).imgAreaSelect({parent:d,instance:!0,handles:!0,keys:!0,minWidth:3,minHeight:3,onInit:function(){d.children().mousedown(function(a){var c,d,f=!1;a.shiftKey&&(c=e.iasapi.getSelection(),d=e.getSelRatio(b),f=c&&c.width&&c.height?c.width+":"+c.height:d),e.iasapi.setOptions({aspectRatio:f})})},onSelectStart:function(){imageEdit.setDisabled(a("#imgedit-crop-sel-"+b),1)},onSelectEnd:function(a,c){imageEdit.setCropSelection(b,c)},onSelectChange:function(a,b){var c=imageEdit.hold.sizer;f.val(imageEdit.round(b.width/c)),g.val(imageEdit.round(b.height/c))}})},setCropSelection:function(b,c){var d,e=a("#imgedit-minthumb-"+b).val()||"128:128",f=this.hold.sizer;return e=e.split(":"),c=c||0,!c||c.width<3&&c.height<3?(this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+b),0),this.setDisabled(a("#imgedit-crop-sel-"+b),0),a("#imgedit-sel-width-"+b).val(""),a("#imgedit-sel-height-"+b).val(""),a("#imgedit-selection-"+b).val(""),!1):c.width
0;)g.pop(),i--;h.val(0),g.push(b),f.val(JSON.stringify(g)),e.refreshEditor(c,d,function(){e.setDisabled(a("#image-undo-"+c),!0),e.setDisabled(a("#image-redo-"+c),!1)})},rotate:function(b,c,d,e){return a(e).hasClass("disabled")?!1:(this.addStep({r:{r:b,fw:this.hold.h,fh:this.hold.w}},c,d),void 0)},flip:function(b,c,d,e){return a(e).hasClass("disabled")?!1:(this.addStep({f:{f:b,fw:this.hold.w,fh:this.hold.h}},c,d),void 0)},crop:function(b,c,d){var e=a("#imgedit-selection-"+b).val(),f=this.intval(a("#imgedit-sel-width-"+b).val()),g=this.intval(a("#imgedit-sel-height-"+b).val());return a(d).hasClass("disabled")||""==e?!1:(e=JSON.parse(e),e.w>0&&e.h>0&&f>0&&g>0&&(e.fw=f,e.fh=g,this.addStep({c:e},b,c)),void 0)},undo:function(b,c){var d=this,e=a("#image-undo-"+b),f=a("#imgedit-undone-"+b),g=d.intval(f.val())+1;e.hasClass("disabled")||(f.val(g),d.refreshEditor(b,c,function(){var c=a("#imgedit-history-"+b),f=""!=c.val()?JSON.parse(c.val()):new Array;d.setDisabled(a("#image-redo-"+b),!0),d.setDisabled(e,g0)}))},setNumSelection:function(b){var c,d,e,f,g,h=a("#imgedit-sel-width-"+b),i=a("#imgedit-sel-height-"+b),j=this.intval(h.val()),k=this.intval(i.val()),l=a("#image-preview-"+b),m=l.height(),n=l.width(),o=this.hold.sizer,p=this.iasapi;return 1>j?(h.val(""),!1):1>k?(i.val(""),!1):(j&&k&&(c=p.getSelection())&&(f=c.x1+Math.round(j*o),g=c.y1+Math.round(k*o),d=c.x1,e=c.y1,f>n&&(d=0,f=n,h.val(Math.round(f/o))),g>m&&(e=0,g=m,i.val(Math.round(g/o))),p.setSelection(d,e,f,g),p.update(),this.setCropSelection(b,p.getSelection())),void 0)},round:function(a){var b;return a=Math.round(a),this.hold.sizer>.6?a:(b=a.toString().slice(-1),"1"==b?a-1:"9"==b?a+1:a)},setRatioSelection:function(b,c,d){var e,f,g=this.intval(a("#imgedit-crop-width-"+b).val()),h=this.intval(a("#imgedit-crop-height-"+b).val()),i=a("#image-preview-"+b).height();return this.intval(a(d).val())?(g&&h&&(this.iasapi.setOptions({aspectRatio:g+":"+h}),(e=this.iasapi.getSelection(!0))&&(f=Math.ceil(e.y1+(e.x2-e.x1)/(g/h)),f>i&&(f=i,c?a("#imgedit-crop-height-"+b).val(""):a("#imgedit-crop-width-"+b).val("")),this.iasapi.setSelection(e.x1,e.y1,e.x2,f),this.iasapi.update())),void 0):(a(d).val(""),void 0)}}}(jQuery);
\ No newline at end of file
+!function(a){var b=window.imageEdit={iasapi:{},hold:{},postid:"",intval:function(a){return 0|a},setDisabled:function(b,c){c?(b.removeClass("disabled"),a("input",b).removeAttr("disabled")):(b.addClass("disabled"),a("input",b).prop("disabled",!0))},init:function(b){var c=this,d=a("#image-editor-"+c.postid),e=c.intval(a("#imgedit-x-"+b).val()),f=c.intval(a("#imgedit-y-"+b).val());c.postid!==b&&d.length&&c.close(c.postid),c.hold.w=c.hold.ow=e,c.hold.h=c.hold.oh=f,c.hold.xy_ratio=e/f,c.hold.sizer=parseFloat(a("#imgedit-sizer-"+b).val()),c.postid=b,a("#imgedit-response-"+b).empty(),a('input[type="text"]',"#imgedit-panel-"+b).keypress(function(b){var c=b.keyCode;return c>36&&41>c&&a(this).blur(),13===c?(b.preventDefault(),b.stopPropagation(),!1):void 0})},toggleEditor:function(b,c){var d=a("#imgedit-wait-"+b);c?d.height(a("#imgedit-panel-"+b).height()).fadeIn("fast"):d.fadeOut("fast")},toggleHelp:function(b){return a(b).siblings(".imgedit-help").slideToggle("fast"),!1},getTarget:function(b){return a('input[name="imgedit-target-'+b+'"]:checked',"#imgedit-save-target-"+b).val()||"full"},scaleChanged:function(b,c){var d=a("#imgedit-scale-width-"+b),e=a("#imgedit-scale-height-"+b),f=a("#imgedit-scale-warn-"+b),g="",h="";c?(h=""!==d.val()?Math.round(d.val()/this.hold.xy_ratio):"",e.val(h)):(g=""!==e.val()?Math.round(e.val()*this.hold.xy_ratio):"",d.val(g)),h&&h>this.hold.oh||g&&g>this.hold.ow?f.css("visibility","visible"):f.css("visibility","hidden")},getSelRatio:function(b){var c=this.hold.w,d=this.hold.h,e=this.intval(a("#imgedit-crop-width-"+b).val()),f=this.intval(a("#imgedit-crop-height-"+b).val());return e&&f?e+":"+f:c&&d?c+":"+d:"1:1"},filterHistory:function(b,c){var d,e,f,g,h=a("#imgedit-history-"+b).val(),i=[];if(""!==h){if(h=JSON.parse(h),d=this.intval(a("#imgedit-undone-"+b).val()),d>0)for(;d>0;)h.pop(),d--;if(c){if(!h.length)return this.hold.w=this.hold.ow,this.hold.h=this.hold.oh,"";f=h[h.length-1],f=f.c||f.r||f.f||!1,f&&(this.hold.w=f.fw,this.hold.h=f.fh)}for(e in h)g=h[e],g.hasOwnProperty("c")?i[e]={c:{x:g.c.x,y:g.c.y,w:g.c.w,h:g.c.h}}:g.hasOwnProperty("r")?i[e]={r:g.r.r}:g.hasOwnProperty("f")&&(i[e]={f:g.f.f});return JSON.stringify(i)}return""},refreshEditor:function(c,d,e){var f,g,h=this;h.toggleEditor(c,1),f={action:"imgedit-preview",_ajax_nonce:d,postid:c,history:h.filterHistory(c,1),rand:h.intval(1e6*Math.random())},g=a('').on("load",function(){var d,f,h=a("#imgedit-crop-"+c),i=b;h.empty().append(g),d=Math.max(i.hold.w,i.hold.h),f=Math.max(a(g).width(),a(g).height()),i.hold.sizer=d>f?f/d:1,i.initCrop(c,g,h),i.setCropSelection(c,0),"undefined"!=typeof e&&null!==e&&e(),a("#imgedit-history-"+c).val()&&0===a("#imgedit-undone-"+c).val()?a("input.imgedit-submit-btn","#imgedit-panel-"+c).removeAttr("disabled"):a("input.imgedit-submit-btn","#imgedit-panel-"+c).prop("disabled",!0),i.toggleEditor(c,0)}).on("error",function(){a("#imgedit-crop-"+c).empty().append('"),h.toggleEditor(c,0)}).attr("src",ajaxurl+"?"+a.param(f))},action:function(b,c,d){var e,f,g,h,i,j=this;if(j.notsaved(b))return!1;if(e={action:"image-editor",_ajax_nonce:c,postid:b},"scale"===d){if(f=a("#imgedit-scale-width-"+b),g=a("#imgedit-scale-height-"+b),h=j.intval(f.val()),i=j.intval(g.val()),1>h)return f.focus(),!1;if(1>i)return g.focus(),!1;if(h===j.hold.ow||i===j.hold.oh)return!1;e["do"]="scale",e.fwidth=h,e.fheight=i}else{if("restore"!==d)return!1;e["do"]="restore"}j.toggleEditor(b,1),a.post(ajaxurl,e,function(c){a("#image-editor-"+b).empty().append(c),j.toggleEditor(b,0)})},save:function(c,d){var e,f=this.getTarget(c),g=this.filterHistory(c,0);return""===g?!1:(this.toggleEditor(c,1),e={action:"image-editor",_ajax_nonce:d,postid:c,history:g,target:f,context:a("#image-edit-context").length?a("#image-edit-context").val():null,"do":"save"},a.post(ajaxurl,e,function(d){var e=JSON.parse(d);return e.error?(a("#imgedit-response-"+c).html(''+e.error+"
"),b.close(c),void 0):(e.fw&&e.fh&&a("#media-dims-"+c).html(e.fw+" × "+e.fh),e.thumbnail&&a(".thumbnail","#thumbnail-head-"+c).attr("src",""+e.thumbnail),e.msg&&a("#imgedit-response-"+c).html('
"),b.close(c),void 0)}),void 0)},open:function(b,c){var d,e=a("#image-editor-"+b),f=a("#media-head-"+b),g=a("#imgedit-open-btn-"+b),h=g.siblings(".spinner");g.prop("disabled",!0),h.show(),d={action:"image-editor",_ajax_nonce:c,postid:b,"do":"open"},e.load(ajaxurl,d,function(){e.fadeIn("fast"),f.fadeOut("fast",function(){g.removeAttr("disabled"),h.hide()})})},imgLoaded:function(b){var c=a("#image-preview-"+b),d=a("#imgedit-crop-"+b);this.initCrop(b,c,d),this.setCropSelection(b,0),this.toggleEditor(b,0)},initCrop:function(c,d,e){var f=this,g=a("#imgedit-sel-width-"+c),h=a("#imgedit-sel-height-"+c);f.iasapi=a(d).imgAreaSelect({parent:e,instance:!0,handles:!0,keys:!0,minWidth:3,minHeight:3,onInit:function(){e.children().mousedown(function(a){var b,d,e=!1;a.shiftKey&&(b=f.iasapi.getSelection(),d=f.getSelRatio(c),e=b&&b.width&&b.height?b.width+":"+b.height:d),f.iasapi.setOptions({aspectRatio:e})})},onSelectStart:function(){b.setDisabled(a("#imgedit-crop-sel-"+c),1)},onSelectEnd:function(a,d){b.setCropSelection(c,d)},onSelectChange:function(a,c){var d=b.hold.sizer;g.val(b.round(c.width/d)),h.val(b.round(c.height/d))}})},setCropSelection:function(b,c){var d,e=a("#imgedit-minthumb-"+b).val()||"128:128",f=this.hold.sizer;return e=e.split(":"),c=c||0,!c||c.width<3&&c.height<3?(this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+b),0),this.setDisabled(a("#imgedit-crop-sel-"+b),0),a("#imgedit-sel-width-"+b).val(""),a("#imgedit-sel-height-"+b).val(""),a("#imgedit-selection-"+b).val(""),!1):c.width
0;)g.pop(),i--;h.val(0),g.push(b),f.val(JSON.stringify(g)),e.refreshEditor(c,d,function(){e.setDisabled(a("#image-undo-"+c),!0),e.setDisabled(a("#image-redo-"+c),!1)})},rotate:function(b,c,d,e){return a(e).hasClass("disabled")?!1:(this.addStep({r:{r:b,fw:this.hold.h,fh:this.hold.w}},c,d),void 0)},flip:function(b,c,d,e){return a(e).hasClass("disabled")?!1:(this.addStep({f:{f:b,fw:this.hold.w,fh:this.hold.h}},c,d),void 0)},crop:function(b,c,d){var e=a("#imgedit-selection-"+b).val(),f=this.intval(a("#imgedit-sel-width-"+b).val()),g=this.intval(a("#imgedit-sel-height-"+b).val());return a(d).hasClass("disabled")||""===e?!1:(e=JSON.parse(e),e.w>0&&e.h>0&&f>0&&g>0&&(e.fw=f,e.fh=g,this.addStep({c:e},b,c)),void 0)},undo:function(b,c){var d=this,e=a("#image-undo-"+b),f=a("#imgedit-undone-"+b),g=d.intval(f.val())+1;e.hasClass("disabled")||(f.val(g),d.refreshEditor(b,c,function(){var c=a("#imgedit-history-"+b),f=""!==c.val()?JSON.parse(c.val()):[];d.setDisabled(a("#image-redo-"+b),!0),d.setDisabled(e,g0)}))},setNumSelection:function(b){var c,d,e,f,g,h=a("#imgedit-sel-width-"+b),i=a("#imgedit-sel-height-"+b),j=this.intval(h.val()),k=this.intval(i.val()),l=a("#image-preview-"+b),m=l.height(),n=l.width(),o=this.hold.sizer,p=this.iasapi;return 1>j?(h.val(""),!1):1>k?(i.val(""),!1):(j&&k&&(c=p.getSelection())&&(f=c.x1+Math.round(j*o),g=c.y1+Math.round(k*o),d=c.x1,e=c.y1,f>n&&(d=0,f=n,h.val(Math.round(f/o))),g>m&&(e=0,g=m,i.val(Math.round(g/o))),p.setSelection(d,e,f,g),p.update(),this.setCropSelection(b,p.getSelection())),void 0)},round:function(a){var b;return a=Math.round(a),this.hold.sizer>.6?a:(b=a.toString().slice(-1),"1"===b?a-1:"9"===b?a+1:a)},setRatioSelection:function(b,c,d){var e,f,g=this.intval(a("#imgedit-crop-width-"+b).val()),h=this.intval(a("#imgedit-crop-height-"+b).val()),i=a("#image-preview-"+b).height();return this.intval(a(d).val())?(g&&h&&(this.iasapi.setOptions({aspectRatio:g+":"+h}),(e=this.iasapi.getSelection(!0))&&(f=Math.ceil(e.y1+(e.x2-e.x1)/(g/h)),f>i&&(f=i,c?a("#imgedit-crop-height-"+b).val(""):a("#imgedit-crop-width-"+b).val("")),this.iasapi.setSelection(e.x1,e.y1,e.x2,f),this.iasapi.update())),void 0):(a(d).val(""),void 0)}}}(jQuery);
\ No newline at end of file