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