roojs-ui.js
authorAlan Knowles <alan@roojs.com>
Mon, 21 Dec 2015 08:15:05 +0000 (16:15 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 21 Dec 2015 08:15:05 +0000 (16:15 +0800)
roojs-ui-debug.js
roojs-all.js
roojs-debug.js

roojs-all.js
roojs-debug.js
roojs-ui-debug.js
roojs-ui.js

index 98eb234..97978de 100644 (file)
@@ -907,11 +907,14 @@ A.collapse(true);C.collapse(true);var ss=A.compareBoundaryPoints(Range.START_TO_
 A.parentNode.removeChild(A);return;}if(!A.attributes||!A.attributes.length){this.cleanUpChildren(A);return;}function cleanAttr(n,v){if(v.match(/^\./)||v.match(/^\//)){return;}if(v.match(/^(http|https):\/\//)||v.match(/^mailto:/)){return;}if(v.match(/^#/)){return;}
 A.removeAttribute(n);}var D=this.cwhite;var E=this.cblack;function cleanStyle(n,v){if(v.match(/expression/)){A.removeAttribute(n);return;}var F=v.split(/;/);var G=[];Roo.each(F,function(p){p=p.replace(/^\s+/g,'').replace(/\s+$/g,'');if(!p.length){return true;}var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\s+$/g,'');if(D.length&&E.indexOf(l)>-1){return true;}if(D.length&&D.indexOf(l)<0){return true;}
 G.push(p);return true;});if(G.length){A.setAttribute(n,G.join(';'));}else {A.removeAttribute(n);}}for(var i=A.attributes.length-1;i>-1;i--){var a=A.attributes[i];if(a.name.toLowerCase().substr(0,2)=='on'){A.removeAttribute(a.name);continue;}if(Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase())>-1){A.removeAttribute(a.name);continue;}if(Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase())>-1){cleanAttr(a.name,a.value);continue;}if(a.name=='style'){cleanStyle(a.name,a.value);continue;}if(a.name=='class'){if(a.value.match(/^Mso/)){A.className='';}if(a.value.match(/body/)){A.className='';}continue;}}
