(function(){tinymce.create("tinymce.plugins.wpEditImage",{url:"",editor:{},init:function(a,c){var d=this,b={};d.url=c;d.editor=a;d._createButtons();a.addCommand("WP_EditImage",d._editImage);a.onInit.add(function(e){e.dom.events.add(e.getBody(),"mousedown",function(g){var f;if(g.target.nodeName=="IMG"&&(f=e.dom.getParent(g.target,"div.mceTemp"))){if(tinymce.isGecko){e.selection.select(f)}else{if(tinymce.isWebKit){e.dom.events.prevent(g)}}}});e.dom.events.add(e.getBody(),"keydown",function(j){var k,f,i,h,g;if(j.keyCode==13){k=e.selection.getNode();f=e.dom.getParent(k,"dl.wp-caption");if(f){i=e.dom.getParent(f,"div.mceTemp")}if(i){e.dom.events.cancel(j);h=e.dom.create("p",{},"\uFEFF");e.dom.insertAfter(h,i);e.selection.setCursorLocation(h,0);return false}}});if("ontouchstart" in window){e.dom.events.add(e.getBody(),"touchstart",function(f){d._showButtons(f)})}});a.onMouseUp.add(function(f,g){if(tinymce.isWebKit||tinymce.isOpera){return}if(b.x&&(g.clientX!=b.x||g.clientY!=b.y)){var h=f.selection.getNode();if("IMG"==h.nodeName){window.setTimeout(function(){var e=f.dom.getParent(h,"dl.wp-caption"),i;if(h.width!=b.img_w||h.height!=b.img_h){h.className=h.className.replace(/size-[^ "']+/,"")}if(e){i=f.dom.getAttrib(h,"width")||h.width;i=parseInt(i,10);f.dom.setStyle(e,"width",10+i);f.execCommand("mceRepaint")}},100)}}b={}});a.onMouseDown.add(function(f,g){d._showButtons(g)});a.onBeforeSetContent.add(function(e,f){f.content=e.wpSetImgCaption(f.content)});a.onPostProcess.add(function(e,f){if(f.get){f.content=e.wpGetImgCaption(f.content)}});a.wpSetImgCaption=function(e){return d._do_shcode(e)};a.wpGetImgCaption=function(e){return d._get_shcode(e)};a.onBeforeExecCommand.add(function(e,h,g,j){var f,i;if(h=="mceInsertContent"){f=e.dom.getParent(e.selection.getNode(),"div.mceTemp");if(!f){return}i=e.dom.create("p");e.dom.insertAfter(i,f);e.selection.setCursorLocation(i,0)}})},_do_shcode:function(a){return a.replace(/(?:

)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g,function(j,i,h){var d,m,k,l,f,g,e=tinymce.trim;d=i.match(/id=['"]([^'"]*)['"] ?/);if(d){i=i.replace(d[0],"")}m=i.match(/align=['"]([^'"]*)['"] ?/);if(m){i=i.replace(m[0],"")}k=i.match(/width=['"]([0-9]*)['"] ?/);if(k){i=i.replace(k[0],"")}h=e(h);g=h.match(/((?:]+>)?]+>(?:<\/a>)?)([\s\S]*)/i);if(g&&g[2]){l=e(g[2]);g=e(g[1])}else{l=e(i).replace(/caption=['"]/,"").replace(/['"]$/,"");g=h}d=(d&&d[1])?d[1]:"";m=(m&&m[1])?m[1]:"alignnone";k=(k&&k[1])?k[1]:"";if(!k||!l){return h}f="mceTemp";if(m=="aligncenter"){f+=" mceIEcenter"}return'

'+g+'
'+l+"
"})},_get_shcode:function(a){return a.replace(/
]*>([\s\S]+?)<\/div>/g,function(d,c){var e=c.replace(/
]+)>\s*
]+>([\s\S]+?)<\/dt>\s*
]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi,function(i,f,l,j){var k,h,g;g=l.match(/width="([0-9]*)"/);g=(g&&g[1])?g[1]:"";if(!g||!j){return l}k=f.match(/id="([^"]*)"/);k=(k&&k[1])?k[1]:"";h=f.match(/class="([^"]*)"/);h=(h&&h[1])?h[1]:"";h=h.match(/align[a-z]+/)||"alignnone";j=j.replace(/\r\n|\r/g,"\n").replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g,function(b){return b.replace(/[\r\n\t]+/," ")});j=j.replace(/\s*\n\s*/g,"
");return'[caption id="'+k+'" align="'+h+'" width="'+g+'"]'+l+" "+j+"[/caption]"});if(e.indexOf("[caption")!==0){e=c.replace(/[\s\S]*?((?:
]+>)?]+>(?:<\/a>)?)(

[\s\S]*<\/p>)?[\s\S]*/gi,"

$1

$2")}return e})},_createButtons:function(){var b=this,a=tinymce.activeEditor,d=tinymce.DOM,e,c,f;if(d.get("wp_editbtns")){return}f=(window.devicePixelRatio&&window.devicePixelRatio>1)||(window.matchMedia&&window.matchMedia("(min-resolution:130dpi)").matches);d.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"});e=d.add("wp_editbtns","img",{src:f?b.url+"/img/image-2x.png":b.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.edit_img")});tinymce.dom.Event.add(e,"mousedown",function(g){b._editImage();a.plugins.wordpress._hideButtons()});c=d.add("wp_editbtns","img",{src:f?b.url+"/img/delete-2x.png":b.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.del_img")});tinymce.dom.Event.add(c,"mousedown",function(j){var g=tinymce.activeEditor,i=g.selection.getNode(),h;if(i.nodeName=="IMG"&&g.dom.getAttrib(i,"class").indexOf("mceItem")==-1){if((h=g.dom.getParent(i,"div"))&&g.dom.hasClass(h,"mceTemp")){g.dom.remove(h)}else{if(i.parentNode.nodeName=="A"&&i.parentNode.childNodes.length==1){i=i.parentNode}if(i.parentNode.nodeName=="P"&&i.parentNode.childNodes.length==1){i=i.parentNode}g.dom.remove(i)}g.execCommand("mceRepaint");return false}g.plugins.wordpress._hideButtons()})},_editImage:function(){var d=tinymce.activeEditor,e=this.url,g=d.selection.getNode(),c,f,a,b=g.className;if(b.indexOf("mceItem")!=-1||b.indexOf("wpGallery")!=-1||g.nodeName!="IMG"){return}c=tinymce.DOM.getViewPort();f=680<(c.h-70)?680:c.h-70;a=650