From 10f9d134e94f565e2adb3f66b95d9ba764cbea87 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 30 Nov 2023 14:07:14 +0800 Subject: [PATCH] fix #7873 - links to footnotes removed on paste --- Roo/HtmlEditorCore.js | 1 + Roo/htmleditor/Filter.js | 15 ++++++++ Roo/htmleditor/FilterHashLink.js | 10 ++--- Roo/htmleditor/FilterLongBr.js | 4 +- Roo/htmleditor/FilterParagraph.js | 3 +- Roo/htmleditor/FilterSpan.js | 2 +- buildSDK/dependancy_bootstrap.txt | 1 + buildSDK/dependancy_ui.txt | 1 + roojs-all.js | 27 ++++++++------ roojs-bootstrap-debug.js | 61 ++++++++++++++++++++++++++++--- roojs-bootstrap.js | 27 ++++++++------ roojs-debug.js | 61 ++++++++++++++++++++++++++++--- roojs-ui-debug.js | 61 ++++++++++++++++++++++++++++--- roojs-ui.js | 27 ++++++++------ 14 files changed, 238 insertions(+), 63 deletions(-) diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index c8105fe8f9..2f3d5bf48a 100644 --- a/Roo/HtmlEditorCore.js +++ b/Roo/HtmlEditorCore.js @@ -722,6 +722,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { // should be fonts.. 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 }); diff --git a/Roo/htmleditor/Filter.js b/Roo/htmleditor/Filter.js index 6d5cf8f224..46035687b7 100644 --- a/Roo/htmleditor/Filter.js +++ b/Roo/htmleditor/Filter.js @@ -77,5 +77,20 @@ Roo.htmleditor.Filter.prototype = { } node.parentNode.removeChild(node); + }, + + searchTag : function(dom) + { + if(this.tag === false) { + return; + } + + var els = dom.getElementsByTagName(this.tag); + + Roo.each(Array.from(els), function(e){ + if(this.replaceTag) { + this.replaceTag(e); + } + }, this); } }; \ No newline at end of file diff --git a/Roo/htmleditor/FilterHashLink.js b/Roo/htmleditor/FilterHashLink.js index 6cfadc36f4..268ffc732a 100644 --- a/Roo/htmleditor/FilterHashLink.js +++ b/Roo/htmleditor/FilterHashLink.js @@ -9,7 +9,8 @@ Roo.htmleditor.FilterHashLink = function(cfg) { // no need to apply config. - this.walk(cfg.node); + // this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterHashLink, Roo.htmleditor.Filter, @@ -24,12 +25,7 @@ var a = node.attributes[i]; if(a.name.toLowerCase() == 'href' && a.value.startsWith('#')) { - var ar = Array.from(node.childNodes); - for (var i = 0; i < ar.length; i++) { - node.parentNode.insertBefore(ar[i], node); - } - - node.parentNode.removeChild(node); + this.removeNodeKeepChildren(node); } } diff --git a/Roo/htmleditor/FilterLongBr.js b/Roo/htmleditor/FilterLongBr.js index 39f464bd4f..c5ebe0b684 100644 --- a/Roo/htmleditor/FilterLongBr.js +++ b/Roo/htmleditor/FilterLongBr.js @@ -9,7 +9,7 @@ Roo.htmleditor.FilterLongBr = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, @@ -43,8 +43,6 @@ Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, - - if (!node.previousSibling) { return false; } diff --git a/Roo/htmleditor/FilterParagraph.js b/Roo/htmleditor/FilterParagraph.js index 5c5f2277a0..295f026c41 100644 --- a/Roo/htmleditor/FilterParagraph.js +++ b/Roo/htmleditor/FilterParagraph.js @@ -10,7 +10,7 @@ Roo.htmleditor.FilterParagraph = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, @@ -31,6 +31,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node); return false; // no need to walk.. } + var ar = Array.from(node.childNodes); for (var i = 0; i < ar.length; i++) { node.removeChild(ar[i]); diff --git a/Roo/htmleditor/FilterSpan.js b/Roo/htmleditor/FilterSpan.js index 7d16d7da28..f861611bb3 100644 --- a/Roo/htmleditor/FilterSpan.js +++ b/Roo/htmleditor/FilterSpan.js @@ -9,7 +9,7 @@ Roo.htmleditor.FilterSpan = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren, diff --git a/buildSDK/dependancy_bootstrap.txt b/buildSDK/dependancy_bootstrap.txt index 9546b34ddc..be94028645 100644 --- a/buildSDK/dependancy_bootstrap.txt +++ b/buildSDK/dependancy_bootstrap.txt @@ -147,6 +147,7 @@ Roo.htmleditor.FilterBlack Roo.htmleditor.FilterComment Roo.htmleditor.FilterKeepChildren Roo.htmleditor.FilterParagraph +Roo.htmleditor.FilterHashLink Roo.htmleditor.FilterSpan Roo.htmleditor.FilterTableWidth Roo.htmleditor.FilterWord diff --git a/buildSDK/dependancy_ui.txt b/buildSDK/dependancy_ui.txt index f89656e412..16b1cc4023 100644 --- a/buildSDK/dependancy_ui.txt +++ b/buildSDK/dependancy_ui.txt @@ -111,6 +111,7 @@ Roo.htmleditor.FilterBlack Roo.htmleditor.FilterComment Roo.htmleditor.FilterKeepChildren Roo.htmleditor.FilterParagraph +Roo.htmleditor.FilterHashLink Roo.htmleditor.FilterSpan Roo.htmleditor.FilterTableWidth Roo.htmleditor.FilterWord diff --git a/roojs-all.js b/roojs-all.js index e2cea354f9..14ebbe5227 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1897,7 +1897,7 @@ Roo.htmleditor={}; 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 e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1:case e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":":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);},removeNodeKeepChildren:function(A){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]); continue;}}}ar=Array.from(A.childNodes);for(var i=0;i0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); +Roo.htmleditor.FilterSpan=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterSpan,Roo.htmleditor.FilterKeepChildren,{tag:'SPAN',replaceTag:function(A){if(A.attributes&&A.attributes.length>0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); return false;}}); // Roo/htmleditor/FilterTableWidth.js Roo.htmleditor.FilterTableWidth=function(A){this.tag=['TABLE','TD','TR','TH','THEAD','TBODY'];this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterTableWidth,Roo.htmleditor.Filter,{replaceTag:function(A){if(A.hasAttribute('width')){A.removeAttribute('width'); @@ -1952,7 +1955,7 @@ Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I }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); +Roo.htmleditor.FilterLongBr=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterLongBr,Roo.htmleditor.Filter,{tag:'BR',replaceTag:function(A){var ps=A.nextSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.nextSibling;}if(!ps&&['TD','TH','LI','H1','H2','H3','H4','H5','H6'].indexOf(A.parentNode.tagName)>-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; }if(!ps||['BR','H1','H2','H3','H4','H5','H6'].indexOf(ps.tagName)<0){return false;}A.parentNode.removeChild(A);return false;}}); // Roo/htmleditor/FilterBlock.js @@ -2100,14 +2103,14 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne }).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});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(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.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);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);var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e); -this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); +);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); +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); +var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e);this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); var A=this.doc.createElement(tg.toLowerCase());A.appendChild(range.extractContents());range.insertNode(A);return;}this.execCmd("formatblock",tg);this.undoManager.addEvent();},insertText:function(A){var B=this.createRange();B.deleteContents();B.insertNode(this.doc.createTextNode(A)); this.undoManager.addEvent();},relayCmd:function(A,B){switch(A){case 'justifyleft':case 'justifyright':case 'justifycenter':var n=this.getParentElement();var td=n.closest('td');if(td){var bl=Roo.htmleditor.Block.factory(td);bl.textAlign=A.replace('justify',''); bl.updateElement();this.owner.fireEvent('editorevent',this);return;}this.execCmd('styleWithCSS',true);break;case 'bold':case 'italic':case 'underline':this.execCmd('styleWithCSS',false);break;default:break;}this.win.focus();this.execCmd(A,B);this.owner.fireEvent('editorevent',this); diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index f274f2644d..2fa75b767e 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -27099,6 +27099,22 @@ Roo.htmleditor.Filter.prototype = { } node.parentNode.removeChild(node); + }, + + searchTag : function(dom) + { + if(this.tag === false) { + return; + } + + var els = dom.getElementsByTagName(this.tag); + + Roo.each(Array.from(els), function(e){ + Roo.log(e); + if(this.replaceTag) { + this.replaceTag(e); + } + }, this); } }; @@ -27376,7 +27392,7 @@ Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack, Roo.htmleditor.FilterParagraph = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, @@ -27397,6 +27413,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node); return false; // no need to walk.. } + var ar = Array.from(node.childNodes); for (var i = 0; i < ar.length; i++) { node.removeChild(ar[i]); @@ -27416,6 +27433,41 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, } });/** + * @class Roo.htmleditor.FilterHashLink + * remove hash link + * @constructor + * Run a new Hash Link Filter + * @param {Object} config Configuration options + */ + + Roo.htmleditor.FilterHashLink = function(cfg) + { + // no need to apply config. + // this.walk(cfg.node); + this.searchTag(cfg.node); + } + + Roo.extend(Roo.htmleditor.FilterHashLink, Roo.htmleditor.Filter, + { + + tag : 'A', + + + replaceTag : function(node) + { + for(var i = 0; i < node.attributes.length; i ++) { + var a = node.attributes[i]; + + if(a.name.toLowerCase() == 'href' && a.value.startsWith('#')) { + this.removeNodeKeepChildren(node); + } + } + + return false; + + } + + });/** * @class Roo.htmleditor.FilterSpan * filter span's with no attributes out.. * @constructor @@ -27426,7 +27478,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, Roo.htmleditor.FilterSpan = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren, @@ -28025,7 +28077,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, Roo.htmleditor.FilterLongBr = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, @@ -28059,8 +28111,6 @@ Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, - - if (!node.previousSibling) { return false; } @@ -32045,6 +32095,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { // should be fonts.. 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 }); diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index db25651ed9..f8a7af96da 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1183,7 +1183,7 @@ this.push({type:'endparagraph',pos:this.cpos,row:this.row,col:this.col});}}; 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 e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1:case e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":":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);},removeNodeKeepChildren:function(A){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]); continue;}}}ar=Array.from(A.childNodes);for(var i=0;i0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); +Roo.htmleditor.FilterSpan=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterSpan,Roo.htmleditor.FilterKeepChildren,{tag:'SPAN',replaceTag:function(A){if(A.attributes&&A.attributes.length>0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); return false;}}); // Roo/htmleditor/FilterTableWidth.js Roo.htmleditor.FilterTableWidth=function(A){this.tag=['TABLE','TD','TR','TH','THEAD','TBODY'];this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterTableWidth,Roo.htmleditor.Filter,{replaceTag:function(A){if(A.hasAttribute('width')){A.removeAttribute('width'); @@ -1238,7 +1241,7 @@ Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I }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); +Roo.htmleditor.FilterLongBr=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterLongBr,Roo.htmleditor.Filter,{tag:'BR',replaceTag:function(A){var ps=A.nextSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.nextSibling;}if(!ps&&['TD','TH','LI','H1','H2','H3','H4','H5','H6'].indexOf(A.parentNode.tagName)>-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; }if(!ps||['BR','H1','H2','H3','H4','H5','H6'].indexOf(ps.tagName)<0){return false;}A.parentNode.removeChild(A);return false;}}); // Roo/htmleditor/FilterBlock.js @@ -1386,14 +1389,14 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne }).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});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(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.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);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);var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e); -this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); +);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); +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); +var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e);this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); var A=this.doc.createElement(tg.toLowerCase());A.appendChild(range.extractContents());range.insertNode(A);return;}this.execCmd("formatblock",tg);this.undoManager.addEvent();},insertText:function(A){var B=this.createRange();B.deleteContents();B.insertNode(this.doc.createTextNode(A)); this.undoManager.addEvent();},relayCmd:function(A,B){switch(A){case 'justifyleft':case 'justifyright':case 'justifycenter':var n=this.getParentElement();var td=n.closest('td');if(td){var bl=Roo.htmleditor.Block.factory(td);bl.textAlign=A.replace('justify',''); bl.updateElement();this.owner.fireEvent('editorevent',this);return;}this.execCmd('styleWithCSS',true);break;case 'bold':case 'italic':case 'underline':this.execCmd('styleWithCSS',false);break;default:break;}this.win.focus();this.execCmd(A,B);this.owner.fireEvent('editorevent',this); diff --git a/roojs-debug.js b/roojs-debug.js index 8b4e7148d1..e5fc1601e5 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -45749,6 +45749,22 @@ Roo.htmleditor.Filter.prototype = { } node.parentNode.removeChild(node); + }, + + searchTag : function(dom) + { + if(this.tag === false) { + return; + } + + var els = dom.getElementsByTagName(this.tag); + + Roo.each(Array.from(els), function(e){ + Roo.log(e); + if(this.replaceTag) { + this.replaceTag(e); + } + }, this); } }; @@ -46026,7 +46042,7 @@ Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack, Roo.htmleditor.FilterParagraph = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, @@ -46047,6 +46063,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node); return false; // no need to walk.. } + var ar = Array.from(node.childNodes); for (var i = 0; i < ar.length; i++) { node.removeChild(ar[i]); @@ -46066,6 +46083,41 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, } });/** + * @class Roo.htmleditor.FilterHashLink + * remove hash link + * @constructor + * Run a new Hash Link Filter + * @param {Object} config Configuration options + */ + + Roo.htmleditor.FilterHashLink = function(cfg) + { + // no need to apply config. + // this.walk(cfg.node); + this.searchTag(cfg.node); + } + + Roo.extend(Roo.htmleditor.FilterHashLink, Roo.htmleditor.Filter, + { + + tag : 'A', + + + replaceTag : function(node) + { + for(var i = 0; i < node.attributes.length; i ++) { + var a = node.attributes[i]; + + if(a.name.toLowerCase() == 'href' && a.value.startsWith('#')) { + this.removeNodeKeepChildren(node); + } + } + + return false; + + } + + });/** * @class Roo.htmleditor.FilterSpan * filter span's with no attributes out.. * @constructor @@ -46076,7 +46128,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, Roo.htmleditor.FilterSpan = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren, @@ -46675,7 +46727,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, Roo.htmleditor.FilterLongBr = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, @@ -46709,8 +46761,6 @@ Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, - - if (!node.previousSibling) { return false; } @@ -50695,6 +50745,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { // should be fonts.. 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 }); diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 5ed01045cd..1650d8df94 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21247,6 +21247,22 @@ Roo.htmleditor.Filter.prototype = { } node.parentNode.removeChild(node); + }, + + searchTag : function(dom) + { + if(this.tag === false) { + return; + } + + var els = dom.getElementsByTagName(this.tag); + + Roo.each(Array.from(els), function(e){ + Roo.log(e); + if(this.replaceTag) { + this.replaceTag(e); + } + }, this); } }; @@ -21524,7 +21540,7 @@ Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack, Roo.htmleditor.FilterParagraph = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, @@ -21545,6 +21561,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node); return false; // no need to walk.. } + var ar = Array.from(node.childNodes); for (var i = 0; i < ar.length; i++) { node.removeChild(ar[i]); @@ -21564,6 +21581,41 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, } });/** + * @class Roo.htmleditor.FilterHashLink + * remove hash link + * @constructor + * Run a new Hash Link Filter + * @param {Object} config Configuration options + */ + + Roo.htmleditor.FilterHashLink = function(cfg) + { + // no need to apply config. + // this.walk(cfg.node); + this.searchTag(cfg.node); + } + + Roo.extend(Roo.htmleditor.FilterHashLink, Roo.htmleditor.Filter, + { + + tag : 'A', + + + replaceTag : function(node) + { + for(var i = 0; i < node.attributes.length; i ++) { + var a = node.attributes[i]; + + if(a.name.toLowerCase() == 'href' && a.value.startsWith('#')) { + this.removeNodeKeepChildren(node); + } + } + + return false; + + } + + });/** * @class Roo.htmleditor.FilterSpan * filter span's with no attributes out.. * @constructor @@ -21574,7 +21626,7 @@ Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter, Roo.htmleditor.FilterSpan = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterSpan, Roo.htmleditor.FilterKeepChildren, @@ -22173,7 +22225,7 @@ Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter, Roo.htmleditor.FilterLongBr = function(cfg) { // no need to apply config. - this.walk(cfg.node); + this.searchTag(cfg.node); } Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, @@ -22207,8 +22259,6 @@ Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter, - - if (!node.previousSibling) { return false; } @@ -26193,6 +26243,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { // should be fonts.. 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 }); diff --git a/roojs-ui.js b/roojs-ui.js index b8107cc54e..407b816167 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -950,7 +950,7 @@ Roo.htmleditor={}; 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 e.tagName.indexOf(":")>-1&&typeof(this.tag)=='object'&&this.tag.indexOf(":")>-1:case e.tagName.indexOf(":")>-1&&typeof(this.tag)=='string'&&this.tag==":":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);},removeNodeKeepChildren:function(A){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]); continue;}}}ar=Array.from(A.childNodes);for(var i=0;i0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); +Roo.htmleditor.FilterSpan=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterSpan,Roo.htmleditor.FilterKeepChildren,{tag:'SPAN',replaceTag:function(A){if(A.attributes&&A.attributes.length>0){return true;}Roo.htmleditor.FilterKeepChildren.prototype.replaceTag.call(this,A); return false;}}); // Roo/htmleditor/FilterTableWidth.js Roo.htmleditor.FilterTableWidth=function(A){this.tag=['TABLE','TD','TR','TH','THEAD','TBODY'];this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterTableWidth,Roo.htmleditor.Filter,{replaceTag:function(A){if(A.hasAttribute('width')){A.removeAttribute('width'); @@ -1005,7 +1008,7 @@ Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I }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); +Roo.htmleditor.FilterLongBr=function(A){this.searchTag(A.node);};Roo.extend(Roo.htmleditor.FilterLongBr,Roo.htmleditor.Filter,{tag:'BR',replaceTag:function(A){var ps=A.nextSibling;while(ps&&ps.nodeType==3&&ps.nodeValue.trim().length<1){ps=ps.nextSibling;}if(!ps&&['TD','TH','LI','H1','H2','H3','H4','H5','H6'].indexOf(A.parentNode.tagName)>-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; }if(!ps||['BR','H1','H2','H3','H4','H5','H6'].indexOf(ps.tagName)<0){return false;}A.parentNode.removeChild(A);return false;}}); // Roo/htmleditor/FilterBlock.js @@ -1153,14 +1156,14 @@ var r=new FileReader();var t=this;r.addEventListener('load',function(){var d=(ne }).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});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(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.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);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);var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e); -this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); +);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); +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); +var A=this.win.getSelection();A.removeAllRanges();A.addRange(range);}}this.fireEditorEvent(e);this.syncValue();},fireEditorEvent:function(e){this.owner.fireEvent('editorevent',this,e);},insertTag:function(tg){if(tg.toLowerCase()=='span'||tg.toLowerCase()=='code'||tg.toLowerCase()=='sup'||tg.toLowerCase()=='sub'){range=this.createRange(this.getSelection()); var A=this.doc.createElement(tg.toLowerCase());A.appendChild(range.extractContents());range.insertNode(A);return;}this.execCmd("formatblock",tg);this.undoManager.addEvent();},insertText:function(A){var B=this.createRange();B.deleteContents();B.insertNode(this.doc.createTextNode(A)); this.undoManager.addEvent();},relayCmd:function(A,B){switch(A){case 'justifyleft':case 'justifyright':case 'justifycenter':var n=this.getParentElement();var td=n.closest('td');if(td){var bl=Roo.htmleditor.Block.factory(td);bl.textAlign=A.replace('justify',''); bl.updateElement();this.owner.fireEvent('editorevent',this);return;}this.execCmd('styleWithCSS',true);break;case 'bold':case 'italic':case 'underline':this.execCmd('styleWithCSS',false);break;default:break;}this.win.focus();this.execCmd(A,B);this.owner.fireEvent('editorevent',this); -- 2.39.2