-this.cleanUpChildren(A);},cleanWord:function(A){var _t=this;var B=function(){if(!A.childNodes.length){return;}for(var i=A.childNodes.length-1;i>-1;i--){_t.cleanWord(A.childNodes[i]);}};if(!A){this.cleanWord(this.doc.body);return;}if(A.nodeName=="#text"){return;}if(A.nodeName=="#comment"){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0];A.removeChild(cn);A.parentNode.insertBefore(cn,A);}
-A.parentNode.removeChild(A);B();return;}if(A.className.length){var cn=A.className.split(/\W+/);var cna=[];Roo.each(cn,function(C){if(C.match(/Mso[a-zA-Z]+/)){return;}
-cna.push(C);});A.className=cna.length?cna.join(' '):'';if(!cna.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var styles=A.getAttribute("style").split(";");var nstyle=[];Roo.each(styles,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}
-nstyle.push(s);});A.setAttribute("style",nstyle.length?nstyle.join(';'):'');if(!nstyle.length){A.removeAttribute('style');}}
-B();},domToHTML:function(A,B,C){B=B||0;C=C||false;if(!A){return this.domToHTML(this.doc.body);}var j;var D=false;var E=A.nodeName;var F=Roo.util.Format.htmlEncode(A.tagName);if(E=='#text'){return C?A.nodeValue:A.nodeValue.trim();}var G='';if(E!='BODY'){var i=0;if(F){var H=[];for(i=0;i<A.attributes.length;i++){var I=A.attributes.item(i).name;if(!A.attributes.item(i).value.length){continue;}
+this.cleanUpChildren(A);},cleanWord:function(A){if(!A){this.cleanWord(this.doc.body);return;}if(A.nodeName=="#text"){return;}if(A.nodeName=="#comment"){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0];A.removeChild(cn);A.parentNode.insertBefore(cn,A);}
+A.parentNode.removeChild(A);this.iterateChildren(A,this.cleanWord);return;}if(A.className.length){var cn=A.className.split(/\W+/);var B=[];Roo.each(cn,function(E){if(E.match(/Mso[a-zA-Z]+/)){return;}
+B.push(E);});A.className=B.length?B.join(' '):'';if(!B.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var C=A.getAttribute("style").split(";");var D=[];Roo.each(C,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}
+D.push(s);});A.setAttribute("style",D.length?D.join(';'):'');if(!D.length){A.removeAttribute('style');}}
+this.iterateChildren(A,this.cleanWord);},iterateChildren:function(A,fn){if(!A.childNodes.length){return;}for(var i=A.childNodes.length-1;i>-1;i--){fn.call(this,A.childNodes[i])}},cleanTableWidths:function(A){if(!A){this.cleanTableWidths(this.doc.body);return;}if(A.nodeName=="#text"||A.nodeName=="#comment"){return;}
+Roo.log(A.tagName);if(!A.tagName.toLowerCase().match(/^(table|td|tr)$/)){this.iterateChildren(A,this.cleanTableWidths);return;}if(A.hasAttribute('width')){A.removeAttribute('width');}if(A.hasAttribute("style")){var B=A.getAttribute("style").split(";");var C=[];Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^\s*(width|min-width)\s*$/)){return;}
+C.push(s);});A.setAttribute("style",C.length?C.join(';'):'');if(!C.length){A.removeAttribute('style');}}
+this.iterateChildren(A,this.cleanTableWidths);},domToHTML:function(A,B,C){B=B||0;C=C||false;if(!A){return this.domToHTML(this.doc.body);}var j;var D=false;var E=A.nodeName;var F=Roo.util.Format.htmlEncode(A.tagName);if(E=='#text'){return C?A.nodeValue:A.nodeValue.trim();}var G='';if(E!='BODY'){var i=0;if(F){var H=[];for(i=0;i<A.attributes.length;i++){var I=A.attributes.item(i).name;if(!A.attributes.item(i).value.length){continue;}
 H.push(I+'="'+Roo.util.Format.htmlEncode(A.attributes.item(i).value)+'"');}
 G="<"+A.tagName+(H.length?(' '+H.join(' ')):'')+">";}else {}}else {F=false;}if(['IMG','BR','HR','INPUT'].indexOf(F)>-1){return G;}if(['PRE','TEXTAREA','TD','A','SPAN'].indexOf(F)>-1){C=true;}
 i=0;var J=A.childNodes.item(i);var D=true;var K='';lastnode='';while(J){var L=C;if(lastnode=='SPAN'){L=true;}if(J.nodeName=='#text'){var M=Roo.util.Format.htmlEncode(J.nodeValue);M=C?M:M.trim();if(!L&&M.length>80){K+="\n"+(new Array(B+1)).join("  ");}
@@ -943,7 +946,7 @@ this.wrap.dom.innerHTML='';this.wrap.remove();}},onFirstFocus:function(){this.ed
 Roo.form.HtmlEditor.ToolbarStandard=function(A){Roo.apply(this,A);this.disable=this.disable||{};Roo.applyIf(this.disable,{fontSize:true,colors:true,specialElements:true});}
 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,{tb:false,rendered:false,editor:false,editorcore:false,disable:false,createLinkText:'Please enter the URL for the link:',defaultLinkValue:'http:/'+'/',fontFamilies:['Arial','Courier New','Tahoma','Times New Roman','Verdana'],specialChars:["&#169;","&#174;","&#8482;","&#163;","&#8230;","&#247;","&#8364;","&#176;"],specialElements:[{text:"Insert Table",xtype:'MenuItem',xns:Roo.Menu,ihtml:'<table><tr><td>Cell</td></tr></table>'},{text:"Insert Image",xtype:'MenuItem',xns:Roo.Menu,ihtml:'<img src="about:blank"/>'}],inputElements:["form","input:text","input:hidden","input:checkbox","input:radio","input:password","input:submit","input:button","select","textarea","label"],formats:[["p"],["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],["pre"],["code"],["abbr"],["acronym"],["address"],["cite"],["samp"],["var"],['div'],['span']],cleanStyles:["font-size"],defaultFont:'tahoma',fontSelect:false,formatCombo:false,init:function(A){this.editor=A;this.editorcore=A.editorcore?A.editorcore:A;var B=this.editorcore;var _t=this;var C=B.frameId;var D=this;function btn(id,H,I){var J=C+'-'+id;return {id:J,cmd:id,cls:'x-btn-icon x-edit-'+id,enableToggle:H!==false,scope:_t,handler:I||_t.relayBtnCmd,clickEvent:'mousedown',tooltip:D.buttonTips[id]||undefined,tabIndex:-1};}var tb=new Roo.Toolbar(A.wrap.dom.firstChild);this.tb=tb;tb.el.on('click',function(e){e.preventDefault();});if(!this.disable.font){};if(!this.disable.formats){this.formatCombo=new Roo.form.ComboBox({store:new Roo.data.SimpleStore({id:'tag',fields:['tag'],data:this.formats}),blockFocus:true,name:'',displayField:'tag',typeAhead:false,mode:'local',editable:false,triggerAction:'all',emptyText:'Add tag',selectOnFocus:true,width:135,listeners:{'select':function(c,r,i){B.insertTag(r.get('tag'));A.focus();}}});tb.addField(this.formatCombo);}if(!this.disable.format){tb.add(btn('bold'),btn('italic'),btn('underline'));};if(!this.disable.fontSize){tb.add('-',btn('increasefontsize',false,B.adjustFont),btn('decreasefontsize',false,B.adjustFont));};if(!this.disable.colors){tb.add('-',{id:B.frameId+'-forecolor',cls:'x-btn-icon x-edit-forecolor',clickEvent:'mousedown',tooltip:this.buttonTips['forecolor']||undefined,tabIndex:-1,menu:new Roo.menu.ColorMenu({allowReselect:true,focus:Roo.emptyFn,value:'000000',plain:true,selectHandler:function(cp,H){B.execCmd('forecolor',Roo.isSafari||Roo.isIE?'#'+H:H);A.deferFocus();},scope:B,clickEvent:'mousedown'})},{id:B.frameId+'backcolor',cls:'x-btn-icon x-edit-backcolor',clickEvent:'mousedown',tooltip:this.buttonTips['backcolor']||undefined,tabIndex:-1,menu:new Roo.menu.ColorMenu({focus:Roo.emptyFn,value:'FFFFFF',plain:true,allowReselect:true,selectHandler:function(cp,H){if(Roo.isGecko){B.execCmd('useCSS',false);B.execCmd('hilitecolor',H);B.execCmd('useCSS',true);A.deferFocus();}else {B.execCmd(Roo.isOpera?'hilitecolor':'backcolor',Roo.isSafari||Roo.isIE?'#'+H:H);A.deferFocus();}},scope:B,clickEvent:'mousedown'})});};if(!this.disable.alignments){tb.add('-',btn('justifyleft'),btn('justifycenter'),btn('justifyright'));};if(!this.disable.links){tb.add('-',btn('createlink',false,this.createLink));};if(!this.disable.lists){tb.add('-',btn('insertorderedlist'),btn('insertunorderedlist'));}if(!this.disable.sourceEdit){tb.add('-',btn('sourceedit',true,function(H){this.toggleSourceEdit(H.pressed);}));}var E={};if(!this.disable.special){E={text:"&#169;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialChars.length;i++){E.menu.items.push({html:this.specialChars[i],handler:function(a,b){B.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';','')));},tabIndex:-1});}
 tb.add(E);}var F={};if(!this.disable.cleanStyles){F={cls:'x-btn-icon x-btn-clear',menu:{items:[]}};for(var i=0;i<this.cleanStyles.length;i++){F.menu.items.push({actiontype:this.cleanStyles[i],html:'Remove '+this.cleanStyles[i],handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.style.removeProperty(a.actiontype);});B.syncValue();},tabIndex:-1});}
-F.menu.items.push({actiontype:'word',html:'Remove MS Word Formating',handler:function(a,b){B.cleanWord();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'all',html:'Remove All Styles',handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.removeAttribute('style');});B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'word',html:'Tidy HTML Source',handler:function(a,b){B.doc.body.innerHTML=B.domToHTML();B.syncValue();},tabIndex:-1});tb.add(F);}if(!this.disable.specialElements){var G={text:"Other;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialElements.length;i++){G.menu.items.push(Roo.apply({handler:function(a,b){A.insertAtCursor(this.ihtml);}},this.specialElements[i]));}
+F.menu.items.push({actiontype:'tablewidths',html:'Remove Table Widths',handler:function(a,b){B.cleanTableWidths();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'word',html:'Remove MS Word Formating',handler:function(a,b){B.cleanWord();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'all',html:'Remove All Styles',handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.removeAttribute('style');});B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'tidy',html:'Tidy HTML Source',handler:function(a,b){B.doc.body.innerHTML=B.domToHTML();B.syncValue();},tabIndex:-1});tb.add(F);}if(!this.disable.specialElements){var G={text:"Other;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialElements.length;i++){G.menu.items.push(Roo.apply({handler:function(a,b){A.insertAtCursor(this.ihtml);}},this.specialElements[i]));}
 tb.add(G);}if(this.btns){for(var i=0;i<this.btns.length;i++){var b=Roo.factory(this.btns[i],Roo.form);b.cls='x-edit-none';if(typeof(this.btns[i].cls)!='undefined'&&this.btns[i].cls.indexOf('x-init-enable')!==-1){b.cls+=' x-init-enable';}
 b.scope=B;tb.add(b);}}
 this.tb.items.each(function(H){if(H.id!=B.frameId+'-sourceedit'&&(typeof(H.cls)!='undefined'&&H.cls.indexOf('x-init-enable')===-1)){H.disable();}});this.rendered=true;A.on('editorevent',this.updateToolbar,this);},relayBtnCmd:function(A){this.editorcore.relayCmd(A.cmd);},createLink:function(){Roo.log("create link?");var A=prompt(this.createLinkText,this.defaultLinkValue);if(A&&A!='http:/'+'/'){this.editorcore.relayCmd('createlink',A);}},updateToolbar:function(){if(!this.editorcore.activated){this.editor.onFirstFocus();return;}var A=this.tb.items.map,B=this.editorcore.doc,C=this.editorcore.frameId;if(!this.disable.font&&!Roo.isSafari){}if(!this.disable.format){A[C+'-bold'].toggle(B.queryCommandState('bold'));A[C+'-italic'].toggle(B.queryCommandState('italic'));A[C+'-underline'].toggle(B.queryCommandState('underline'));}if(!this.disable.alignments){A[C+'-justifyleft'].toggle(B.queryCommandState('justifyleft'));A[C+'-justifycenter'].toggle(B.queryCommandState('justifycenter'));A[C+'-justifyright'].toggle(B.queryCommandState('justifyright'));}if(!Roo.isSafari&&!this.disable.lists){A[C+'-insertorderedlist'].toggle(B.queryCommandState('insertorderedlist'));A[C+'-insertunorderedlist'].toggle(B.queryCommandState('insertunorderedlist'));}var D=this.editorcore.getAllAncestors();if(this.formatCombo){var E=this.formatCombo.store;this.formatCombo.setValue("");for(var i=0;i<D.length;i++){if(D[i]&&E.query('tag',D[i].tagName.toLowerCase(),false).length){this.formatCombo.setValue(D[i].tagName.toLowerCase());break;}}}
index c1d9d84..0371de0 100644 (file)
@@ -42249,21 +42249,12 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
         
         
     },
+    
     /**
      * Clean up MS wordisms...
      */
     cleanWord : function(node)
     {
-        var _t = this;
-        var cleanWordChildren = function()
-        {
-            if (!node.childNodes.length) {
-                return;
-            }
-            for (var i = node.childNodes.length-1; i > -1 ; i--) {
-               _t.cleanWord(node.childNodes[i]);
-            }
-        }
         
         
         if (!node) {
@@ -42293,7 +42284,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
                 node.parentNode.insertBefore(cn, node);
             }
             node.parentNode.removeChild(node);
-            cleanWordChildren();
+            this.iterateChildren(node, this.cleanWord);
             return;
         }
         // clean styles
@@ -42337,11 +42328,87 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
                 node.removeAttribute('style');
             }
         }
