-
Notifications
You must be signed in to change notification settings - Fork 19
/
csscritic.js
76 lines (65 loc) · 2.07 KB
/
csscritic.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
/*
* CSS Critic loader
*
* Just include
* <script src="csscritic.js"></script>
* and you are good to go.
*/
/*jslint evil: true */
(function () {
"use strict";
var cssDependencies = ["src/reporter/niceReporter.css"],
jsDependencies = [
"src/scope.js",
"src/reporter/niceReporter.js",
"src/reporter/urlQueryFilter.js",
"src/jobQueue.js",
"src/browserRenderer.js",
"src/indexedDbStorage.js",
"src/util.js",
"src/reporting.js",
"src/regression.js",
"src/main.js",
"packageVersion.js",
"src/init.js",
],
externalJsDependencies = [
"rasterizehtml/dist/rasterizeHTML.allinone.js",
"imagediff/imagediff.js",
];
var getCurrentScript = function () {
return (
document.currentScript ||
(function () {
var scripts = document.getElementsByTagName("script");
return scripts[scripts.length - 1];
})()
);
};
var getBasePath = function () {
var script = getCurrentScript(),
src = script.attributes.src.value;
return src.substring(0, src.lastIndexOf("/") + 1);
};
var loadCssDependency = function (path) {
document.write('<link rel="stylesheet" href="' + path + '">');
};
var loadJsDependency = function (path) {
document.write('<script src="' + path + '"></script>');
};
var loadExternalJsDependency = function (basePath, path) {
loadJsDependency(basePath + "../../node_modules/" + path);
// Fallback to npm <3
loadJsDependency(basePath + "node_modules/" + path);
};
var basePath = getBasePath();
cssDependencies.forEach(function (path) {
loadCssDependency(basePath + path);
});
externalJsDependencies.forEach(function (path) {
loadExternalJsDependency(basePath, path);
});
jsDependencies.forEach(function (path) {
loadJsDependency(basePath + path);
});
})();