From d6ef67a635e53c5d2d29c727792c155b41f263f1 Mon Sep 17 00:00:00 2001 From: leon Date: Mon, 27 Mar 2023 11:27:18 +0800 Subject: [PATCH] fix #7605 - revamp_image_managment_code --- Roo/bootstrap/Component.js | 2 +- Roo/bootstrap/form/HtmlEditor.js | 1 + Roo/bootstrap/form/HtmlEditorToolbar/Standard.js | 6 ++++-- roojs-bootstrap-debug.js | 9 ++++++--- roojs-bootstrap.js | 14 +++++++------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Roo/bootstrap/Component.js b/Roo/bootstrap/Component.js index 3279787574..a533a00816 100644 --- a/Roo/bootstrap/Component.js +++ b/Roo/bootstrap/Component.js @@ -360,7 +360,7 @@ Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, { if (!skip_children) { for(var i =0;i < items.length;i++) { // Roo.log(['add child', items[i]]); - nitems.push(cn.addxtype(Roo.apply({}, items[i]))); + nitems.push(cn.addxtype(items[i].xns == false ? items[i] : Roo.apply({}, items[i]))); } } diff --git a/Roo/bootstrap/form/HtmlEditor.js b/Roo/bootstrap/form/HtmlEditor.js index 448413edc6..3e659339cf 100644 --- a/Roo/bootstrap/form/HtmlEditor.js +++ b/Roo/bootstrap/form/HtmlEditor.js @@ -122,6 +122,7 @@ Roo.bootstrap.form.HtmlEditor = function(config){ * Fires when on any editor when an image is deleted * @param {Roo.bootstrap.form.HtmlEditor} this * @param {HTMLElement} img could also be a figure if blocks are enabled + * @param {HTMLElement} oldSrc source of image being replaced */ imagedelete: true }); diff --git a/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js b/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js index 1ae985461b..dcea277dd7 100644 --- a/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js +++ b/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js @@ -253,12 +253,13 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp var reader = new FileReader(); reader.addEventListener('load', (function() { if (bl) { + var oldSrc = bl.image_src; bl.image_src = reader.result; //bl.caption = f.name; bl.updateElement(sn); this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); - editor.owner.fireEvent('imageupdate', editor.owner, sn); + editor.owner.fireEvent('imageupdate', editor.owner, sn, oldSrc); // we only do the first file!! and replace. return; } @@ -274,10 +275,11 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp } // just a standard img.. if (sn && sn.tagName.toUpperCase() == 'IMG') { + var oldSrc = sn.src; sn.src = reader.result; this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); - editor.owner.fireEvent('imageupdate', editor.owner, sn); + editor.owner.fireEvent('imageupdate', editor.owner, sn, oldSrc); return; } editor.insertAtCursor(''); diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index acd4889e03..87455f0173 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -580,7 +580,7 @@ Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, { if (!skip_children) { for(var i =0;i < items.length;i++) { // Roo.log(['add child', items[i]]); - nitems.push(cn.addxtype(Roo.apply({}, items[i]))); + nitems.push(cn.addxtype(items[i].xns == false ? items[i] : Roo.apply({}, items[i]))); } } @@ -32581,6 +32581,7 @@ Roo.bootstrap.form.HtmlEditor = function(config){ * Fires when on any editor when an image is deleted * @param {Roo.bootstrap.form.HtmlEditor} this * @param {HTMLElement} img could also be a figure if blocks are enabled + * @param {HTMLElement} oldSrc source of image being replaced */ imagedelete: true }); @@ -33166,12 +33167,13 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp var reader = new FileReader(); reader.addEventListener('load', (function() { if (bl) { + var oldSrc = bl.image_src; bl.image_src = reader.result; //bl.caption = f.name; bl.updateElement(sn); this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); - editor.owner.fireEvent('imageupdate', editor.owner, sn); + editor.owner.fireEvent('imageupdate', editor.owner, sn, oldSrc); // we only do the first file!! and replace. return; } @@ -33187,10 +33189,11 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp } // just a standard img.. if (sn && sn.tagName.toUpperCase() == 'IMG') { + var oldSrc = sn.src; sn.src = reader.result; this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); - editor.owner.fireEvent('imageupdate', editor.owner, sn); + editor.owner.fireEvent('imageupdate', editor.owner, sn, oldSrc); return; } editor.insertAtCursor(''); diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index f79404aaaa..01e8bee139 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -38,9 +38,9 @@ var E=Roo.XComponent.build_from_html;var F=(A.xtype=='Body');var G=(Roo.get(docu skip_children=false;if(!C){if(!this[B](true)){A.items=[];return A;}cn=Roo.factory(A);cn.parentType=this.xtype;cn.parentId=this.id;var E=Roo.XComponent.build_from_html;if(E&&Roo.get(document.body).attr('xtype')=='Roo.bootstrap.Body'){var F=Roo.get(this[B](false)); var G=F?F.child('>*[xtype]'):false;if(G){}if(G&&G.attr('xtype').split('.').pop()==cn.xtype){cn.el=G;}else{Roo.debug&&Roo.log("MISSING "+cn.xtype+" on child of "+(this.el?this.el.attr('xbuilderid'):'no parent'));Roo.debug&&Roo.log(F);Roo.debug&&Roo.log(G); Roo.debug&&Roo.log(cn);}}if(E&&D&&!cn.el&&cn.can_build_overlaid){Roo.debug&&Roo.log('skipping render');Roo.debug&&Roo.log(A);if(!cn.el){Roo.debug&&Roo.log('skipping all children');skip_children=true;}}else{cn.render&&cn.render(this[B](true));}}var H=[];if(!A.items||!A.items.length){cn.items=H; -return cn;}var I=A.items;delete A.items;if(!skip_children){for(var i=0;i'); -this.addFiles(A,true);}).createDelegate(this));D.readAsDataURL(f);},onBtnClick:function(id){this.editorcore.relayCmd(id);this.editorcore.focus();},onLinkClick:function(A){var B=this.selectedNode&&this.selectedNode.tagName.toUpperCase()=='A'?this.selectedNode.getAttribute('href'):''; -Roo.bootstrap.MessageBox.show({title:"Add / Edit Link URL",msg:"Enter the URL for the link",buttons:Roo.bootstrap.MessageBox.OKCANCEL,minWidth:250,scope:this,prompt:true,multiline:false,modal:true,value:B,fn:function(C,D){if(C!='ok'){this.editorcore.focus(); +var D=new FileReader();D.addEventListener('load',(function(){if(bl){var E=bl.image_src;bl.image_src=D.result;bl.updateElement(sn);this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn,E);return;} +if(this.editorcore.enableBlocks){var F=new Roo.htmleditor.BlockFigure({image_src:D.result,caption:'',caption_display:'none'});C.insertAtCursor(F.toHTML());this.addFiles(A,true);return;}if(sn&&sn.tagName.toUpperCase()=='IMG'){var E=sn.src;sn.src=D.result;this.editor.syncValue(); +C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn,E);return;}C.insertAtCursor('');this.addFiles(A,true);}).createDelegate(this));D.readAsDataURL(f);},onBtnClick:function(id){this.editorcore.relayCmd(id); +this.editorcore.focus();},onLinkClick:function(A){var B=this.selectedNode&&this.selectedNode.tagName.toUpperCase()=='A'?this.selectedNode.getAttribute('href'):'';Roo.bootstrap.MessageBox.show({title:"Add / Edit Link URL",msg:"Enter the URL for the link",buttons:Roo.bootstrap.MessageBox.OKCANCEL,minWidth:250,scope:this,prompt:true,multiline:false,modal:true,value:B,fn:function(C,D){if(C!='ok'){this.editorcore.focus(); return;}if(B!=''){this.selectedNode.setAttribute('href',D);return;}if(D&&D.match(/http(s):\/\/.+/)){this.editorcore.relayCmd('createlink',D);}this.editorcore.focus();}});},updateToolbar:function(A,ev,B){if(!this.editorcore.activated){this.editor.onFirstFocus(); return;}var C=this.buttons;var D=this.editorcore.doc;var E=false;C.each(function(e){if(e.enableToggle&&e.cmd){E=E||(['align-left','align-right','align-center','image','link','underline'].indexOf(e.btnid)<0&&D.queryCommandState(e.cmd));e.setActive(D.queryCommandState(e.cmd)); }},this);if(ev&&(ev.type=='mouseup'||ev.type=='click')&&ev.target&&ev.target.tagName!='BODY'){B=ev.target;}var F=this.editorcore.getAllAncestors();if(!B){B=F.length?(F[0]?F[0]:F[1]):this.editorcore.doc.body;B=B?B:this.editorcore.doc.body;B=B.tagName.length?B:this.editorcore.doc.body; -- 2.39.2