Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2979:d5432dd0924e
JSHinted
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Fri, 12 Jan 2018 15:45:47 +0000 |
parents | 7483f1bae6e1 |
children | b3ebd07e7a0f cb81b0e8d31a |
comparison
equal
deleted
inserted
replaced
2978:7483f1bae6e1 | 2979:d5432dd0924e |
---|---|
694 span.textContent = option.text; | 694 span.textContent = option.text; |
695 td.appendChild(span); | 695 td.appendChild(span); |
696 tr = document.createElement('div'); | 696 tr = document.createElement('div'); |
697 tr.setAttribute('name', 'option'); | 697 tr.setAttribute('name', 'option'); |
698 tr.className = "popup-option-checbox"; | 698 tr.className = "popup-option-checbox"; |
699 var resp = undefined; | 699 var resp; |
700 if (node.response.length > 0) { | 700 if (node.response.length > 0) { |
701 resp = node.response.find(function (a) { | 701 resp = node.response.find(function (a) { |
702 return a.name == option.name; | 702 return a.name == option.name; |
703 }); | 703 }); |
704 } | 704 } |
1265 } else if (a.type === "outside-reference") { | 1265 } else if (a.type === "outside-reference") { |
1266 or.push(a); | 1266 or.push(a); |
1267 } else { | 1267 } else { |
1268 remainder.push(a); | 1268 remainder.push(a); |
1269 } | 1269 } |
1270 }) | 1270 }); |
1271 if (page.poolSize > 0 || page.randomiseOrder) { | 1271 if (page.poolSize > 0 || page.randomiseOrder) { |
1272 page.randomiseOrder = true; | 1272 page.randomiseOrder = true; |
1273 if (page.poolSize === 0) { | 1273 if (page.poolSize === 0) { |
1274 page.poolSize = page.audioElements.length; | 1274 page.poolSize = page.audioElements.length; |
1275 } | 1275 } |
2038 } | 2038 } |
2039 }; | 2039 }; |
2040 | 2040 |
2041 this.bufferStart = function (startTime) { | 2041 this.bufferStart = function (startTime) { |
2042 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); | 2042 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); |
2043 if (this.bufferNode && this.bufferNode.state == 0) { | 2043 if (this.bufferNode && this.bufferNode.state === 0) { |
2044 this.bufferNode.state = 1; | 2044 this.bufferNode.state = 1; |
2045 if (this.bufferNode.loop == true) { | 2045 if (this.bufferNode.loop === true) { |
2046 this.bufferNode.start(startTime); | 2046 this.bufferNode.start(startTime); |
2047 } else { | 2047 } else { |
2048 this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); | 2048 this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); |
2049 } | 2049 } |
2050 } | 2050 } |
2379 registerKeyBinding: function (key, audioObject) { | 2379 registerKeyBinding: function (key, audioObject) { |
2380 if (typeof key != "string" || key.length != 1) { | 2380 if (typeof key != "string" || key.length != 1) { |
2381 throw ("Key must be a singular character"); | 2381 throw ("Key must be a singular character"); |
2382 } | 2382 } |
2383 var included = this.keys.findIndex(function (k) { | 2383 var included = this.keys.findIndex(function (k) { |
2384 return k.key == key | 2384 return k.key == key; |
2385 }) >= 0; | 2385 }) >= 0; |
2386 if (included) { | 2386 if (included) { |
2387 throw ("Key " + key + " already bounded!"); | 2387 throw ("Key " + key + " already bounded!"); |
2388 } | 2388 } |
2389 this.keys.push({ | 2389 this.keys.push({ |
2412 }); | 2412 }); |
2413 } | 2413 } |
2414 | 2414 |
2415 function keypress(key) { | 2415 function keypress(key) { |
2416 var index = this.keys.findIndex(function (k) { | 2416 var index = this.keys.findIndex(function (k) { |
2417 return k.key == key | 2417 return k.key == key; |
2418 }); | 2418 }); |
2419 if (index >= 0) { | 2419 if (index >= 0) { |
2420 audioEngineContext.play(this.keys[index].audioObject.id); | 2420 audioEngineContext.play(this.keys[index].audioObject.id); |
2421 } | 2421 } |
2422 } | 2422 } |
2423 | 2423 |
2424 function trackCommentFocus() { | 2424 function trackCommentFocus() { |
2425 return document.activeElement.className.indexOf("trackComment") >= 0; | 2425 return document.activeElement.className.indexOf("trackComment") >= 0; |
2426 } | 2426 } |
2427 if (e.key === " ") { | 2427 if (e.key === " ") { |
2428 if (isPlaying() && trackCommentFocus() == false) { | 2428 if (isPlaying() && trackCommentFocus() === false) { |
2429 e.preventDefault(); | 2429 e.preventDefault(); |
2430 audioEngineContext.stop(); | 2430 audioEngineContext.stop(); |
2431 } | 2431 } |
2432 } else { | 2432 } else { |
2433 keypress.call(this, e.key); | 2433 keypress.call(this, e.key); |
3694 }; | 3694 }; |
3695 | 3695 |
3696 // Make the request | 3696 // Make the request |
3697 req.send([hold.innerHTML]); | 3697 req.send([hold.innerHTML]); |
3698 }); | 3698 }); |
3699 }; | 3699 } |
3700 | 3700 |
3701 function keyPromise() { | 3701 function keyPromise() { |
3702 return new Promise(function (resolve, reject) { | 3702 return new Promise(function (resolve, reject) { |
3703 var req = new XMLHttpRequest(); | 3703 var req = new XMLHttpRequest(); |
3704 req.open("GET", returnURL + "php/requestKey.php?saveFilenamePrefix=" + parent.filenamePrefix, true); | 3704 req.open("GET", returnURL + "php/requestKey.php?saveFilenamePrefix=" + parent.filenamePrefix, true); |
3719 req.onerror = function () { | 3719 req.onerror = function () { |
3720 reject(Error("Network Error")); | 3720 reject(Error("Network Error")); |
3721 }; | 3721 }; |
3722 | 3722 |
3723 req.send(); | 3723 req.send(); |
3724 }) | 3724 }); |
3725 } | 3725 } |
3726 | 3726 |
3727 var requestChains = null; | 3727 var requestChains = null; |
3728 var sessionKey = null; | 3728 var sessionKey = null; |
3729 var object = {}; | 3729 var object = {}; |
3732 "key": { | 3732 "key": { |
3733 "get": function () { | 3733 "get": function () { |
3734 return sessionKey; | 3734 return sessionKey; |
3735 }, | 3735 }, |
3736 "set": function (a) { | 3736 "set": function (a) { |
3737 throw ("Cannot set read-only property") | 3737 throw ("Cannot set read-only property"); |
3738 } | 3738 } |
3739 }, | 3739 }, |
3740 "request": { | 3740 "request": { |
3741 "value": new XMLHttpRequest() | 3741 "value": new XMLHttpRequest() |
3742 }, | 3742 }, |
3773 }); | 3773 }); |
3774 } | 3774 } |
3775 }, | 3775 }, |
3776 "update": { | 3776 "update": { |
3777 "value": function () { | 3777 "value": function () { |
3778 if (this.key == null || requestChains === undefined) { | 3778 if (this.key === null || requestChains === undefined) { |
3779 throw ("Cannot save as key == null"); | 3779 throw ("Cannot save as key == null"); |
3780 } | 3780 } |
3781 this.parent.root.setAttribute("state", "update"); | 3781 this.parent.root.setAttribute("state", "update"); |
3782 requestChains = requestChains.then(postUpdate); | 3782 requestChains = requestChains.then(postUpdate); |
3783 } | 3783 } |
3784 }, | 3784 }, |
3785 "finish": { | 3785 "finish": { |
3786 "value": function () { | 3786 "value": function () { |
3787 if (this.key == null || requestChains === undefined) { | 3787 if (this.key === null || requestChains === undefined) { |
3788 throw ("Cannot save as key == null"); | 3788 throw ("Cannot save as key == null"); |
3789 } | 3789 } |
3790 this.parent.finish(); | 3790 this.parent.finish(); |
3791 return requestChains.then(postUpdate()).then(function () { | 3791 return requestChains.then(postUpdate()).then(function () { |
3792 console.log("OK"); | 3792 console.log("OK"); |
3793 }, function () { | 3793 }, function () { |
3794 createProjectSave("local"); | 3794 createProjectSave("local"); |
3795 }) | 3795 }); |
3796 } | 3796 } |
3797 } | 3797 } |
3798 }); | 3798 }); |
3799 return object; | 3799 return object; |
3800 })(this); | 3800 })(this); |