-
Notifications
You must be signed in to change notification settings - Fork 5
/
SpecRunner.html
138 lines (113 loc) · 3.32 KB
/
SpecRunner.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<title>MooTools Milk Sprinter</title>
<style>
#iframes iframe {
width: 100%;
height: 300px;
}
#suiteselection {
overflow: hidden;
}
#suiteselection div {
float: left;
margin-right: 20px;
}
#runspecs {
margin: 20px;
}
</style>
</head>
<body>
<div id="suiteselection"></div>
<div><button id="runspecs">Run!</button></div>
<div id="iframes"></div>
<script src="SimpleRequest.js"></script>
<script type="text/javascript">
var suites = {
'Base': [],
'DOM': []
};
var indexOf = function(array, el){
for (var i = 0; i < array.length; i++){
if (array[i] == el) return i;
}
return -1;
};
var stringifyModulesHash = function(){
var parts = [];
for (var suite in suites){
if (suites[suite].length) parts.push(suite + ':' + suites[suite].join(','));
}
return parts.join(';');
};
var parseModulesHash = function(){
var _packages = location.hash.slice(1).split(';');
for (var i = 0; i < _packages.length; i++){
var parts = _packages[i].split(':');
suites[parts[0]] = parts[1] ? parts[1].split(',') : [];
}
};
// loading the iframes
var run = function(){
var iframesWrapper = document.getElementById('iframes');
iframesWrapper.innerHTML = '';
for (var name in suites){
var packagesuites = suites[name];
for (var j = 0; j < packagesuites.length; j++){
var heading = document.createElement('h3');
heading.innerHTML = name;
iframesWrapper.appendChild(heading);
var iframe = document.createElement('iframe');
iframesWrapper.appendChild(iframe);
iframe.src = '../' + name + '/Specs/'
+ packagesuites[j] + '.html?' + +(new Date)
+ '&path=' + encodeURI(location.pathname.match(/(.*\/)\w+\.html$/i)[1]);
}
}
location.hash = '#' + stringifyModulesHash();
};
// load suites.json for the suite selection
var suiteselection = document.getElementById('suiteselection');
for (var module in suites) (function(module){
var wrapper = document.createElement('div');
wrapper.innerHTML = '<h2>' + module + '</h2>loading...';
suiteselection.appendChild(wrapper);
new SimpleRequest().send('../' + module + '/Specs/suites.json', function(json){
var data = window.JSON && JSON.parse ? JSON.parse(json) : eval('(' + json + ')');
var html = '<h2>' + module + '</h2>';
for (var name in data){
var _name = module + ':' + name;
var _id = module + '-' + name;
html += '<input type="checkbox" name="'
+ _name + '" id="' + _id + '"'
+ (suites[module] && (indexOf(suites[module], name) != -1) ? ' checked' : '')
+ '><label for="' + _id + '">'
+ name + '</label><br>';
}
wrapper.innerHTML = html;
});
})(module);
var runButton = document.getElementById('runspecs');
runButton.onclick = function(){
var inputs = suiteselection.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++){
var input = inputs[i];
var parts = input.name.split(':');
var packagesuites = suites[parts[0]];
var index = indexOf(packagesuites, parts[1]);
if (input.checked && index == -1){
packagesuites.push(parts[1]);
} else if (!input.checked && index != -1){
packagesuites.splice(index, 1);
}
}
run();
};
// do it!
parseModulesHash();
run();
</script>
</body>
</html>