+        this.iterateChildren(node, this.cleanWord);
+        
+        
+        
+    },
+    /**
+     * iterateChildren of a Node, calling fn each time, using this as the scole..
+     * @param {DomNode} node node to iterate children of.
+     * @param {Function} fn method of this class to call on each item.
+     */
+    iterateChildren : function(node, fn)
+    {
+        if (!node.childNodes.length) {
+                return;
+        }
+        for (var i = node.childNodes.length-1; i > -1 ; i--) {
+           fn.call(this, node.childNodes[i])
+        }
+    },
+    
+    
+    /**
+     * cleanTableWidths.
+     *
+     * Quite often pasting from word etc.. results in tables with column and widths.
+     * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
+     *
+     */
+    cleanTableWidths : function(node)
+    {
+         
+         
+        if (!node) {
+            this.cleanTableWidths(this.doc.body);
+            return;
+        }
+        
+        // ignore list...
+        if (node.nodeName == "#text" || node.nodeName == "#comment") {
+            return; 
+        }
+        Roo.log(node.tagName);
+        if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
+            this.iterateChildren(node, this.cleanTableWidths);
+            return;
+        }
+        if (node.hasAttribute('width')) {
+            node.removeAttribute('width');
+        }
+        
+         
+        if (node.hasAttribute("style")) {
+            // pretty basic...
+            
+            var styles = node.getAttribute("style").split(";");
+            var nstyle = [];
+            Roo.each(styles, function(s) {
+                if (!s.match(/:/)) {
+                    return;
+                }
+                var kv = s.split(":");
+                if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
+                    return;
+                }
+                // what ever is left... we allow.
+                nstyle.push(s);
+            });
+            node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
+            if (!nstyle.length) {
+                node.removeAttribute('style');
+            }
+        }
         
