-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgrade.js
110 lines (90 loc) · 2.72 KB
/
cgrade.js
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
(function(document) {
var target, tests = {}, test = 'standards-mode',
docElem = document.documentElement,
SCRIPT = "script",
TEXTJS = "text/javascript",
STYLE = "style",
TEXTCSS = "text/css";
tests['pass'] = {
pre: function() { return true;},
test: function() {
return true;
}
};
tests['fail'] = {
pre: function() { return false;},
test: function() {
return false;
}
};
tests['standards-mode'] = {
pre: function() { return true;},
test: function() {
// http://acidmartin.wordpress.com/2008/10/21/using-compatmode-to-determine-the-standards-compliance-mode-of-the-page-on-the-client/
return document.compatMode === 'CSS1Compat';
}
};
tests['child-selector'] = {
pre: function() { return true;},
test: function() {
}
};
tests['inline-block'] = {
pre: function() { return true;},
test: function() {
}
};
tests['inline-block-no-workaround'] = {
pre: function() { return true;},
test: function() {
}
};
tests['w3c-events'] = {
pre: function() { return true;},
test: function() {
return !!document.addEventListener;
}
};
function theTest() {
return tests[test].test();
}
function preTest() {
target = document.getElementsByTagName(SCRIPT)[0];
return true;
}
function buildDynamicTag(tag, type) {
var elem = document.createElement(tag);
elem.type = type
return elem;
}
function putInHead(elem) {
// http://www.stevesouders.com/blog/2010/05/11/appendchild-vs-insertbefore/
target.parentNode.insertBefore(elem, target);
}
function loadJsAsynch() {
var script = buildDynamicTag(SCRIPT, TEXTJS);
script.async = true; // should this be "true"? string v bool
script.src = "main.js";
putInHead(script);
}
function insertFoucPreventer() {
docElem.className = docElem.className.replace(/\bno-js\b/i, "js loading");
var style = buildDynamicTag(STYLE, TEXTCSS);
var css = ".loading .hideload {display:none};";
// http://www.phpied.com/dynamic-script-and-style-elements-in-ie/
if (style.styleSheet) {
//weird IE way
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
putInHead(style);
}
function doIt() {
if (preTest() && theTest()) {
insertFoucPreventer();
loadJsAsynch();
}
}
doIt();
})(window.document);