WordPress/wp-includes/js/tinymce/plugins/wpeditimage/plugin.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

tinymce.PluginManager.add("wpeditimage",function(g){var r,u,n,c,a,e=tinymce.each,l=tinymce.trim,t=tinymce.Env.iOS;function i(e){return!(!g.dom.getAttrib(e,"data-mce-placeholder")&&!g.dom.getAttrib(e,"data-mce-object"))}function o(e){e=g.$(e).parents("[contenteditable]");return e&&"false"===e.attr("contenteditable")}function d(e){return e.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g,function(e,t,n){var a,i,o,r,c,d=t.match(/id=['"]([^'"]*)['"] ?/);return(c=(t=(i=(t=(a=(t=d?t.replace(d[0],""):t).match(/align=['"]([^'"]*)['"] ?/))?t.replace(a[0],""):t).match(/class=['"]([^'"]*)['"] ?/))?t.replace(i[0],""):t).match(/width=['"]([0-9]*)['"] ?/))&&(t=t.replace(c[0],"")),r=(r=(n=l(n)).match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i))&&r[2]?(o=l(r[2]),l(r[1])):(o=l(t).replace(/caption=['"]/,"").replace(/['"]$/,""),n),d=d&&d[1]?d[1].replace(/[<>&]+/g,""):"",a=a&&a[1]?a[1]:"alignnone",i=i&&i[1]?" "+i[1].replace(/[<>&]+/g,""):"",(c=(c=!c&&r?r.match(/width=['"]([0-9]*)['"]/):c)&&c[1]?c[1]:c)&&o?(c=parseInt(c,10),g.getParam("wpeditimage_html5_captions")||(c+=10),'<div class="mceTemp"><dl id="'+d+'" class="wp-caption '+a+i+'" style="width: '+c+'px"><dt class="wp-caption-dt">'+r+'</dt><dd class="wp-caption-dd">'+o+"</dd></dl></div>"):n})}function s(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=n.match(/width="([0-9]*)"/);return r=r&&r[1]?r[1]:"",o=(i=(i=t.match(/class="([^"]*)"/))&&i[1]?i[1]:"").match(/align[a-z]+/i)||"alignnone",r&&a?'[caption id="'+(t=(t=t.match(/id="([^"]*)"/))&&t[1]?t[1]:"")+'" align="'+o+'" width="'+r+'"'+(i=(i=i.replace(/wp-caption ?|align[a-z]+ ?/gi,""))&&' class="'+i+'"')+"]"+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"!==o[0]?n.replace(/><img/,' class="'+o[0]+'"><img'):n})).indexOf("[caption")?t.replace(/[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi,"<p>$1</p>$2"):n})}function h(e){return e&&(e.textContent||e.innerText).replace(/\ufeff/g,"")}function m(e){var t=g.dom.getParent(e,"div.mceTemp");(t=t||"IMG"!==e.nodeName?t:g.dom.getParent(e,"a"))?(t.nextSibling?g.selection.select(t.nextSibling):t.previousSibling?g.selection.select(t.previousSibling):g.selection.select(t.parentNode),g.selection.collapse(!0),g.dom.remove(t)):g.dom.remove(e),g.nodeChanged(),g.undoManager.add()}return g.addButton("wp_img_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){m(g.selection.getNode())}}),g.addButton("wp_img_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var e,t,n,p;e=g.selection.getNode(),"undefined"!=typeof wp&&wp.media?(n=function(e){var t,n,a,i,o=[],r=g.dom,c=/^\d+$/;(n={attachment_id:!1,size:"custom",caption:"",align:"none",extraClasses:"",link:!1,linkUrl:"",linkClassName:"",linkTargetBlank:!1,linkRel:"",title:""}).url=r.getAttrib(e,"src"),n.alt=r.getAttrib(e,"alt"),n.title=r.getAttrib(e,"title"),a=r.getAttrib(e,"width"),i=r.getAttrib(e,"height"),(!c.test(a)||parseInt(a,10)<1)&&(a=e.naturalWidth||e.width);(!c.test(i)||parseInt(i,10)<1)&&(i=e.naturalHeight||e.height);n.customWidth=n.width=a,n.customHeight=n.height=i,c=tinymce.explode(e.className," "),t=[],tinymce.each(c,function(e){/^wp-image/.test(e)?n.attachment_id=parseInt(e.replace("wp-image-",""),10):/^align/.test(e)?n.align=e.replace("align",""):/^size/.test(e)?n.size=e.replace("size-",""):t.push(e)}),n.extraClasses=t.join(" "),(a=r.getParents(e,".wp-caption")).length&&(a=a[0],c=a.className.split(" "),tinymce.each(c,function(e){/^align/.test(e)?n.align=e.replace("align",""):e&&"wp-caption"!==e&&o.push(e)}),n.captionClassName=o.join(" "),(i=r.select("dd.wp-caption-dd",a