sync values before triggering delete
authorAlan <alan@roojs.com>
Fri, 17 Feb 2023 07:36:54 +0000 (15:36 +0800)
committerAlan <alan@roojs.com>
Fri, 17 Feb 2023 07:36:54 +0000 (15:36 +0800)
Roo/bootstrap/form/HtmlEditorToolbar/Standard.js
roojs-bootstrap-debug.js
roojs-bootstrap.js

index 72ccc68..1ae9854 100644 (file)
@@ -231,6 +231,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
   
         if (!far.length) {
             if (fire_add) {
+                this.editor.syncValue();
                 editor.owner.fireEvent('editorevent', editor.owner, false);
                 editor.owner.fireEvent('imageadd', editor.owner, false);
             }
@@ -255,6 +256,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
                 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);
                 // we only do the first file!! and replace.
@@ -273,6 +275,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
             // just a standard img..
             if (sn && sn.tagName.toUpperCase() == 'IMG') {
                 sn.src = reader.result;
+                this.editor.syncValue();
                 editor.owner.fireEvent('editorevent', editor.owner, false);
                 editor.owner.fireEvent('imageupdate', editor.owner, sn);
                 return;
@@ -445,6 +448,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
                 selection.addRange(range);
                 this.updateToolbar(null, null, null);
                 if (sn.tagName.toUpperCase() == 'FIGURE') {
+                    this.editor.syncValue();
                     this.editor.fireEvent('imagedelete', this.editor, sn);
                 }
                 
@@ -469,6 +473,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
         selection.removeAllRanges();
         selection.addRange(range);
         if (sn.tagName.toUpperCase() == 'IMG"') {
+            this.editor.syncValue();
             this.editor.fireEvent('imagedelete', this.editor, sn);
         }
         
index c03f007..e47a90a 100644 (file)
@@ -33134,6 +33134,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
   
         if (!far.length) {
             if (fire_add) {
+                this.editor.syncValue();
                 editor.owner.fireEvent('editorevent', editor.owner, false);
                 editor.owner.fireEvent('imageadd', editor.owner, false);
             }
@@ -33158,6 +33159,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
                 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);
                 // we only do the first file!! and replace.
@@ -33176,6 +33178,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
             // just a standard img..
             if (sn && sn.tagName.toUpperCase() == 'IMG') {
                 sn.src = reader.result;
+                this.editor.syncValue();
                 editor.owner.fireEvent('editorevent', editor.owner, false);
                 editor.owner.fireEvent('imageupdate', editor.owner, sn);
                 return;
@@ -33348,6 +33351,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
                 selection.addRange(range);
                 this.updateToolbar(null, null, null);
                 if (sn.tagName.toUpperCase() == 'FIGURE') {
+                    this.editor.syncValue();
                     this.editor.fireEvent('imagedelete', this.editor, sn);
                 }
                 
@@ -33372,6 +33376,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
         selection.removeAllRanges();
         selection.addRange(range);
         if (sn.tagName.toUpperCase() == 'IMG"') {
+            this.editor.syncValue();
             this.editor.fireEvent('imagedelete', this.editor, sn);
         }
         
index bb37c5d..29c75de 100644 (file)
@@ -1423,9 +1423,9 @@ F('list-ol','insertorderedlist',true);F('pencil',false,true,function(G){Roo.log(
 i<E.length;i++){this.buttons.add(this.addxtypeChild(E[i]));}this.buildToolbarDelete();D.on('editorevent',this.updateToolbar,this);},buildToolbarDelete:function(){this.deleteBtn=this.addxtypeChild({size:'sm',xtype:'Button',xns:Roo.bootstrap,fa:'trash',listeners:{click:this.onDelete.createDelegate(this)}
 });this.deleteBtn.hide();},onImageClick:function(){if(this.input){this.input.un('change',this.onFileSelected,this);}this.input=Roo.get(document.body).createChild({tag:'input',type:'file',style:'display:none',multiple:'multiple'});this.input.on('change',this.onFileSelected,this);
 this.input.dom.click();},onFileSelected:function(e){e.preventDefault();if(typeof(this.input.dom.files)=='undefined'||!this.input.dom.files.length){return;}this.addFiles(Array.prototype.slice.call(this.input.dom.files),false);},addFiles:function(A,B){var C=this.editorcore;
-if(!A.length){if(B){C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageadd',C.owner,false);}return;}var f=A.pop();if(!f.type.match(/^image/)){this.addFiles(A,B);return;}var sn=this.selectedNode;var bl=sn&&this.editorcore.enableBlocks?Roo.htmleditor.Block.factory(sn):false;
-var D=new FileReader();D.addEventListener('load',(function(){if(bl){bl.image_src=D.result;bl.updateElement(sn);C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn);return;}if(this.editorcore.enableBlocks){var E=new Roo.htmleditor.BlockFigure({image_src:D.result,caption:'',caption_display:'none'}
-);C.insertAtCursor(E.toHTML());this.addFiles(A,true);return;}if(sn&&sn.tagName.toUpperCase()=='IMG'){sn.src=D.result;C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn);return;}C.insertAtCursor('<img src="'+D.result+'">');
+if(!A.length){if(B){this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageadd',C.owner,false);}return;}var f=A.pop();if(!f.type.match(/^image/)){this.addFiles(A,B);return;}var sn=this.selectedNode;var bl=sn&&this.editorcore.enableBlocks?Roo.htmleditor.Block.factory(sn):false;
+var D=new FileReader();D.addEventListener('load',(function(){if(bl){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);return;}if(this.editorcore.enableBlocks){var E=new Roo.htmleditor.BlockFigure({image_src:D.result,caption:'',caption_display:'none'}
+);C.insertAtCursor(E.toHTML());this.addFiles(A,true);return;}if(sn&&sn.tagName.toUpperCase()=='IMG'){sn.src=D.result;this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn);return;}C.insertAtCursor('<img src="'+D.result+'">');
 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();
@@ -1435,10 +1435,10 @@ return;}var C=this.buttons;var D=this.editorcore.doc;var E=false;C.each(function
 });var H=false;if(db&&this.editorcore.enableBlocks){H=Roo.htmleditor.Block.factory(db);if(H){db.className=(db.classList.length>0?db.className+' ':'')+' roo-ed-selection';B=this.selectedNode=db;}}var tn=B&&B.tagName.toUpperCase()||'';if(!H&&B&&tn!='A'){var I=B.closest('A');
 if(I){B=I;}}C.get('link').setActive(tn=='A'&&this.selectedNode.hasAttribute('href'));C.get('image').setActive(tn=='IMG'||this.editorcore.enableBlocks&&tn=='FIGURE');C.get('underline').setActive(tn=='U'||B.closest('u')?true:false);Roo.bootstrap.menu.Manager.hideAll();
 if(E||(tn.length&&tn=='BODY')){this.deleteBtn.hide();return;}this.deleteBtn.show();},onFirstFocus:function(){this.buttons.each(function(A){A.enable();});},onDelete:function(){var A=this.editorcore.createRange();var B=this.editorcore.getSelection();var sn=this.selectedNode;
-A.setStart(sn,0);A.setEnd(sn,0);if(sn.hasAttribute('data-block')){var C=Roo.htmleditor.Block.factory(this.selectedNode);if(C){sn=C.removeNode();sn.parentNode.removeChild(sn);B.removeAllRanges();B.addRange(A);this.updateToolbar(null,null,null);if(sn.tagName.toUpperCase()=='FIGURE'){this.editor.fireEvent('imagedelete',this.editor,sn);
-}this.selectedNode=false;this.editorcore.fireEditorEvent(false);return;}}if(!sn){return;}if(sn&&sn.tagName=='BODY'){return;}var D=sn.childNodes[0]||sn.nextSibling||sn.previousSibling||sn.parentNode;a=new Roo.htmleditor.FilterKeepChildren({tag:false});a.replaceTag(sn);
-B.removeAllRanges();B.addRange(A);if(sn.tagName.toUpperCase()=='IMG"'){this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);},toggleSourceEdit:function(A){if(A){Roo.log("disabling buttons");this.buttons.each(function(B){if(B.cmd!='pencil'){B.disable();
-}});}else{Roo.log("enabling buttons");if(this.editorcore.initialized){this.buttons.each(function(B){B.enable();});}}Roo.log("calling toggole on editor");this.editor.toggleSourceEdit(A);}});
+A.setStart(sn,0);A.setEnd(sn,0);if(sn.hasAttribute('data-block')){var C=Roo.htmleditor.Block.factory(this.selectedNode);if(C){sn=C.removeNode();sn.parentNode.removeChild(sn);B.removeAllRanges();B.addRange(A);this.updateToolbar(null,null,null);if(sn.tagName.toUpperCase()=='FIGURE'){this.editor.syncValue();
+this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);return;}}if(!sn){return;}if(sn&&sn.tagName=='BODY'){return;}var D=sn.childNodes[0]||sn.nextSibling||sn.previousSibling||sn.parentNode;a=new Roo.htmleditor.FilterKeepChildren({tag:false}
+);a.replaceTag(sn);B.removeAllRanges();B.addRange(A);if(sn.tagName.toUpperCase()=='IMG"'){this.editor.syncValue();this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);},toggleSourceEdit:function(A){if(A){Roo.log("disabling buttons");
+this.buttons.each(function(B){if(B.cmd!='pencil'){B.disable();}});}else{Roo.log("enabling buttons");if(this.editorcore.initialized){this.buttons.each(function(B){B.enable();});}}Roo.log("calling toggole on editor");this.editor.toggleSourceEdit(A);}});
 // Roo/bootstrap/form/Markdown.js
 Roo.bootstrap.form.Markdown=function(A){Roo.bootstrap.form.Markdown.superclass.constructor.call(this,A);};Roo.extend(Roo.bootstrap.form.Markdown,Roo.bootstrap.form.TextArea,{editing:false,initEvents:function(){Roo.bootstrap.form.TextArea.prototype.initEvents.call(this);
 this.markdownEl=this.el.createChild({cls:'roo-markdown-area'});this.inputEl().addClass('d-none');if(this.getValue()==''){this.markdownEl.dom.innerHTML=String.format('<span class="roo-placeholder">{0}</span>',this.placeholder||'');}else{this.markdownEl.dom.innerHTML=Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue()));