From 579feecfc35dde5daf36dd73963d9eccec4aa030 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 13 Jan 2022 12:25:34 +0800 Subject: [PATCH] fix msword paste --- Roo/HtmlEditorCore.js | 5 +++-- Roo/htmleditor/Filter.js | 2 +- Roo/htmleditor/FilterBlack.js | 2 +- roojs-all.js | 6 +++--- roojs-debug.js | 9 +++++---- roojs-ui-debug.js | 9 +++++---- roojs-ui.js | 6 +++--- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index b997fb1b5f..c8a66a8edc 100644 --- a/Roo/HtmlEditorCore.js +++ b/Roo/HtmlEditorCore.js @@ -617,7 +617,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); // should be fonts.. - new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT' ]} ); + new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', 'O:P' ]} ); new Roo.htmleditor.FilterParagraph({ node : d }); new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); @@ -1546,7 +1546,8 @@ Roo.HtmlEditorCore.black = [ 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT', 'SCRIPT', 'STYLE' ,'TITLE', 'XML', //'FONT' // CLEAN LATER.. - 'COLGROUP', 'COL' // messy tables. + 'COLGROUP', 'COL' // messy tables. + ]; Roo.HtmlEditorCore.clean = [ // ?? needed??? diff --git a/Roo/htmleditor/Filter.js b/Roo/htmleditor/Filter.js index c8e7960282..2e270bdd71 100644 --- a/Roo/htmleditor/Filter.js +++ b/Roo/htmleditor/Filter.js @@ -34,7 +34,7 @@ Roo.htmleditor.Filter.prototype = { Roo.each( Array.from(dom.childNodes), function( e ) { switch(true) { - case e.nodeType == 8 && typeof(this.replaceComment) != 'undefined': // comment + case e.nodeType == 8 && this.replaceComment !== false: // comment this.replaceComment(e); return; diff --git a/Roo/htmleditor/FilterBlack.js b/Roo/htmleditor/FilterBlack.js index 1863525d9b..76189ac3af 100644 --- a/Roo/htmleditor/FilterBlack.js +++ b/Roo/htmleditor/FilterBlack.js @@ -16,7 +16,7 @@ Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter, { tag : true, // all elements. - replace : function(n) + replaceTag : function(n) { n.parentNode.removeChild(n); } diff --git a/roojs-all.js b/roojs-all.js index 8b4cac3160..dcd28c276e 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1890,7 +1890,7 @@ this.push({type:'groupstart',pos:this.cpos,row:this.row,col:this.col});},emitEnd // Roo/htmleditor/namespace.js Roo.htmleditor={}; // Roo/htmleditor/Filter.js -Roo.htmleditor.Filter=function(A){Roo.apply(this.cfg);};Roo.htmleditor.Filter.prototype={node:false,tag:false,replaceComment:false,replaceTag:false,walk:function(A){Roo.each(Array.from(A.childNodes),function(e){switch(true){case e.nodeType==8&&typeof(this.replaceComment)!='undefined':this.replaceComment(e); +Roo.htmleditor.Filter=function(A){Roo.apply(this.cfg);};Roo.htmleditor.Filter.prototype={node:false,tag:false,replaceComment:false,replaceTag:false,walk:function(A){Roo.each(Array.from(A.childNodes),function(e){switch(true){case e.nodeType==8&&this.replaceComment!==false:this.replaceComment(e); return;case e.nodeType!=1:return;case this.tag===true:case typeof(this.tag)=='object'&&this.tag.indexOf(e.tagName)>-1:case typeof(this.tag)=='string'&&this.tag==e.tagName:if(this.replaceTag&&false===this.replaceTag(e)){return;}if(e.hasChildNodes()){this.walk(e); }return;default:if(e.hasChildNodes()){this.walk(e);}}},this);}}; // Roo/htmleditor/FilterAttributes.js @@ -1903,7 +1903,7 @@ this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterAttributes,Roo.htmleditor.Fi var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\s+$/g,'');if(this.style_black.length&&(this.style_black.indexOf(l)>-1||this.style_black.indexOf(l.toLowerCase())>-1)){return true;}if(this.style_white.length&&style_white.indexOf(l)<0&&style_white.indexOf(l.toLowerCase())<0){return true; }C.push(p);return true;},this);if(C.length){A.setAttribute(n,C.join(';'));}else{A.removeAttribute(n);}}}); // Roo/htmleditor/FilterBlack.js -Roo.htmleditor.FilterBlack=function(A){Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterBlack,Roo.htmleditor.Filter,{tag:true,replace:function(n){n.parentNode.removeChild(n);}}); +Roo.htmleditor.FilterBlack=function(A){Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterBlack,Roo.htmleditor.Filter,{tag:true,replaceTag:function(n){n.parentNode.removeChild(n);}}); // Roo/htmleditor/FilterComment.js Roo.htmleditor.FilterComment=function(A){this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterComment,Roo.htmleditor.Filter,{replaceComment:function(n){n.parentNode.removeChild(n);}}); // Roo/htmleditor/FilterKeepChildren.js @@ -2072,7 +2072,7 @@ new Roo.htmleditor.KeyEnter({core:this});this.owner.fireEvent('initialize',this) var B=A.createObjectURL(cd.files[0]);this.insertAtCursor('');return false;}var C=cd.getData('text/html');var D=new Roo.rtf.Parser(cd.getData('text/rtf'));var E=D.doc?D.doc.getElementsByType('pict'):[];Roo.log(E);E=E.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable)/); }).map(function(g){return g.toDataURL();});C=this.cleanWordChars(C);var d=(new DOMParser().parseFromString(C,'text/html')).body;var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables"); return false;}if(E.length>0){Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',E[i]);});}if(this.autoClean){new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align'],attrib_clean:['href','src']} -);new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return; +);new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT','O:P']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return; }var G=new Roo.htmleditor.BlockFigure({image_src:F.src});G.updateElement(F);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}e.preventDefault();return false;},onDestroy:function(){if(this.rendered){} },onFirstFocus:function(){this.assignDocWin();this.undoManager=new Roo.lib.UndoManager(100,(this.doc.body||this.doc.documentElement));this.activated=true;if(Roo.isGecko){this.win.focus();var s=this.win.getSelection();if(!s.focusNode||s.focusNode.nodeType!=3){var r=s.getRangeAt(0); r.selectNodeContents((this.doc.body||this.doc.documentElement));r.collapse(true);this.deferFocus();}try{this.execCmd('useCSS',true);this.execCmd('styleWithCSS',false);}catch(e){}}this.owner.fireEvent('activate',this);},adjustFont:function(A){var B=A.cmd=='increasefontsize'?1:-1; diff --git a/roojs-debug.js b/roojs-debug.js index ee87264929..3d1c57d249 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -45590,7 +45590,7 @@ Roo.htmleditor.Filter.prototype = { Roo.each( Array.from(dom.childNodes), function( e ) { switch(true) { - case e.nodeType == 8 && typeof(this.replaceComment) != 'undefined': // comment + case e.nodeType == 8 && this.replaceComment !== false: // comment this.replaceComment(e); return; @@ -45790,7 +45790,7 @@ Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter, { tag : true, // all elements. - replace : function(n) + replaceTag : function(n) { n.parentNode.removeChild(n); } @@ -50037,7 +50037,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); // should be fonts.. - new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT' ]} ); + new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', 'O:P' ]} ); new Roo.htmleditor.FilterParagraph({ node : d }); new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); @@ -50966,7 +50966,8 @@ Roo.HtmlEditorCore.black = [ 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT', 'SCRIPT', 'STYLE' ,'TITLE', 'XML', //'FONT' // CLEAN LATER.. - 'COLGROUP', 'COL' // messy tables. + 'COLGROUP', 'COL' // messy tables. + ]; Roo.HtmlEditorCore.clean = [ // ?? needed??? diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index f45cf90bed..bfe5132e1a 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21121,7 +21121,7 @@ Roo.htmleditor.Filter.prototype = { Roo.each( Array.from(dom.childNodes), function( e ) { switch(true) { - case e.nodeType == 8 && typeof(this.replaceComment) != 'undefined': // comment + case e.nodeType == 8 && this.replaceComment !== false: // comment this.replaceComment(e); return; @@ -21321,7 +21321,7 @@ Roo.extend(Roo.htmleditor.FilterBlack, Roo.htmleditor.Filter, { tag : true, // all elements. - replace : function(n) + replaceTag : function(n) { n.parentNode.removeChild(n); } @@ -25568,7 +25568,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); // should be fonts.. - new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT' ]} ); + new Roo.htmleditor.FilterKeepChildren({node : d, tag : [ 'FONT', 'O:P' ]} ); new Roo.htmleditor.FilterParagraph({ node : d }); new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); @@ -26497,7 +26497,8 @@ Roo.HtmlEditorCore.black = [ 'IFRAME', 'LAYER', 'LINK', 'META', 'OBJECT', 'SCRIPT', 'STYLE' ,'TITLE', 'XML', //'FONT' // CLEAN LATER.. - 'COLGROUP', 'COL' // messy tables. + 'COLGROUP', 'COL' // messy tables. + ]; Roo.HtmlEditorCore.clean = [ // ?? needed??? diff --git a/roojs-ui.js b/roojs-ui.js index d82a3c4faa..66bb9ae07c 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -945,7 +945,7 @@ this.push({type:'groupstart',pos:this.cpos,row:this.row,col:this.col});},emitEnd // Roo/htmleditor/namespace.js Roo.htmleditor={}; // Roo/htmleditor/Filter.js -Roo.htmleditor.Filter=function(A){Roo.apply(this.cfg);};Roo.htmleditor.Filter.prototype={node:false,tag:false,replaceComment:false,replaceTag:false,walk:function(A){Roo.each(Array.from(A.childNodes),function(e){switch(true){case e.nodeType==8&&typeof(this.replaceComment)!='undefined':this.replaceComment(e); +Roo.htmleditor.Filter=function(A){Roo.apply(this.cfg);};Roo.htmleditor.Filter.prototype={node:false,tag:false,replaceComment:false,replaceTag:false,walk:function(A){Roo.each(Array.from(A.childNodes),function(e){switch(true){case e.nodeType==8&&this.replaceComment!==false:this.replaceComment(e); return;case e.nodeType!=1:return;case this.tag===true:case typeof(this.tag)=='object'&&this.tag.indexOf(e.tagName)>-1:case typeof(this.tag)=='string'&&this.tag==e.tagName:if(this.replaceTag&&false===this.replaceTag(e)){return;}if(e.hasChildNodes()){this.walk(e); }return;default:if(e.hasChildNodes()){this.walk(e);}}},this);}}; // Roo/htmleditor/FilterAttributes.js @@ -958,7 +958,7 @@ this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterAttributes,Roo.htmleditor.Fi var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\s+$/g,'');if(this.style_black.length&&(this.style_black.indexOf(l)>-1||this.style_black.indexOf(l.toLowerCase())>-1)){return true;}if(this.style_white.length&&style_white.indexOf(l)<0&&style_white.indexOf(l.toLowerCase())<0){return true; }C.push(p);return true;},this);if(C.length){A.setAttribute(n,C.join(';'));}else{A.removeAttribute(n);}}}); // Roo/htmleditor/FilterBlack.js -Roo.htmleditor.FilterBlack=function(A){Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterBlack,Roo.htmleditor.Filter,{tag:true,replace:function(n){n.parentNode.removeChild(n);}}); +Roo.htmleditor.FilterBlack=function(A){Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterBlack,Roo.htmleditor.Filter,{tag:true,replaceTag:function(n){n.parentNode.removeChild(n);}}); // Roo/htmleditor/FilterComment.js Roo.htmleditor.FilterComment=function(A){this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterComment,Roo.htmleditor.Filter,{replaceComment:function(n){n.parentNode.removeChild(n);}}); // Roo/htmleditor/FilterKeepChildren.js @@ -1127,7 +1127,7 @@ new Roo.htmleditor.KeyEnter({core:this});this.owner.fireEvent('initialize',this) var B=A.createObjectURL(cd.files[0]);this.insertAtCursor('');return false;}var C=cd.getData('text/html');var D=new Roo.rtf.Parser(cd.getData('text/rtf'));var E=D.doc?D.doc.getElementsByType('pict'):[];Roo.log(E);E=E.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable)/); }).map(function(g){return g.toDataURL();});C=this.cleanWordChars(C);var d=(new DOMParser().parseFromString(C,'text/html')).body;var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables"); return false;}if(E.length>0){Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',E[i]);});}if(this.autoClean){new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align'],attrib_clean:['href','src']} -);new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return; +);new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT','O:P']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return; }var G=new Roo.htmleditor.BlockFigure({image_src:F.src});G.updateElement(F);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}e.preventDefault();return false;},onDestroy:function(){if(this.rendered){} },onFirstFocus:function(){this.assignDocWin();this.undoManager=new Roo.lib.UndoManager(100,(this.doc.body||this.doc.documentElement));this.activated=true;if(Roo.isGecko){this.win.focus();var s=this.win.getSelection();if(!s.focusNode||s.focusNode.nodeType!=3){var r=s.getRangeAt(0); r.selectNodeContents((this.doc.body||this.doc.documentElement));r.collapse(true);this.deferFocus();}try{this.execCmd('useCSS',true);this.execCmd('styleWithCSS',false);}catch(e){}}this.owner.fireEvent('activate',this);},adjustFont:function(A){var B=A.cmd=='increasefontsize'?1:-1; -- 2.39.2