roojs-bootstrap.js
authorAlan <alan@roojs.com>
Thu, 16 Feb 2023 07:52:24 +0000 (15:52 +0800)
committerAlan <alan@roojs.com>
Thu, 16 Feb 2023 07:52:24 +0000 (15:52 +0800)
roojs-bootstrap-debug.js
Roo/bootstrap/form/HtmlEditorToolbar/Standard.js

Roo/bootstrap/form/HtmlEditorToolbar/Standard.js
roojs-bootstrap-debug.js
roojs-bootstrap.js

index 9cda23e..4efd23b 100644 (file)
@@ -300,8 +300,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
         btns.get('link').setActive(tn == 'A');
         
         Roo.bootstrap.menu.Manager.hideAll();
-        
-        
+         
         
         Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e) {
             e.classList.remove('roo-ed-selection');
index de3b5b8..10862b7 100644 (file)
@@ -33009,11 +33009,20 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
         btn('align-center', 'justifycenter',true);
         btn('align-right' , 'justifyright',true);
         btn('link', false, true, function(btn) {
-            
-            Roo.bootstrap.MessageBox.prompt(
-                "Add / Edit Link URL",
-                "Enter the URL for the link",
-                function(pressed, url) {
+            var url = this.selectedNode && this.selectedNode.tagName.toUpperCase() == 'A' ?
+                    this.selectedNode.getAttribute('url') : '';
+                
+            Roo.bootstrap.MessageBox.show({
+                title : "Add / Edit Link URL",
+                msg : "Enter the URL for the link",
+                buttons: this.OKCANCEL,
+                minWidth: 250,
+                scope : scope,
+                prompt:true,
+                multiline: false,
+                modal : true,
+                value : url,
+                fn:  function(pressed, url) {
                     if (pressed != 'ok') {
                         return;
                     }
@@ -33022,7 +33031,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
                         this.editorcore.relayCmd('createlink', url);
                     }
                 }
-            );
+            });
         });
         btn('list','insertunorderedlist',true);
         btn('list-ol','insertorderedlist',true);
@@ -33111,6 +33120,43 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp
             sel = ev.target;
             
         }
