WordPress/wp-includes/js/tinymce/plugins/wpeditimage/plugin.min.js
Andrew Ozz a16cc19790 TinyMCE:
- Fix toolbar icons in IE9.
- Remove background gradients in IE < 10.
- Lint our plugins.
- Add draggable attribute to the caption wrapper and make the captioned images non-draggable in Chrome.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26880


git-svn-id: http://core.svn.wordpress.org/trunk@26763 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-30 01:54:11 +00:00

1 line
6.2 KiB
JavaScript

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){if(-1===b.indexOf("<img "))return"";var 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});return 0!==c.indexOf("[caption")&&(c=b.replace(/[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi,"<p>$1</p>$2")),c})}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:"Image caption"};b.data.splice(b.data.length-1,0,c)}}),a.on("wpNewImageRefresh",function(a){var c,d;(c=b.getParent(a.node,"dl.wp-caption"))&&(c.style.width||(d=parseInt(a.node.clientWidth,10)+10,d=d?d+"px":"50%",b.setStyle(c,"width",d)))}),a.on("wpImageFormSubmit",function(c){var d,e,f,g,h,i=c.imgData.data,j=c.imgData.node,k=c.imgData.caption,l="",m="",n="";return i.id="__wp-temp-img-id",c.imgData.cancel=!0,i.style||(i.style=null),i.src?(j?(h=j.id||null,b.setAttribs(j,i),d=b.getParent(j,"dl.wp-caption"),k?d?(e=b.select("dd.wp-caption-dd",d)[0])&&(e.innerHTML=k):(j.className&&(l=j.className.match(/wp-image-([0-9]+)/),m=j.className.match(/align(left|right|center|none)/)),m?(m=m[0],j.className=j.className.replace(/align(left|right|center|none)/g,"")):m="alignnone",m=' class="wp-caption '+m+'"',l&&(l=' id="attachment_'+l[1]+'"'),n=i.width||j.clientWidth,n&&(n=parseInt(n,10)+10,n=' style="width: '+n+'px"'),j.parentNode&&"A"===j.parentNode.nodeName?(g=b.getOuterHTML(j.parentNode),f=j.parentNode):(g=b.getOuterHTML(j),f=j),g="<dl "+l+m+n+">"+'<dt class="wp-caption-dt">'+g+'</dt><dd class="wp-caption-dd">'+k+"</dd></dl>",(e=b.getParent(j,"p"))?(d=b.create("div",{"class":"mceTemp",draggable:"true"},g),b.insertAfter(d,e),a.selection.select(d),a.nodeChanged(),b.remove(f),b.isEmpty(e)&&b.remove(e)):a.selection.setContent('<div class="mceTemp" draggable="true">'+g+"</div>")):d&&(g="A"===j.parentNode.nodeName?b.getOuterHTML(j.parentNode):b.getOuterHTML(j),e=b.create("p",{},g),b.insertAfter(e,d.parentNode),a.selection.select(e),a.nodeChanged(),b.remove(d.parentNode))):(g=b.createHTML("img",i),k?(f=a.selection.getNode(),i.width&&(n=parseInt(i.width,10)+10,n=' style="width: '+n+'px"'),g='<dl class="wp-caption alignnone"'+n+">"+'<dt class="wp-caption-dt">'+g+'</dt><dd class="wp-caption-dd">'+k+"</dd></dl>",e="P"===f.nodeName?f:b.getParent(f,"p"),e&&"P"===e.nodeName?(d=b.create("div",{"class":"mceTemp",draggable:"true"},g),b.insertAfter(d,e),a.selection.select(d),a.nodeChanged(),b.isEmpty(e)&&b.remove(e)):a.selection.setContent('<div class="mceTemp" draggable="true">'+g+"</div>")):a.selection.setContent(g)),j=b.get("__wp-temp-img-id"),b.setAttrib(j,"id",h),c.imgData.node=j,void 0):(j&&((d=b.getParent(j,"div.mceTemp"))?b.remove(d):"A"===j.parentNode.nodeName?b.remove(j.parentNode):b.remove(j),a.nodeChanged()),void 0)}),a.on("wpLoadImageData",function(a){var c,d=a.imgData.data,e=a.imgData.node;(c=b.getParent(e,"dl.wp-caption"))&&(c=b.select("dd.wp-caption-dd",c)[0],d.caption=c?c.innerHTML:"")}),b.bind(a.getDoc(),"dragstart",function(c){var d=a.selection.getNode();"IMG"===d.nodeName&&b.getParent(d,".wp-caption")&&c.preventDefault()})}),a.on("BeforeExecCommand",function(b){var c,d,e,f,g=b.command,h=a.dom;if("mceInsertContent"===g){if((c=h.getParent(a.selection.getNode(),"div.mceTemp"))&&(d=h.create("p"),h.insertAfter(d,c),a.selection.setCursorLocation(d,0),a.nodeChanged(),tinymce.Env.ie>8))return setTimeout(function(){a.selection.setCursorLocation(d,0),a.selection.setContent(b.value)},500),!1}else if(("JustifyLeft"===g||"JustifyRight"===g||"JustifyCenter"===g)&&(c=a.selection.getNode(),f=g.substr(7).toLowerCase(),f="align"+f,e=h.is(c,"dl.wp-caption")?c:h.getParent(c,"dl.wp-caption")))return h.hasClass(e,f)?(h.removeClass(e,f),h.addClass(e,"alignnone")):(e.className=e.className.replace(/align[^ ]+/g,""),h.addClass(e,f)),!1}),a.on("keydown",function(b){var c,d,e,f,g=a.selection,h=a.dom;if(b.keyCode===tinymce.util.VK.ENTER)d=h.getParent(a.selection.getNode(),"div.mceTemp"),d&&(h.events.cancel(b),tinymce.each(h.select("dt, dd",d),function(a){h.isEmpty(a)&&h.remove(a)}),f=tinymce.Env.ie?"":'<br data-mce-bogus="1" />',e=h.create("p",null,f),h.insertAfter(e,d),g.setCursorLocation(e,0),a.nodeChanged());else if((b.keyCode===tinymce.util.VK.DELETE||b.keyCode===tinymce.util.VK.BACKSPACE)&&(c=g.getNode(),"DIV"===c.nodeName&&h.hasClass(c,"mceTemp")?d=c:("IMG"===c.nodeName||"DT"===c.nodeName||"A"===c.nodeName)&&(d=h.getParent(c,"div.mceTemp")),d))return h.events.cancel(b),d.nextSibling?g.select(d.nextSibling):d.previousSibling?g.select(d.previousSibling):g.select(d.parentNode),g.collapse(!0),a.nodeChanged(),h.remove(d),d=null,!1}),a.wpSetImgCaption=function(a){return b(a)},a.wpGetImgCaption=function(a){return c(a)},a.on("BeforeSetContent",function(b){b.content=a.wpSetImgCaption(b.content)}),a.on("PostProcess",function(b){b.get&&(b.content=a.wpGetImgCaption(b.content))}),{_do_shcode:b,_get_shcode:c}});