2019-10-05 15:49:10 -04:00
|
|
|
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(/(?:<p>)?\[(?: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 [^>]+>)?<img [^>]+>(?:<\/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),'<div class="mceTemp"><dl id="'+a+'" class="wp-caption '+i+o+'" style="width: '+d+'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+r+"</dd></dl></div>"):n})}function c(e){return e.replace(/(?:<div [^>]+mceTemp[^>]+>)?\s*(<dl [^>]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g,function(e,t){var n="";return-1===t.indexOf("<img ")||-1!==t.indexOf("</p>")?t.replace(/<d[ldt]( [^>]+)?>/g,"").replace(/<\/d[ldt]>/g,""):(-1===(n=t.replace(/\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\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,"<br />"))+"[/caption]":("alignnone"!==r[0]&&(n=n.replace(/><img/,' class="'+r[0]+'"><img')),n)})).indexOf("[caption")&&(n=t.replace(/[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi,"<p>$1</p>$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)}
|