mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 13:16:31 -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;
|
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 () {
|
getHTML: function () {
|
||||||
var brs = [],
|
var brs = [],
|
||||||
node, fixer, html, l;
|
node, fixer, html, l;
|
||||||
|
@ -1425,17 +1436,8 @@
|
||||||
setHTML: function ( html ) {
|
setHTML: function ( html ) {
|
||||||
var frag = doc.createDocumentFragment(),
|
var frag = doc.createDocumentFragment(),
|
||||||
div = createElement( 'DIV' ),
|
div = createElement( 'DIV' ),
|
||||||
styles = '',
|
|
||||||
child;
|
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
|
// Parse HTML into DOM tree
|
||||||
div.innerHTML = html;
|
div.innerHTML = html;
|
||||||
frag.appendChild( div.empty() );
|
frag.appendChild( div.empty() );
|
||||||
|
@ -1457,15 +1459,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// And insert new content
|
// 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.appendChild( frag );
|
||||||
body.fixCursor();
|
body.fixCursor();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue