]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js
Wordpress 3.7
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpeditimage / editor_plugin.js
index fae5b5c985bff6ffb267c88c3fba2f2d5dce0c3f..4884c021ad0aba274d4bece22149de9b275db2df 100644 (file)
@@ -1 +1 @@
-(function(){tinymce.create("tinymce.plugins.wpEditImage",{init:function(a,c){var d=this,b={};d.url=c;d._createButtons();a.addCommand("WP_EditImage",function(){var i=a.selection.getNode(),g=tinymce.DOM.getViewPort(),h=g.h,e=(720<g.w)?720:g.w,f=a.dom.getAttrib(i,"class");if(f.indexOf("mceItem")!=-1||f.indexOf("wpGallery")!=-1||i.nodeName!="IMG"){return}tb_show("",c+"/editimage.html?ver=321&TB_iframe=true");tinymce.DOM.setStyles("TB_window",{width:(e-50)+"px",height:(h-45)+"px","margin-left":"-"+parseInt(((e-50)/2),10)+"px"});if(!tinymce.isIE6){tinymce.DOM.setStyles("TB_window",{top:"20px",marginTop:"0"})}tinymce.DOM.setStyles("TB_iframeContent",{width:(e-50)+"px",height:(h-75)+"px"});tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")});a.onInit.add(function(e){tinymce.dom.Event.add(e.getBody(),"dragstart",function(f){if(!tinymce.isGecko&&f.target.nodeName=="IMG"&&e.dom.getParent(f.target,"dl.wp-caption")){return tinymce.dom.Event.cancel(f)}})});a.onMouseUp.add(function(f,g){if(tinymce.isWebKit||tinymce.isOpera){return}if(b.x&&(g.clientX!=b.x||g.clientY!=b.y)){var h=f.selection.getNode();if("IMG"==h.nodeName){window.setTimeout(function(){var e,i;if(h.width!=b.img_w||h.height!=b.img_h){h.className=h.className.replace(/size-[^ "']+/,"")}if(f.dom.getParent(h,"div.mceTemp")){e=f.dom.getParent(h,"dl.wp-caption");if(e){i=f.dom.getAttrib(h,"width")||h.width;i=parseInt(i,10);f.dom.setStyle(e,"width",10+i);f.execCommand("mceRepaint")}}},100)}}b={}});a.onMouseDown.add(function(f,g){if(g.target&&(g.target.nodeName=="IMG"||(g.target.firstChild&&g.target.firstChild.nodeName=="IMG"))){b={x:g.clientX,y:g.clientY,img_w:g.target.clientWidth,img_h:g.target.clientHeight};if(f.dom.getAttrib(g.target,"class").indexOf("mceItem")==-1){f.plugins.wordpress._showButtons(g.target,"wp_editbtns")}}});a.onKeyPress.add(function(f,j){var k,g,i,h;if(j.keyCode==13){k=f.selection.getNode();g=f.dom.getParent(k,"dl.wp-caption");i=f.dom.getParent(g,"div.mceTemp");if(g&&i){h=f.dom.create("p",{},"&nbsp;");f.dom.insertAfter(h,i);if(h.firstChild){f.selection.select(h.firstChild)}else{f.selection.select(h)}tinymce.dom.Event.cancel(j);return false}}});a.onBeforeSetContent.add(function(e,f){f.content=d._do_shcode(f.content)});a.onPostProcess.add(function(e,f){if(f.get){f.content=d._get_shcode(f.content)}})},_do_shcode:function(a){return a.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?[\s\u00a0]*/g,function(g,d,k){var j,f,e,h,i;d=d.replace(/\\'|\\&#39;|\\&#039;/g,"&#39;").replace(/\\"|\\&quot;/g,"&quot;");k=k.replace(/\\&#39;|\\&#039;/g,"&#39;").replace(/\\&quot;/g,"&quot;");j=d.match(/id=['"]([^'"]+)/i);f=d.match(/align=['"]([^'"]+)/i);e=d.match(/width=['"]([0-9]+)/);h=d.match(/caption=['"]([^'"]+)/i);j=(j&&j[1])?j[1]:"";f=(f&&f[1])?f[1]:"alignnone";e=(e&&e[1])?e[1]:"";h=(h&&h[1])?h[1]:"";if(!e||!h){return k}i=(f=="aligncenter")?"mceTemp mceIEcenter":"mceTemp";return'<div class="'+i+'" draggable><dl id="'+j+'" class="wp-caption '+f+'" style="width: '+(10+parseInt(e))+'px"><dt class="wp-caption-dt">'+k+'</dt><dd class="wp-caption-dd">'+h+"</dd></dl></div>"})},_get_shcode:function(a){return a.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi,function(g,d,j,h){var i,f,e;i=d.match(/id=['"]([^'"]+)/i);f=d.match(/class=['"]([^'"]+)/i);e=j.match(/width=['"]([0-9]+)/);i=(i&&i[1])?i[1]:"";f=(f&&f[1])?f[1]:"alignnone";e=(e&&e[1])?e[1]:"";if(!e||!h){return j}f=f.match(/align[^ '"]+/)||"alignnone";h=h.replace(/<\S[^<>]*>/gi,"").replace(/'/g,"&#39;").replace(/"/g,"&quot;");return'[caption id="'+i+'" align="'+f+'" width="'+e+'" caption="'+h+'"]'+j+"[/caption]"})},_createButtons:function(){var b=this,a=tinyMCE.activeEditor,d=tinymce.DOM,e,c;d.remove("wp_editbtns");d.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"});e=d.add("wp_editbtns","img",{src:b.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.edit_img")});tinymce.dom.Event.add(e,"mousedown",function(g){var f=tinyMCE.activeEditor;f.windowManager.bookmark=f.selection.getBookmark("simple");f.execCommand("WP_EditImage")});c=d.add("wp_editbtns","img",{src:b.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.del_img")});tinymce.dom.Event.add(c,"mousedown",function(i){var f=tinyMCE.activeEditor,g=f.selection.getNode(),h;if(g.nodeName=="IMG"&&f.dom.getAttrib(g,"class").indexOf("mceItem")==-1){if((h=f.dom.getParent(g,"div"))&&f.dom.hasClass(h,"mceTemp")){f.dom.remove(h)}else{if((h=f.dom.getParent(g,"A"))&&h.childNodes.length==1){f.dom.remove(h)}else{f.dom.remove(g)}}f.execCommand("mceRepaint");return false}})},getInfo:function(){return{longname:"Edit Image",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wpeditimage",tinymce.plugins.wpEditImage)})();
\ No newline at end of file
+!function(){tinymce.create("tinymce.plugins.wpEditImage",{url:"",editor:{},init:function(a,b){var c=this,d={};c.url=b,c.editor=a,c._createButtons(),a.addCommand("WP_EditImage",c._editImage),a.onInit.add(function(a){a.dom.events.add(a.getBody(),"mousedown",function(b){var c;"IMG"==b.target.nodeName&&(c=a.dom.getParent(b.target,"div.mceTemp"))&&(tinymce.isGecko?a.selection.select(c):tinymce.isWebKit&&a.dom.events.prevent(b))}),a.dom.events.add(a.getBody(),"keydown",function(b){var c,d,e,f;return 13==b.keyCode&&(c=a.selection.getNode(),d=a.dom.getParent(c,"dl.wp-caption"),d&&(e=a.dom.getParent(d,"div.mceTemp")),e)?(a.dom.events.cancel(b),f=a.dom.create("p",{},""),a.dom.insertAfter(f,e),a.selection.setCursorLocation(f,0),!1):void 0}),"ontouchstart"in window&&a.dom.events.add(a.getBody(),"touchstart",function(a){c._showButtons(a)})}),a.onMouseUp.add(function(a,b){if(!tinymce.isWebKit&&!tinymce.isOpera){if(d.x&&(b.clientX!=d.x||b.clientY!=d.y)){var c=a.selection.getNode();"IMG"==c.nodeName&&window.setTimeout(function(){var b,e=a.dom.getParent(c,"dl.wp-caption");(c.width!=d.img_w||c.height!=d.img_h)&&(c.className=c.className.replace(/size-[^ "']+/,"")),e&&(b=a.dom.getAttrib(c,"width")||c.width,b=parseInt(b,10),a.dom.setStyle(e,"width",10+b),a.execCommand("mceRepaint"))},100)}d={}}}),a.onMouseDown.add(function(a,b){c._showButtons(b)}),a.onBeforeSetContent.add(function(a,b){b.content=a.wpSetImgCaption(b.content)}),a.onPostProcess.add(function(a,b){b.get&&(b.content=a.wpGetImgCaption(b.content))}),a.wpSetImgCaption=function(a){return c._do_shcode(a)},a.wpGetImgCaption=function(a){return c._get_shcode(a)},a.onBeforeExecCommand.add(function(a,b){var c,d;if("mceInsertContent"==b){if(c=a.dom.getParent(a.selection.getNode(),"div.mceTemp"),!c)return;d=a.dom.create("p"),a.dom.insertAfter(d,c),a.selection.setCursorLocation(d,0)}})},_do_shcode:function(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),i=c.match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i),i&&i[2]?(g=j(i[2]),i=j(i[1])):(g=j(b).replace(/caption=['"]/,"").replace(/['"]$/,""),i=c),d=d&&d[1]?d[1]:"",e=e&&e[1]?e[1]:"alignnone",f=f&&f[1]?f[1]:"",f&&g?(h="mceTemp","aligncenter"==e&&(h+=" mceIEcenter"),'<div class="'+h+'"><dl id="'+d+'" class="wp-caption '+e+'" style="width: 10'+parseInt(f)+'px"><dt class="wp-caption-dt">'+i+'</dt><dd class="wp-caption-dd">'+g+"</dd></dl></div>"):c})},_get_shcode:function(a){return a.replace(/<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g,function(a,b){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})},_createButtons:function(){var a,b,c,d=this,e=tinymce.activeEditor,f=tinymce.DOM;f.get("wp_editbtns")||(c=window.devicePixelRatio&&window.devicePixelRatio>1||window.matchMedia&&window.matchMedia("(min-resolution:130dpi)").matches,f.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"}),a=f.add("wp_editbtns","img",{src:c?d.url+"/img/image-2x.png":d.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:e.getLang("wpeditimage.edit_img")}),tinymce.dom.Event.add(a,"mousedown",function(){d._editImage(),e.plugins.wordpress._hideButtons()}),b=f.add("wp_editbtns","img",{src:c?d.url+"/img/delete-2x.png":d.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:e.getLang("wpeditimage.del_img")}),tinymce.dom.Event.add(b,"mousedown",function(){var a,b=tinymce.activeEditor,c=b.selection.getNode();return"IMG"==c.nodeName&&-1==b.dom.getAttrib(c,"class").indexOf("mceItem")?((a=b.dom.getParent(c,"div"))&&b.dom.hasClass(a,"mceTemp")?b.dom.remove(a):("A"==c.parentNode.nodeName&&1==c.parentNode.childNodes.length&&(c=c.parentNode),"P"==c.parentNode.nodeName&&1==c.parentNode.childNodes.length&&(c=c.parentNode),b.dom.remove(c)),b.execCommand("mceRepaint"),!1):(b.plugins.wordpress._hideButtons(),void 0)}))},_editImage:function(){var a,b,c,d=tinymce.activeEditor,e=this.url,f=d.selection.getNode(),g=f.className;-1==g.indexOf("mceItem")&&-1==g.indexOf("wpGallery")&&"IMG"==f.nodeName&&(a=tinymce.DOM.getViewPort(),b=680<a.h-70?680:a.h-70,c=650<a.w?650:a.w,d.windowManager.open({file:e+"/editimage.html",width:c+"px",height:b+"px",inline:!0}))},_showButtons:function(a){var b=this.editor,c=a.target;if("IMG"!=c.nodeName){if(!c.firstChild||"IMG"!=c.firstChild.nodeName||1!=c.childNodes.length)return b.plugins.wordpress._hideButtons(),void 0;c=c.firstChild}-1==b.dom.getAttrib(c,"class").indexOf("mceItem")&&(mouse={x:a.clientX,y:a.clientY,img_w:c.clientWidth,img_h:c.clientHeight},"touchstart"==a.type&&(b.selection.select(c),b.dom.events.cancel(a)),b.plugins.wordpress._hideButtons(),b.plugins.wordpress._showButtons(c,"wp_editbtns"))},getInfo:function(){return{longname:"Edit Image",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}}),tinymce.PluginManager.add("wpeditimage",tinymce.plugins.wpEditImage)}();
\ No newline at end of file