+        
+        var ans = this.editorcore.getAllAncestors();
+        if (!sel) { 
+            sel = ans.length ? (ans[0] ?  ans[0]  : ans[1]) : this.editorcore.doc.body;
+            sel = sel ? sel : this.editorcore.doc.body;
+            sel = sel.tagName.length ? sel : this.editorcore.doc.body;
+            
+        }
+        
+        var tn = sel.tagName.toUpperCase();
+        var lastSel = this.selectedNode;
+        this.selectedNode = sel;
+         
+        // ok see if we are editing a block?
+        
+        var db = false;
+        // you are not actually selecting the block.
+        if (sel && sel.hasAttribute('data-block')) {
+            db = sel;
+        } else if (sel && sel.closest('[data-block]')) {
+            db = sel.closest('[data-block]');
+        }
+        
+       
+        var block = false;
+        if (db && this.editorcore.enableBlocks) {
+            block = Roo.htmleditor.Block.factory(db);
+            
+            if (block) {
+                db.className = (
+                        db.classList.length > 0  ? db.className + ' ' : ''
+                    )  + 'roo-ed-selection';
+                this.selectedNode = db;
+            }
+        }
+        
+        // highlight the 'a'..
         var tn = sel && sel.tagName.toUpperCase() || '';
         if (sel && tn != 'A') {
             var asel = sel.closest('A');
index feb861d..41b1247 100644 (file)
@@ -1417,13 +1417,16 @@ Roo.bootstrap.form.HtmlEditorToolbar.Standard=function(A){Roo.apply(this,A);this
 this.editor=A.editor;this.editorcore=A.editor.editorcore;this.buttons=new Roo.util.MixedCollection(false,function(o){return o.btnid;});};Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard,Roo.bootstrap.nav.Simplebar,{bar:true,editor:false,editorcore:false,formats:["p","h1","h2","h3","h4","h5","h6","pre","code","abbr","acronym","address","cite","samp","var",'div','span'],deleteBtn:false,onRender:function(ct,A){Roo.bootstrap.form.HtmlEditorToolbar.Standard.superclass.onRender.call(this,ct,A);
 Roo.log(this.el);this.el.dom.style.marginBottom='0';var B=this;var C=this.editorcore;var D=this.editor;var E=[];var F=function(id,G,H,I,J){var K=H?'toggle':'click';var a={size:'sm',xtype:'Button',xns:Roo.bootstrap,btnid:id,fa:id,cmd:G,enableToggle:H!==false,html:J||'',pressed:H?false:null,listeners:{}
 };a.listeners[H?'toggle':'click']=function(){I?I.call(B,this):B.onBtnClick.call(B,G||id);};E.push(a);return a;};var style={xtype:'Button',size:'sm',xns:Roo.bootstrap,fa:'font',menu:{xtype:'Menu',xns:Roo.bootstrap,items:[]}};Roo.each(this.formats,function(f){style.menu.items.push({xtype:'MenuItem',xns:Roo.bootstrap,html:'<'+f+' style="margin:2px">'+f+'</'+f+'>',tagname:f,listeners:{click:function(){C.insertTag(this.tagname);
-D.focus();}}});});E.push(style);F('bold',false,true);F('italic',false,true);F('align-left','justifyleft',true);F('align-center','justifycenter',true);F('align-right','justifyright',true);F('link',false,true,function(G){Roo.bootstrap.MessageBox.prompt("Add / Edit Link URL","Enter the URL for the link",function(H,I){if(H!='ok'){return;
-}if(I&&I.match(/http(s):\/\/.+/)){this.editorcore.relayCmd('createlink',I);}});});F('list','insertunorderedlist',true);F('list-ol','insertorderedlist',true);F('pencil',false,true,function(G){Roo.log(this);this.toggleSourceEdit(G.pressed);});if(this.editor.btns.length>0){for(var i=0;
-i<this.editor.btns.length;i++){E.push(this.editor.btns[i]);}}this.xtype='NavSimplebar';for(var i=0;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)}
+D.focus();}}});});E.push(style);F('bold',false,true);F('italic',false,true);F('align-left','justifyleft',true);F('align-center','justifycenter',true);F('align-right','justifyright',true);F('link',false,true,function(G){var H=this.selectedNode&&this.selectedNode.tagName.toUpperCase()=='A'?this.selectedNode.getAttribute('url'):'';
+Roo.bootstrap.MessageBox.show({title:"Add / Edit Link URL",msg:"Enter the URL for the link",buttons:this.OKCANCEL,minWidth:250,scope:scope,prompt:true,multiline:false,modal:true,value:H,fn:function(I,J){if(I!='ok'){return;}if(J&&J.match(/http(s):\/\/.+/)){this.editorcore.relayCmd('createlink',J);
+}}});});F('list','insertunorderedlist',true);F('list-ol','insertorderedlist',true);F('pencil',false,true,function(G){Roo.log(this);this.toggleSourceEdit(G.pressed);});if(this.editor.btns.length>0){for(var i=0;i<this.editor.btns.length;i++){E.push(this.editor.btns[i]);
+}}this.xtype='NavSimplebar';for(var i=0;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();},onBtnClick:function(id){this.editorcore.relayCmd(id);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||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 tn=B&&B.tagName.toUpperCase()||'';
-if(B&&tn!='A'){var F=B.closest('A');if(F){B=F;}}C.get('link').setActive(tn=='A');Roo.bootstrap.menu.Manager.hideAll();Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e){e.classList.remove('roo-ed-selection');});
-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;
+C.each(function(e){if(e.enableToggle&&e.cmd){E=E||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;}var tn=B.tagName.toUpperCase();var G=this.selectedNode;this.selectedNode=B;var db=false;if(B&&B.hasAttribute('data-block')){db=B;
+}else if(B&&B.closest('[data-block]')){db=B.closest('[data-block]');}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';this.selectedNode=db;
+}}var tn=B&&B.tagName.toUpperCase()||'';if(B&&tn!='A'){var I=B.closest('A');if(I){B=I;}}C.get('link').setActive(tn=='A');Roo.bootstrap.menu.Manager.hideAll();Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e){e.classList.remove('roo-ed-selection');
+});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(tb.selectedNode);if(C){C.removeNode();B.removeAllRanges();B.addRange(A);this.updateToolbar(null,null,null);}}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);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);}});