comparison ape.js @ 657:1e64848f5940

Added ape.css, removed styles from .js to clean up.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 10 Apr 2015 12:02:10 +0100
parents 0a401224660b
children 2d28a7a86c56
comparison
equal deleted inserted replaced
656:0a401224660b 657:1e64848f5940
20 function loadInterface(xmlDoc) { 20 function loadInterface(xmlDoc) {
21 21
22 // Get the dimensions of the screen available to the page 22 // Get the dimensions of the screen available to the page
23 var width = window.innerWidth; 23 var width = window.innerWidth;
24 var height = window.innerHeight; 24 var height = window.innerHeight;
25
26 // Set background to grey #ddd
27 document.getElementsByTagName('body')[0].style.backgroundColor = '#ddd';
28 25
29 // The injection point into the HTML page 26 // The injection point into the HTML page
30 var insertPoint = document.getElementById("topLevelBody"); 27 var insertPoint = document.getElementById("topLevelBody");
31 var testContent = document.createElement('div'); 28 var testContent = document.createElement('div');
32 testContent.id = 'testContent'; 29 testContent.id = 'testContent';
102 // Create the slider box to hold the slider elements 99 // Create the slider box to hold the slider elements
103 var canvas = document.createElement('div'); 100 var canvas = document.createElement('div');
104 canvas.id = 'slider'; 101 canvas.id = 'slider';
105 // Must have a known EXACT width, as this is used later to determine the ratings 102 // Must have a known EXACT width, as this is used later to determine the ratings
106 canvas.style.width = width - 100 +"px"; 103 canvas.style.width = width - 100 +"px";
107 canvas.style.height = 150 + "px";
108 canvas.style.marginBottom = "25px";
109 canvas.style.backgroundColor = '#eee';
110 canvas.align = "left"; 104 canvas.align = "left";
111 sliderBox.appendChild(canvas); 105 sliderBox.appendChild(canvas);
112 106
113 // Global parent for the comment boxes on the page 107 // Global parent for the comment boxes on the page
114 var feedbackHolder = document.createElement('div'); 108 var feedbackHolder = document.createElement('div');
164 // Create a slider per track 158 // Create a slider per track
165 159
166 var trackSliderObj = document.createElement('div'); 160 var trackSliderObj = document.createElement('div');
167 trackSliderObj.className = 'track-slider'; 161 trackSliderObj.className = 'track-slider';
168 trackSliderObj.id = 'track-slider-'+index; 162 trackSliderObj.id = 'track-slider-'+index;
169 trackSliderObj.style.position = 'absolute';
170 // Distribute it randomnly 163 // Distribute it randomnly
171 var w = window.innerWidth - 100; 164 var w = window.innerWidth - 100;
172 w = Math.random()*w; 165 w = Math.random()*w;
173 trackSliderObj.style.left = Math.floor(w)+50+'px'; 166 trackSliderObj.style.left = Math.floor(w)+50+'px';
174 trackSliderObj.style.height = "150px";
175 trackSliderObj.style.width = "10px";
176 trackSliderObj.style.backgroundColor = 'rgb(100,200,100)';
177 trackSliderObj.innerHTML = '<span>'+index+'</span>'; 167 trackSliderObj.innerHTML = '<span>'+index+'</span>';
178 trackSliderObj.style.float = "left";
179 trackSliderObj.draggable = true; 168 trackSliderObj.draggable = true;
180 trackSliderObj.ondragend = dragEnd; 169 trackSliderObj.ondragend = dragEnd;
181 170
182 // Onclick, switch playback to that track 171 // Onclick, switch playback to that track
183 trackSliderObj.onclick = function() { 172 trackSliderObj.onclick = function() {
206 postTest = postTest[0]; 195 postTest = postTest[0];
207 if (preTest != undefined || postTest != undefined) 196 if (preTest != undefined || postTest != undefined)
208 { 197 {
209 testContent.style.zIndex = 1; 198 testContent.style.zIndex = 1;
210 var blank = document.createElement('div'); 199 var blank = document.createElement('div');
211 blank.id = 'testHalt'; 200 blank.className = 'testHalt';
212 blank.style.zIndex = 2;
213 blank.style.width = window.innerWidth + 'px';
214 blank.style.height = window.innerHeight + 'px';
215 blank.style.position = 'absolute';
216 blank.style.top = '0';
217 blank.style.left = '0';
218 insertPoint.appendChild(blank); 201 insertPoint.appendChild(blank);
219 } 202 }
220 203
221 // Create Pre-Test Box 204 // Create Pre-Test Box
222 if (preTest != undefined && preTest.children.length >= 1) 205 if (preTest != undefined && preTest.children.length >= 1)
223 { 206 {
224 207
225 var preTestHolder = document.createElement('div'); 208 var preTestHolder = document.createElement('div');
226 preTestHolder.id = 'preTestHolder'; 209 preTestHolder.id = 'preTestHolder';
227 preTestHolder.style.zIndex = 2; 210 preTestHolder.className = 'popupHolder';
228 preTestHolder.style.width = '500px';
229 preTestHolder.style.height = '250px';
230 preTestHolder.style.backgroundColor = '#fff';
231 preTestHolder.style.position = 'absolute'; 211 preTestHolder.style.position = 'absolute';
232 preTestHolder.style.left = (window.innerWidth/2)-250 + 'px'; 212 preTestHolder.style.left = (window.innerWidth/2)-250 + 'px';
233 preTestHolder.style.top = (window.innerHeight/2)-125 + 'px'; 213 preTestHolder.style.top = (window.innerHeight/2)-125 + 'px';
234 // Parse the first box 214 // Parse the first box
235 var preTestOption = document.createElement('div'); 215 var preTestOption = document.createElement('div');
251 preTestOption.appendChild(textEnter); 231 preTestOption.appendChild(textEnter);
252 } 232 }
253 var nextButton = document.createElement('button'); 233 var nextButton = document.createElement('button');
254 nextButton.id = 'preTestNext'; 234 nextButton.id = 'preTestNext';
255 nextButton.value = '1'; 235 nextButton.value = '1';
256 nextButton.innerHTML = 'next'; 236 nextButton.innerHTML = 'Next';
257 nextButton.style.position = 'relative';
258 nextButton.style.left = '450px';
259 nextButton.style.top = '175px';
260 nextButton.onclick = function() { 237 nextButton.onclick = function() {
261 // Need to find and parse preTest again! 238 // Need to find and parse preTest again!
262 var preTest = projectXML.find('PreTest')[0]; 239 var preTest = projectXML.find('PreTest')[0];
263 // Check if current state is a question! 240 // Check if current state is a question!
264 if (preTest.children[this.value-1].nodeName == 'question') { 241 if (preTest.children[this.value-1].nodeName == 'question') {
280 { 257 {
281 var textHold = document.createElement('span'); 258 var textHold = document.createElement('span');
282 textHold.innerHTML = child.innerHTML; 259 textHold.innerHTML = child.innerHTML;
283 var textEnter = document.createElement('textarea'); 260 var textEnter = document.createElement('textarea');
284 textEnter.id = child.attributes['id'].value + 'response'; 261 textEnter.id = child.attributes['id'].value + 'response';
262 var br = document.createElement('br');
285 preTestOption.innerHTML = null; 263 preTestOption.innerHTML = null;
286 preTestOption.appendChild(textHold); 264 preTestOption.appendChild(textHold);
265 preTestOption.appendChild(br);
287 preTestOption.appendChild(textEnter); 266 preTestOption.appendChild(textEnter);
288 } 267 }
289 } else { 268 } else {
290 // Time to clear 269 // Time to clear
291 preTestHolder.style.zIndex = -1; 270 preTestHolder.style.zIndex = -1;
292 preTestHolder.style.visibility = 'hidden'; 271 preTestHolder.style.visibility = 'hidden';
293 var blank = document.getElementById('testHalt'); 272 var blank = document.getElementsByClassName('testHalt')[0];
294 blank.style.zIndex = -2; 273 blank.style.zIndex = -2;
295 blank.style.visibility = 'hidden'; 274 blank.style.visibility = 'hidden';
296 } 275 }
297 this.value++; 276 this.value++;
298 }; 277 };
304 283
305 } 284 }
306 285
307 function dragEnd(ev) { 286 function dragEnd(ev) {
308 // Function call when a div has been dropped 287 // Function call when a div has been dropped
288 var slider = document.getElementById('slider');
309 if (ev.x >= 50 && ev.x < window.innerWidth-50) { 289 if (ev.x >= 50 && ev.x < window.innerWidth-50) {
310 this.style.left = (ev.x)+'px'; 290 this.style.left = (ev.x)+'px';
311 } else { 291 } else {
312 if (ev.x<50) { 292 if (ev.x<50) {
313 this.style.left = '50px'; 293 this.style.left = '50px';