allow <code class=...>, temporary MathJax fix, try to fix pre-filled inputs bug
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 29 Jan 2018 16:01:18 +0000 (17:01 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 29 Jan 2018 16:01:18 +0000 (17:01 +0100)
public/javascripts/assessment.js
routes/assessments.js

index d0567d5..91e34fc 100644 (file)
@@ -15,6 +15,15 @@ function checkWindowSize()
        return window.innerWidth >= screen.width-3 && window.innerHeight >= screen.height-3;
 };
 
        return window.innerWidth >= screen.width-3 && window.innerHeight >= screen.height-3;
 };
 
+function libsRefresh()
+{
+       // Run Prism + MathJax on questions text
+       $("#statements").find("code[class^=language-]").each( (i,elem) => {
+               Prism.highlightElement(elem);
+       });
+       MathJax.Hub.Queue(["Typeset",MathJax.Hub,"statements"]);
+}
+
 new Vue({
        el: "#assessment",
        data: {
 new Vue({
        el: "#assessment",
        data: {
@@ -183,6 +192,9 @@ new Vue({
                                        document.location.href= "/fullscreen";
                                }, false);
                        },
                                        document.location.href= "/fullscreen";
                                }, false);
                        },
+                       updated: function() {
+                               libsRefresh(); //TODO: shouldn't be required: "MathJax" strings on start and assign them to assessment.questions. ...
+                       },
                        methods: {
                                inputId: function(i,j) {
                                        return "q" + i + "_" + "input" + j;
                        methods: {
                                inputId: function(i,j) {
                                        return "q" + i + "_" + "input" + j;
@@ -300,18 +312,12 @@ new Vue({
                                {
                                        // Resuming
                                        let indices = paper.inputs.map( input => { return input.index; });
                                {
                                        // Resuming
                                        let indices = paper.inputs.map( input => { return input.index; });
-                                       let remainingIndices = _.difference(_.range(assessment.questions.length), indices);
+                                       let remainingIndices = _.difference( _.range(assessment.questions.length).map(String), indices );
                                        assessment.indices = indices.concat( _.shuffle(remainingIndices) );
                                }
                                assessment.index = !!paper ? paper.inputs.length : 0;
                                        assessment.indices = indices.concat( _.shuffle(remainingIndices) );
                                }
                                assessment.index = !!paper ? paper.inputs.length : 0;
+                               Vue.nextTick(libsRefresh);
                                this.stage = 2;
                                this.stage = 2;
-                               Vue.nextTick( () => {
-                                       // Run Prism + MathJax on questions text
-                                       $("#statements").find("code[class^=language-]").each( (i,elem) => {
-                                               Prism.highlightElement(elem);
-                                       });
-                                       MathJax.Hub.Queue(["Typeset",MathJax.Hub,"statements"]);
-                               });
                        };
                        if (assessment.mode == "open")
                                return initializeStage2();
                        };
                        if (assessment.mode == "open")
                                return initializeStage2();
index 49410c4..dc749ed 100644 (file)
@@ -8,6 +8,10 @@ const params = require("../config/parameters");
 const validator = require("../public/javascripts/utils/validation");
 const ObjectId = require("bson-objectid");
 const sanitizeHtml = require('sanitize-html');
 const validator = require("../public/javascripts/utils/validation");
 const ObjectId = require("bson-objectid");
 const sanitizeHtml = require('sanitize-html');
+const sanitizeOpts = {
+       allowedTags: sanitizeHtml.defaults.allowedTags.concat([ 'img' ]),
+       allowedAttributes: { code: [ 'class' ] },
+};
 
 router.get("/add/assessment", access.ajax, access.logged, (req,res) => {
        const name = req.query["name"];
 
 router.get("/add/assessment", access.ajax, access.logged, (req,res) => {
        const name = req.query["name"];
@@ -27,7 +31,6 @@ router.post("/update/assessment", access.ajax, access.logged, (req,res) => {
        let error = validator(assessment, "Assessment");
        if (error.length > 0)
                return res.json({errmsg:error});
        let error = validator(assessment, "Assessment");
        if (error.length > 0)
                return res.json({errmsg:error});
-       const sanitizeOpts = {allowedTags: sanitizeHtml.defaults.allowedTags.concat([ 'img' ]) };
        assessment.introduction = sanitizeHtml(assessment.introduction, sanitizeOpts);
        assessment.conclusion = sanitizeHtml(assessment.conclusion, sanitizeOpts);
        assessment.questions.forEach( q => {
        assessment.introduction = sanitizeHtml(assessment.introduction, sanitizeOpts);
        assessment.conclusion = sanitizeHtml(assessment.conclusion, sanitizeOpts);
        assessment.questions.forEach( q => {