Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2583:5f7c11fa5f83
Added <surveyslider> to <survey> nodes. Supports min, max, minText and maxText.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 31 Oct 2016 16:34:55 +0000 |
parents | a6b32c473577 |
children | 89f787e2e90c |
comparison
equal
deleted
inserted
replaced
2582:224842b28bf2 | 2583:5f7c11fa5f83 |
---|---|
797 } | 797 } |
798 this.popupResponse.appendChild(table); | 798 this.popupResponse.appendChild(table); |
799 } else if (node.specification.type == 'number') { | 799 } else if (node.specification.type == 'number') { |
800 var input = document.createElement('input'); | 800 var input = document.createElement('input'); |
801 input.type = 'textarea'; | 801 input.type = 'textarea'; |
802 if (node.min != null) { | 802 if (node.specification.min != null) { |
803 input.min = node.specification.min; | 803 input.min = node.specification.min; |
804 } | 804 } |
805 if (node.max != null) { | 805 if (node.specification.max != null) { |
806 input.max = node.specification.max; | 806 input.max = node.specification.max; |
807 } | 807 } |
808 if (node.step != null) { | 808 if (node.specification.step != null) { |
809 input.step = node.specification.step; | 809 input.step = node.specification.step; |
810 } | 810 } |
811 if (node.response != undefined) { | 811 if (node.response != undefined) { |
812 input.value = node.response; | 812 input.value = node.response; |
813 } | 813 } |
821 } else if (node.specification.type == "youtube") { | 821 } else if (node.specification.type == "youtube") { |
822 var iframe = document.createElement("iframe"); | 822 var iframe = document.createElement("iframe"); |
823 iframe.className = "youtube"; | 823 iframe.className = "youtube"; |
824 iframe.src = node.specification.url; | 824 iframe.src = node.specification.url; |
825 this.popupResponse.appendChild(iframe); | 825 this.popupResponse.appendChild(iframe); |
826 } else if (node.specification.type == "slider") { | |
827 var hold = document.createElement('div'); | |
828 var input = document.createElement('input'); | |
829 input.type = 'range'; | |
830 input.style.width = "90%"; | |
831 if (node.specification.min != null) { | |
832 input.min = node.specification.min; | |
833 } | |
834 if (node.specification.max != null) { | |
835 input.max = node.specification.max; | |
836 } | |
837 if (node.response != undefined) { | |
838 input.value = node.response; | |
839 } | |
840 hold.className = "survey-slider-text-holder"; | |
841 var minText = document.createElement('span'); | |
842 var maxText = document.createElement('span'); | |
843 minText.textContent = node.specification.leftText; | |
844 maxText.textContent = node.specification.rightText; | |
845 hold.appendChild(minText); | |
846 hold.appendChild(maxText); | |
847 this.popupResponse.appendChild(input); | |
848 this.popupResponse.appendChild(hold); | |
849 this.popupResponse.style.textAlign = "center"; | |
826 } | 850 } |
827 if (this.currentIndex + 1 == this.popupOptions.length) { | 851 if (this.currentIndex + 1 == this.popupOptions.length) { |
828 if (this.node.location == "pre") { | 852 if (this.node.location == "pre") { |
829 this.buttonProceed.textContent = 'Start'; | 853 this.buttonProceed.textContent = 'Start'; |
830 } else { | 854 } else { |
1065 interfaceContext.lightbox.post("Error", 'Number is above the maximum value of ' + node.max); | 1089 interfaceContext.lightbox.post("Error", 'Number is above the maximum value of ' + node.max); |
1066 return; | 1090 return; |
1067 } | 1091 } |
1068 node.response = input.value; | 1092 node.response = input.value; |
1069 // Perform the conditional | 1093 // Perform the conditional |
1094 for (var condition of node.specification.conditions) { | |
1095 var pass = false; | |
1096 switch (condition.check) { | |
1097 case "contains": | |
1098 console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING"); | |
1099 break; | |
1100 case "greaterThan": | |
1101 if (node.response > Number(condition.value)) { | |
1102 pass = true; | |
1103 } | |
1104 break; | |
1105 case "lessThan": | |
1106 if (node.response < Number(condition.value)) { | |
1107 pass = true; | |
1108 } | |
1109 break; | |
1110 case "equals": | |
1111 if (node.response == condition.value) { | |
1112 pass = true; | |
1113 } | |
1114 break; | |
1115 } | |
1116 var jumpID; | |
1117 if (pass) { | |
1118 jumpID = condition.jumpToOnPass; | |
1119 } else { | |
1120 jumpID = condition.jumpToOnFail; | |
1121 } | |
1122 if (jumpID != undefined) { | |
1123 var index = this.popupOptions.findIndex(function (item, index, element) { | |
1124 if (item.specification.id == jumpID) { | |
1125 return true; | |
1126 } else { | |
1127 return false; | |
1128 } | |
1129 }, this); | |
1130 this.currentIndex = index - 1; | |
1131 break; | |
1132 } | |
1133 } | |
1134 } else if (node.specification.type == 'slider') { | |
1135 var input = this.popupContent.getElementsByTagName('input')[0]; | |
1136 node.response = input.value; | |
1070 for (var condition of node.specification.conditions) { | 1137 for (var condition of node.specification.conditions) { |
1071 var pass = false; | 1138 var pass = false; |
1072 switch (condition.check) { | 1139 switch (condition.check) { |
1073 case "contains": | 1140 case "contains": |
1074 console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING"); | 1141 console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING"); |
3325 surveyresult = surveyresult.nextElementSibling; | 3392 surveyresult = surveyresult.nextElementSibling; |
3326 } | 3393 } |
3327 switch (node.specification.type) { | 3394 switch (node.specification.type) { |
3328 case "number": | 3395 case "number": |
3329 case "question": | 3396 case "question": |
3397 case "slider": | |
3330 var child = this.parent.document.createElement('response'); | 3398 var child = this.parent.document.createElement('response'); |
3331 child.textContent = node.response; | 3399 child.textContent = node.response; |
3332 surveyresult.appendChild(child); | 3400 surveyresult.appendChild(child); |
3333 break; | 3401 break; |
3334 case "radio": | 3402 case "radio": |