From: Alan Date: Wed, 28 Feb 2024 08:38:50 +0000 (+0800) Subject: fix #8042 - clean up empty tags X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=8cd3f1abd9357f6b173fbca3cd7324e88b3450ff fix #8042 - clean up empty tags --- diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index d426fb9ddc..f8a8164d58 100644 --- a/Roo/HtmlEditorCore.js +++ b/Roo/HtmlEditorCore.js @@ -419,6 +419,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { ], attrib_clean : ['href', 'src' ] }); + new Roo.htmleditor.FilterEmpty({ node : div}); var tidy = new Roo.htmleditor.TidySerializer({ inner: true @@ -736,6 +737,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); new Roo.htmleditor.FilterComment({ node : d }); + new Roo.htmleditor.FilterEmpty({ node : d}); } diff --git a/Roo/htmleditor/FilterEmpty.js b/Roo/htmleditor/FilterEmpty.js index 642f9925dd..383d5aa27e 100644 --- a/Roo/htmleditor/FilterEmpty.js +++ b/Roo/htmleditor/FilterEmpty.js @@ -1,6 +1,6 @@ /** * @class Roo.htmleditor.FilterEmpty - * filter empty elements (normally on paste) + * filter empty elements * @constructor * Run a new Empty Filter * @param {Object} config Configuration options @@ -12,22 +12,32 @@ Roo.htmleditor.FilterEmpty = function(cfg) this.walk(cfg.node); } -Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterBlack, +Roo.extend(Roo.htmleditor.FilterEmpty, Roo.htmleditor.FilterBlack, { - tag : 'B', + tag : true, replaceTag : function(node) { - if (node.innerHTML.trim() != '') { - return true; + // start from leaf node + if(node.hasChildNodes()) { + this.walk(node); } - if (node.attributes && node.attributes.length > 0) { - return true; // walk if there are any. + + // only filter empty leaf element with certain tags + if( + ['B', 'I', 'U', 'S'].indexOf(node.tagName) < 0 + || + node.attributes && node.attributes.length > 0 + || + node.hasChildNodes() + ) { + return false; // don't walk } + Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this, node); - return false; + return false; // don't walk } diff --git a/Roo/htmleditor/FilterStyleToTag.js b/Roo/htmleditor/FilterStyleToTag.js index db7128b80e..20ba0685ef 100644 --- a/Roo/htmleditor/FilterStyleToTag.js +++ b/Roo/htmleditor/FilterStyleToTag.js @@ -14,12 +14,12 @@ Roo.htmleditor.FilterStyleToTag = function(cfg) { this.tags = { - B : [ 'fontWeight' , 'bold'], - I : [ 'fontStyle' , 'italic'], + B : [ 'fontWeight' , 'bold', 'font-weight'], + I : [ 'fontStyle' , 'italic', 'font-style'], //pre : [ 'font-style' , 'italic'], // h1.. h6 ?? font-size? - SUP : [ 'verticalAlign' , 'super' ], - SUB : [ 'verticalAlign' , 'sub' ] + SUP : [ 'verticalAlign' , 'super', 'vertical-align'], + SUB : [ 'verticalAlign' , 'sub', 'vertical-align'] }; @@ -52,7 +52,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, for (var k in this.tags) { if (node.style[this.tags[k][0]] == this.tags[k][1]) { inject.push(k); - node.style.removeProperty(this.tags[k][0]); + node.style.removeProperty(this.tags[k][2]); } } if (!inject.length) { @@ -65,7 +65,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, nn.appendChild(nc); nn = nc; }); - for(var i = 0;i < cn.length;cn++) { + for(var i = 0;i < cn.length;i++) { node.removeChild(cn[i]); nn.appendChild(cn[i]); } diff --git a/buildSDK/dependancy_bootstrap.txt b/buildSDK/dependancy_bootstrap.txt index be94028645..34d1a848e3 100644 --- a/buildSDK/dependancy_bootstrap.txt +++ b/buildSDK/dependancy_bootstrap.txt @@ -145,6 +145,7 @@ Roo.htmleditor.Filter Roo.htmleditor.FilterAttributes Roo.htmleditor.FilterBlack Roo.htmleditor.FilterComment +Roo.htmleditor.FilterEmpty Roo.htmleditor.FilterKeepChildren Roo.htmleditor.FilterParagraph Roo.htmleditor.FilterHashLink diff --git a/buildSDK/dependancy_ui.txt b/buildSDK/dependancy_ui.txt index dcf507c3d7..acbfe60104 100644 --- a/buildSDK/dependancy_ui.txt +++ b/buildSDK/dependancy_ui.txt @@ -114,6 +114,7 @@ Roo.htmleditor.Filter Roo.htmleditor.FilterAttributes Roo.htmleditor.FilterBlack Roo.htmleditor.FilterComment +Roo.htmleditor.FilterEmpty Roo.htmleditor.FilterKeepChildren Roo.htmleditor.FilterParagraph Roo.htmleditor.FilterHashLink diff --git a/docs/json/roodata.json b/docs/json/roodata.json index 4993723296..4dd59e3b78 100644 --- a/docs/json/roodata.json +++ b/docs/json/roodata.json @@ -278001,6 +278001,16 @@ "tree_children" : [], "tree_parent" : [] }, + "Roo.htmleditor.FilterEmpty" : { + "props" : [], + "events" : [], + "methods" : [], + "isAbstract" : false, + "isBuilderTop" : false, + "implementations" : [], + "tree_children" : [], + "tree_parent" : [] + }, "Roo.htmleditor.FilterHashLink" : { "props" : [], "events" : [], diff --git a/docs/src/Roo_HtmlEditorCore.js.html b/docs/src/Roo_HtmlEditorCore.js.html index 582fd7b513..b8c203d7c5 100644 --- a/docs/src/Roo_HtmlEditorCore.js.html +++ b/docs/src/Roo_HtmlEditorCore.js.html @@ -419,6 +419,7 @@ ], attrib_clean : ['href', 'src' ] }); + new Roo.htmleditor.FilterEmpty({ node : div}); var tidy = new Roo.htmleditor.TidySerializer({ inner: true @@ -736,6 +737,7 @@ new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); new Roo.htmleditor.FilterComment({ node : d }); + new Roo.htmleditor.FilterEmpty({ node : d}); } diff --git a/docs/src/Roo_htmleditor_FilterStyleToTag.js.html b/docs/src/Roo_htmleditor_FilterStyleToTag.js.html index 9e9ae4f770..3473ecfc13 100644 --- a/docs/src/Roo_htmleditor_FilterStyleToTag.js.html +++ b/docs/src/Roo_htmleditor_FilterStyleToTag.js.html @@ -14,12 +14,12 @@ { this.tags = { - B : [ 'fontWeight' , 'bold'], - I : [ 'fontStyle' , 'italic'], + B : [ 'fontWeight' , 'bold', 'font-weight'], + I : [ 'fontStyle' , 'italic', 'font-style'], //pre : [ 'font-style' , 'italic'], // h1.. h6 ?? font-size? - SUP : [ 'verticalAlign' , 'super' ], - SUB : [ 'verticalAlign' , 'sub' ] + SUP : [ 'verticalAlign' , 'super', 'vertical-align'], + SUB : [ 'verticalAlign' , 'sub', 'vertical-align'] }; @@ -52,7 +52,7 @@ for (var k in this.tags) { if (node.style[this.tags[k][0]] == this.tags[k][1]) { inject.push(k); - node.style.removeProperty(this.tags[k][0]); + node.style.removeProperty(this.tags[k][2]); } } if (!inject.length) { @@ -65,7 +65,7 @@ nn.appendChild(nc); nn = nc; }); - for(var i = 0;i < cn.length;cn++) { + for(var i = 0;i < cn.length;i++) { node.removeChild(cn[i]); nn.appendChild(cn[i]); } diff --git a/docs/tree.json b/docs/tree.json index 0306e131fb..32f9e061fa 100644 --- a/docs/tree.json +++ b/docs/tree.json @@ -1301,6 +1301,11 @@ "cn" : [], "is_class" : false }, + { + "name" : "Roo.htmleditor.FilterEmpty", + "cn" : [], + "is_class" : false + }, { "name" : "Roo.htmleditor.FilterHashLink", "cn" : [], diff --git a/examples/test.html b/examples/test.html index a7ce7a63e6..f46676f53b 100644 --- a/examples/test.html +++ b/examples/test.html @@ -8,19 +8,16 @@ + + -

