mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Add styles via separate API method.
<style></style> must not be included text supplied to setHTML call.
This commit is contained in:
parent
a8e6e5b391
commit
43634a3ba4
1 changed files with 12 additions and 19 deletions
|
@ -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 <head>
|
||||
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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue