Mercurial > hg > webaudioevaluationtool
comparison interfaces/ape.js @ 3072:2dcf6aaa7c4c
Potential fix for #122
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 31 Oct 2017 22:18:29 +0000 |
parents | afb1de9be046 |
children | 87b3657abce7 |
comparison
equal
deleted
inserted
replaced
3071:afb1de9be046 | 3072:2dcf6aaa7c4c |
---|---|
329 trackObj.classList.remove("track-slider-playing"); | 329 trackObj.classList.remove("track-slider-playing"); |
330 } | 330 } |
331 this.enable = function () { | 331 this.enable = function () { |
332 trackObj.addEventListener("mousedown", this); | 332 trackObj.addEventListener("mousedown", this); |
333 trackObj.addEventListener("mouseup", this); | 333 trackObj.addEventListener("mouseup", this); |
334 trackObj.addEventListener("touchstart", this); | |
335 trackObj.addEventListener("touchend", this); | |
336 trackObj.addEventListener("touchcancel", this); | |
337 trackObj.classList.remove("track-slider-disabled"); | 334 trackObj.classList.remove("track-slider-disabled"); |
338 labelHolder.textContent = label; | 335 labelHolder.textContent = label; |
339 } | 336 } |
340 this.updateLoading = function (progress) { | 337 this.updateLoading = function (progress) { |
341 labelHolder.textContent = progress + "%"; | 338 labelHolder.textContent = progress + "%"; |
348 } | 345 } |
349 this.error = function () { | 346 this.error = function () { |
350 trackObj.classList.add("error-colour"); | 347 trackObj.classList.add("error-colour"); |
351 trackObj.removeEventListener("mousedown"); | 348 trackObj.removeEventListener("mousedown"); |
352 trackObj.removeEventListener("mouseup"); | 349 trackObj.removeEventListener("mouseup"); |
353 trackObj.removeEventListener("touchstart"); | |
354 trackObj.removeEventListener("touchmove"); | |
355 trackObj.removeEventListener("touchend"); | |
356 trackObj.removeEventListener("touchcancel"); | |
357 } | 350 } |
358 var timing = undefined; | 351 var timing = undefined; |
359 this.handleEvent = function (e) { | 352 this.handleEvent = function (e) { |
360 // This is only for the mousedown / touchdown | 353 // This is only for the mousedown / touchdown |
361 if (e.preventDefault) { | 354 if (e.preventDefault) { |
362 e.preventDefault(); | 355 e.preventDefault(); |
363 } | 356 } |
364 if (e.type == "mousedown" || e.type == "touchstart") { | 357 if (e.type == "mousedown") { |
365 axisInterface.mousedown(this); | 358 axisInterface.mousedown(this); |
366 } else if (e.type == "mouseup" || e.type == "touchend" || e.type == "touchcancel") { | 359 } else if (e.type == "mouseup" || e.type == "touchend" || e.type == "touchcancel") { |
367 axisInterface.mouseup(this); | 360 axisInterface.mouseup(this); |
368 metric.moved(audioEngineContext.timer.getTestTime(), this.value); | 361 metric.moved(audioEngineContext.timer.getTestTime(), this.value); |
369 console.log("Slider " + label + " on axis " + axisInterface.name + " moved to " + this.value); | 362 console.log("Slider " + label + " on axis " + axisInterface.name + " moved to " + this.value); |
370 } else if (e.type == "touchmove") { | |
371 //axisInterface.handleEvent(e); | |
372 } | 363 } |
373 } | 364 } |
374 this.clicked = function (e) { | 365 this.clicked = function (e) { |
375 AOI.clicked(); | 366 AOI.clicked(); |
376 } | 367 } |
568 } | 559 } |
569 UI.selected = undefined; | 560 UI.selected = undefined; |
570 UI.startTime = undefined; | 561 UI.startTime = undefined; |
571 } | 562 } |
572 this.handleEvent = function (event) { | 563 this.handleEvent = function (event) { |
564 function getTargetSlider(target) { | |
565 return sliders.find(function (a) { | |
566 return a.DOM == target; | |
567 }); | |
568 } | |
573 var time = audioEngineContext.timer.getTestTime(); | 569 var time = audioEngineContext.timer.getTestTime(); |
574 if (event.preventDefault) { | 570 if (event.preventDefault) { |
575 event.preventDefault(); | 571 event.preventDefault(); |
576 } | 572 } |
577 if (UI.selected === undefined) { | 573 if (UI.selected === undefined) { |
578 return; | 574 return; |
575 } | |
576 if (event.type == "touchstart") { | |
577 var selected = getTargetSlider(event.target); | |
578 if (typeof selected != "object") { | |
579 return; | |
580 } | |
581 UI.selected = selected; | |
579 } | 582 } |
580 if (event.type == "mousemove") { | 583 if (event.type == "mousemove") { |
581 var move = event.clientX - 6; | 584 var move = event.clientX - 6; |
582 var w = $(sliderRail).width(); | 585 var w = $(sliderRail).width(); |
583 move = Math.max(50, move); | 586 move = Math.max(50, move); |
584 move = Math.min(w, move); | 587 move = Math.min(w, move); |
585 UI.selected.value = (move / w); | 588 UI.selected.value = (move / w); |
586 } else if (event.type == "touchmove") { | 589 } else if (event.type == "touchmove") { |
587 var move; | 590 if (UI.selected == getTargetSlider(event.target)) { |
588 if (event.targetTouches) { | 591 var move; |
589 move = event.targetTouches[0].clientX - 6; | 592 if (event.targetTouches) { |
590 } else if (event.originalEvent.targetTouches) { | 593 move = event.targetTouches[0].clientX - 6; |
591 move = event.originalEvent.targetTouches[0].clientX - 6; | 594 } else if (event.originalEvent.targetTouches) { |
592 } else { | 595 move = event.originalEvent.targetTouches[0].clientX - 6; |
593 return; | 596 } else { |
594 } | 597 return; |
595 var w = $(event.currentTarget).width(); | 598 } |
596 move = Math.max(50, move); | 599 var w = $(event.currentTarget).width(); |
597 move = Math.min(w, move); | 600 move = Math.max(50, move); |
598 UI.selected.value = (move / w); | 601 move = Math.min(w, move); |
602 UI.selected.value = (move / w); | |
603 } | |
604 } else if (event.type == "touchend" || event.type == "touchcancel") { | |
605 if (UI.selected == getTargetSlider(event.target)) { | |
606 UI.selected.handleEvent(event); | |
607 } | |
599 } | 608 } |
600 } | 609 } |
601 this.checkAllMoved = function () { | 610 this.checkAllMoved = function () { |
602 var notMoved = sliders.filter(function (s) { | 611 var notMoved = sliders.filter(function (s) { |
603 return !s.hasMoved(); | 612 return !s.hasMoved(); |
640 return "On axis \"" + interfaceObject.title + "\", you have not used the required width of the scales"; | 649 return "On axis \"" + interfaceObject.title + "\", you have not used the required width of the scales"; |
641 } | 650 } |
642 return ""; | 651 return ""; |
643 } | 652 } |
644 sliderRail.addEventListener("mousemove", this); | 653 sliderRail.addEventListener("mousemove", this); |
654 sliderRail.addEventListener("touchstart", this); | |
645 sliderRail.addEventListener("touchmove", this); | 655 sliderRail.addEventListener("touchmove", this); |
656 sliderRail.addEventListener("touchend", this); | |
657 sliderRail.addEventListener("touchcancel", this); | |
646 Object.defineProperties(this, { | 658 Object.defineProperties(this, { |
647 "sliderRail": { | 659 "sliderRail": { |
648 "value": sliderRail | 660 "value": sliderRail |
649 } | 661 } |
650 }); | 662 }); |