X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FHtmlEditorCore.js;h=9eb3ab65ac68d5c3b31e3796b838f913b5f1476a;hb=61bc45258e16a779856dd2ad0862630b489e4583;hp=94b1ec50a0f61efc61937f4089b61e46c7541a2c;hpb=e6bf1fb0f34ee35ae92eb0c81aa749682350ccad;p=roojs1 diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index 94b1ec50a0..9eb3ab65ac 100644 --- a/Roo/HtmlEditorCore.js +++ b/Roo/HtmlEditorCore.js @@ -133,7 +133,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { black: false, white: false, - + bodyCls : '', /** * Protected method that will not generally be called directly. It @@ -161,19 +161,26 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' + ''; } else { - + st = ''; } st += ''; + var cls = 'roo-htmleditor-body'; + + if(this.bodyCls.length){ + cls += ' ' + this.bodyCls; + } return '' + st + //' + - ' '; + ' '; }, // private @@ -328,17 +335,32 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { html = this.cleanHtml(html); // fix up the special chars.. normaly like back quotes in word... // however we do not want to do this with chinese.. - html = html.replace(/([\x80-\uffff])/g, function (a, b) { - var cc = b.charCodeAt(); - if ( + html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) { + + var cc = match.charCodeAt(); + + // Get the character value, handling surrogate pairs + if (match.length == 2) { + // It's a surrogate pair, calculate the Unicode code point + var high = match.charCodeAt(0) - 0xD800; + var low = match.charCodeAt(1) - 0xDC00; + cc = (high * 0x400) + low + 0x10000; + } else if ( (cc >= 0x4E00 && cc < 0xA000 ) || (cc >= 0x3400 && cc < 0x4E00 ) || (cc >= 0xf900 && cc < 0xfb00 ) ) { - return b; - } - return "&#"+cc+";" + return match; + } + + // No, use a numeric entity. Here we brazenly (and possibly mistakenly) + return "&#" + cc + ";"; + + }); + + + if(this.owner.fireEvent('beforesync', this, html) !== false){ this.el.dom.value = html; this.owner.fireEvent('sync', this, html); @@ -353,7 +375,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { pushValue : function(){ if(this.initialized){ var v = this.el.dom.value.trim(); - Roo.log(v); + // if(v.length < 1){ // v = ' '; // } @@ -522,7 +544,11 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { insertTag : function(tg) { // could be a bit smarter... -> wrap the current selected tRoo.. - if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') { + if (tg.toLowerCase() == 'span' || + tg.toLowerCase() == 'code' || + tg.toLowerCase() == 'sup' || + tg.toLowerCase() == 'sub' + ) { range = this.createRange(this.getSelection()); var wrappingNode = this.doc.createElement(tg.toLowerCase()); @@ -1018,6 +1044,11 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1; + // spans with no attributes - just remove them.. + if ((!node.attributes || !node.attributes.length) && lcname == 'span') { + remove_keep_children = true; + } + // remove as rendering on yahoo mailer is borked with this. // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer.. @@ -1038,6 +1069,10 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { } if (!node.attributes || !node.attributes.length) { + + + + this.cleanUpChildren(node); return; } @@ -1048,7 +1083,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { if (v.match(/^\./) || v.match(/^\//)) { return; } - if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) { + if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) { return; } if (v.match(/^#/)) { @@ -1134,11 +1169,11 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { if (a.name == 'class') { if (a.value.match(/^Mso/)) { - node.className = ''; + node.removeAttribute('class'); } - if (a.value.match(/body/)) { - node.className = ''; + if (a.value.match(/^body$/)) { + node.removeAttribute('class'); } continue; } @@ -1159,12 +1194,29 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { */ cleanWord : function(node) { - - if (!node) { this.cleanWord(this.doc.body); return; } + + if( + node.nodeName == 'SPAN' && + !node.hasAttributes() && + node.childNodes.length == 1 && + node.firstChild.nodeName == "#text" + ) { + var textNode = node.firstChild; + node.removeChild(textNode); + if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters.. + node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node); + } + node.parentNode.insertBefore(textNode, node); + if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters.. + node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node); + } + node.parentNode.removeChild(node); + } + if (node.nodeName == "#text") { // clean up silly Windows -- stuff? return; @@ -1179,16 +1231,20 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { node.parentNode.removeChild(node); return; } - + //Roo.log(node.tagName); // remove - but keep children.. - if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) { + if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) { + //Roo.log('-- removed'); while (node.childNodes.length) { var cn = node.childNodes[0]; node.removeChild(cn); node.parentNode.insertBefore(cn, node); + // move node to parent - and clean it.. + this.cleanWord(cn); } node.parentNode.removeChild(node); - this.iterateChildren(node, this.cleanWord); + /// no need to iterate chidlren = it's got none.. + //this.iterateChildren(node, this.cleanWord); return; } // clean styles @@ -1548,6 +1604,17 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){ s.remove(); }); + }, + + setStyle : function(style) + { + Roo.get(this.iframe.contentDocument.head).createChild({ + tag : 'style', + type : 'text/css', + html : style + }); + + return; } // hide stuff that is not compatible