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

1 line
9.8 KiB
JavaScript
Raw Permalink Normal View History

!function(g){var d=window.imageEdit={iasapi:{},hold:{},postid:"",_view:!1,handleCropToolClick:function(i,t,e){var a=g("#image-preview-"+i),s=this.iasapi.getSelection();isNaN(s.x1)&&(this.setCropSelection(i,{x1:0,y1:0,x2:a.innerWidth(),y2:a.innerHeight(),width:a.innerWidth(),height:a.innerHeight()}),s=this.iasapi.getSelection()),0===s.x1&&0===s.y1&&0===s.x2&&0===s.y2?(this.iasapi.setSelection(0,0,a.innerWidth(),a.innerHeight(),!0),this.iasapi.setOptions({show:!0}),this.iasapi.update()):d.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=g("#image-editor-"+t.postid),a=t.intval(g("#imgedit-x-"+i).val()),s=t.intval(g("#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=s,t.hold.xy_ratio=a/s,t.hold.sizer=parseFloat(g("#imgedit-sizer-"+i).val()),t.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){i=g("#imgedit-wait-"+i);t?i.fadeIn("fast"):i.fadeOut("fast")},toggleHelp:function(i){i=g(i);return i.attr("aria-expanded","false"===i.attr("aria-expanded")?"true":"false").parents(".imgedit-group-top").toggleClass("imgedit-help-toggled").find(".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,e){var a=g("#imgedit-scale-width-"+i),s=g("#imgedit-scale-height-"+i),o=g("#imgedit-scale-warn-"+i),n="",i="";!1!==this.validateNumeric(e)&&(t?(i=""!==a.val()?Math.round(a.val()/this.hold.xy_ratio):"",s.val(i)):(n=""!==s.val()?Math.round(s.val()*this.hold.xy_ratio):"",a.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,s,o=g("#imgedit-history-"+i).val(),n=[];if(""===o)return"";if(o=JSON.parse(o),0<(e=this.intval(g("#imgedit-undone-"+i).val())))for(;0<e;)o.pop(),e--;if(t){if(!o.length)return this.hold.w=this.hold.ow,this.hold.h=this.hold.oh,"";(t=(t=o[o.length-1]).c||t.r||t.f||!1)&&(this.hold.w=t.fw,this.hold.h=t.fh)}for(a in o)(s=o[a]).hasOwnProperty("c")?n[a]={c:{x:s.c.x,y:s.c.y,w:s.c.w,h:s.c.h}}:s.hasOwnProperty("r")?n[a]={r:s.r.r}:s.hasOwnProperty("f")&&(n[a]={f:s.f.f});return JSON.stringify(n)},refreshEditor:function(s,i,o){var n,t=this;t.toggleEditor(s,1),i={action:"imgedit-preview",_ajax_nonce:i,postid:s,history:t.filterHistory(s,1),rand:t.intval(1e6*Math.random())},n=g('<img id="image-preview-'+s+'" alt="" />').on("load",{history:i.history},function(i){var t,e=g("#imgedit-crop-"+s),a=d;""!==i.data.history&&(t=JSON.parse(i.data.history))[t.length-1].hasOwnProperty("c")&&(a.setDisabled(g("#image-undo-"+s),!0),g("#image-undo-"+s).focus()),e.empty().append(n),i=Math.max(a.hold.w,a.hold.h),t=Math.max(g(n).width(),g(n).height()),a.hold.sizer=t<i?t/i:1,a.initCrop(s,n,e),null!=o&&o(),g("#imgedit-history-"+s).val()&&"0"===g("#imgedit-undone-"+s).val()?g("input.imgedit-submit-btn","#imgedit-panel-"+s).removeAttr("disabled"):g("input.imgedit-submit-btn","#imgedit-panel-"+s).prop("disabled",!0),a.toggleEditor(s,0)}).on("error",function(){g("#imgedit-crop-"+s).empty().append('<div class="error"><p>'+imageEditL10n.error+"</p></div>"),t.toggleEditor(s,0)}).attr("src",ajaxurl+"?"+g.param(i))},action:function(t,i,e){var a,s,o,n,d=this;if(d.notsaved(t))return!1;if(a={action:"image-editor",_ajax_nonce:i,postid:t},"scale"===e){if(s=g("#imgedit-scale-width-"+t),o=g("#imgedit-scale-height-"+t),n=d.intval(s.val()),i=d.intval(o.val()),n<1)return s.focus(),!1;if(i<1)return o.focus(),!1;if(n===d.hold.ow||i===d.hold.oh)return!1;a.do="scale",a.fwidth=n,a.fheight=i}else{if("re