comparison js/core.js @ 3034:49eca76782d2

Fix #218
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 26 Sep 2017 09:34:38 +0100
parents 63af2e23c3d2
children 9d4f0934cf34
comparison
equal deleted inserted replaced
3033:21e3777edf58 3034:49eca76782d2
1081 p = new DOMParser(); 1081 p = new DOMParser();
1082 lastNodeStart = new Date(); 1082 lastNodeStart = new Date();
1083 this.popupResponse.innerHTML = ""; 1083 this.popupResponse.innerHTML = "";
1084 this.popupTitle.innerHTML = ""; 1084 this.popupTitle.innerHTML = "";
1085 var strings = node.specification.statement.split("\n"); 1085 var strings = node.specification.statement.split("\n");
1086 strings.forEach(function(e,i,a){ 1086 strings.forEach(function (e, i, a) {
1087 a[i] = e.trim(); 1087 a[i] = e.trim();
1088 }); 1088 });
1089 node.specification.statement = strings.join("\n"); 1089 node.specification.statement = strings.join("\n");
1090 var statementElements = p.parseFromString(converter.makeHtml(node.specification.statement), "text/html").querySelector("body").children; 1090 var statementElements = p.parseFromString(converter.makeHtml(node.specification.statement), "text/html").querySelector("body").children;
1091 while(statementElements.length > 0) { 1091 while (statementElements.length > 0) {
1092 this.popupTitle.appendChild(statementElements[0]); 1092 this.popupTitle.appendChild(statementElements[0]);
1093 } 1093 }
1094 if (node.specification.type == 'question') { 1094 if (node.specification.type == 'question') {
1095 postQuestion.call(this, node); 1095 postQuestion.call(this, node);
1096 } else if (node.specification.type == 'checkbox') { 1096 } else if (node.specification.type == 'checkbox') {
2638 } 2638 }
2639 this.holder.style.width = boxwidth + "px"; 2639 this.holder.style.width = boxwidth + "px";
2640 this.textArea.style.width = boxwidth - 6 + "px"; 2640 this.textArea.style.width = boxwidth - 6 + "px";
2641 }; 2641 };
2642 this.resize(); 2642 this.resize();
2643 this.check = function () {
2644 if (this.specification.mandatory && this.textArea.value.length == 0) {
2645 return false;
2646 }
2647 return true;
2648 }
2643 }; 2649 };
2644 2650
2645 this.radioBox = function (commentQuestion) { 2651 this.radioBox = function (commentQuestion) {
2646 this.specification = commentQuestion; 2652 this.specification = commentQuestion;
2647 // Create document objects to hold the comment boxes 2653 // Create document objects to hold the comment boxes
2713 boxwidth = 400; 2719 boxwidth = 400;
2714 } 2720 }
2715 this.holder.style.width = boxwidth + "px"; 2721 this.holder.style.width = boxwidth + "px";
2716 }; 2722 };
2717 this.resize(); 2723 this.resize();
2724 this.check = function () {
2725 if (this.specification.mandatory) {
2726 var selected = this.options.find(function (o) {
2727 return o.checked;
2728 });
2729 if (selected === undefined) {
2730 return false;
2731 }
2732 }
2733 return true;
2734 };
2718 }; 2735 };
2719 2736
2720 this.checkboxBox = function (commentQuestion) { 2737 this.checkboxBox = function (commentQuestion) {
2721 this.specification = commentQuestion; 2738 this.specification = commentQuestion;
2722 // Create document objects to hold the comment boxes 2739 // Create document objects to hold the comment boxes
2779 boxwidth = 400; 2796 boxwidth = 400;
2780 } 2797 }
2781 this.holder.style.width = boxwidth + "px"; 2798 this.holder.style.width = boxwidth + "px";
2782 }; 2799 };
2783 this.resize(); 2800 this.resize();
2801 this.check = function () {
2802 if (this.specification.mandatory) {
2803 var selected = this.options.filter(function (o) {
2804 return o.checked;
2805 });
2806 if (selected.length === 0) {
2807 return false;
2808 }
2809 }
2810 return true;
2811 };
2784 }; 2812 };
2785 2813
2786 this.sliderBox = function (commentQuestion) { 2814 this.sliderBox = function (commentQuestion) {
2787 this.specification = commentQuestion; 2815 this.specification = commentQuestion;
2788 this.holder = document.createElement("div"); 2816 this.holder = document.createElement("div");
2836 } 2864 }
2837 this.holder.style.width = boxwidth + "px"; 2865 this.holder.style.width = boxwidth + "px";
2838 this.slider.style.width = boxwidth - 24 + "px"; 2866 this.slider.style.width = boxwidth - 24 + "px";
2839 }; 2867 };
2840 this.resize(); 2868 this.resize();
2869 this.check = function () {
2870 return true;
2871 };
2841 }; 2872 };
2842 2873
2843 this.createCommentQuestion = function (element) { 2874 this.createCommentQuestion = function (element) {
2844 var node; 2875 var node;
2845 if (element.type == 'question') { 2876 if (element.type == 'question') {
2856 }; 2887 };
2857 2888
2858 this.deleteCommentQuestions = function () { 2889 this.deleteCommentQuestions = function () {
2859 this.commentQuestions = []; 2890 this.commentQuestions = [];
2860 }; 2891 };
2892
2893 this.checkCommentQuestions = function () {
2894 var failed = this.commentQuestions.filter(function (a) {
2895 return a.check() === false;
2896 });
2897 if (failed.length === 0) {
2898 return true;
2899 }
2900 this.lightbox.post("Error", "Please answer the questions on the page.");
2901 return false;
2902 }
2861 2903
2862 this.outsideReferenceDOM = function (audioObject, index, inject) { 2904 this.outsideReferenceDOM = function (audioObject, index, inject) {
2863 this.parent = audioObject; 2905 this.parent = audioObject;
2864 this.outsideReferenceHolder = document.createElement('button'); 2906 this.outsideReferenceHolder = document.createElement('button');
2865 this.outsideReferenceHolder.className = 'outside-reference'; 2907 this.outsideReferenceHolder.className = 'outside-reference';