2014-01-29 05:43:30 +01:00
|
|
|
tinymce.PluginManager.add("wpeditimage",function(a){function b(a){return a.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g,function(a,b,c){var d,e,f,g,h,i,j=tinymce.trim;return d=b.match(/id=['"]([^'"]*)['"] ?/),d&&(b=b.replace(d[0],"")),e=b.match(/align=['"]([^'"]*)['"] ?/),e&&(b=b.replace(e[0],"")),f=b.match(/width=['"]([0-9]*)['"] ?/),f&&(b=b.replace(f[0],"")),c=j(c),h=c.match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i),h&&h[2]?(g=j(h[2]),h=j(h[1])):(g=j(b).replace(/caption=['"]/,"").replace(/['"]$/,""),h=c),d=d&&d[1]?d[1]:"",e=e&&e[1]?e[1]:"alignnone",f=f&&f[1]?f[1]:"",f&&g?(i=parseInt(f,10)+10,'<div class="mceTemp" draggable="true"><dl id="'+d+'" class="wp-caption '+e+'" style="width: '+i+'px"><dt class="wp-caption-dt">'+h+'</dt><dd class="wp-caption-dd">'+g+"</dd></dl></div>"):c})}function c(a){return a.replace(/<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g,function(a,b){var c="";return-1===b.indexOf("<img ")?(c=b.match(/<dd [^>]+>([\s\S]+?)<\/dd>/i),c&&c[1]?"<p>"+c[1]+"</p>":""):(c=b.replace(/<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi,function(a,b,c,d){var e,f,g;return g=c.match(/width="([0-9]*)"/),g=g&&g[1]?g[1]:"",g&&d?(e=b.match(/id="([^"]*)"/),e=e&&e[1]?e[1]:"",f=b.match(/class="([^"]*)"/),f=f&&f[1]?f[1]:"",f=f.match(/align[a-z]+/)||"alignnone",d=d.replace(/\r\n|\r/g,"\n").replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g,function(a){return a.replace(/[\r\n\t]+/," ")}),d=d.replace(/\s*\n\s*/g,"<br />"),'[caption id="'+e+'" align="'+f+'" width="'+g+'"]'+c+" "+d+"[/caption]"):c}),0!==c.indexOf("[caption")&&(c=b.replace(/[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi,"<p>$1</p>$2")),c)})}function d(b){var c,d,e,f;return d={attachment_id:!1,url:!1,height:"",width:"",size:"none",caption:"",alt:"",align:"none",link:!1,linkUrl:""},d.url=a.dom.getAttrib(b,"src"),d.alt=a.dom.getAttrib(b,"alt"),d.width=parseInt(a.dom.getAttrib(b,"width"),10),d.height=parseInt(a.dom.getAttrib(b,"height"),10),c=b.className.split(" "),tinymce.each(c,function(a){/^wp-image/.test(a)&&(d.attachment_id=parseInt(a.replace("wp-image-",""),10)),/^align/.test(a)&&(d.align=a.replace("align","")),/^size/.test(a)&&(d.size=a.replace("size-",""))}),e=a.dom.getParents(b,".wp-caption"),e.length&&(e=e[0],c=e.className.split(" "),tinymce.each(c,function(a){/^align/.test(a)&&(d.align=a.replace("align",""))}),f=a.dom.select("dd.wp-caption-dd",e),f.length&&(f=f[0],d.caption=a.serializer.serialize(f).replace(/<br[^>]*>/g,"$&\n").replace(/^<p>/,"").replace(/<\/p>$/,""))),"A"===b.parentNode.nodeName&&(d.linkUrl=a.dom.getAttrib(b.parentNode,"href")),d}function e(b,c){var d,e,g,h,i,j,k;c.caption?(h=f(c,"html"),e=c.width+10,d="align"+c.align,h='<dl id="'+c.attachment_id+'" class="wp-caption '+d+'" style="width: '+e+'px"><dt class="wp-caption-dt">'+h+'</dt><dd class="wp-caption-dd">'+c.caption+"</dd></dl>",g=a.dom.create("div",{"class":"mceTemp",draggable:"true"},h)):g=f(c,"node"),j=b,i=a.dom.getParent(b,".mceTemp"),i?j=i:"A"===b.parentNode.nodeName&&(j=b.parentNode),k=a.dom.uniqueId("wp_"),a.dom.setAttrib(g,"data-wp-replace-id",k),a.dom.replace(g,j),g=a.dom.select('[data-wp-replace-id="'+k+'"]')[0],a.dom.setAttrib(g,"data-wp-replace-id",""),a.selection.select("IMG"===g.nodeName?g:a.dom.select("img",g)[0]),a.nodeChanged()}function f(b,c){var d,e=[];if(c=c?c:"node",b.caption||e.push("align"+b.align),b.attachment_id&&(e.push("wp-image-"+b.attachment_id),b.size&&e.push("size-"+b.size)),d={src:b.url,width:b.width,height:b.height,alt:b.alt},e.length&&(d["class"]=e.join(" ")),b.linkUrl){if("node"===c)return a.dom.create("a",{href:b.linkUrl},a.dom.createHTML("img",d));if("html"===c)return a.dom.createHTML("a",{href:b.linkUrl},a.dom.createHTML("img",d))}else{if("node"===c)return a.dom.create("img",d);if("html"===c)return a.dom.createHTML("img",d)}}return a.on("init",function(){var b=a.dom;a.on("wpLoadImageForm",function(b){if(!a.getParam("wpeditimage_disable_captions")){var c={type:"textbox",flex:1,name:"caption",minHeight:60,multiline:!0,scroll:!0,label:"
|