WordPress/wp-admin/js/image-edit.min.js

1 line
8.9 KiB
JavaScript
Raw Normal View History

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('<img id="image-preview-'+b+'" />').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('<div class="error"><p>'+imageEditL10n.error+"</p></div>"),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('<div class="error"><p>'+d.error+"</p><div>"),imageEdit.close(b),void 0):(d.fw&&d.fh&&a("#media-dims-"+b).html(d.fw+" &times; "+d.fh),d.thumbna