-
-(function() {
- tinymce.create('tinymce.plugins.wpEditImage', {
-
- init : function(ed, url) {
- var t = this;
-
- t.url = url;
- t._createButtons();
-
- // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
- ed.addCommand('WP_EditImage', function() {
- var el = ed.selection.getNode(), vp = tinymce.DOM.getViewPort(), H = vp.h, W = ( 720 < vp.w ) ? 720 : vp.w;
- var cls = ed.dom.getAttrib(el, 'class');
-
- if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
- return;
-
- tb_show('', url + '/editimage.html?ver=321&TB_iframe=true');
- tinymce.DOM.setStyles('TB_window', {
- 'width':( W - 50 )+'px',
- 'height':( H - 45 )+'px',
- 'margin-left':'-'+parseInt((( W - 50 ) / 2),10) + 'px'
- });
-
- if ( ! tinymce.isIE6 ) {
- tinymce.DOM.setStyles('TB_window', {
- 'top':'20px',
- 'marginTop':'0'
- });
- }
-
- tinymce.DOM.setStyles('TB_iframeContent', {
- 'width':( W - 50 )+'px',
- 'height':( H - 75 )+'px'
- });
- tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
- });
-
- ed.onInit.add(function(ed) {
- tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
- ed.plugins.wpeditimage.hideButtons();
- });
- });
-
- ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
- ed.plugins.wpeditimage.hideButtons();
- });
-
- ed.onSaveContent.add(function(ed, o) {
- ed.plugins.wpeditimage.hideButtons();
- });
-
- ed.onMouseUp.add(function(ed, e) {
- if ( tinymce.isOpera ) {
- if ( e.target.nodeName == 'IMG' )
- ed.plugins.wpeditimage.showButtons(e.target);
- } else if ( ! tinymce.isWebKit ) {
- var n = ed.selection.getNode(), DL;
-
- if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {
- window.setTimeout(function(){
- var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
-
- if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
- ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
- ed.execCommand('mceRepaint');
- }
- }, 100);
- }
- }
- });
-
- ed.onMouseDown.add(function(ed, e) {
- if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
- t.hideButtons();
- return;
- }
- ed.plugins.wpeditimage.showButtons(e.target);
- });
-
- ed.onKeyPress.add(function(ed, e) {
- var DL, DIV;
-
- if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
- var P = ed.dom.create('p', {}, ' ');
- if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' )
- ed.dom.insertAfter( P, DIV );
- else ed.dom.insertAfter( P, DL );
-
- tinymce.dom.Event.cancel(e);
- ed.selection.select(P);
- return false;
- }
- });
-
- ed.onBeforeSetContent.add(function(ed, o) {
- o.content = t._do_shcode(o.content);
- });
-
- ed.onPostProcess.add(function(ed, o) {
- if (o.get)
- o.content = t._get_shcode(o.content);
- });
- },
-
- _do_shcode : function(co) {
- return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
- b = b.replace(/\\'|\\'|\\'/g, ''').replace(/\\"|\\"/g, '"');
- c = c.replace(/\\'|\\'/g, ''').replace(/\\"/g, '"');
- var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/align=['"]([^'"]+)/i);
- var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/i);
-
- id = ( id && id[1] ) ? id[1] : '';
- cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
- w = ( w && w[1] ) ? w[1] : '';
- cap = ( cap && cap[1] ) ? cap[1] : '';
- if ( ! w || ! cap ) return c;
-
- var div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
-
- return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
- 'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
- });
- },
-
- _get_shcode : function(co) {
- return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){
- var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/class=['"]([^'"]+)/i);
- var w = c.match(/width=['"]([0-9]+)/);
-
- id = ( id && id[1] ) ? id[1] : '';
- cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
- w = ( w && w[1] ) ? w[1] : '';
-
- if ( ! w || ! cap ) return c;
- cls = cls.match(/align[^ '"]+/) || 'alignnone';
- cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, ''').replace(/"/g, '"');
-
- return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
- });
- },
-
- showButtons : function(n) {
- var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
- var cls = ed.dom.getAttrib(n, 'class');
-
- if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
- return;
-
- vp = ed.dom.getViewPort(ed.getWin());
- p1 = DOM.getPos(ed.getContentAreaContainer());
- p2 = ed.dom.getPos(n);
-
- X = Math.max(p2.x - vp.x, 0) + p1.x;
- Y = Math.max(p2.y - vp.y, 0) + p1.y;
-
- DOM.setStyles('wp_editbtns', {
- 'top' : Y+5+'px',
- 'left' : X+5+'px',
- 'display' : 'block'
- });
-
- t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
- },
-
- hideButtons : function() {
- if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
-
- tinymce.DOM.hide('wp_editbtns');
- window.clearTimeout(this.btnsTout);
- },
-
- _createButtons : function() {
- var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM;
-
- DOM.remove('wp_editbtns');
-
- var wp_editbtns = DOM.add(document.body, 'div', {
- id : 'wp_editbtns',
- style : 'display:none;'
- });
-
- var wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
- src : t.url+'/img/image.png',
- id : 'wp_editimgbtn',
- width : '24',
- height : '24',
- title : ed.getLang('wpeditimage.edit_img')
- });
-
- wp_editimgbtn.onmousedown = function(e) {
- var ed = tinyMCE.activeEditor;
- ed.windowManager.bookmark = ed.selection.getBookmark('simple');
- ed.execCommand("WP_EditImage");
- this.parentNode.style.display = 'none';
- };
-
- var wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
- src : t.url+'/img/delete.png',
- id : 'wp_delimgbtn',
- width : '24',
- height : '24',
- title : ed.getLang('wpeditimage.del_img')
- });
-
- wp_delimgbtn.onmousedown = function(e) {
- var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
-
- if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
- if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
- ed.dom.remove(p);
- else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
- ed.dom.remove(p);
- else ed.dom.remove(el);
-
- this.parentNode.style.display = 'none';
- ed.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);
-})();
+(function(){tinymce.create("tinymce.plugins.wpEditImage",{init:function(a,b){var c=this;c.url=b;c._createButtons();a.addCommand("WP_EditImage",function(){var h=a.selection.getNode(),f=tinymce.DOM.getViewPort(),g=f.h,d=(720<f.w)?720:f.w,e=a.dom.getAttrib(h,"class");if(e.indexOf("mceItem")!=-1||e.indexOf("wpGallery")!=-1||h.nodeName!="IMG"){return}tb_show("",b+"/editimage.html?ver=321&TB_iframe=true");tinymce.DOM.setStyles("TB_window",{width:(d-50)+"px",height:(g-45)+"px","margin-left":"-"+parseInt(((d-50)/2),10)+"px"});if(!tinymce.isIE6){tinymce.DOM.setStyles("TB_window",{top:"20px",marginTop:"0"})}tinymce.DOM.setStyles("TB_iframeContent",{width:(d-50)+"px",height:(g-75)+"px"});tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")});a.onInit.add(function(d){tinymce.dom.Event.add(d.getBody(),"dragstart",function(f){if(!tinymce.isGecko&&f.target.nodeName=="IMG"&&d.dom.getParent(f.target,"dl.wp-caption")){return tinymce.dom.Event.cancel(f)}})});a.onMouseUp.add(function(d,f){if(tinymce.isWebKit||tinymce.isOpera){return}if(d.dom.getParent(f.target,"div.mceTemp")||d.dom.is(f.target,"div.mceTemp")){window.setTimeout(function(){var e=tinyMCE.activeEditor,i=e.selection.getNode(),g,h;if("IMG"==i.nodeName){g=e.dom.getParent(i,"dl.wp-caption");h=e.dom.getAttrib(i,"width")||i.width;h=parseInt(h,10);if(g&&h!=(parseInt(e.dom.getStyle(g,"width"),10)-10)){e.dom.setStyle(g,"width",10+h);e.execCommand("mceRepaint")}}},100)}});a.onMouseDown.add(function(d,g){var f;if(g.target.nodeName=="IMG"&&d.dom.getAttrib(g.target,"class").indexOf("mceItem")==-1){d.plugins.wordpress._showButtons(g.target,"wp_editbtns");if(tinymce.isGecko&&(f=d.dom.getParent(g.target,"dl.wp-caption"))&&d.dom.hasClass(f.parentNode,"mceTemp")){d.selection.select(f.parentNode)}}});a.onKeyPress.add(function(d,i){var j,f,h,g;if(i.keyCode==13){j=d.selection.getNode();f=d.dom.getParent(j,"dl.wp-caption");h=d.dom.getParent(f,"div.mceTemp");if(f&&h){g=d.dom.create("p",{}," ");d.dom.insertAfter(g,h);if(g.firstChild){d.selection.select(g.firstChild)}else{d.selection.select(g)}tinymce.dom.Event.cancel(i);return false}}});a.onBeforeSetContent.add(function(d,e){e.content=c._do_shcode(e.content)});a.onPostProcess.add(function(d,e){if(e.get){e.content=c._get_shcode(e.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(/\\'|\\'|\\'/g,"'").replace(/\\"|\\"/g,""");k=k.replace(/\\'|\\'/g,"'").replace(/\\"/g,""");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,"'").replace(/"/g,""");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