From 2dd06c4c3e0f351d16332bd7a5fba608af1219ca Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 7 Jan 2022 16:26:28 +0800 Subject: [PATCH] sync --- Roo/htmleditor/TidySerializer.js | 37 ++--------------------------- docs/src/Roo_HtmlEditorCore.js.html | 4 ++-- roojs-bootstrap-debug.js | 28 ++++++++++++++++------ roojs-bootstrap.js | 26 ++++++++++---------- 4 files changed, 38 insertions(+), 57 deletions(-) diff --git a/Roo/htmleditor/TidySerializer.js b/Roo/htmleditor/TidySerializer.js index 013e8d9983..f1fc44d1b8 100644 --- a/Roo/htmleditor/TidySerializer.js +++ b/Roo/htmleditor/TidySerializer.js @@ -6,7 +6,6 @@ * @constructor * @method Serializer * @param {Object} settings Name/value settings object. - * @param {tinymce.html.Schema} schema Schema instance to use. */ @@ -16,8 +15,7 @@ Roo.htmleditor.TidySerializer = function(settings) this.writer = new Roo.htmleditor.TidyWriter(settings); - //settings.validate = !('validate' in settings) || settings.validate; - // self.schema = schema = schema || new Schema(); + }; Roo.htmleditor.TidySerializer.prototype = { @@ -98,38 +96,7 @@ Roo.htmleditor.TidySerializer.prototype = { var writer = this.writer; var attrs = node.attributes; // Sort attributes - /* - if (validate && attrs && attrs.length > 1) { - sortedAttrs = []; - sortedAttrs.map = {}; - elementRule = schema.getElementRule(node.name); - if (elementRule) { - for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) { - attrName = elementRule.attributesOrder[i]; - if (attrName in attrs.map) { - attrValue = attrs.map[attrName]; - sortedAttrs.map[attrName] = attrValue; - sortedAttrs.push({ - name: attrName, - value: attrValue - }); - } - } - for (i = 0, l = attrs.length; i < l; i++) { - attrName = attrs[i].name; - if (!(attrName in sortedAttrs.map)) { - attrValue = attrs.map[attrName]; - sortedAttrs.map[attrName] = attrValue; - sortedAttrs.push({ - name: attrName, - value: attrValue - }); - } - } - attrs = sortedAttrs; - } - } - */ + writer.start(node.nodeName, attrs, isEmpty, node); if (isEmpty) { return; diff --git a/docs/src/Roo_HtmlEditorCore.js.html b/docs/src/Roo_HtmlEditorCore.js.html index 806a0ecf8f..3e9daa7a5f 100644 --- a/docs/src/Roo_HtmlEditorCore.js.html +++ b/docs/src/Roo_HtmlEditorCore.js.html @@ -196,7 +196,7 @@ 'IMG { cursor: pointer } ' + '</style>'; - st += '<meta name="google" content="notranslate">' + st += '<meta name="google" content="notranslate">'; var cls = 'notranslate roo-htmleditor-body'; @@ -379,7 +379,7 @@ var tidy = new Roo.htmleditor.TidySerializer({ inner: true }); - var html = tidy.serialize(div) + var html = tidy.serialize(div); if(Roo.isSafari){ diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index 1ca0224ee8..e66fdc2593 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -27175,7 +27175,7 @@ Roo.extend(Roo.htmleditor.BlockFigure, Roo.htmleditor.Block, { tag : 'img', contenteditable : 'false', src : this.image_src, - alt : d.innerText.replace(/\n/g, " "), // removeHTML.. + alt : d.innerText.replace(/\n/g, " ").replace(/\s+/g, ' ').trim(), // removeHTML and reduce spaces.. style: { width : 'auto', 'max-width': '100%', @@ -28723,14 +28723,16 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { st += ''; - - var cls = 'roo-htmleditor-body'; + + st += ''; + + var cls = 'notranslate roo-htmleditor-body'; if(this.bodyCls.length){ cls += ' ' + this.bodyCls; } - return '' + st + + return '' + st + //' + @@ -28857,7 +28859,8 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { * @param {String} html The HTML to be cleaned * return {String} The cleaned HTML */ - cleanHtml : function(html){ + cleanHtml : function(html) + { html = String(html); if(html.length > 5){ if(Roo.isSafari){ // strip safari nonsense @@ -28886,18 +28889,27 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { var bd = (this.doc.body || this.doc.documentElement); + var sel = this.win.getSelection(); var div = document.createElement('div'); div.innerHTML = bd.innerHTML; - + var gtx = div.getElementsByClassName('gtx-trans-icon'); // google translate - really annoying and difficult to get rid of. + if (gtx.length > 0) { + var rm = gtx.item(0).parentNode; + rm.parentNode.removeChild(rm); + } + if (this.enableBlocks) { new Roo.htmleditor.FilterBlock({ node : div }); } //?? tidy? + var tidy = new Roo.htmleditor.TidySerializer({ + inner: true + }); + var html = tidy.serialize(div); - var html = div.innerHTML; if(Roo.isSafari){ var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element! var m = bs ? bs.match(/text-align:(.*?);/i) : false; @@ -29036,6 +29048,8 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { //var ss = this.el.getStyles( 'background-image', 'background-repeat'); //ss['background-attachment'] = 'fixed'; // w3c dbody.bgProperties = 'fixed'; // ie + dbody.setAttribute("translate", "no"); + //Roo.DomHelper.applyStyles(dbody, ss); Roo.EventManager.on(this.doc, { diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index 16c8e04d2b..1854804461 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1180,7 +1180,7 @@ var b=B();b.image_src=this.getValue();b.updateElement();D();A.editorcore.onEdito var b=B();b.width=r.get('val');b.updateElement();D();A.editorcore.onEditorEvent();}},xns:C.form,store:{xtype:'SimpleStore',data:[['auto'],['50%'],['100%']],fields:['val'],xns:Roo.data}},{xtype:'TextItem',text:"Align: ",xns:C.Toolbar},{xtype:'ComboBox',allowBlank:false,displayField:'val',editable:true,listWidth:100,triggerAction:'all',typeAhead:true,valueField:'val',width:70,name:'align',listeners:{select:function(F,r,G){A.editorcore.selectNode(A.tb.selectedNode); var b=B();b.align=r.get('val');b.updateElement();D();A.editorcore.onEditorEvent();}},xns:C.form,store:{xtype:'SimpleStore',data:[['left'],['right'],['center']],fields:['val'],xns:Roo.data}},{xtype:'Button',text:'Hide Caption',name:'caption_display',pressed:false,enableToggle:true,setValue:function(v){this.toggle(v=='block'?false:true); },listeners:{toggle:function(F,G){var b=B();b.caption_display=b.caption_display=='block'?'none':'block';this.setText(b.caption_display=='block'?"Hide Caption":"Show Caption");b.updateElement();D();A.editorcore.selectNode(A.tb.selectedNode);A.editorcore.onEditorEvent(); -}},xns:C.Toolbar}];},toObject:function(){var d=document.createElement('div');d.innerHTML=this.caption;var m=this.width=='50%'&&this.align=='center'?'0 auto':0;var A={tag:'img',contenteditable:'false',src:this.image_src,alt:d.innerText.replace(/\n/g," "),style:{width:'auto','max-width':'100%',margin:'0px'} +}},xns:C.Toolbar}];},toObject:function(){var d=document.createElement('div');d.innerHTML=this.caption;var m=this.width=='50%'&&this.align=='center'?'0 auto':0;var A={tag:'img',contenteditable:'false',src:this.image_src,alt:d.innerText.replace(/\n/g," ").replace(/\s+/g,' ').trim(),style:{width:'auto','max-width':'100%',margin:'0px'} };if(this.href.length>0){A={tag:'a',href:this.href,contenteditable:'true',cn:[A]};}if(this.video_url.length>0){A={tag:'div',cls:this.cls,frameborder:0,allowfullscreen:true,width:420,height:315,src:this.video_url,cn:[A]};}return {tag:'figure','data-block':'Figure',contenteditable:'false',style:{display:'block',float:this.align,'max-width':this.width,width:'auto',margin:m,padding:'10px'} ,align:this.align,cn:[A,{tag:'figcaption',contenteditable:true,style:{'text-align':'left','margin-top':'16px','font-size':'16px','line-height':'24px','font-style':'italic',display:this.caption_display},cls:this.cls.length>0?(this.cls+'-thumbnail'):'',html:this.caption} ]};},readElement:function(A){this.video_url=this.getVal(A,'div','src');this.cls=this.getVal(A,'div','class');this.href=this.getVal(A,'a','href');this.image_src=this.getVal(A,'img','src');this.align=this.getVal(A,'figure','align');this.caption=this.getVal(A,'figcaption','html'); @@ -1240,24 +1240,24 @@ if(c.col!=this.cellData.col){A[i][this.cellData.col].colspan--;}else if(c.colspa Roo.HtmlEditorCore=function(A){Roo.HtmlEditorCore.superclass.constructor.call(this,A);this.addEvents({initialize:true,activate:true,beforesync:true,beforepush:true,sync:true,push:true,editorevent:true});this.applyBlacklists();};Roo.extend(Roo.HtmlEditorCore,Roo.Component,{owner:false,resizable:false,height:300,width:500,autoClean:true,enableBlocks:true,stylesheets:false,language:'en',allowComments:false,frameId:false,validationEvent:false,deferHeight:true,initialized:false,activated:false,sourceEditMode:false,onFocus:Roo.emptyFn,iframePad:3,hideMode:'offsets',clearUp:true,black:false,white:false,bodyCls:'',undoManager:false,getDocMarkup:function(){var st=''; if(this.stylesheets===false){Roo.get(document.head).select('style').each(function(B){st+=B.dom.outerHTML||new XMLSerializer().serializeToString(B.dom);});Roo.get(document.head).select('link').each(function(B){st+=B.dom.outerHTML||new XMLSerializer().serializeToString(B.dom); });}else if(!this.stylesheets.length){st='';}else{for(var i in this.stylesheets){if(typeof(this.stylesheets[i])!='string'){continue;}st+=''; -}}st+='';var A='roo-htmleditor-body';if(this.bodyCls.length){A+=' '+this.bodyCls;}return ''+st+' '; +}}st+='';st+='';var A='notranslate roo-htmleditor-body';if(this.bodyCls.length){A+=' '+this.bodyCls;}return ''+st+' '; },onRender:function(ct,A){var _t=this;this.el=this.owner.inputEl?this.owner.inputEl():this.owner.el;this.el.dom.style.border='0 none';this.el.dom.setAttribute('tabIndex',-1);this.el.addClass('x-hidden hide');if(Roo.isIE){this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')} this.frameId=Roo.id();var B=this.owner.wrap.createChild({tag:'iframe',cls:'form-control',id:this.frameId,name:this.frameId,frameBorder:'no','src':Roo.SSL_SECURE_URL?Roo.SSL_SECURE_URL:"javascript:false"},this.el);this.iframe=B.dom;this.assignDocWin();this.doc.designMode='on'; this.doc.open();this.doc.write(this.getDocMarkup());this.doc.close();var C={run:function(){this.assignDocWin();if(this.doc.body||this.doc.readyState=='complete'){try{this.doc.designMode="on";}catch(e){return;}Roo.TaskMgr.stop(C);this.initEditor.defer(10,this); }},interval:10,duration:10000,scope:this};Roo.TaskMgr.start(C);},onResize:function(w,h){Roo.log('resize: '+w+','+h);if(!this.iframe){return;}if(typeof w=='number'){this.iframe.style.width=w+'px';}if(typeof h=='number'){this.iframe.style.height=h+'px';if(this.doc){(this.doc.body||this.doc.documentElement).style.height=(h-(this.iframePad*2))+'px'; }}},toggleSourceEdit:function(A){this.sourceEditMode=A===true;if(this.sourceEditMode){Roo.get(this.iframe).addClass(['x-hidden','hide','d-none']);}else{Roo.get(this.iframe).removeClass(['x-hidden','hide','d-none']);this.deferFocus();}},cleanHtml:function(A){A=String(A); if(A.length>5){if(Roo.isSafari){A=A.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi,'');}}if(A==' '){A='';}return A;},syncValue:function(){if(this.initialized){this.undoManager.addEvent();var bd=(this.doc.body||this.doc.documentElement); -var A=document.createElement('div');A.innerHTML=bd.innerHTML;if(this.enableBlocks){new Roo.htmleditor.FilterBlock({node:A});}var B=A.innerHTML;if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){B='
'+B+'
'; -}}B=this.cleanHtml(B);B=B.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g,function(C){var cc=C.charCodeAt();if(C.length==2){var D=C.charCodeAt(0)-0xD800;var E=C.charCodeAt(1)-0xDC00;cc=(D*0x400)+E+0x10000;}else if((cc>=0x4E00&&cc<0xA000)||(cc>=0x3400&&cc<0x4E00)||(cc>=0xf900&&cc<0xfb00)){return C; -}return "&#"+cc+";";});if(this.owner.fireEvent('beforesync',this,B)!==false){this.el.dom.value=B;this.owner.fireEvent('sync',this,B);}}},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});}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';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} -);if(Roo.isGecko){Roo.EventManager.on(this.doc,'keypress',this.mozKeyPress,this);}if(Roo.isIE||Roo.isSafari||Roo.isOpera){Roo.EventManager.on(this.doc,'keydown',this.fixKeys,this);}this.initialized=true;new Roo.htmleditor.KeyEnter({core:this});this.owner.fireEvent('initialize',this); -this.pushValue();},onPasteEvent:function(e,v){var cd=(e.browserEvent.clipboardData||window.clipboardData);if(cd.files.length>0){var A=(window.createObjectURL&&window)||(window.URL&&URL.revokeObjectURL&&URL)||(window.webkitURL&&webkitURL);var B=A.createObjectURL(cd.files[0]); -this.insertAtCursor('');return false;}var C=cd.getData('text/html');var D=new Roo.rtf.Parser(cd.getData('text/rtf'));var E=D.doc?D.doc.getElementsByType('pict'):[];Roo.log(E);E=E.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable)/); +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){new Roo.htmleditor.FilterBlock({node:B} +);}var D=new Roo.htmleditor.TidySerializer({inner:true});var E=D.serialize(B);if(Roo.isSafari){var bs=bd.getAttribute('style');var m=bs?bs.match(/text-align:(.*?);/i):false;if(m&&m[1]){E='
'+E+'
';}}E=this.cleanHtml(E);E=E.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,E)!==false){this.el.dom.value=E; +this.owner.fireEvent('sync',this,E);}}},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});}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});if(Roo.isGecko){Roo.EventManager.on(this.doc,'keypress',this.mozKeyPress,this);}if(Roo.isIE||Roo.isSafari||Roo.isOpera){Roo.EventManager.on(this.doc,'keydown',this.fixKeys,this);}this.initialized=true; +new Roo.htmleditor.KeyEnter({core:this});this.owner.fireEvent('initialize',this);this.pushValue();},onPasteEvent:function(e,v){var cd=(e.browserEvent.clipboardData||window.clipboardData);if(cd.files.length>0){var A=(window.createObjectURL&&window)||(window.URL&&URL.revokeObjectURL&&URL)||(window.webkitURL&&webkitURL); +var B=A.createObjectURL(cd.files[0]);this.insertAtCursor('');return false;}var C=cd.getData('text/html');var D=new Roo.rtf.Parser(cd.getData('text/rtf'));var E=D.doc?D.doc.getElementsByType('pict'):[];Roo.log(E);E=E.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable)/); }).map(function(g){return g.toDataURL();});C=this.cleanWordChars(C);var d=(new DOMParser().parseFromString(C,'text/html')).body;var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables"); return false;}if(E.length>0){Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',E[i]);});}if(this.autoClean){new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align'],attrib_clean:['href','src']} );new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return; -- 2.39.2