/
many-css-resources.html
110 lines (93 loc) · 2.65 KB
/
many-css-resources.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE HTML>
<html>
<head>
<title>Many CSS Resources test</title>
<script>
curl = {
paths: {
curl: '../src/curl'
}
};
</script>
<script src="../src/curl.js" type="text/javascript"></script>
<script type="text/javascript">
(function () {
"use strict";
// local css file
curl(['css!stuff/base.css'/*, 'domReady!'*/]).then(
function () {
write('SUCCESS! loaded local css file.');
// TODO: we need a better test than this:
if (document.body.offsetHeight - document.body.clientHeight > 0) {
write('SUCCESS! applied rules from css file.');
}
else {
write('FAILED! did not apply rules from css file.');
}
},
function () {
write('FAILED! did not load local css file.');
}
);
// XD css file
curl(['css!http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css']).then(
function () {
write('SUCCESS! loaded XD css file.');
},
function () {
write('FAILED! did not load XD css file.');
}
);
// HTTP error
curl(['css!bogus.css']).then(
function () {
write('FAILED! error handler didn\'t fire for 404 HTTP error.');
},
function () {
write('SUCCESS! detected 404 HTTP error.');
}
);
// test cascade
curl(['css!stuff/cascade-start.css', 'css!stuff/cascade-middle.css', 'css!stuff/cascade-end.css']).then(
function () {
var testEl = document.getElementById('test-cascade');
write((testEl.offsetTop == 33 ? 'SUCCESS' : 'FAILED') + ': css cascaded correctly through three levels.');
write((testEl.offsetLeft == 20 ? 'SUCCESS' : 'FAILED') + ': css cascaded correctly through two levels.');
},
function (ex) { write('FAILED: cascade tests did not run.') }
);
// test empty stylesheet
curl(['css!stuff/blank']).then(
function () { write('SUCCESS: should load blank stylesheet.'); },
function () { write('FAILED: should load blank stylesheet.'); }
);
// 31 should be enough to cause IE to fail. see if we can load more than that
var howMany = 70, total = 0, all = [];
for (var i = 0; i < howMany; i++) {
all.push('css!stuff/base.css?which=' + i + '&bust=' + Math.random() + new Date().valueOf());
}
curl(all).then(
function () {
write('SUCCESS: all ' + howMany + ' css files loaded.');
},
function (ex) {
write('FAILED: not all ' + howMany + ' css files loaded. ' + ex.message);
}
);
function write (msg) {
curl(['domReady!'], function () {
document.body.appendChild(document.createElement('div')).innerHTML = msg;
});
}
function getComputedStyle (el) {
return window.getComputedStyle ? window.getComputedStyle(el, null) : el.currentStyle;
}
}());
</script>
</head>
<body>
<div id="test-cascade-parent">
<p id="test-cascade">test element</p>
</div>
</body>
</html>