1 line
5.9 KiB
JavaScript
1 line
5.9 KiB
JavaScript
|
var imageEdit;(function(a){imageEdit={iasapi:{},intval:function(b){return b|0},setState:function(c,b){if(b){c.removeAttr("disabled")}else{c.attr("disabled","disabled")}},setClass:function(b,d){if(d){b.removeClass("disabled")}else{b.addClass("disabled")}},gcd:function(d,c){var e;if(d==0||c==0){return 0}else{if(d==c){return d}else{do{e=d%c;d=c;c=e}while(e!=0);return d}}},toggleEditor:function(d,b){var c=a("#imgedit-wait-"+d);if(b){c.height(a("#imgedit-panel-"+d).height()).fadeIn("fast")}else{c.height(500).fadeOut("fast")}},isChecked:function(b){return(!b.attr("disabled")&&b[0].checked)},getAspect:function(e){var b=this.isChecked(a("#imgedit-scale-switch-"+e)),d,c;if(b){d=this.intval(a("#imgedit-aspect-x-"+e).val());c=this.intval(a("#imgedit-aspect-y-"+e).val());return d/c}else{return 0}},scaleWidthChanged:function(d){var c=a("#imgedit-scale-width-"+d),b;if(!c.attr("disabled")){b=this.getAspect(d);if(b!=0){a("#imgedit-scale-height-"+d).val((c.val()!="")?this.intval(c.val()/b):"")}}},scaleHeightChanged:function(d){var c=a("#imgedit-scale-height-"+d),b;if(!c.attr("disabled")){b=this.getAspect(d);if(b!=0){a("#imgedit-scale-width-"+d).val((c.val()!="")?this.intval(c.val()*b):"")}}},setDefaultAspect:function(h){var b=this,d,c=a("#image-preview-"+h),f=c.attr("width"),e=c.attr("height");while((d=b.gcd(f,e))>1){f=b.intval(Math.ceil(f/d));e=b.intval(Math.ceil(e/d))}if(f>10&&e>10){while(f>10&&e>10){f=b.intval(Math.ceil(f/10));e=b.intval(Math.ceil(e/10))}while((d=b.gcd(f,e))>1){f=b.intval(Math.ceil(f/d));e=b.intval(Math.ceil(e/d))}}a("#imgedit-aspect-x-"+h).val(f);a("#imgedit-aspect-y-"+h).val(e)},filterHistory:function(d){var c=a("#imgedit-history-"+d).val(),b;if(c!=""){b=this.intval(a("#imgedit-undone-"+d).val());if(b>0){c=JSON.parse(c);while(b>0){c.pop();b--}c=JSON.stringify(c)}}return c},refreshEditor:function(g,c,f){var b=this,e,d;b.toggleEditor(g,1);e={action:"load-preview-image",_ajax_nonce:c,postid:g,history:b.filterHistory(g),rand:b.intval(Math.random()*1000000)};d=a('<img id="image-preview-'+g+'" />');d.load(function(){var h=a("#imgedit-crop-"+g);h.empty().append(d);b.initCrop(g,d,h);a("#imgedit-panel-"+g).show();if((typeof f!="unknown")&&f!=null){f()}b.toggleEditor(g,0)}).attr("src",ajaxurl+"?"+a.param(e))},save:function(b,i){var l=this,f=-1,c=-1,k,g,e,d=l.isChecked(a("#imgedit-scale-switch-"+b)),j=a("#imgedit-save-target-"+b).val();if(d){k=a("#imgedit-scale-width-"+b);g=a("#imgedit-scale-height-"+b);f=l.intval(k.val());c=l.intval(g.val());if(f<=0){k.focus();return}else{if(c<=0){g.focus();return}}}l.toggleEditor(b,1);e={action:"image-edit-save",_ajax_nonce:i,postid:b,history:l.filterHistory(b),target:j,fwidth:f,fheight:c};a.post(ajaxurl,e,function(p){var m=p.split("!"),s,o,q,h,n,t;for(n=0;n<m.length;n++){s=m[n].split("=");if(s.length==2){switch(s[0]){case"full":o=s[1].split("x");if(o.length==2){q=o[0];h=o[1];a("#image-dims-"+b).html(q+" × "+h)}a("#imgedit-history-"+b).val("");a("#imgedit-undone-"+b).val(0);l.setClass(a("#image-undo-"+b),false);l.setClass(a("#image-redo-"+b),false);break;case"thumbnail":t=a("#media-item-"+b);if(t.length==0){t=a("#media-dims-"+b).closest(".media-item-info")}t=t.find(".thumbnail");t.attr("src",s[1]);break;case"error":a("#imgedit-panel-"+b).html(s[1])}}}l.toggleEditor(b,0)})},open:function(i,e){var d=this,g,f=a("#image-editor-"+i),c=a("#media-head-"+i),b=a("#imgedit-open-btn-"+i),h=b.siblings("img");b.attr("disabled","disabled");h.css("visibility","visible");g={action:"open-image-editor",_ajax_nonce:e,postid:i};f.load(ajaxurl,g,function(){f.fadeIn("fast");c.fadeOut("fast",function(){b.removeAttr("disabled");h.css("visibility","hidden")});d.toggleEditor(i,1);a("#image-preview-"+i).load(function(){var j=imageEdit,k=a("#imgedit-crop-"+i);j.initCrop(i,this,k);j.setDefaultAspect(i);j.toggleEditor(i,0)})})},initCrop:function(e,d,c){var b=this;b.iasapi=a(d).imgAreaSelect({parent:c,instance:true,handles:true,keys:true,minHeight:5,minWidth:5,onInit:function(f,g){c.children().mousedown(function(j){var i,h=false,l=b.intval(a("#imgedit-aspect-x-"+e).val()),k=b.intval(a("#imgedit-aspect-y-"
|