-        cleanWordChildren();
+        this.iterateChildren(node, this.cleanTableWidths);
         
         
     },
+    
+    
+    
+    
     domToHTML : function(currentElement, depth, nopadtext) {
         
         depth = depth || 0;
@@ -43707,6 +43774,15 @@ Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,  {
                     tabIndex:-1
                 });
             }
+             cmenu.menu.items.push({
+                actiontype : 'tablewidths',
+                html: 'Remove Table Widths',
+                handler: function(a,b) {
+                    editorcore.cleanTableWidths();
+                    editorcore.syncValue();
+                },
+                tabIndex:-1
+            });
             cmenu.menu.items.push({
                 actiontype : 'word',
                 html: 'Remove MS Word Formating',
@@ -43731,7 +43807,7 @@ Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,  {
                 tabIndex:-1
             });
              cmenu.menu.items.push({
-                actiontype : 'word',
+                actiontype : 'tidy',
                 html: 'Tidy HTML Source',
                 handler: function(a,b) {
                     editorcore.doc.body.innerHTML = editorcore.domToHTML();
index 8e00287..53ee3d8 100644 (file)
@@ -25803,21 +25803,12 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
         
         
     },
+    
     /**
      * Clean up MS wordisms...
      */
     cleanWord : function(node)
     {
-        var _t = this;
-        var cleanWordChildren = function()
-        {
-            if (!node.childNodes.length) {
-                return;
-            }
-            for (var i = node.childNodes.length-1; i > -1 ; i--) {
-               _t.cleanWord(node.childNodes[i]);
-            }
-        }
         
         
         if (!node) {
@@ -25847,7 +25838,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
                 node.parentNode.insertBefore(cn, node);
             }
             node.parentNode.removeChild(node);
-            cleanWordChildren();
+            this.iterateChildren(node, this.cleanWord);
             return;
         }
         // clean styles
@@ -25891,11 +25882,87 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component,  {
                 node.removeAttribute('style');
             }
         }
+        this.iterateChildren(node, this.cleanWord);
+        
+        
+        
+    },
+    /**
+     * iterateChildren of a Node, calling fn each time, using this as the scole..
+     * @param {DomNode} node node to iterate children of.
+     * @param {Function} fn method of this class to call on each item.
+     */
+    iterateChildren : function(node, fn)
+    {
+        if (!node.childNodes.length) {
+                return;
+        }
+        for (var i = node.childNodes.length-1; i > -1 ; i--) {
+           fn.call(this, node.childNodes[i])
+        }
+    },
+    
+    
+    /**
+     * cleanTableWidths.
+     *
+     * Quite often pasting from word etc.. results in tables with column and widths.
+     * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
+     *
+     */
+    cleanTableWidths : function(node)
+    {
+         
+         
+        if (!node) {
+            this.cleanTableWidths(this.doc.body);
+            return;
+        }
+        
+        // ignore list...
+        if (node.nodeName == "#text" || node.nodeName == "#comment") {
+            return; 
+        }
+        Roo.log(node.tagName);
+        if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
+            this.iterateChildren(node, this.cleanTableWidths);
+            return;
+        }
+        if (node.hasAttribute('width')) {
+            node.removeAttribute('width');
+        }
+        
+         
+        if (node.hasAttribute("style")) {
+            // pretty basic...
+            
+            var styles = node.getAttribute("style").split(";");
+            var nstyle = [];
+            Roo.each(styles, function(s) {
+                if (!s.match(/:/)) {
+                    return;
+                }
+                var kv = s.split(":");
+                if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
+                    return;
+                }
+                // what ever is left... we allow.
+                nstyle.push(s);
+            });
+            node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
+            if (!nstyle.length) {
+                node.removeAttribute('style');
+            }
+        }
         
