changeset 2399:5d7ad658c699

Hotfix: Multiple audioElements with type="outside-reference" may be duplicated / incorrectly sent through randomisation. Fixed.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 26 May 2016 16:06:42 +0100
parents c970a531228c
children e7601d5ff17b 5e1fb07919e7 2f6a1f510ade
files js/core.js
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/js/core.js	Thu May 26 15:02:11 2016 +0100
+++ b/js/core.js	Thu May 26 16:06:42 2016 +0100
@@ -1095,19 +1095,23 @@
 			{
 				this.currentStateMap = this.stateMap[this.stateIndex];
                 // Find and extract the outside reference
-                var elements = [], ref = null;
-                for (var elem of this.currentStateMap.audioElements) {
-                    if (elem.type == "outside-reference") {ref = elem;}
-                    else {elements.push(elem);}
+                var elements = [], ref = [];
+                var elem;
+                while(elem = this.currentStateMap.audioElements.pop())
+                {
+                    if (elem.type == "outside-reference") {
+                        ref.push(elem);
+                    }
+                    else {
+                        elements.push(elem);
+                    }
                 }
 				if (this.currentStateMap.randomiseOrder)
 				{
-					this.currentStateMap.audioElements = randomiseOrder(elements);
+					elements = randomiseOrder(elements);
 				}
-                if (ref != null)
-                {
-                    this.currentStateMap.audioElements.push(ref);
-                }
+                this.currentStateMap.audioElements = elements.concat(ref);
+                
                 this.currentStore = storage.testPages[this.stateIndex];
 				if (this.currentStateMap.preTest != null)
 				{