X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FHtmlEditorCore.js;h=ab52b4cbee1fc1c9e41a68bc58e1481dcfc3e8b9;hb=96a2dcc293658ca410a23a5c6304ffd2761a4169;hp=bcc5be3cfa9666e52046a5cfab2cb5bde073521c;hpb=6d541a99cae32efac454089cf43c82165fb44f0a;p=roojs1 diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index bcc5be3cfa..ab52b4cbee 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); @@ -587,8 +609,6 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { insertAtCursor : function(text) { - - if(!this.activated){ return; } @@ -939,13 +959,16 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { var nodeIsBefore = ss == 1; var nodeIsAfter = ee == -1; - if (nodeIsBefore && nodeIsAfter) + if (nodeIsBefore && nodeIsAfter) { return 0; // outer - if (!nodeIsBefore && nodeIsAfter) + } + if (!nodeIsBefore && nodeIsAfter) { return 1; //right trailed. + } - if (nodeIsBefore && !nodeIsAfter) + if (nodeIsBefore && !nodeIsAfter) { return 2; // left trailed. + } // fully contined. return 3; }, @@ -1017,6 +1040,17 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1; + + if (!node.attributes || !node.attributes.length) { + + if (lcname == 'span' && + node.childNodes.length == 1 && + node.childNodes[0].nodeName.toLowerCase() = '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.. @@ -1037,6 +1071,10 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { } if (!node.attributes || !node.attributes.length) { + + + + this.cleanUpChildren(node); return; } @@ -1047,7 +1085,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(/^#/)) { @@ -1136,7 +1174,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { node.className = ''; } - if (a.value.match(/body/)) { + if (a.value.match(/^body$/)) { node.className = ''; } continue; @@ -1158,12 +1196,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; @@ -1238,7 +1293,8 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { }, /** * 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) { @@ -1271,8 +1327,9 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { 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')) { @@ -1290,7 +1347,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { return; } var kv = s.split(":"); - if (kv[0].match(/^width|min-width/)) { + if (kv[0].match(/^\s*(width|min-width)\s*$/)) { return; } // what ever is left... we allow. @@ -1302,7 +1359,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { } } - cleanWordChildren(); + this.iterateChildren(node, this.cleanTableWidths); }, @@ -1545,6 +1602,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