- md5
- b7c133fdf6b15221862a7036d8d77ca8
- sha1
- 7cadce6f30b18e43b77991b88357ab7d66c2af23
- sha256
- 0f0c407514dec5c827cd52cc0d1090223063d00cc1638cff3aad85a1938cdcf1
var imageEdit;!function(g){imageEdit={iasapi:{},hold:{},postid:"",intval:function(i){return 0|i},setDisabled:function(i,t){t?(i.removeClass("disabled"),g("input",i).removeAttr("disabled")):(i.addClass("disabled"),g("input",i).prop("disabled",!0))},init:function(i,t){var e=this,a=g("#image-editor-"+e.postid),o=e.intval(g("#imgedit-x-"+i).val()),n=e.intval(g("#imgedit-y-"+i).val());e.postid!=i&&a.length&&e.close(e.postid),e.hold.w=e.hold.ow=o,e.hold.h=e.hold.oh=n,e.hold.xy_ratio=o/n,e.hold.sizer=parseFloat(g("#imgedit-sizer-"+i).val()),e.postid=i,g("#imgedit-response-"+i).empty(),g('input[type="text"]',"#imgedit-panel-"+i).keypress(function(i){var t=i.keyCode;if(36<t&&t<41&&g(this).blur(),13==t)return i.preventDefault(),i.stopPropagation(),!1})},toggleEditor:function(i,t){var e=g("#imgedit-wait-"+i);t?e.height(g("#imgedit-panel-"+i).height()).fadeIn("fast"):e.fadeOut("fast")},toggleHelp:function(i){return g(i).siblings(".imgedit-help").slideToggle("fast"),!1},getTarget:function(i){return g('input[name="imgedit-target-'+i+'"]:checked',"#imgedit-save-target-"+i).val()||"full"},scaleChanged:function(i,t){var e=g("#imgedit-scale-width-"+i),a=g("#imgedit-scale-height-"+i),o=g("#imgedit-scale-warn-"+i),n="",i="";t?(i=""!=e.val()?Math.round(e.val()/this.hold.xy_ratio):"",a.val(i)):(n=""!=a.val()?Math.round(a.val()*this.hold.xy_ratio):"",e.val(n)),i&&i>this.hold.oh||n&&n>this.hold.ow?o.css("visibility","visible"):o.css("visibility","hidden")},getSelRatio:function(i){var t=this.hold.w,e=this.hold.h,a=this.intval(g("#imgedit-crop-width-"+i).val()),i=this.intval(g("#imgedit-crop-height-"+i).val());return a&&i?a+":"+i:t&&e?t+":"+e:"1:1"},filterHistory:function(i,t){var e,a,o,n=g("#imgedit-history-"+i).val(),d=[];if(""==n)return"";if(n=JSON.parse(n),0<(e=this.intval(g("#imgedit-undone-"+i).val())))for(;0<e;)n.pop(),e--;if(t){if(!n.length)return this.hold.w=this.hold.ow,this.hold.h=this.hold.oh,"";(t=(t=n[n.length-1]).c||t.r||t.f||!1)&&(this.hold.w=t.fw,this.hold.h=t.fh)}for(a in n)(o=n[a]).hasOwnProperty("c")?d[a]={c:{x:o.c.x,y:o.c.y,w:o.c.w,h:o.c.h}}:o.hasOwnProperty("r")?d[a]={r:o.r.r}:o.hasOwnProperty("f")&&(d[a]={f:o.f.f});return JSON.stringify(d)},refreshEditor:function(o,i,n){var d,t=this;t.toggleEditor(o,1),i={action:"imgedit-preview",_ajax_nonce:i,postid:o,history:t.filterHistory(o,1),rand:t.intval(1e6*Math.random())},d=g('<img id="image-preview-'+o+'" />').on("load",function(){var i,t,e=g("#imgedit-crop-"+o),a=imageEdit;e.empty().append(d),i=Math.max(a.hold.w,a.hold.h),t=Math.max(g(d).width(),g(d).height()),a.hold.sizer=t<i?t/i:1,a.initCrop(o,d,e),a.setCropSelection(o,0),"unknown"!=typeof n&&null!=n&&n(),g("#imgedit-history-"+o).val()&&0==g("#imgedit-undone-"+o).val()?g("input.imgedit-submit-btn","#imgedit-panel-"+o).removeAttr("disabled"):g("input.imgedit-submit-btn","#imgedit-panel-"+o).prop("disabled",!0),a.toggleEditor(o,0)}).on("error",function(){g("#imgedit-crop-"+o).empty().append('<div class="error"><p>'+imageEditL10n.error+"</p></div>"),t.toggleEditor(o,0)}).attr("src",ajaxurl+"?"+g.param(i))},action:function(t,i,e){var a,o,n,d,s=this;if(s.notsaved(t))return!1;if(a={action:"image-editor",_ajax_nonce:i,postid:t},"scale"==e){if(o=g("#imgedit-scale-width-"+t),n=g("#imgedit-scale-height-"+t),d=s.intval(o.val()),i=s.intval(n.val()),d<1)return o.focus(),!1;if(i<1)return n.focus(),!1;if(d==s.hold.ow||i==s.hold.oh)return!1;a.do="scale",a.fwidth=d,a.fheight=i}else{if("restore"!=e)return!1;a.do="restore"}s.toggleEditor(t,1),g.post(ajaxurl,a,function(i){g("#image-editor-"+t).empty().append(i),s.toggleEditor(t,0)})},save:function(t,i){var e=this.getTarget(t),a=this.filterHistory(t,0);if(""==a)return!1;this.toggleEditor(t,1),e={action:"image-editor",_ajax_nonce:i,postid:t,history:a,target:e,context:g("#image-edit-context").length?g("#image-edit-context").val():null,do:"save"},g.post(ajaxurl,e,function(i){i=JSON.parse(i);if(i.error)return g("#imgedit-response-"+t).html('<div class="error"><p>'+i.error+"</p><div>"),void imageEdit.close(t);i.fw&&i.fh&&g("#media-dims-"+t).html(i.fw+" × "+i.fh),i.thumbnail&&g(".thumbnail","#thumbnail-head-"+t).attr("src",""+i.thumbnail),i.msg&&g("#imgedit-response-"+t).html('<div class="updated"><p>'+i.msg+"</p></div>"),imageEdit.close(t)})},open:function(i,t){var e=g("#image-editor-"+i),a=g("#media-head-"+i),o=g("#imgedit-open-btn-"+i),n=o.siblings(".spinner");o.prop("disabled",!0),n.show(),i={action:"image-editor",_ajax_nonce:t,postid:i,do:"open"},e.load(ajaxurl,i,function(){e.fadeIn("fast"),a.fadeOut("fast",function(){o.removeAttr("disabled"),n.hide()})})},imgLoaded:function(i){var t=g("#image-preview-"+i),e=g("#imgedit-crop-"+i);this.initCrop(i,t,e),this.setCropSelection(i,0),this.toggleEditor(i,0)},initCrop:function(a,i,e){var o=this,n=g("#imgedit-sel-width-"+a),d=g("#imgedit-sel-height-"+a);o.iasapi=g(i).imgAreaSelect({parent:e,instance:!0,handles:!0,keys:!0,minWidth:3,minHeight:3,onInit:function(i,t){e.children().mousedown(function(i){var t,e=!1;i.shiftKey&&(t=o.iasapi.getSelection(),i=o.getSelRatio(a),e=t&&t.width&&t.height?t.width+":"+t.height:i),o.iasapi.setOptions({aspectRatio:e})})},onSelectStart:function(i,t){imageEdit.setDisabled(g("#imgedit-crop-sel-"+a),1)},onSelectEnd:function(i,t){imageEdit.setCropSelection(a,t)},onSelectChange:function(i,t){var e=imageEdit.hold.sizer;n.val(imageEdit.round(t.width/e)),d.val(imageEdit.round(t.height/e))}})},setCropSelection:function(i,t){var e=g("#imgedit-minthumb-"+i).val()||"128:128",a=this.hold.sizer,e=e.split(":");return!(t=t||0)||t.width<3&&t.height<3?(this.setDisabled(g(".imgedit-crop","#imgedit-panel-"+i),0),this.setDisabled(g("#imgedit-crop-sel-"+i),0),g("#imgedit-sel-width-"+i).val(""),g("#imgedit-sel-height-"+i).val(""),g("#imgedit-selection-"+i).val(""),!1):t.width<e[0]*a&&t.height<e[1]*a?(this.setDisabled(g(".imgedit-crop","#imgedit-panel-"+i),0),g("#imgedit-selection-"+i).val(""),!1):(t={x:t.x1,y:t.y1,w:t.width,h:t.height},this.setDisabled(g(".imgedit-crop","#imgedit-panel-"+i),1),void g("#imgedit-selection-"+i).val(JSON.stringify(t)))},close:function(i,t){if((t=t||!1)&&this.notsaved(i))return!1;this.iasapi={},this.hold={},g("#image-editor-"+i).fadeOut("fast",function(){g("#media-head-"+i).fadeIn("fast"),g(this).empty()})},notsaved:function(i){var t=g("#imgedit-history-"+i).val(),t=""!=t?JSON.parse(t):new Array;return this.intval(g("#imgedit-undone-"+i).val())<t.length&&!confirm(g("#imgedit-leaving-"+i).html())},addStep:function(i,t,e){for(var a=this,o=g("#imgedit-history-"+t),n=""!=o.val()?JSON.parse(o.val()):new Array,d=g("#imgedit-undone-"+t),s=a.intval(d.val());0<s;)n.pop(),s--;d.val(0),n.push(i),o.val(JSON.stringify(n)),a.refreshEditor(t,e,function(){a.setDisabled(g("#image-undo-"+t),!0),a.setDisabled(g("#image-redo-"+t),!1)})},rotate:function(i,t,e,a){if(g(a).hasClass("disabled"))return!1;this.addStep({r:{r:i,fw:this.hold.h,fh:this.hold.w}},t,e)},flip:function(i,t,e,a){if(g(a).hasClass("disabled"))return!1;this.addStep({f:{f:i,fw:this.hold.w,fh:this.hold.h}},t,e)},crop:function(i,t,e){var a=g("#imgedit-selection-"+i).val(),o=this.intval(g("#imgedit-sel-width-"+i).val()),n=this.intval(g("#imgedit-sel-height-"+i).val());if(g(e).hasClass("disabled")||""==a)return!1;0<(a=JSON.parse(a)).w&&0<a.h&&0<o&&0<n&&(a.fw=o,a.fh=n,this.addStep({c:a},i,t))},undo:function(t,i){var e=this,a=g("#image-undo-"+t),o=g("#imgedit-undone-"+t),n=e.intval(o.val())+1;a.hasClass("disabled")||(o.val(n),e.refreshEditor(t,i,function(){var i=g("#imgedit-history-"+t),i=""!=i.val()?JSON.parse(i.val()):new Array;e.setDisabled(g("#image-redo-"+t),!0),e.setDisabled(a,n<i.length)}))},redo:function(i,t){var e=this,a=g("#image-redo-"+i),o=g("#imgedit-undone-"+i),n=e.intval(o.val())-1;a.hasClass("disabled")||(o.val(n),e.refreshEditor(i,t,function(){e.setDisabled(g("#image-undo-"+i),!0),e.setDisabled(a,0<n)}))},setNumSelection:function(i){var t,e=g("#imgedit-sel-width-"+i),a=g("#imgedit-sel-height-"+i),o=this.intval(e.val()),n=this.intval(a.val()),d=g("#image-preview-"+i),s=d.height(),r=d.width(),l=this.hold.sizer,h=this.iasapi;return o<1?(e.val(""),!1):n<1?(a.val(""),!1):void(o&&n&&(t=h.getSelection())&&(d=t.x1+Math.round(o*l),o=t.y1+Math.round(n*l),n=t.x1,t=t.y1,r<d&&(n=0,d=r,e.val(Math.round(d/l))),s<o&&(t=0,o=s,a.val(Math.round(o/l))),h.setSelection(n,t,d,o),h.update(),this.setCropSelection(i,h.getSelection())))},round:function(i){var t;return i=Math.round(i),.6<this.hold.sizer?i:"1"==(t=i.toString().slice(-1))?i-1:"9"==t?i+1:i},setRatioSelection:function(i,t,e){var a,o=this.intval(g("#imgedit-crop-width-"+i).val()),n=this.intval(g("#imgedit-crop-height-"+i).val()),d=g("#image-preview-"+i).height();this.intval(g(e).val())?o&&n&&(this.iasapi.setOptions({aspectRatio:o+":"+n}),(a=this.iasapi.getSelection(!0))&&(d<(n=Math.ceil(a.y1+(a.x2-a.x1)/(o/n)))&&(n=d,g(t?"#imgedit-crop-height-"+i:"#imgedit-crop-width-"+i).val("")),this.iasapi.setSelection(a.x1,a.y1,a.x2,n),this.iasapi.update())):g(e).val("")}}}(jQuery);
The same content is in 6 releases, WordPress 3.7.36 to 3.7.41. See them all, or every version of this file.