From 201d24f044ff00db9294ea0dc4dcfff58ddb5393 Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 22 Oct 2009 05:30:29 +0000 Subject: [PATCH] TinyMCE in Firefox: fix crash when dragging images with caption, drag the image together with the caption (only in Firefox 3.5+) git-svn-id: http://svn.automattic.com/wordpress/trunk@12085 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../plugins/wpeditimage/editor_plugin.dev.js | 60 ++++++++++--------- .../plugins/wpeditimage/editor_plugin.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js index 2e256a07a4..02e722fe09 100644 --- a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js +++ b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js @@ -40,6 +40,13 @@ tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) { ed.plugins.wpeditimage.hideButtons(); }); + + tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) { + ed.plugins.wpeditimage.hideButtons(); + + if ( !tinymce.isGecko && e.target.nodeName == 'IMG' && ed.dom.getParent(e.target, 'dl.wp-caption') ) + return tinymce.dom.Event.cancel(e); + }); }); ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { @@ -51,33 +58,32 @@ }); ed.onMouseUp.add(function(ed, e) { - var n, DL; - - if ( tinymce.isOpera ) { - if ( e.target.nodeName == 'IMG' ) - ed.plugins.wpeditimage.showButtons(e.target); - } else if ( ! tinymce.isWebKit ) { - n = ed.selection.getNode(); - - 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); - } + if ( tinymce.isWebKit || tinymce.isOpera ) + return; + + if ( ed.dom.getParent(e.target, 'div.mceTemp') || ed.dom.is(e.target, 'div.mceTemp') ) { + window.setTimeout(function(){ + var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'dl.wp-caption'); + + if ( DL && n.width != ( parseInt(ed.dom.getStyle(DL, 'width'), 10) - 10 ) ) { + ed.dom.setStyle(DL, 'width', parseInt(n.width, 10) + 10); + ed.execCommand('mceRepaint'); + } + }, 100); } }); ed.onMouseDown.add(function(ed, e) { - if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) { + var p; + + if ( e.target.nodeName != 'IMG' ) { t.hideButtons(); return; } ed.plugins.wpeditimage.showButtons(e.target); + + if ( tinymce.isGecko && (p = ed.dom.getParent(e.target, 'dl.wp-caption')) && ed.dom.hasClass(p.parentNode, 'mceTemp') ) + ed.selection.select(p.parentNode); }); ed.onKeyPress.add(function(ed, e) { @@ -124,7 +130,7 @@ div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp'; - return '
'+c+'
'+cap+'
'; }); }, @@ -196,12 +202,10 @@ title : ed.getLang('wpeditimage.edit_img') }); - wp_editimgbtn.onmousedown = function(e) { - var ed = tinyMCE.activeEditor; + tinymce.dom.Event.add(wp_editimgbtn, 'mousedown', function(e) { ed.windowManager.bookmark = ed.selection.getBookmark('simple'); ed.execCommand("WP_EditImage"); - this.parentNode.style.display = 'none'; - }; + }); wp_delimgbtn = DOM.add('wp_editbtns', 'img', { src : t.url+'/img/delete.png', @@ -211,7 +215,7 @@ title : ed.getLang('wpeditimage.del_img') }); - wp_delimgbtn.onmousedown = function(e) { + tinymce.dom.Event.add(wp_delimgbtn, 'mousedown', function(e) { var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p; if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) { @@ -219,13 +223,13 @@ 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); + else + ed.dom.remove(el); - this.parentNode.style.display = 'none'; ed.execCommand('mceRepaint'); return false; } - }; + }); }, getInfo : function() { diff --git a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js index 9c17ed34f0..311e460f75 100644 --- a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js +++ b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js @@ -1 +1 @@ -(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
'+k+'
'+h+"
"})},_get_shcode:function(a){return a.replace(/
\s*]+)>\s*]+>([\s\S]+?)<\/dt>\s*]+>(.+?)<\/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]"})},showButtons:function(d){var j=this,e=tinyMCE.activeEditor,g,f,a,i=tinymce.DOM,c,b,h=e.dom.getAttrib(d,"class");if(h.indexOf("mceItem")!=-1||h.indexOf("wpGallery")!=-1){return}a=e.dom.getViewPort(e.getWin());g=i.getPos(e.getContentAreaContainer());f=e.dom.getPos(d);c=Math.max(f.x-a.x,0)+g.x;b=Math.max(f.y-a.y,0)+g.y;i.setStyles("wp_editbtns",{top:b+5+"px",left:c+5+"px",display:"block"});j.btnsTout=window.setTimeout(function(){e.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 d=this,b=tinyMCE.activeEditor,e=tinymce.DOM,a,c,f;e.remove("wp_editbtns");a=e.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"});c=e.add("wp_editbtns","img",{src:d.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:b.getLang("wpeditimage.edit_img")});c.onmousedown=function(h){var g=tinyMCE.activeEditor;g.windowManager.bookmark=g.selection.getBookmark("simple");g.execCommand("WP_EditImage");this.parentNode.style.display="none"};f=e.add("wp_editbtns","img",{src:d.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:b.getLang("wpeditimage.del_img")});f.onmousedown=function(j){var g=tinyMCE.activeEditor,h=g.selection.getNode(),i;if(h.nodeName=="IMG"&&g.dom.getAttrib(h,"class").indexOf("mceItem")==-1){if((i=g.dom.getParent(h,"div"))&&g.dom.hasClass(i,"mceTemp")){g.dom.remove(i)}else{if((i=g.dom.getParent(h,"A"))&&i.childNodes.length==1){g.dom.remove(i)}else{g.dom.remove(h)}}this.parentNode.style.display="none";g.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",{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
'+k+'
'+h+"
"})},_get_shcode:function(a){return a.replace(/
\s*]+)>\s*]+>([\s\S]+?)<\/dt>\s*]+>(.+?)<\/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]"})},showButtons:function(d){var j=this,e=tinyMCE.activeEditor,g,f,a,i=tinymce.DOM,c,b,h=e.dom.getAttrib(d,"class");if(h.indexOf("mceItem")!=-1||h.indexOf("wpGallery")!=-1){return}a=e.dom.getViewPort(e.getWin());g=i.getPos(e.getContentAreaContainer());f=e.dom.getPos(d);c=Math.max(f.x-a.x,0)+g.x;b=Math.max(f.y-a.y,0)+g.y;i.setStyles("wp_editbtns",{top:b+5+"px",left:c+5+"px",display:"block"});j.btnsTout=window.setTimeout(function(){e.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 d=this,b=tinyMCE.activeEditor,e=tinymce.DOM,a,c,f;e.remove("wp_editbtns");a=e.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"});c=e.add("wp_editbtns","img",{src:d.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:b.getLang("wpeditimage.edit_img")});tinymce.dom.Event.add(c,"mousedown",function(g){b.windowManager.bookmark=b.selection.getBookmark("simple");b.execCommand("WP_EditImage")});f=e.add("wp_editbtns","img",{src:d.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:b.getLang("wpeditimage.del_img")});tinymce.dom.Event.add(f,"mousedown",function(j){var g=tinyMCE.activeEditor,h=g.selection.getNode(),i;if(h.nodeName=="IMG"&&g.dom.getAttrib(h,"class").indexOf("mceItem")==-1){if((i=g.dom.getParent(h,"div"))&&g.dom.hasClass(i,"mceTemp")){g.dom.remove(i)}else{if((i=g.dom.getParent(h,"A"))&&i.childNodes.length==1){g.dom.remove(i)}else{g.dom.remove(h)}}g.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 diff --git a/wp-includes/version.php b/wp-includes/version.php index c41bbe5bb2..dbf64e3b61 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -22,7 +22,7 @@ $wp_db_version = 12060; * * @global string $tinymce_version */ -$tinymce_version = '327-1235a'; +$tinymce_version = '327-1235'; /** * Holds the cache manifest version