Write the CSS serially in order to remove async loading

This commit is contained in:
Christopher Chedeau
2014-04-14 10:15:37 -07:00
parent d0d8cd0bcf
commit b9356e5d85
2 changed files with 16 additions and 33 deletions

View File

@@ -1,25 +1,27 @@
function setupIframe(callback) {
var iframe = (function() {
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var doc = iframe.contentDocument;
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', 'style.css');
doc.head.appendChild(link);
var style = document.createElement('style');
style.innerText = (function() {/*
body, div {
box-sizing: border-box;
requestAnimationFrame(function wait() {
if (doc.styleSheets.length) {
callback(iframe);
} else {
requestAnimationFrame(wait);
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 0;
padding: 0;
}
})
}
*/} + '').slice(15, -4);
doc.head.appendChild(style);
var iframe = null;
return iframe;
})();
function computeDOMLayout(node) {
var body = iframe.contentDocument.body;
@@ -97,14 +99,6 @@ function testLayout(node, expectedLayout) {
}
describe('Layout', function() {
beforeEach(function(done) {
if (iframe) {
done();
} else {
setupIframe(function(ifrm) { iframe = ifrm; done(); });
}
});
it('should layout a single node with width and height', function() {
testLayout({
style: {width: 100, height: 200}
@@ -474,7 +468,6 @@ describe('Layout', function() {
});
});
it('should layout randomly', function() {
function RNG(seed) {
this.state = seed;

View File

@@ -1,10 +0,0 @@
* {
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 0;
padding: 0;
}