tinymce.PluginManager.add("wpeditimage",function(C){var l,y,n,s,a,e=tinymce.each,m=tinymce.trim,t=tinymce.Env.iOS;function i(e){return!(!C.dom.getAttrib(e,"data-mce-placeholder")&&!C.dom.getAttrib(e,"data-mce-object"))}function o(e){var t=C.$(e).parents("[contenteditable]");return t&&"false"===t.attr("contenteditable")}function r(e){return e.replace(/(?:

)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g,function(e,t,n){var a,i,o,r,c,d;return(a=t.match(/id=['"]([^'"]*)['"] ?/))&&(t=t.replace(a[0],"")),(i=t.match(/align=['"]([^'"]*)['"] ?/))&&(t=t.replace(i[0],"")),(o=t.match(/class=['"]([^'"]*)['"] ?/))&&(t=t.replace(o[0],"")),(d=t.match(/width=['"]([0-9]*)['"] ?/))&&(t=t.replace(d[0],"")),c=(c=(n=m(n)).match(/((?:]+>)?]+>(?:<\/a>)?)([\s\S]*)/i))&&c[2]?(r=m(c[2]),m(c[1])):(r=m(t).replace(/caption=['"]/,"").replace(/['"]$/,""),n),a=a&&a[1]?a[1].replace(/[<>&]+/g,""):"",i=i&&i[1]?i[1]:"alignnone",o=o&&o[1]?" "+o[1].replace(/[<>&]+/g,""):"",!d&&c&&(d=c.match(/width=['"]([0-9]*)['"]/)),d&&d[1]&&(d=d[1]),d&&r?(d=parseInt(d,10),C.getParam("wpeditimage_html5_captions")||(d+=10),'

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

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

$1

$2")),n)})}function A(e){return e&&!!(e.textContent||e.innerText).replace(/\ufeff/g,"")}function p(e){var t=C.dom.getParent(e,"div.mceTemp");t||"IMG"!==e.nodeName||(t=C.dom.getParent(e,"a")),t?(t.nextSibling?C.selection.select(t.nextSibling):t.previousSibling?C.selection.select(t.previousSibling):C.selection.select(t.parentNode),C.selection.collapse(!0),C.dom.remove(t)):C.dom.remove(e),C.nodeChanged(),C.undoManager.add()}return C.addButton("wp_img_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){p(C.selection.getNode())}}),C.addButton("wp_img_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){!function(e){var t,n,a,i;if("undefined"==typeof wp||!wp.media)return C.execCommand("mceImage");a=function(e){var t,n,a,i,o,r,c,d,l=[],s=C.dom,m=/^\d+$/;(a={attachment_id:!1,size:"custom",caption:"",align:"none",extraClasses:"",link:!1,linkUrl:"",linkClassName:"",linkTargetBlank:!1,linkRel:"",title:""}).url=s.getAttrib(e,"src"),a.alt=s.getAttrib(e,"alt"),a.title=s.getAttrib(e,"title"),c=s.getAttrib(e,"width"),d=s.getAttrib(e,"height"),(!m.test(c)||parseInt(c,10)<1)&&(c=e.naturalWidth||e.width);(!m.test(d)||parseInt(d,10)<1)&&(d=e.naturalHeight||e.height);a.customWidth=a.width=c,a.customHeight=a.height=d,t=tinymce.explode(e.className," "),n=[],tinymce.each(t,function(e){/^wp-image/.test(e)?a.attachment_id=parseInt(e.replace("wp-image-",""),10):/^align/.test(e)?a.align=e.replace("align",""):/^size/.test(e)?a.size=e.replace("size-",""):n.push(e)}),a.extraClasses=n.join(" "),(i=s.getParents(e,".wp-caption")).length&&(i=i[0],t=i.className.split(" "),tinymce.each(t,function(e){/^align/.test(e)?a.align=e.replace("align",""):e&&"wp-caption"!==e&&l.push(e)}),a.captionClassName=l.join(" "),(o=s.select("dd.wp-caption-dd",i)).length&&(o=o[0],a.caption=C.serializer.serialize(o).replace(/]*>/g,"$&\n").replace(/^

/,"").replace(/<\/p>$/,"")));e.parentNode&&"A"===e.parentNode.nodeName&&(r=e.parentNode,a.linkUrl=s.getAttrib(r,"href"),a.linkTargetBlank="_blank"===s.getAttrib(r,"target"),a.linkRel=s.getAttrib(r,"rel"),a.linkClassName=r.className);return a}(e),C.$(e).attr("data-wp-editing",1),wp.media.events.trigger("editor:image-edit",{editor:C,metadata:a,image:e}),t=wp.media({frame:"image",state:"image-details",metadata:a}),wp.media.events.trigger("editor:frame-create",{frame:t}),n=function(e){C.undoManager.transact(function(){!function(e,t){var n,a,i,o,r,c,d,l,s,m,p,g,u,f,h,w,v,N,b,_=C.dom;if(!e||!e.length)return;l=e[0],(n=tinymce.explode(t.extraClasses," "))||(n=[]);t.caption||n.push("align"+t.align);t.attachment_id&&(n.push("wp-image-"+t.attachment_id),t.size&&"custom"!==t.size&&n.push("size-"+t.size));h=t.width,w=t.height,"custom"===t.size&&(h=t.customWidth,w=t.customHeight);u={src:t.url,width:h||null,height:w||null,title:t.title||null,class:n.join(" ")||null},_.setAttribs(l,u),e.attr("alt",t.alt||""),f={href:t.linkUrl,rel:t.linkRel||null,target:t.linkTargetBlank?"_blank":null,class:t.linkClassName||null},l.parentNode&&"A"===l.parentNode.nodeName&&!A(l.parentNode)?t.linkUrl?_.setAttribs(l.parentNode,f):_.remove(l.parentNode,!0):t.linkUrl&&((d=_.getParent(l,"a"))&&_.insertAfter(l,d),d=_.create("a",f),l.parentNode.insertBefore(d,l),d.appendChild(l));s=C.dom.getParent(l,".mceTemp"),i=l.parentNode&&"A"===l.parentNode.nodeName&&!A(l.parentNode)?l.parentNode:l;t.caption?(t.caption=function(e){if(!e||-1===e.indexOf("<")&&-1===e.indexOf(">"))return e;y=y||new tinymce.html.Serializer({},C.schema);return y.serialize(C.parser.parse(e,{forced_root_block:!1}))}(t.caption),g=t.attachment_id?"attachment_"+t.attachment_id:null,v="align"+(t.align||"none"),a="wp-caption "+v,t.captionClassName&&(a+=" "+t.captionClassName.replace(/[<>&]+/g,"")),C.getParam("wpeditimage_html5_captions")||(h=parseInt(h,10),h+=10),s?((p=_.select("dl.wp-caption",s)).length&&_.setAttribs(p,{id:g,class:a,style:"width: "+h+"px"}),(m=_.select(".wp-caption-dd",s)).length&&_.setHTML(m[0],t.caption)):(o="

'+t.caption+"
",c=_.create("div",{class:"mceTemp"},o),(r=_.getParent(i,"p"))?r.parentNode.insertBefore(c,r):i.parentNode.insertBefore(c,i),C.$(c).find("dt.wp-caption-dt").append(i),r&&_.isEmpty(r)&&_.remove(r))):s&&(r=_.create("p"),s.parentNode.insertBefore(r,s),r.appendChild(i),_.remove(s));e=C.$(l),N=e.attr("srcset"),b=e.attr("src"),N&&b&&(b=b.replace(/[?#].*/,""),-1===N.indexOf(b)&&e.attr("srcset",null).attr("sizes",null));wp.media.events&&wp.media.events.trigger("editor:image-update",{editor:C,metadata:t,image:l});C.nodeChanged()}(i,e)}),t.detach()},t.state("image-details").on("update",n),t.state("replace-image").on("replace",n),t.on("close",function(){C.focus(),t.detach(),(i=C.$("img[data-wp-editing]")).removeAttr("data-wp-editing")}),t.open()}(C.selection.getNode())}}),e({alignleft:"Align left",aligncenter:"Align center",alignright:"Align right",alignnone:"No alignment"},function(e,a){var t=a.slice(5);C.addButton("wp_img_"+a,{tooltip:e,icon:"dashicon dashicons-align-"+t,cmd:"alignnone"===a?"wpAlignNone":"Justify"+t.slice(0,1).toUpperCase()+t.slice(1),onPostRender:function(){var n=this;C.on("NodeChange",function(e){var t;"IMG"===e.element.nodeName&&(t=C.dom.getParent(e.element,".wp-caption")||e.element,"alignnone"===a?n.active(!/\balign(left|center|right)\b/.test(t.className)):n.active(C.dom.hasClass(t,a)))})}})}),C.once("preinit",function(){C.wp&&C.wp._createToolbar&&(l=C.wp._createToolbar(["wp_img_alignleft","wp_img_aligncenter","wp_img_alignright","wp_img_alignnone","wp_img_edit","wp_img_remove"]))}),C.on("wptoolbar",function(e){"IMG"!==e.element.nodeName||i(e.element)||(e.toolbar=l)}),t&&C.on("init",function(){C.on("touchstart",function(e){"IMG"!==e.target.nodeName||o(e.target)||(n=!0)}),C.dom.bind(C.getDoc(),"touchmove",function(){n=!1}),C.on("touchend",function(e){if(n&&"IMG"===e.target.nodeName&&!o(e.target)){var t=e.target;n=!1,window.setTimeout(function(){C.selection.select(t),C.nodeChanged()},100)}else l&&l.hide()})}),C.on("init",function(){var t=C.dom,e=C.getParam("wpeditimage_html5_captions")?"html5-captions":"html4-captions";t.addClass(C.getBody(),e),tinymce.Env.ie&&10',a=c.create("p",null,i),"DD"===t.nodeName?c.insertAfter(a,n):n.parentNode.insertBefore(a,n),C.nodeChanged(),o.setCursorLocation(a,0));else if((r===d.DELETE||r===d.BACKSPACE)&&("DIV"===(t=o.getNode()).nodeName&&c.hasClass(t,"mceTemp")?n=t:"IMG"!==t.nodeName&&"DT"!==t.nodeName&&"A"!==t.nodeName||(n=c.getParent(t,"div.mceTemp")),n))return c.events.cancel(e),p(t),!1}),tinymce.Env.gecko&&C.on("undo redo",function(){"IMG"===C.selection.getNode().nodeName&&C.selection.collapse()}),C.wpSetImgCaption=function(e){return r(e)},C.wpGetImgCaption=function(e){return c(e)},C.on("beforeGetContent",function(e){"raw"!==e.format&&C.$('img[id="__wp-temp-img-id"]').removeAttr("id")}),C.on("BeforeSetContent",function(e){"raw"!==e.format&&(e.content=C.wpSetImgCaption(e.content))}),C.on("PostProcess",function(e){e.get&&(e.content=C.wpGetImgCaption(e.content))}),C.on("dragstart",function(){var e=C.selection.getNode();"IMG"===e.nodeName&&((a=C.dom.getParent(e,".mceTemp"))||"A"!==e.parentNode.nodeName||A(e.parentNode)||(a=e.parentNode))}),C.on("drop",function(e){var t=C.dom,n=tinymce.dom.RangeUtils.getCaretRangeFromPoint(e.clientX,e.clientY,C.getDoc());n&&t.getParent(n.startContainer,".mceTemp")?e.preventDefault():a&&(e.preventDefault(),C.undoManager.transact(function(){n&&C.selection.setRng(n),C.selection.setNode(a),t.remove(a)})),a=null}),C.wp=C.wp||{},C.wp.isPlaceholder=i,{_do_shcode:r,_get_shcode:c}});