-        cleanWordChildren();
+        this.iterateChildren(node, this.cleanTableWidths);
         
         
     },
+    
+    
+    
+    
     domToHTML : function(currentElement, depth, nopadtext) {
         
         depth = depth || 0;
@@ -27261,6 +27328,15 @@ Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,  {
                     tabIndex:-1
                 });
             }
+             cmenu.menu.items.push({
+                actiontype : 'tablewidths',
+                html: 'Remove Table Widths',
+                handler: function(a,b) {
+                    editorcore.cleanTableWidths();
+                    editorcore.syncValue();
+                },
+                tabIndex:-1
+            });
             cmenu.menu.items.push({
                 actiontype : 'word',
                 html: 'Remove MS Word Formating',
@@ -27285,7 +27361,7 @@ Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,  {
                 tabIndex:-1
             });
              cmenu.menu.items.push({
-                actiontype : 'word',
+                actiontype : 'tidy',
                 html: 'Tidy HTML Source',
                 handler: function(a,b) {
                     editorcore.doc.body.innerHTML = editorcore.domToHTML();
index 47bb6c7..c4ab55a 100644 (file)
@@ -572,11 +572,14 @@ A.collapse(true);C.collapse(true);var ss=A.compareBoundaryPoints(Range.START_TO_
 A.parentNode.removeChild(A);return;}if(!A.attributes||!A.attributes.length){this.cleanUpChildren(A);return;}function cleanAttr(n,v){if(v.match(/^\./)||v.match(/^\//)){return;}if(v.match(/^(http|https):\/\//)||v.match(/^mailto:/)){return;}if(v.match(/^#/)){return;}
 A.removeAttribute(n);}var D=this.cwhite;var E=this.cblack;function cleanStyle(n,v){if(v.match(/expression/)){A.removeAttribute(n);return;}var F=v.split(/;/);var G=[];Roo.each(F,function(p){p=p.replace(/^\s+/g,'').replace(/\s+$/g,'');if(!p.length){return true;}var l=p.split(':').shift().replace(/\s+/g,'');l=l.replace(/^\s+/g,'').replace(/\s+$/g,'');if(D.length&&E.indexOf(l)>-1){return true;}if(D.length&&D.indexOf(l)<0){return true;}
 G.push(p);return true;});if(G.length){A.setAttribute(n,G.join(';'));}else {A.removeAttribute(n);}}for(var i=A.attributes.length-1;i>-1;i--){var a=A.attributes[i];if(a.name.toLowerCase().substr(0,2)=='on'){A.removeAttribute(a.name);continue;}if(Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase())>-1){A.removeAttribute(a.name);continue;}if(Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase())>-1){cleanAttr(a.name,a.value);continue;}if(a.name=='style'){cleanStyle(a.name,a.value);continue;}if(a.name=='class'){if(a.value.match(/^Mso/)){A.className='';}if(a.value.match(/body/)){A.className='';}continue;}}
-this.cleanUpChildren(A);},cleanWord:function(A){var _t=this;var B=function(){if(!A.childNodes.length){return;}for(var i=A.childNodes.length-1;i>-1;i--){_t.cleanWord(A.childNodes[i]);}};if(!A){this.cleanWord(this.doc.body);return;}if(A.nodeName=="#text"){return;}if(A.nodeName=="#comment"){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0];A.removeChild(cn);A.parentNode.insertBefore(cn,A);}
-A.parentNode.removeChild(A);B();return;}if(A.className.length){var cn=A.className.split(/\W+/);var cna=[];Roo.each(cn,function(C){if(C.match(/Mso[a-zA-Z]+/)){return;}
-cna.push(C);});A.className=cna.length?cna.join(' '):'';if(!cna.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var styles=A.getAttribute("style").split(";");var nstyle=[];Roo.each(styles,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}
-nstyle.push(s);});A.setAttribute("style",nstyle.length?nstyle.join(';'):'');if(!nstyle.length){A.removeAttribute('style');}}
-B();},domToHTML:function(A,B,C){B=B||0;C=C||false;if(!A){return this.domToHTML(this.doc.body);}var j;var D=false;var E=A.nodeName;var F=Roo.util.Format.htmlEncode(A.tagName);if(E=='#text'){return C?A.nodeValue:A.nodeValue.trim();}var G='';if(E!='BODY'){var i=0;if(F){var H=[];for(i=0;i<A.attributes.length;i++){var I=A.attributes.item(i).name;if(!A.attributes.item(i).value.length){continue;}
+this.cleanUpChildren(A);},cleanWord:function(A){if(!A){this.cleanWord(this.doc.body);return;}if(A.nodeName=="#text"){return;}if(A.nodeName=="#comment"){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0];A.removeChild(cn);A.parentNode.insertBefore(cn,A);}
+A.parentNode.removeChild(A);this.iterateChildren(A,this.cleanWord);return;}if(A.className.length){var cn=A.className.split(/\W+/);var B=[];Roo.each(cn,function(E){if(E.match(/Mso[a-zA-Z]+/)){return;}
+B.push(E);});A.className=B.length?B.join(' '):'';if(!B.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var C=A.getAttribute("style").split(";");var D=[];Roo.each(C,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}
+D.push(s);});A.setAttribute("style",D.length?D.join(';'):'');if(!D.length){A.removeAttribute('style');}}
+this.iterateChildren(A,this.cleanWord);},iterateChildren:function(A,fn){if(!A.childNodes.length){return;}for(var i=A.childNodes.length-1;i>-1;i--){fn.call(this,A.childNodes[i])}},cleanTableWidths:function(A){if(!A){this.cleanTableWidths(this.doc.body);return;}if(A.nodeName=="#text"||A.nodeName=="#comment"){return;}
+Roo.log(A.tagName);if(!A.tagName.toLowerCase().match(/^(table|td|tr)$/)){this.iterateChildren(A,this.cleanTableWidths);return;}if(A.hasAttribute('width')){A.removeAttribute('width');}if(A.hasAttribute("style")){var B=A.getAttribute("style").split(";");var C=[];Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^\s*(width|min-width)\s*$/)){return;}
+C.push(s);});A.setAttribute("style",C.length?C.join(';'):'');if(!C.length){A.removeAttribute('style');}}
+this.iterateChildren(A,this.cleanTableWidths);},domToHTML:function(A,B,C){B=B||0;C=C||false;if(!A){return this.domToHTML(this.doc.body);}var j;var D=false;var E=A.nodeName;var F=Roo.util.Format.htmlEncode(A.tagName);if(E=='#text'){return C?A.nodeValue:A.nodeValue.trim();}var G='';if(E!='BODY'){var i=0;if(F){var H=[];for(i=0;i<A.attributes.length;i++){var I=A.attributes.item(i).name;if(!A.attributes.item(i).value.length){continue;}
 H.push(I+'="'+Roo.util.Format.htmlEncode(A.attributes.item(i).value)+'"');}
 G="<"+A.tagName+(H.length?(' '+H.join(' ')):'')+">";}else {}}else {F=false;}if(['IMG','BR','HR','INPUT'].indexOf(F)>-1){return G;}if(['PRE','TEXTAREA','TD','A','SPAN'].indexOf(F)>-1){C=true;}
 i=0;var J=A.childNodes.item(i);var D=true;var K='';lastnode='';while(J){var L=C;if(lastnode=='SPAN'){L=true;}if(J.nodeName=='#text'){var M=Roo.util.Format.htmlEncode(J.nodeValue);M=C?M:M.trim();if(!L&&M.length>80){K+="\n"+(new Array(B+1)).join("  ");}
@@ -608,7 +611,7 @@ this.wrap.dom.innerHTML='';this.wrap.remove();}},onFirstFocus:function(){this.ed
 Roo.form.HtmlEditor.ToolbarStandard=function(A){Roo.apply(this,A);this.disable=this.disable||{};Roo.applyIf(this.disable,{fontSize:true,colors:true,specialElements:true});}
 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,{tb:false,rendered:false,editor:false,editorcore:false,disable:false,createLinkText:'Please enter the URL for the link:',defaultLinkValue:'http:/'+'/',fontFamilies:['Arial','Courier New','Tahoma','Times New Roman','Verdana'],specialChars:["&#169;","&#174;","&#8482;","&#163;","&#8230;","&#247;","&#8364;","&#176;"],specialElements:[{text:"Insert Table",xtype:'MenuItem',xns:Roo.Menu,ihtml:'<table><tr><td>Cell</td></tr></table>'},{text:"Insert Image",xtype:'MenuItem',xns:Roo.Menu,ihtml:'<img src="about:blank"/>'}],inputElements:["form","input:text","input:hidden","input:checkbox","input:radio","input:password","input:submit","input:button","select","textarea","label"],formats:[["p"],["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],["pre"],["code"],["abbr"],["acronym"],["address"],["cite"],["samp"],["var"],['div'],['span']],cleanStyles:["font-size"],defaultFont:'tahoma',fontSelect:false,formatCombo:false,init:function(A){this.editor=A;this.editorcore=A.editorcore?A.editorcore:A;var B=this.editorcore;var _t=this;var C=B.frameId;var D=this;function btn(id,H,I){var J=C+'-'+id;return {id:J,cmd:id,cls:'x-btn-icon x-edit-'+id,enableToggle:H!==false,scope:_t,handler:I||_t.relayBtnCmd,clickEvent:'mousedown',tooltip:D.buttonTips[id]||undefined,tabIndex:-1};}var tb=new Roo.Toolbar(A.wrap.dom.firstChild);this.tb=tb;tb.el.on('click',function(e){e.preventDefault();});if(!this.disable.font){};if(!this.disable.formats){this.formatCombo=new Roo.form.ComboBox({store:new Roo.data.SimpleStore({id:'tag',fields:['tag'],data:this.formats}),blockFocus:true,name:'',displayField:'tag',typeAhead:false,mode:'local',editable:false,triggerAction:'all',emptyText:'Add tag',selectOnFocus:true,width:135,listeners:{'select':function(c,r,i){B.insertTag(r.get('tag'));A.focus();}}});tb.addField(this.formatCombo);}if(!this.disable.format){tb.add(btn('bold'),btn('italic'),btn('underline'));};if(!this.disable.fontSize){tb.add('-',btn('increasefontsize',false,B.adjustFont),btn('decreasefontsize',false,B.adjustFont));};if(!this.disable.colors){tb.add('-',{id:B.frameId+'-forecolor',cls:'x-btn-icon x-edit-forecolor',clickEvent:'mousedown',tooltip:this.buttonTips['forecolor']||undefined,tabIndex:-1,menu:new Roo.menu.ColorMenu({allowReselect:true,focus:Roo.emptyFn,value:'000000',plain:true,selectHandler:function(cp,H){B.execCmd('forecolor',Roo.isSafari||Roo.isIE?'#'+H:H);A.deferFocus();},scope:B,clickEvent:'mousedown'})},{id:B.frameId+'backcolor',cls:'x-btn-icon x-edit-backcolor',clickEvent:'mousedown',tooltip:this.buttonTips['backcolor']||undefined,tabIndex:-1,menu:new Roo.menu.ColorMenu({focus:Roo.emptyFn,value:'FFFFFF',plain:true,allowReselect:true,selectHandler:function(cp,H){if(Roo.isGecko){B.execCmd('useCSS',false);B.execCmd('hilitecolor',H);B.execCmd('useCSS',true);A.deferFocus();}else {B.execCmd(Roo.isOpera?'hilitecolor':'backcolor',Roo.isSafari||Roo.isIE?'#'+H:H);A.deferFocus();}},scope:B,clickEvent:'mousedown'})});};if(!this.disable.alignments){tb.add('-',btn('justifyleft'),btn('justifycenter'),btn('justifyright'));};if(!this.disable.links){tb.add('-',btn('createlink',false,this.createLink));};if(!this.disable.lists){tb.add('-',btn('insertorderedlist'),btn('insertunorderedlist'));}if(!this.disable.sourceEdit){tb.add('-',btn('sourceedit',true,function(H){this.toggleSourceEdit(H.pressed);}));}var E={};if(!this.disable.special){E={text:"&#169;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialChars.length;i++){E.menu.items.push({html:this.specialChars[i],handler:function(a,b){B.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';','')));},tabIndex:-1});}
 tb.add(E);}var F={};if(!this.disable.cleanStyles){F={cls:'x-btn-icon x-btn-clear',menu:{items:[]}};for(var i=0;i<this.cleanStyles.length;i++){F.menu.items.push({actiontype:this.cleanStyles[i],html:'Remove '+this.cleanStyles[i],handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.style.removeProperty(a.actiontype);});B.syncValue();},tabIndex:-1});}
-F.menu.items.push({actiontype:'word',html:'Remove MS Word Formating',handler:function(a,b){B.cleanWord();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'all',html:'Remove All Styles',handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.removeAttribute('style');});B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'word',html:'Tidy HTML Source',handler:function(a,b){B.doc.body.innerHTML=B.domToHTML();B.syncValue();},tabIndex:-1});tb.add(F);}if(!this.disable.specialElements){var G={text:"Other;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialElements.length;i++){G.menu.items.push(Roo.apply({handler:function(a,b){A.insertAtCursor(this.ihtml);}},this.specialElements[i]));}
+F.menu.items.push({actiontype:'tablewidths',html:'Remove Table Widths',handler:function(a,b){B.cleanTableWidths();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'word',html:'Remove MS Word Formating',handler:function(a,b){B.cleanWord();B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'all',html:'Remove All Styles',handler:function(a,b){var c=Roo.get(B.doc.body);c.select('[style]').each(function(s){s.dom.removeAttribute('style');});B.syncValue();},tabIndex:-1});F.menu.items.push({actiontype:'tidy',html:'Tidy HTML Source',handler:function(a,b){B.doc.body.innerHTML=B.domToHTML();B.syncValue();},tabIndex:-1});tb.add(F);}if(!this.disable.specialElements){var G={text:"Other;",cls:'x-edit-none',menu:{items:[]}};for(var i=0;i<this.specialElements.length;i++){G.menu.items.push(Roo.apply({handler:function(a,b){A.insertAtCursor(this.ihtml);}},this.specialElements[i]));}
 tb.add(G);}if(this.btns){for(var i=0;i<this.btns.length;i++){var b=Roo.factory(this.btns[i],Roo.form);b.cls='x-edit-none';if(typeof(this.btns[i].cls)!='undefined'&&this.btns[i].cls.indexOf('x-init-enable')!==-1){b.cls+=' x-init-enable';}
 b.scope=B;tb.add(b);}}
 this.tb.items.each(function(H){if(H.id!=B.frameId+'-sourceedit'&&(typeof(H.cls)!='undefined'&&H.cls.indexOf('x-init-enable')===-1)){H.disable();}});this.rendered=true;A.on('editorevent',this.updateToolbar,this);},relayBtnCmd:function(A){this.editorcore.relayCmd(A.cmd);},createLink:function(){Roo.log("create link?");var A=prompt(this.createLinkText,this.defaultLinkValue);if(A&&A!='http:/'+'/'){this.editorcore.relayCmd('createlink',A);}},updateToolbar:function(){if(!this.editorcore.activated){this.editor.onFirstFocus();return;}var A=this.tb.items.map,B=this.editorcore.doc,C=this.editorcore.frameId;if(!this.disable.font&&!Roo.isSafari){}if(!this.disable.format){A[C+'-bold'].toggle(B.queryCommandState('bold'));A[C+'-italic'].toggle(B.queryCommandState('italic'));A[C+'-underline'].toggle(B.queryCommandState('underline'));}if(!this.disable.alignments){A[C+'-justifyleft'].toggle(B.queryCommandState('justifyleft'));A[C+'-justifycenter'].toggle(B.queryCommandState('justifycenter'));A[C+'-justifyright'].toggle(B.queryCommandState('justifyright'));}if(!Roo.isSafari&&!this.disable.lists){A[C+'-insertorderedlist'].toggle(B.queryCommandState('insertorderedlist'));A[C+'-insertunorderedlist'].toggle(B.queryCommandState('insertunorderedlist'));}var D=this.editorcore.getAllAncestors();if(this.formatCombo){var E=this.formatCombo.store;this.formatCombo.setValue("");for(var i=0;i<D.length;i++){if(D[i]&&E.query('tag',D[i].tagName.toLowerCase(),false).length){this.formatCombo.setValue(D[i].tagName.toLowerCase());break;}}}