From 43634a3ba4d69c028d3560e9d5a389970311dcc7 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 17 Nov 2011 18:37:49 +1100 Subject: [PATCH] Add styles via separate API method. must not be included text supplied to setHTML call. --- source/Editor.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/source/Editor.js b/source/Editor.js index b9c5b41..dfb9b87 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1400,6 +1400,17 @@ return doc; }, + addStyles: function ( styles ) { + if ( styles ) { + var style = createElement( 'STYLE', { + type: 'text/css' + }); + style.appendChild( doc.createTextNode( styles ) ); + doc.documentElement.firstChild.appendChild( style ); + } + return this; + }, + getHTML: function () { var brs = [], node, fixer, html, l; @@ -1425,24 +1436,15 @@ setHTML: function ( html ) { var frag = doc.createDocumentFragment(), div = createElement( 'DIV' ), - styles = '', child; - // Extract styles to insert into - styleExtractor.lastIndex = 0; - html = html.replace( styleExtractor, - function ( _, rules ) { - styles += rules.replace( //g, '' ); - return ''; - }); - // Parse HTML into DOM tree div.innerHTML = html; frag.appendChild( div.empty() ); cleanTree( frag, true ); cleanupBRs( frag ); - + wrapTopLevelInline( frag, 'DIV' ); // Fix cursor @@ -1457,15 +1459,6 @@ } // And insert new content - // Add the styles - if ( styles ) { - var style = createElement( 'STYLE', { - type: 'text/css' - }); - style.appendChild( doc.createTextNode( styles ) ); - doc.documentElement.firstChild.appendChild( style ); - } - body.appendChild( frag ); body.fixCursor();