/*! This file is auto-generated */ !function(m){var l=window.imageEdit={iasapi:{},hold:{},postid:"",_view:!1,handleCropToolClick:function(i,t,e){var a=m("#image-preview-"+i),o=this.iasapi.getSelection();isNaN(o.x1)&&(this.setCropSelection(i,{x1:0,y1:0,x2:a.innerWidth(),y2:a.innerHeight(),width:a.innerWidth(),height:a.innerHeight()}),o=this.iasapi.getSelection()),0===o.x1&&0===o.y1&&0===o.x2&&0===o.y2?(this.iasapi.setSelection(0,0,a.innerWidth(),a.innerHeight(),!0),this.iasapi.setOptions({show:!0}),this.iasapi.update()):l.crop(i,t,e)},intval:function(i){return 0|i},setDisabled:function(i,t){t?i.removeClass("disabled").prop("disabled",!1):i.addClass("disabled").prop("disabled",!0)},init:function(i){var t=this,e=m("#image-editor-"+t.postid),a=t.intval(m("#imgedit-x-"+i).val()),o=t.intval(m("#imgedit-y-"+i).val());t.postid!==i&&e.length&&t.close(t.postid),t.hold.w=t.hold.ow=a,t.hold.h=t.hold.oh=o,t.hold.xy_ratio=a/o,t.hold.sizer=parseFloat(m("#imgedit-sizer-"+i).val()),t.postid=i,m("#imgedit-response-"+i).empty(),m('input[type="text"]',"#imgedit-panel-"+i).keypress(function(i){var t=i.keyCode;if(36this.hold.oh||n&&n>this.hold.ow?s.css("visibility","visible"):s.css("visibility","hidden"))},getSelRatio:function(i){var t=this.hold.w,e=this.hold.h,a=this.intval(m("#imgedit-crop-width-"+i).val()),o=this.intval(m("#imgedit-crop-height-"+i).val());return a&&o?a+":"+o:t&&e?t+":"+e:"1:1"},filterHistory:function(i,t){var e,a,o,s,n=m("#imgedit-history-"+i).val(),d=[];if(""===n)return"";if(n=JSON.parse(n),0<(e=this.intval(m("#imgedit-undone-"+i).val())))for(;0').on("load",{history:t.history},function(i){var t,e,a,o=m("#imgedit-crop-"+n),s=l;""!==i.data.history&&(a=JSON.parse(i.data.history))[a.length-1].hasOwnProperty("c")&&(s.setDisabled(m("#image-undo-"+n),!0),m("#image-undo-"+n).focus()),o.empty().append(r),t=Math.max(s.hold.w,s.hold.h),e=Math.max(m(r).width(),m(r).height()),s.hold.sizer=e

'+imageEditL10n.error+"

"),e.toggleEditor(n,0)}).attr("src",ajaxurl+"?"+m.param(t))},action:function(t,i,e){var a,o,s,n,d,r=this;if(r.notsaved(t))return!1;if(a={action:"image-editor",_ajax_nonce:i,postid:t},"scale"===e){if(o=m("#imgedit-scale-width-"+t),s=m("#imgedit-scale-height-"+t),n=r.intval(o.val()),d=r.intval(s.val()),n<1)return o.focus(),!1;if(d<1)return s.focus(),!1;if(n===r.hold.ow||d===r.hold.oh)return!1;a.do="scale",a.fwidth=n,a.fheight=d}else{if("restore"!==e)return!1;a.do="restore"}r.toggleEditor(t,1),m.post(ajaxurl,a,function(i){m("#image-editor-"+t).empty().append(i),r.toggleEditor(t,0),r._view&&r._view.refresh()})},save:function(e,i){var t,a=this.getTarget(e),o=this.filterHistory(e,0),s=this;if(""===o)return!1;this.toggleEditor(e,1),t={action:"image-editor",_ajax_nonce:i,postid:e,history:o,target:a,context:m("#image-edit-context").length?m("#image-edit-context").val():null,do:"save"},m.post(ajaxurl,t,function(i){var t=JSON.parse(i);if(t.error)return m("#imgedit-response-"+e).html('

'+t.error+"

"),void l.close(e);t.fw&&t.fh&&m("#media-dims-"+e).html(t.fw+" × "+t.fh),t.thumbnail&&m(".thumbnail","#thumbnail-head-"+e).attr("src",""+t.thumbnail),t.msg&&m("#imgedit-response-"+e).html('

'+t.msg+"

"),s._view?s._view.save():l.close(e)})},open:function(t,i,e){this._view=e;var a,o=m("#image-editor-"+t),s=m("#media-head-"+t),n=m("#imgedit-open-btn-"+t),d=n.siblings(".spinner");if(!n.hasClass("button-activated"))return d.addClass("is-active"),a={action:"image-editor",_ajax_nonce:i,postid:t,do:"open"},m.ajax({url:ajaxurl,type:"post",data:a,beforeSend:function(){n.addClass("button-activated")}}).done(function(i){o.html(i),s.fadeOut("fast",function(){o.fadeIn("fast"),n.removeClass("button-activated"),d.removeClass("is-active")}),l.init(t)})},imgLoaded:function(i){var t=m("#image-preview-"+i),e=m("#imgedit-crop-"+i);void 0===this.hold.sizer&&this.init(i),this.initCrop(i,t,e),this.setCropSelection(i,{x1:0,y1:0,x2:0,y2:0,width:t.innerWidth(),height:t.innerHeight()}),this.toggleEditor(i,0),m(document).trigger("image-editor-image-loaded")},focusManager:function(){setTimeout(function(){m(".imgedit-wrap").find(":tabbable:first").focus()},100)},initCrop:function(o,i,t){var s=this,a=m("#imgedit-sel-width-"+o),n=m("#imgedit-sel-height-"+o),e=m(i);e.data("imgAreaSelect")||(s.iasapi=e.imgAreaSelect({parent:t,instance:!0,handles:!0,keys:!0,minWidth:3,minHeight:3,onInit:function(i){m(i).next().css("position","absolute").nextAll(".imgareaselect-outer").css("position","absolute"),t.children().on("mousedown, touchstart",function(i){var t,e,a=!1;i.shiftKey&&(t=s.iasapi.getSelection(),e=s.getSelRatio(o),a=t&&t.width&&t.height?t.width+":"+t.height:e),s.iasapi.setOptions({aspectRatio:a})})},onSelectStart:function(){l.setDisabled(m("#imgedit-crop-sel-"+o),1)},onSelectEnd:function(i,t){l.setCropSelection(o,t)},onSelectChange:function(i,t){var e=l.hold.sizer;a.val(l.round(t.width/e)),n.val(l.round(t.height/e))}}))},setCropSelection:function(i,t){var e;if(!(t=t||0)||t.width<3&&t.height<3)return this.setDisabled(m(".imgedit-crop","#imgedit-panel-"+i),1),this.setDisabled(m("#imgedit-crop-sel-"+i),1),m("#imgedit-sel-width-"+i).val(""),m("#imgedit-sel-height-"+i).val(""),m("#imgedit-selection-"+i).val(""),!1;e={x:t.x1,y:t.y1,w:t.width,h:t.height},this.setDisabled(m(".imgedit-crop","#imgedit-panel-"+i),1),m("#imgedit-selection-"+i).val(JSON.stringify(e))},close:function(i,t){if((t=t||!1)&&this.notsaved(i))return!1;this.iasapi={},this.hold={},this._view?this._view.back():m("#image-editor-"+i).fadeOut("fast",function(){m("#media-head-"+i).fadeIn("fast",function(){m("#imgedit-open-btn-"+i).focus()}),m(this).empty()})},notsaved:function(i){var t=m("#imgedit-history-"+i).val(),e=""!==t?JSON.parse(t):[];return this.intval(m("#imgedit-undone-"+i).val())