comparison js/core.js @ 2579:d83b38564fbb

#137. Modified <commentquestion> nodes in pages to have a proper list structure. Differently labelled nodes depending on type <commentquestion>, <commentradio>. Added slider and converted project.xml to match new specifications. AB_example.xml shows new slider type
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Sun, 30 Oct 2016 13:57:37 +0000
parents bf17cc19c1c0
children a6b32c473577
comparison
equal deleted inserted replaced
2578:bf17cc19c1c0 2579:d83b38564fbb
2628 } 2628 }
2629 }; 2629 };
2630 this.resize(); 2630 this.resize();
2631 }; 2631 };
2632 2632
2633 this.sliderBox = function (commentQuestion) {
2634 this.specification = commentQuestion;
2635 this.holder = document.createElement("div");
2636 this.holder.className = 'comment-div';
2637 this.string = document.createElement("span");
2638 this.string.innerHTML = commentQuestion.statement;
2639 this.slider = document.createElement("input");
2640 this.slider.type = "range";
2641 this.slider.min = commentQuestion.min;
2642 this.slider.max = commentQuestion.max;
2643 this.slider.step = commentQuestion.step;
2644 this.slider.value = commentQuestion.value;
2645 var br = document.createElement('br');
2646
2647 this.holder.appendChild(this.string);
2648 this.holder.appendChild(br);
2649 this.holder.appendChild(this.slider);
2650
2651 this.exportXMLDOM = function (storePoint) {
2652 var root = storePoint.parent.document.createElement('comment');
2653 root.id = this.specification.id;
2654 root.setAttribute('type', this.specification.type);
2655 console.log("Question: " + this.string.textContent);
2656 console.log("Response: " + this.slider.value);
2657 var question = storePoint.parent.document.createElement('question');
2658 question.textContent = this.string.textContent;
2659 var response = storePoint.parent.document.createElement('response');
2660 response.textContent = this.slider.value;
2661 root.appendChild(question);
2662 root.appendChild(response);
2663 storePoint.XMLDOM.appendChild(root);
2664 return root;
2665 };
2666 this.resize = function () {
2667 var boxwidth = (window.innerWidth - 100) / 2;
2668 if (boxwidth >= 600) {
2669 boxwidth = 600;
2670 } else if (boxwidth < 400) {
2671 boxwidth = 400;
2672 }
2673 this.holder.style.width = boxwidth + "px";
2674 this.slider.style.width = boxwidth - 24 + "px";
2675 };
2676 this.resize();
2677 };
2678
2633 this.createCommentQuestion = function (element) { 2679 this.createCommentQuestion = function (element) {
2634 var node; 2680 var node;
2635 if (element.type == 'question') { 2681 if (element.type == 'question') {
2636 node = new this.commentBox(element); 2682 node = new this.commentBox(element);
2637 } else if (element.type == 'radio') { 2683 } else if (element.type == 'radio') {
2638 node = new this.radioBox(element); 2684 node = new this.radioBox(element);
2639 } else if (element.type == 'checkbox') { 2685 } else if (element.type == 'checkbox') {
2640 node = new this.checkboxBox(element); 2686 node = new this.checkboxBox(element);
2687 } else if (element.type == 'slider') {
2688 node = new this.sliderBox(element);
2641 } 2689 }
2642 this.commentQuestions.push(node); 2690 this.commentQuestions.push(node);
2643 return node; 2691 return node;
2644 }; 2692 };
2645 2693