-
Notifications
You must be signed in to change notification settings - Fork 137
/
startup.js
248 lines (202 loc) · 8.85 KB
/
startup.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*************************************************************************
(C) Copyright AudioLabs 2017
This source code is protected by copyright law and international treaties. This source code is made available to You subject to the terms and conditions of the Software License for the webMUSHRA.js Software. Said terms and conditions have been made available to You prior to Your download of this source code. By downloading this source code You agree to be bound by the above mentionend terms and conditions, which can also be found here: https://www.audiolabs-erlangen.de/resources/webMUSHRA. Any unauthorised use of this source code may result in severe civil and criminal penalties, and will be prosecuted to the maximum extent possible under law.
**************************************************************************/
function checkOrientation() {//when changing from potrait to landscape change to the rigth width
var siteWidth = document.body.scrollWidth;
$("#header").css("width", siteWidth.toString());
}
window.onresize = function(event) {
if (pageManager.getCurrentPage() && pageManager.getCurrentPage().isMushra == true) {
pageManager.getCurrentPage().renderCanvas("mushra_items");
}
checkOrientation();
};
// $(document).ready(function(){
// $(window).scroll(function(){
// $('#header').css({
// 'left': $(this).scrollLeft()//Note commented because it causes the endless scrolling to the left
// });
// });
// });
// callbacks
function callbackFilesLoaded() {
pageManager.start();
pageTemplateRenderer.renderProgressBar(("page_progressbar"));
pageTemplateRenderer.renderHeader(("page_header"));
pageTemplateRenderer.renderNavigation(("page_navigation"));
if (config.stopOnErrors == false || !errorHandler.errorOccurred()) {
$.mobile.loading("hide");
$("body").children().children().removeClass('ui-disabled');
} else {
var errors = errorHandler.getErrors();
var ul = $("<ul style='text-align:left;'></ul>");
$('#popupErrorsContent').append(ul);
for (var i = 0; i < errors.length; ++i) {
ul.append($('<li>' + errors[i] + '</li>'));
}
$("#popupErrors").popup("open");
$.mobile.loading("hide");
}
if ($.mobile.activePage) {
$.mobile.activePage.trigger('create');
}
}
function callbackURLFound() {
var errors = errorHandler.getErrors();
var ul = $("<ul style='text-align:left;'></ul>");
$('#popupErrorsContent').append(ul);
for (var i = 0; i < errors.length; ++i) {
ul.append($('<li>' + errors[i] + '</li>'));
}
$("#popupErrors").popup("open");
}
function addPagesToPageManager(_pageManager, _pages) {
for (var i = 0; i < _pages.length; ++i) {
if (Array.isArray(_pages[i])) {
if (_pages[i][0] === "random") {
_pages[i].shift();
shuffle(_pages[i]);
}
addPagesToPageManager(_pageManager, _pages[i]);
} else {
var pageConfig = _pages[i];
if (pageConfig.type == "generic") {
_pageManager.addPage(new GenericPage(_pageManager, pageConfig));
} else if (pageConfig.type == "consent") {
_pageManager.addPage(new ConsentPage(_pageManager, pageTemplateRenderer, pageConfig));
} else if (pageConfig.type == "volume") {
var volumePage = new VolumePage(_pageManager, audioContext, audioFileLoader, pageConfig, config.bufferSize, errorHandler, config.language);
_pageManager.addPage(volumePage);
} else if (pageConfig.type == "mushra") {
var mushraPage = new MushraPage(_pageManager, audioContext, config.bufferSize, audioFileLoader, session, pageConfig, mushraValidator, errorHandler, config.language);
_pageManager.addPage(mushraPage);
} else if ( pageConfig.type == "spatial"){
_pageManager.addPage(new SpatialPage(_pageManager, pageConfig, session, audioContext, config.bufferSize, audioFileLoader, errorHandler, config.language));
} else if (pageConfig.type == "paired_comparison") {
var pcPageManager = new PairedComparisonPageManager();
pcPageManager.createPages(_pageManager, pageTemplateRenderer, pageConfig, audioContext, config.bufferSize, audioFileLoader, session, errorHandler, config.language);
pcPageManager = null;
} else if (pageConfig.type == "bs1116") {
var bs1116PageManager = new BS1116PageManager();
bs1116PageManager.createPages(_pageManager, pageTemplateRenderer, pageConfig, audioContext, config.bufferSize, audioFileLoader, session, errorHandler, config.language);
bs1116PageManager = null;
} else if (pageConfig.type == "likert_single_stimulus") {
var likertSingleStimulusPageManager = new LikertSingleStimulusPageManager();
likertSingleStimulusPageManager.createPages(_pageManager, pageTemplateRenderer, pageConfig, audioContext, config.bufferSize, audioFileLoader, session, errorHandler, config.language);
likertSingleStimulusPageManager = null;
} else if (pageConfig.type == "likert_multi_stimulus") {
var likertMultiStimulusPage = new LikertMultiStimulusPage(pageManager, pageTemplateRenderer, pageConfig, audioContext, config.bufferSize, audioFileLoader, session, errorHandler, config.language);
_pageManager.addPage(likertMultiStimulusPage);
} else if (pageConfig.type == "finish") {
var finishPage = new FinishPage(_pageManager, session, dataSender, pageConfig, config.language);
_pageManager.addPage(finishPage);
} else {
errorHandler.sendError("Type not specified.");
}
}
}
}
for (var i = 0; i < $("body").children().length; i++) {
if ($("body").children().eq(i).attr('id') != "popupErrors" && $("body").children().eq(i).attr('id') != "popupDialog") {
$("body").children().eq(i).addClass('ui-disabled');
}
}
function startup(config) {
if (config == null) {
errorHandler.sendError("URL couldn't be found!");
callbackURLFound();
}
$.mobile.page.prototype.options.theme = 'a';
var interval = setInterval(function() {
$.mobile.loading("show", {
text : "Loading...",
textVisible : true,
theme : "a",
html : ""
});
clearInterval(interval);
}, 1);
if (pageManager !== null) { // clear everything for new experiment
pageTemplateRenderer.clear();
$("#page_content").empty();
$('#header').empty();
}
localizer = new Localizer();
localizer.initializeNLSFragments(nls);
pageManager = null;
audioContext;
audioFileLoader = null;
mushraValidator = null;
dataSender = null;
session = null;
pageTemplateRenderer = null;
interval2 = null;
document.title = config.testname;
$('#header').append(document.createTextNode(config.testname));
pageManager = new PageManager("pageManager", "page_content", localizer);
window.AudioContext = window.AudioContext || window.webkitAudioContext;
if ( typeof AudioContext !== 'undefined') {
audioContext = new AudioContext();
} else if ( typeof webkitAudioContext !== 'undefined') {
audioContext = new webkitAudioContext();
}
document.addEventListener("click", function () {
if (audioContext.state !== 'running') {
audioContext.resume();
}
}, true);
try {
audioContext.destination.channelCountMode = "explicit";
audioContext.destination.channelInterpretation = "discrete";
audioContext.destination.channelCount = audioContext.destination.maxChannelCount;
} catch (e) {
console.log("webMUSHRA: Could not set channel count of destination node.");
console.log(e);
}
audioContext.volume = 1.0;
audioFileLoader = new AudioFileLoader(audioContext, errorHandler);
mushraValidator = new MushraValidator(errorHandler);
dataSender = new DataSender(config);
session = new Session();
session.testId = config.testId;
session.config = configFile;
if (config.language == undefined) {
config.language = 'en';
}
pageTemplateRenderer = new PageTemplateRenderer(pageManager, config.showButtonPreviousPage, config.language);
pageManager.addCallbackPageEventChanged(pageTemplateRenderer.refresh.bind(pageTemplateRenderer));
addPagesToPageManager(pageManager, config.pages);
interval2 = setInterval(function() {
clearInterval(interval2);
audioFileLoader.startLoading(callbackFilesLoaded);
}, 10);
}
// start code (loads config)
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var config = null;
var configArg = getParameterByName("config");
var configFile = '';
if (configArg) {
configFile = 'configs/' + configArg;
} else {
configFile = 'configs/default.yaml';
}
// global variables
var errorHandler = new ErrorHandler();
var localizer = null;
var pageManager = null;
var audioContext = null;
var audioFileLoader = null;
var mushraValidator = null;
var dataSender = null;
var session = null;
var pageTemplateRenderer = null;
var interval2 = null;
YAML.load(configFile, (function(result) {
config = result;
startup(result);
}));