Test

-
-
-abc -

1122

-

-33 -
-b +TESTBCD + +asd + diff --git a/examples/test.js b/examples/test.js index d6a71d2291..58a9d0709a 100644 --- a/examples/test.js +++ b/examples/test.js @@ -1,6 +1,4 @@ Roo.onReady(function() { - new Roo.htmleditor.FilterHashLink({ node : document.body }); - new Roo.htmleditor.FilterParagraph({ node : document.body }); - new Roo.htmleditor.FilterLongBr({ node : document.body }); - new Roo.htmleditor.FilterSpan({ node : document.body }); + new Roo.htmleditor.FilterStyleToTag({ node : document.body}); + new Roo.htmleditor.FilterEmpty({ node : document.body }); }); \ No newline at end of file diff --git a/roojs-all.js b/roojs-all.js index 6d05efd377..80796a5043 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -2026,6 +2026,9 @@ var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\ 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/FilterEmpty.js +Roo.htmleditor.FilterEmpty=function(A){this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterEmpty,Roo.htmleditor.FilterBlack,{tag:true,replaceTag:function(A){if(A.hasChildNodes()){this.walk(A);}if(['B','I','U','S'].indexOf(A.tagName)<0||A.attributes&&A.attributes.length>0||A.hasChildNodes()){return false; +}Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this,A);return false;}}); // Roo/htmleditor/FilterKeepChildren.js Roo.htmleditor.FilterKeepChildren=function(A){Roo.apply(this,A);if(this.tag===false){return;}if((typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)){this.cleanNamespace=true;}this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterKeepChildren,Roo.htmleditor.FilterBlack,{cleanNamespace:false,replaceTag:function(A){var ar=Array.from(A.childNodes); for(var i=0;i-1)||(typeof(this.tag)=='string'&&this.tag==e.tagName)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":")){this.replaceTag(ar[i]); @@ -2066,9 +2069,9 @@ return;}var O=N['margin-left'];if(typeof(J[O])=='undefined'){max_margins++;J[O]= }var tr=td.parentNode;if(tr.nodeName!='TR'){return;}var D=tr.parentNode;if(D.nodeName!='TBODY'){return;}var E=D.parentNode;if(E.nodeName!='TABLE'){return;}if(E.getElementsByTagName('tr').length!=2){return;}if(E.getElementsByTagName('td').length!=3){return; }if(E.innerText.trim()!=''){return;}var p=E.parentNode;C.parentNode.removeChild(C);p.insertBefore(C,E);p.removeChild(E);});}}); // Roo/htmleditor/FilterStyleToTag.js -Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I:['fontStyle','italic'],SUP:['verticalAlign','super'],SUB:['verticalAlign','sub']};Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterStyleToTag,Roo.htmleditor.Filter,{tag:true,tags:false,replaceTag:function(A){if(A.getAttribute("style")===null){return true; -}var B=[];for(var k in this.tags){if(A.style[this.tags[k][0]]==this.tags[k][1]){B.push(k);A.style.removeProperty(this.tags[k][0]);}}if(!B.length){return true;}var cn=Array.from(A.childNodes);var nn=A;Roo.each(B,function(t){var nc=A.ownerDocument.createElement(t); -nn.appendChild(nc);nn=nc;});for(var i=0;i-1){A.parentNode.removeChild(A); return false;}if(!ps||ps.nodeType!=1){return false;}if(!ps||ps.tagName!='BR'){return false;}if(!A.previousSibling){return false;}var ps=A.previousSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.previousSibling;}if(!ps||ps.nodeType!=1){return false; @@ -2205,11 +2208,11 @@ catch(e){return;}Roo.TaskMgr.stop(D);this.initEditor.defer(10,this);}},interval: return A;},syncValue:function(){if(this.initialized){if(this.undoManager){this.undoManager.addEvent();}var bd=(this.doc.body||this.doc.documentElement);var A=this.win.getSelection();var B=document.createElement('div');B.innerHTML=bd.innerHTML;var C=B.getElementsByClassName('gtx-trans-icon'); if(C.length>0){var rm=C.item(0).parentNode;rm.parentNode.removeChild(rm);}if(this.enableBlocks){Array.from(bd.getElementsByTagName('img')).forEach(function(F){var G=F.closest('figure');if(G){var bf=new Roo.htmleditor.BlockFigure({node:G});bf.updateElement(); }});new Roo.htmleditor.FilterBlock({node:B});}var D=B.innerHTML;if(this.autoClean){new Roo.htmleditor.FilterBlack({node:B,tag:this.black});new Roo.htmleditor.FilterAttributes({node:B,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-caption-display','data-width','data-caption','start','style','class','allowfullscreen','frameborder','width','height','alt'],attrib_clean:['href','src']} -);var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
';}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt(); -if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F;}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D; -this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement);d.innerHTML=v;this.el.dom.value=d.innerHTML; -this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}this.updateLanguage(); -var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); +);new Roo.htmleditor.FilterEmpty({node:B});var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
'; +}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt();if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F; +}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D;this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement); +d.innerHTML=v;this.el.dom.value=d.innerHTML;this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); +}this.updateLanguage();var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); }else{this.el.focus();}},assignDocWin:function(){var A=this.iframe;if(Roo.isIE){this.doc=A.contentWindow.document;this.win=A.contentWindow;}else{if(!Roo.get(this.frameId)&&!A.contentDocument){return;}this.doc=(A.contentDocument||Roo.get(this.frameId).dom.document); this.win=(A.contentWindow||Roo.get(this.frameId).dom.contentWindow);}},initEditor:function(){this.assignDocWin();this.doc.designMode="on";this.doc.open();this.doc.write(this.getDocMarkup());this.doc.close();var A=(this.doc.body||this.doc.documentElement); A.bgProperties='fixed';A.setAttribute("translate","no");Roo.EventManager.on(this.doc,{'mouseup':this.onEditorEvent,'dblclick':this.onEditorEvent,'click':this.onEditorEvent,'keyup':this.onEditorEvent,buffer:100,scope:this});Roo.EventManager.on(this.doc,{'paste':this.onPasteEvent,scope:this} @@ -2222,9 +2225,9 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne this.insertAtCursor("You can not nest tables");return false;}if(B.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(E){E.parentNode.insertBefore(d.ownerDocument.createElement('img'),E);E.parentNode.removeChild(E);});Roo.each(d.getElementsByTagName('img'),function(E,i){E.setAttribute('src',B[i]); });}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan'],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.FilterHashLink({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} -);}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); -}e.preventDefault();this.owner.fireEvent('paste',this);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); +);new Roo.htmleditor.FilterEmpty({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' ')); +if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}e.preventDefault();this.owner.fireEvent('paste',this);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;var v=parseInt(this.doc.queryCommandValue('FontSize')||3,10);if(Roo.isSafari){var sm={10:1,13:2,16:3,18:4,24:5,32:6,48:7} ;v=(v<10)?10:v;v=(v>48)?48:v;v=typeof(sm[v])=='undefined'?1:sm[v];}v=Math.max(1,v+B);this.execCmd('FontSize',v);},onEditorEvent:function(e){if(e&&(e.ctrlKey||e.metaKey)&&e.keyCode===90){return;}if(e&&e.target.nodeName=='BODY'&&e.type=="mouseup"&&this.doc.body.lastChild){var lc=this.doc.body.lastChild; while((lc.nodeType==3&&lc.nodeValue=='')||lc.id=='gtx-trans'){lc=lc.previousSibling;}if(lc.nodeType==1&&lc.nodeName!='BR'){var ns=this.doc.createElement('br');this.doc.body.appendChild(ns);range=this.doc.createRange();range.setStartAfter(ns);range.collapse(true); diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index 5df7fa19a1..657326e15f 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -27315,6 +27315,49 @@ Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter, { n.parentNode.removeChild(n); } +});/** + * @class Roo.htmleditor.FilterEmpty + * filter empty elements + * @constructor + * Run a new Empty Filter + * @param {Object} config Configuration options + */ + +Roo.htmleditor.FilterEmpty = function(cfg) +{ + // no need to apply config. + this.walk(cfg.node); +} + +Roo.extend(Roo.htmleditor.FilterEmpty, Roo.htmleditor.FilterBlack, +{ + + tag : true, + + + replaceTag : function(node) + { + // start from leaf node + if(node.hasChildNodes()) { + this.walk(node); + } + + // only filter empty leaf element with certain tags + if( + ['B', 'I', 'U', 'S'].indexOf(node.tagName) < 0 + || + node.attributes && node.attributes.length > 0 + || + node.hasChildNodes() + ) { + return false; // don't walk + } + + Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this, node); + return false; // don't walk + + } + });/** * @class Roo.htmleditor.FilterKeepChildren * remove tags but keep children @@ -28010,12 +28053,12 @@ Roo.htmleditor.FilterStyleToTag = function(cfg) { this.tags = { - B : [ 'fontWeight' , 'bold'], - I : [ 'fontStyle' , 'italic'], + B : [ 'fontWeight' , 'bold', 'font-weight'], + I : [ 'fontStyle' , 'italic', 'font-style'], //pre : [ 'font-style' , 'italic'], // h1.. h6 ?? font-size? - SUP : [ 'verticalAlign' , 'super' ], - SUB : [ 'verticalAlign' , 'sub' ] + SUP : [ 'verticalAlign' , 'super', 'vertical-align'], + SUB : [ 'verticalAlign' , 'sub', 'vertical-align'] }; @@ -28048,7 +28091,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, for (var k in this.tags) { if (node.style[this.tags[k][0]] == this.tags[k][1]) { inject.push(k); - node.style.removeProperty(this.tags[k][0]); + node.style.removeProperty(this.tags[k][2]); } } if (!inject.length) { @@ -28061,7 +28104,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, nn.appendChild(nc); nn = nc; }); - for(var i = 0;i < cn.length;cn++) { + for(var i = 0;i < cn.length;i++) { node.removeChild(cn[i]); nn.appendChild(cn[i]); } @@ -31812,6 +31855,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { ], attrib_clean : ['href', 'src' ] }); + new Roo.htmleditor.FilterEmpty({ node : div}); var tidy = new Roo.htmleditor.TidySerializer({ inner: true @@ -32129,6 +32173,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); new Roo.htmleditor.FilterComment({ node : d }); + new Roo.htmleditor.FilterEmpty({ node : d}); } diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index e7186ca00e..6d372ef4b1 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1197,6 +1197,9 @@ var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\ 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/FilterEmpty.js +Roo.htmleditor.FilterEmpty=function(A){this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterEmpty,Roo.htmleditor.FilterBlack,{tag:true,replaceTag:function(A){if(A.hasChildNodes()){this.walk(A);}if(['B','I','U','S'].indexOf(A.tagName)<0||A.attributes&&A.attributes.length>0||A.hasChildNodes()){return false; +}Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this,A);return false;}}); // Roo/htmleditor/FilterKeepChildren.js Roo.htmleditor.FilterKeepChildren=function(A){Roo.apply(this,A);if(this.tag===false){return;}if((typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)){this.cleanNamespace=true;}this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterKeepChildren,Roo.htmleditor.FilterBlack,{cleanNamespace:false,replaceTag:function(A){var ar=Array.from(A.childNodes); for(var i=0;i-1)||(typeof(this.tag)=='string'&&this.tag==e.tagName)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":")){this.replaceTag(ar[i]); @@ -1237,9 +1240,9 @@ return;}var O=N['margin-left'];if(typeof(J[O])=='undefined'){max_margins++;J[O]= }var tr=td.parentNode;if(tr.nodeName!='TR'){return;}var D=tr.parentNode;if(D.nodeName!='TBODY'){return;}var E=D.parentNode;if(E.nodeName!='TABLE'){return;}if(E.getElementsByTagName('tr').length!=2){return;}if(E.getElementsByTagName('td').length!=3){return; }if(E.innerText.trim()!=''){return;}var p=E.parentNode;C.parentNode.removeChild(C);p.insertBefore(C,E);p.removeChild(E);});}}); // Roo/htmleditor/FilterStyleToTag.js -Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I:['fontStyle','italic'],SUP:['verticalAlign','super'],SUB:['verticalAlign','sub']};Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterStyleToTag,Roo.htmleditor.Filter,{tag:true,tags:false,replaceTag:function(A){if(A.getAttribute("style")===null){return true; -}var B=[];for(var k in this.tags){if(A.style[this.tags[k][0]]==this.tags[k][1]){B.push(k);A.style.removeProperty(this.tags[k][0]);}}if(!B.length){return true;}var cn=Array.from(A.childNodes);var nn=A;Roo.each(B,function(t){var nc=A.ownerDocument.createElement(t); -nn.appendChild(nc);nn=nc;});for(var i=0;i-1){A.parentNode.removeChild(A); return false;}if(!ps||ps.nodeType!=1){return false;}if(!ps||ps.tagName!='BR'){return false;}if(!A.previousSibling){return false;}var ps=A.previousSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.previousSibling;}if(!ps||ps.nodeType!=1){return false; @@ -1376,11 +1379,11 @@ catch(e){return;}Roo.TaskMgr.stop(D);this.initEditor.defer(10,this);}},interval: return A;},syncValue:function(){if(this.initialized){if(this.undoManager){this.undoManager.addEvent();}var bd=(this.doc.body||this.doc.documentElement);var A=this.win.getSelection();var B=document.createElement('div');B.innerHTML=bd.innerHTML;var C=B.getElementsByClassName('gtx-trans-icon'); if(C.length>0){var rm=C.item(0).parentNode;rm.parentNode.removeChild(rm);}if(this.enableBlocks){Array.from(bd.getElementsByTagName('img')).forEach(function(F){var G=F.closest('figure');if(G){var bf=new Roo.htmleditor.BlockFigure({node:G});bf.updateElement(); }});new Roo.htmleditor.FilterBlock({node:B});}var D=B.innerHTML;if(this.autoClean){new Roo.htmleditor.FilterBlack({node:B,tag:this.black});new Roo.htmleditor.FilterAttributes({node:B,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-caption-display','data-width','data-caption','start','style','class','allowfullscreen','frameborder','width','height','alt'],attrib_clean:['href','src']} -);var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
';}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt(); -if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F;}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D; -this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement);d.innerHTML=v;this.el.dom.value=d.innerHTML; -this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}this.updateLanguage(); -var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); +);new Roo.htmleditor.FilterEmpty({node:B});var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
'; +}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt();if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F; +}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D;this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement); +d.innerHTML=v;this.el.dom.value=d.innerHTML;this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); +}this.updateLanguage();var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); }else{this.el.focus();}},assignDocWin:function(){var A=this.iframe;if(Roo.isIE){this.doc=A.contentWindow.document;this.win=A.contentWindow;}else{if(!Roo.get(this.frameId)&&!A.contentDocument){return;}this.doc=(A.contentDocument||Roo.get(this.frameId).dom.document); this.win=(A.contentWindow||Roo.get(this.frameId).dom.contentWindow);}},initEditor:function(){this.assignDocWin();this.doc.designMode="on";this.doc.open();this.doc.write(this.getDocMarkup());this.doc.close();var A=(this.doc.body||this.doc.documentElement); A.bgProperties='fixed';A.setAttribute("translate","no");Roo.EventManager.on(this.doc,{'mouseup':this.onEditorEvent,'dblclick':this.onEditorEvent,'click':this.onEditorEvent,'keyup':this.onEditorEvent,buffer:100,scope:this});Roo.EventManager.on(this.doc,{'paste':this.onPasteEvent,scope:this} @@ -1393,9 +1396,9 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne this.insertAtCursor("You can not nest tables");return false;}if(B.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(E){E.parentNode.insertBefore(d.ownerDocument.createElement('img'),E);E.parentNode.removeChild(E);});Roo.each(d.getElementsByTagName('img'),function(E,i){E.setAttribute('src',B[i]); });}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan'],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.FilterHashLink({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} -);}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); -}e.preventDefault();this.owner.fireEvent('paste',this);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); +);new Roo.htmleditor.FilterEmpty({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' ')); +if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}e.preventDefault();this.owner.fireEvent('paste',this);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;var v=parseInt(this.doc.queryCommandValue('FontSize')||3,10);if(Roo.isSafari){var sm={10:1,13:2,16:3,18:4,24:5,32:6,48:7} ;v=(v<10)?10:v;v=(v>48)?48:v;v=typeof(sm[v])=='undefined'?1:sm[v];}v=Math.max(1,v+B);this.execCmd('FontSize',v);},onEditorEvent:function(e){if(e&&(e.ctrlKey||e.metaKey)&&e.keyCode===90){return;}if(e&&e.target.nodeName=='BODY'&&e.type=="mouseup"&&this.doc.body.lastChild){var lc=this.doc.body.lastChild; while((lc.nodeType==3&&lc.nodeValue=='')||lc.id=='gtx-trans'){lc=lc.previousSibling;}if(lc.nodeType==1&&lc.nodeName!='BR'){var ns=this.doc.createElement('br');this.doc.body.appendChild(ns);range=this.doc.createRange();range.setStartAfter(ns);range.collapse(true); diff --git a/roojs-debug.js b/roojs-debug.js index 11270b70dc..3fc22337d7 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -47920,6 +47920,49 @@ Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter, { n.parentNode.removeChild(n); } +});/** + * @class Roo.htmleditor.FilterEmpty + * filter empty elements + * @constructor + * Run a new Empty Filter + * @param {Object} config Configuration options + */ + +Roo.htmleditor.FilterEmpty = function(cfg) +{ + // no need to apply config. + this.walk(cfg.node); +} + +Roo.extend(Roo.htmleditor.FilterEmpty, Roo.htmleditor.FilterBlack, +{ + + tag : true, + + + replaceTag : function(node) + { + // start from leaf node + if(node.hasChildNodes()) { + this.walk(node); + } + + // only filter empty leaf element with certain tags + if( + ['B', 'I', 'U', 'S'].indexOf(node.tagName) < 0 + || + node.attributes && node.attributes.length > 0 + || + node.hasChildNodes() + ) { + return false; // don't walk + } + + Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this, node); + return false; // don't walk + + } + });/** * @class Roo.htmleditor.FilterKeepChildren * remove tags but keep children @@ -48615,12 +48658,12 @@ Roo.htmleditor.FilterStyleToTag = function(cfg) { this.tags = { - B : [ 'fontWeight' , 'bold'], - I : [ 'fontStyle' , 'italic'], + B : [ 'fontWeight' , 'bold', 'font-weight'], + I : [ 'fontStyle' , 'italic', 'font-style'], //pre : [ 'font-style' , 'italic'], // h1.. h6 ?? font-size? - SUP : [ 'verticalAlign' , 'super' ], - SUB : [ 'verticalAlign' , 'sub' ] + SUP : [ 'verticalAlign' , 'super', 'vertical-align'], + SUB : [ 'verticalAlign' , 'sub', 'vertical-align'] }; @@ -48653,7 +48696,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, for (var k in this.tags) { if (node.style[this.tags[k][0]] == this.tags[k][1]) { inject.push(k); - node.style.removeProperty(this.tags[k][0]); + node.style.removeProperty(this.tags[k][2]); } } if (!inject.length) { @@ -48666,7 +48709,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, nn.appendChild(nc); nn = nc; }); - for(var i = 0;i < cn.length;cn++) { + for(var i = 0;i < cn.length;i++) { node.removeChild(cn[i]); nn.appendChild(cn[i]); } @@ -52417,6 +52460,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { ], attrib_clean : ['href', 'src' ] }); + new Roo.htmleditor.FilterEmpty({ node : div}); var tidy = new Roo.htmleditor.TidySerializer({ inner: true @@ -52734,6 +52778,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); new Roo.htmleditor.FilterComment({ node : d }); + new Roo.htmleditor.FilterEmpty({ node : d}); } diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 129a74c69d..8438c714bc 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -23418,6 +23418,49 @@ Roo.extend(Roo.htmleditor.FilterComment, Roo.htmleditor.Filter, { n.parentNode.removeChild(n); } +});/** + * @class Roo.htmleditor.FilterEmpty + * filter empty elements + * @constructor + * Run a new Empty Filter + * @param {Object} config Configuration options + */ + +Roo.htmleditor.FilterEmpty = function(cfg) +{ + // no need to apply config. + this.walk(cfg.node); +} + +Roo.extend(Roo.htmleditor.FilterEmpty, Roo.htmleditor.FilterBlack, +{ + + tag : true, + + + replaceTag : function(node) + { + // start from leaf node + if(node.hasChildNodes()) { + this.walk(node); + } + + // only filter empty leaf element with certain tags + if( + ['B', 'I', 'U', 'S'].indexOf(node.tagName) < 0 + || + node.attributes && node.attributes.length > 0 + || + node.hasChildNodes() + ) { + return false; // don't walk + } + + Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this, node); + return false; // don't walk + + } + });/** * @class Roo.htmleditor.FilterKeepChildren * remove tags but keep children @@ -24113,12 +24156,12 @@ Roo.htmleditor.FilterStyleToTag = function(cfg) { this.tags = { - B : [ 'fontWeight' , 'bold'], - I : [ 'fontStyle' , 'italic'], + B : [ 'fontWeight' , 'bold', 'font-weight'], + I : [ 'fontStyle' , 'italic', 'font-style'], //pre : [ 'font-style' , 'italic'], // h1.. h6 ?? font-size? - SUP : [ 'verticalAlign' , 'super' ], - SUB : [ 'verticalAlign' , 'sub' ] + SUP : [ 'verticalAlign' , 'super', 'vertical-align'], + SUB : [ 'verticalAlign' , 'sub', 'vertical-align'] }; @@ -24151,7 +24194,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, for (var k in this.tags) { if (node.style[this.tags[k][0]] == this.tags[k][1]) { inject.push(k); - node.style.removeProperty(this.tags[k][0]); + node.style.removeProperty(this.tags[k][2]); } } if (!inject.length) { @@ -24164,7 +24207,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, nn.appendChild(nc); nn = nc; }); - for(var i = 0;i < cn.length;cn++) { + for(var i = 0;i < cn.length;i++) { node.removeChild(cn[i]); nn.appendChild(cn[i]); } @@ -27915,6 +27958,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { ], attrib_clean : ['href', 'src' ] }); + new Roo.htmleditor.FilterEmpty({ node : div}); var tidy = new Roo.htmleditor.TidySerializer({ inner: true @@ -28232,6 +28276,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterSpan({ node : d }); new Roo.htmleditor.FilterLongBr({ node : d }); new Roo.htmleditor.FilterComment({ node : d }); + new Roo.htmleditor.FilterEmpty({ node : d}); } diff --git a/roojs-ui.js b/roojs-ui.js index 8887feccf0..45b5682a21 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -1079,6 +1079,9 @@ var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\ 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/FilterEmpty.js +Roo.htmleditor.FilterEmpty=function(A){this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterEmpty,Roo.htmleditor.FilterBlack,{tag:true,replaceTag:function(A){if(A.hasChildNodes()){this.walk(A);}if(['B','I','U','S'].indexOf(A.tagName)<0||A.attributes&&A.attributes.length>0||A.hasChildNodes()){return false; +}Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this,A);return false;}}); // Roo/htmleditor/FilterKeepChildren.js Roo.htmleditor.FilterKeepChildren=function(A){Roo.apply(this,A);if(this.tag===false){return;}if((typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)){this.cleanNamespace=true;}this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterKeepChildren,Roo.htmleditor.FilterBlack,{cleanNamespace:false,replaceTag:function(A){var ar=Array.from(A.childNodes); for(var i=0;i-1)||(typeof(this.tag)=='string'&&this.tag==e.tagName)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1)||(e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":")){this.replaceTag(ar[i]); @@ -1119,9 +1122,9 @@ return;}var O=N['margin-left'];if(typeof(J[O])=='undefined'){max_margins++;J[O]= }var tr=td.parentNode;if(tr.nodeName!='TR'){return;}var D=tr.parentNode;if(D.nodeName!='TBODY'){return;}var E=D.parentNode;if(E.nodeName!='TABLE'){return;}if(E.getElementsByTagName('tr').length!=2){return;}if(E.getElementsByTagName('td').length!=3){return; }if(E.innerText.trim()!=''){return;}var p=E.parentNode;C.parentNode.removeChild(C);p.insertBefore(C,E);p.removeChild(E);});}}); // Roo/htmleditor/FilterStyleToTag.js -Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I:['fontStyle','italic'],SUP:['verticalAlign','super'],SUB:['verticalAlign','sub']};Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterStyleToTag,Roo.htmleditor.Filter,{tag:true,tags:false,replaceTag:function(A){if(A.getAttribute("style")===null){return true; -}var B=[];for(var k in this.tags){if(A.style[this.tags[k][0]]==this.tags[k][1]){B.push(k);A.style.removeProperty(this.tags[k][0]);}}if(!B.length){return true;}var cn=Array.from(A.childNodes);var nn=A;Roo.each(B,function(t){var nc=A.ownerDocument.createElement(t); -nn.appendChild(nc);nn=nc;});for(var i=0;i-1){A.parentNode.removeChild(A); return false;}if(!ps||ps.nodeType!=1){return false;}if(!ps||ps.tagName!='BR'){return false;}if(!A.previousSibling){return false;}var ps=A.previousSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.previousSibling;}if(!ps||ps.nodeType!=1){return false; @@ -1258,11 +1261,11 @@ catch(e){return;}Roo.TaskMgr.stop(D);this.initEditor.defer(10,this);}},interval: return A;},syncValue:function(){if(this.initialized){if(this.undoManager){this.undoManager.addEvent();}var bd=(this.doc.body||this.doc.documentElement);var A=this.win.getSelection();var B=document.createElement('div');B.innerHTML=bd.innerHTML;var C=B.getElementsByClassName('gtx-trans-icon'); if(C.length>0){var rm=C.item(0).parentNode;rm.parentNode.removeChild(rm);}if(this.enableBlocks){Array.from(bd.getElementsByTagName('img')).forEach(function(F){var G=F.closest('figure');if(G){var bf=new Roo.htmleditor.BlockFigure({node:G});bf.updateElement(); }});new Roo.htmleditor.FilterBlock({node:B});}var D=B.innerHTML;if(this.autoClean){new Roo.htmleditor.FilterBlack({node:B,tag:this.black});new Roo.htmleditor.FilterAttributes({node:B,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-caption-display','data-width','data-caption','start','style','class','allowfullscreen','frameborder','width','height','alt'],attrib_clean:['href','src']} -);var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
';}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt(); -if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F;}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D; -this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement);d.innerHTML=v;this.el.dom.value=d.innerHTML; -this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}this.updateLanguage(); -var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); +);new Roo.htmleditor.FilterEmpty({node:B});var E=new Roo.htmleditor.TidySerializer({inner:true});D=E.serialize(B);}if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){D='
'+D+'
'; +}}D=this.cleanHtml(D);D=D.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(F){var cc=F.charCodeAt();if(F.length==2){var G=F.charCodeAt(0)-0xD800;var H=F.charCodeAt(1)-0xDC00;cc=(G*0x400)+H+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return F; +}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,D)!==false){this.el.dom.value=D;this.owner.fireEvent('sync',this,D);}}},pushValue:function(){if(this.initialized){var v=this.el.dom.value.trim();if(this.owner.fireEvent('beforepush',this,v)!==false){var d=(this.doc.body||this.doc.documentElement); +d.innerHTML=v;this.el.dom.value=d.innerHTML;this.owner.fireEvent('push',this,v);}if(this.autoClean){new Roo.htmleditor.FilterParagraph({node:this.doc.body});new Roo.htmleditor.FilterSpan({node:this.doc.body});}if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); +}this.updateLanguage();var lc=this.doc.body.lastChild;if(lc&&lc.nodeType==1&&lc.getAttribute("contenteditable")=="false"){this.doc.body.appendChild(this.doc.createElement('br'));}}},deferFocus:function(){this.focus.defer(10,this);},focus:function(){if(this.win&&!this.sourceEditMode){this.win.focus(); }else{this.el.focus();}},assignDocWin:function(){var A=this.iframe;if(Roo.isIE){this.doc=A.contentWindow.document;this.win=A.contentWindow;}else{if(!Roo.get(this.frameId)&&!A.contentDocument){return;}this.doc=(A.contentDocument||Roo.get(this.frameId).dom.document); this.win=(A.contentWindow||Roo.get(this.frameId).dom.contentWindow);}},initEditor:function(){this.assignDocWin();this.doc.designMode="on";this.doc.open();this.doc.write(this.getDocMarkup());this.doc.close();var A=(this.doc.body||this.doc.documentElement); A.bgProperties='fixed';A.setAttribute("translate","no");Roo.EventManager.on(this.doc,{'mouseup':this.onEditorEvent,'dblclick':this.onEditorEvent,'click':this.onEditorEvent,'keyup':this.onEditorEvent,buffer:100,scope:this});Roo.EventManager.on(this.doc,{'paste':this.onPasteEvent,scope:this} @@ -1275,9 +1278,9 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne this.insertAtCursor("You can not nest tables");return false;}if(B.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(E){E.parentNode.insertBefore(d.ownerDocument.createElement('img'),E);E.parentNode.removeChild(E);});Roo.each(d.getElementsByTagName('img'),function(E,i){E.setAttribute('src',B[i]); });}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan'],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.FilterHashLink({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} -);}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); -}e.preventDefault();this.owner.fireEvent('paste',this);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); +);new Roo.htmleditor.FilterEmpty({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(E){if(E.closest('figure')){return;}var F=new Roo.htmleditor.BlockFigure({image_src:E.src});F.updateElement(E);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' ')); +if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body);}e.preventDefault();this.owner.fireEvent('paste',this);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;var v=parseInt(this.doc.queryCommandValue('FontSize')||3,10);if(Roo.isSafari){var sm={10:1,13:2,16:3,18:4,24:5,32:6,48:7} ;v=(v<10)?10:v;v=(v>48)?48:v;v=typeof(sm[v])=='undefined'?1:sm[v];}v=Math.max(1,v+B);this.execCmd('FontSize',v);},onEditorEvent:function(e){if(e&&(e.ctrlKey||e.metaKey)&&e.keyCode===90){return;}if(e&&e.target.nodeName=='BODY'&&e.type=="mouseup"&&this.doc.body.lastChild){var lc=this.doc.body.lastChild; while((lc.nodeType==3&&lc.nodeValue=='')||lc.id=='gtx-trans'){lc=lc.previousSibling;}if(lc.nodeType==1&&lc.nodeName!='BR'){var ns=this.doc.createElement('br');this.doc.body.appendChild(ns);range=this.doc.createRange();range.setStartAfter(ns);range.collapse(true);