From 113aec25bf75e0613f959001bdb4066ba35cb6d2 Mon Sep 17 00:00:00 2001 From: cahrens Date: Fri, 7 Oct 2016 15:39:44 -0400 Subject: [PATCH] eslint corrections --- .../xmodule/xmodule/js/src/problem/edit.js | 421 ++++++++++-------- 1 file changed, 232 insertions(+), 189 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.js b/common/lib/xmodule/xmodule/js/src/problem/edit.js index 30d9970539..9c4c9cf082 100644 --- a/common/lib/xmodule/xmodule/js/src/problem/edit.js +++ b/common/lib/xmodule/xmodule/js/src/problem/edit.js @@ -1,63 +1,82 @@ -// Generated by CoffeeScript 1.6.1 +/* global CodeMirror, _, XModule, PrettyPrint */ +// no-useless-escape disabled because of warnings in regexp expressions within the +// "toXML" code. When the "useless escapes" were removed, some of the unit tests +// failed, but only in Jenkins, indicating browser-specific behavior. +/* eslint no-useless-escape: 0 */ + (function() { - var _this = this, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { - for (var key in parent) { - if (__hasProp.call(parent, key)) child[key] = parent[key]; + 'use strict'; + var hasPropsHelper = {}.hasOwnProperty, + extendsHelper = function(child, parent) { + // This helper method was generated by CoffeeScript. Suppressing eslint warnings. + var key; + for (key in parent) { // eslint-disable-line no-restricted-syntax + if (hasPropsHelper.call(parent, key)) { + child[key] = parent[key]; // eslint-disable-line no-param-reassign + } } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; - child.prototype = new ctor(); - child.__super__ = parent.prototype; + child.prototype = new ctor(); // eslint-disable-line no-param-reassign + child.__super__ = parent.prototype; // eslint-disable-line no-param-reassign, no-underscore-dangle return child; }; this.MarkdownEditingDescriptor = (function(_super) { + // The style of these declarations come from CoffeeScript. Rather than rewriting them, + // the eslint warnings are being suppressed. + extendsHelper(MarkdownEditingDescriptor, _super); // eslint-disable-line no-use-before-define - __extends(MarkdownEditingDescriptor, _super); + MarkdownEditingDescriptor.multipleChoiceTemplate = '( ) ' + // eslint-disable-line no-use-before-define + (gettext('incorrect')) + '\n( ) ' + (gettext('incorrect')) + '\n(x) ' + (gettext('correct')) + '\n'; - MarkdownEditingDescriptor.multipleChoiceTemplate = "( ) " + (gettext('incorrect')) + "\n( ) " + (gettext('incorrect')) + "\n(x) " + (gettext('correct')) + "\n"; + MarkdownEditingDescriptor.checkboxChoiceTemplate = '[x] ' + // eslint-disable-line no-use-before-define + (gettext('correct')) + '\n[ ] incorrect\n[x] correct\n'; - MarkdownEditingDescriptor.checkboxChoiceTemplate = "[x] " + (gettext('correct')) + "\n[ ] incorrect\n[x] correct\n"; + MarkdownEditingDescriptor.stringInputTemplate = '= ' + // eslint-disable-line no-use-before-define + (gettext('answer')) + '\n'; - MarkdownEditingDescriptor.stringInputTemplate = "= " + (gettext('answer')) + "\n"; + MarkdownEditingDescriptor.numberInputTemplate = '= ' + // eslint-disable-line no-use-before-define + (gettext('answer')) + ' +- 0.001%\n'; - MarkdownEditingDescriptor.numberInputTemplate = "= " + (gettext('answer')) + " +- 0.001%\n"; + MarkdownEditingDescriptor.selectTemplate = '[[' + // eslint-disable-line no-use-before-define + (gettext('incorrect')) + ', (' + (gettext('correct')) + '), ' + (gettext('incorrect')) + ']]\n'; - MarkdownEditingDescriptor.selectTemplate = "[[" + (gettext('incorrect')) + ", (" + (gettext('correct')) + "), " + (gettext('incorrect')) + "]]\n"; + MarkdownEditingDescriptor.headerTemplate = '' + // eslint-disable-line no-use-before-define + (gettext('Header')) + '\n=====\n'; - MarkdownEditingDescriptor.headerTemplate = "" + (gettext('Header')) + "\n=====\n"; - - MarkdownEditingDescriptor.explanationTemplate = "[explanation]\n" + (gettext('Short explanation')) + "\n[explanation]\n"; + MarkdownEditingDescriptor.explanationTemplate = '[explanation]\n' + // eslint-disable-line no-use-before-define + (gettext('Short explanation')) + '\n[explanation]\n'; function MarkdownEditingDescriptor(element) { - var _this = this; + var that = this; this.toggleCheatsheetVisibility = function() { - return MarkdownEditingDescriptor.prototype.toggleCheatsheetVisibility.apply(_this, arguments); + return MarkdownEditingDescriptor.prototype.toggleCheatsheetVisibility.apply(that, arguments); }; - this.toggleCheatsheet = function(e) { - return MarkdownEditingDescriptor.prototype.toggleCheatsheet.apply(_this, arguments); + this.toggleCheatsheet = function() { + return MarkdownEditingDescriptor.prototype.toggleCheatsheet.apply(that, arguments); }; - this.onToolbarButton = function(e) { - return MarkdownEditingDescriptor.prototype.onToolbarButton.apply(_this, arguments); + this.onToolbarButton = function() { + return MarkdownEditingDescriptor.prototype.onToolbarButton.apply(that, arguments); }; - this.onShowXMLButton = function(e) { - return MarkdownEditingDescriptor.prototype.onShowXMLButton.apply(_this, arguments); + this.onShowXMLButton = function() { + return MarkdownEditingDescriptor.prototype.onShowXMLButton.apply(that, arguments); }; this.element = element; - if ($(".markdown-box", this.element).length !== 0) { - this.markdown_editor = CodeMirror.fromTextArea($(".markdown-box", element)[0], { + if ($('.markdown-box', this.element).length !== 0) { + this.markdown_editor = CodeMirror.fromTextArea($('.markdown-box', element)[0], { lineWrapping: true, mode: null }); this.setCurrentEditor(this.markdown_editor); + // Add listeners for toolbar buttons (only present for markdown editor) this.element.on('click', '.xml-tab', this.onShowXMLButton); this.element.on('click', '.format-buttons button', this.onToolbarButton); this.element.on('click', '.cheatsheet-toggle', this.toggleCheatsheet); + // Hide the XML text area $(this.element.find('.xml-box')).hide(); } else { this.createXMLEditor(); @@ -70,11 +89,9 @@ text: optional argument to override the text passed in via the HTML template */ - - MarkdownEditingDescriptor.prototype.createXMLEditor = function(text) { - this.xml_editor = CodeMirror.fromTextArea($(".xml-box", this.element)[0], { - mode: "xml", + this.xml_editor = CodeMirror.fromTextArea($('.xml-box', this.element)[0], { + mode: 'xml', lineNumbers: true, lineWrapping: true }); @@ -82,16 +99,15 @@ this.xml_editor.setValue(text); } this.setCurrentEditor(this.xml_editor); - $(this.xml_editor.getWrapperElement()).toggleClass("CodeMirror-advanced"); - return this.xml_editor.refresh(); + $(this.xml_editor.getWrapperElement()).toggleClass('CodeMirror-advanced'); + // Need to refresh to get line numbers to display properly. + this.xml_editor.refresh(); }; /* User has clicked to show the XML editor. Before XML editor is swapped in, the user will need to confirm the one-way conversion. */ - - MarkdownEditingDescriptor.prototype.onShowXMLButton = function(e) { e.preventDefault(); if (this.cheatsheet && this.cheatsheet.hasClass('shown')) { @@ -101,7 +117,8 @@ if (this.confirmConversionToXml()) { this.createXMLEditor(MarkdownEditingDescriptor.markdownToXml(this.markdown_editor.getValue())); this.xml_editor.setCursor(0); - return $(this.element.find('.editor-bar')).hide(); + // Hide markdown-specific toolbar buttons + $(this.element.find('.editor-bar')).hide(); } }; @@ -109,58 +126,54 @@ Have the user confirm the one-way conversion to XML. Returns true if the user clicked OK, else false. */ - - MarkdownEditingDescriptor.prototype.confirmConversionToXml = function() { - return confirm(gettext("If you use the Advanced Editor, this problem will be converted to XML and you will not be able to return to the Simple Editor Interface.\n\nProceed to the Advanced Editor and convert this problem to XML?")); + return confirm(gettext('If you use the Advanced Editor, this problem will be converted to XML and you will not be able to return to the Simple Editor Interface.\n\nProceed to the Advanced Editor and convert this problem to XML?')); // eslint-disable-line max-len, no-alert }; /* Event listener for toolbar buttons (only possible when markdown editor is visible). */ - - MarkdownEditingDescriptor.prototype.onToolbarButton = function(e) { var revisedSelection, selection; e.preventDefault(); selection = this.markdown_editor.getSelection(); revisedSelection = null; switch ($(e.currentTarget).attr('class')) { - case "multiple-choice-button": - revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice(selection); - break; - case "string-button": - revisedSelection = MarkdownEditingDescriptor.insertStringInput(selection); - break; - case "number-button": - revisedSelection = MarkdownEditingDescriptor.insertNumberInput(selection); - break; - case "checks-button": - revisedSelection = MarkdownEditingDescriptor.insertCheckboxChoice(selection); - break; - case "dropdown-button": - revisedSelection = MarkdownEditingDescriptor.insertSelect(selection); - break; - case "header-button": - revisedSelection = MarkdownEditingDescriptor.insertHeader(selection); - break; - case "explanation-button": - revisedSelection = MarkdownEditingDescriptor.insertExplanation(selection); - break; + case 'multiple-choice-button': + revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice(selection); + break; + case 'string-button': + revisedSelection = MarkdownEditingDescriptor.insertStringInput(selection); + break; + case 'number-button': + revisedSelection = MarkdownEditingDescriptor.insertNumberInput(selection); + break; + case 'checks-button': + revisedSelection = MarkdownEditingDescriptor.insertCheckboxChoice(selection); + break; + case 'dropdown-button': + revisedSelection = MarkdownEditingDescriptor.insertSelect(selection); + break; + case 'header-button': + revisedSelection = MarkdownEditingDescriptor.insertHeader(selection); + break; + case 'explanation-button': + revisedSelection = MarkdownEditingDescriptor.insertExplanation(selection); + break; + default: + break; } if (revisedSelection !== null) { this.markdown_editor.replaceSelection(revisedSelection); - return this.markdown_editor.focus(); + this.markdown_editor.focus(); } }; /* Event listener for toggling cheatsheet (only possible when markdown editor is visible). */ - - MarkdownEditingDescriptor.prototype.toggleCheatsheet = function(e) { - var _this = this; + var that = this; e.preventDefault(); if (!$(this.markdown_editor.getWrapperElement()).find('.simple-editor-cheatsheet')[0]) { this.cheatsheet = $($('#simple-editor-cheatsheet').html()); @@ -168,15 +181,13 @@ } this.toggleCheatsheetVisibility(); return setTimeout((function() { - return _this.cheatsheet.toggleClass('shown'); + return that.cheatsheet.toggleClass('shown'); }), 10); }; /* Function to toggle cheatsheet visibility. */ - - MarkdownEditingDescriptor.prototype.toggleCheatsheetVisibility = function() { return $('.modal-content').toggleClass('cheatsheet-is-shown'); }; @@ -184,8 +195,6 @@ /* Stores the current editor and hides the one that is not displayed. */ - - MarkdownEditingDescriptor.prototype.setCurrentEditor = function(editor) { if (this.current_editor) { $(this.current_editor.getWrapperElement()).hide(); @@ -200,8 +209,6 @@ result in a new instance of the descriptor. Note that this is NOT the case for cancel-- when cancel is called the instance of the descriptor is reused if edit is selected again. */ - - MarkdownEditingDescriptor.prototype.save = function() { this.element.off('click', '.xml-tab', this.changeEditor); this.element.off('click', '.format-buttons button', this.onToolbarButton); @@ -222,23 +229,30 @@ }; MarkdownEditingDescriptor.insertMultipleChoice = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericChoice(selectedText, '(', ')', MarkdownEditingDescriptor.multipleChoiceTemplate); + return MarkdownEditingDescriptor.insertGenericChoice(selectedText, '(', ')', + MarkdownEditingDescriptor.multipleChoiceTemplate + ); }; MarkdownEditingDescriptor.insertCheckboxChoice = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericChoice(selectedText, '[', ']', MarkdownEditingDescriptor.checkboxChoiceTemplate); + return MarkdownEditingDescriptor.insertGenericChoice(selectedText, '[', ']', + MarkdownEditingDescriptor.checkboxChoiceTemplate + ); }; MarkdownEditingDescriptor.insertGenericChoice = function(selectedText, choiceStart, choiceEnd, template) { - var cleanSelectedText, line, lines, revisedLines, _i, _len; + var cleanSelectedText, line, lines, revisedLines, i, len; if (selectedText.length > 0) { + // Replace adjacent newlines with a single newline, strip any trailing newline cleanSelectedText = selectedText.replace(/\n+/g, '\n').replace(/\n$/, ''); lines = cleanSelectedText.split('\n'); revisedLines = ''; - for (_i = 0, _len = lines.length; _i < _len; _i++) { - line = lines[_i]; + for (i = 0, len = lines.length; i < len; i++) { + line = lines[i]; revisedLines += choiceStart; + // a stand alone x before other text implies that this option is "correct" if (/^\s*x\s+(\S)/i.test(line)) { + // Remove the x and any initial whitespace as long as there's more text on the line line = line.replace(/^\s*x\s+(\S)/i, '$1'); revisedLines += 'x'; } else { @@ -253,23 +267,33 @@ }; MarkdownEditingDescriptor.insertStringInput = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericInput(selectedText, '= ', '', MarkdownEditingDescriptor.stringInputTemplate); + return MarkdownEditingDescriptor.insertGenericInput(selectedText, '= ', '', + MarkdownEditingDescriptor.stringInputTemplate + ); }; MarkdownEditingDescriptor.insertNumberInput = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericInput(selectedText, '= ', '', MarkdownEditingDescriptor.numberInputTemplate); + return MarkdownEditingDescriptor.insertGenericInput(selectedText, '= ', '', + MarkdownEditingDescriptor.numberInputTemplate + ); }; MarkdownEditingDescriptor.insertSelect = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericInput(selectedText, '[[', ']]', MarkdownEditingDescriptor.selectTemplate); + return MarkdownEditingDescriptor.insertGenericInput(selectedText, '[[', ']]', + MarkdownEditingDescriptor.selectTemplate + ); }; MarkdownEditingDescriptor.insertHeader = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericInput(selectedText, '', '\n====\n', MarkdownEditingDescriptor.headerTemplate); + return MarkdownEditingDescriptor.insertGenericInput(selectedText, '', '\n====\n', + MarkdownEditingDescriptor.headerTemplate + ); }; MarkdownEditingDescriptor.insertExplanation = function(selectedText) { - return MarkdownEditingDescriptor.insertGenericInput(selectedText, '[explanation]\n', '\n[explanation]', MarkdownEditingDescriptor.explanationTemplate); + return MarkdownEditingDescriptor.insertGenericInput(selectedText, '[explanation]\n', '\n[explanation]', + MarkdownEditingDescriptor.explanationTemplate + ); }; MarkdownEditingDescriptor.insertGenericInput = function(selectedText, lineStart, lineEnd, template) { @@ -281,11 +305,12 @@ }; MarkdownEditingDescriptor.markdownToXml = function(markdown) { - var demandHintTags, demandHints, finalXml, responseTypesMarkdown, responseTypesXML, toXml; - demandHintTags = []; - toXml = function(markdown) { - var xml = markdown, - i, splits, makeParagraph; + var demandHintTags = [], + finalDemandHints, finalXml, responseTypesMarkdown, responseTypesXML, toXml; + toXml = function(partialMarkdown) { + var xml = partialMarkdown, + i, splits, makeParagraph, serializer, responseType, $xml, responseTypesSelector, + inputtype, beforeInputtype, extractHint, demandhints; var responseTypes = [ 'optionresponse', 'multiplechoiceresponse', 'stringresponse', 'numericalresponse', 'choiceresponse' ]; @@ -302,23 +327,24 @@ // description xml = xml.replace(/>>([^]+?)<' + '\n'; + label = '\n'; // don't add empty tag if (result.length === 1 || !result[1]) { return label; } - return label + '' + result[1] + '\n' - }) + return label + '' + result[1] + '\n'; + }); // Pull out demand hints, || a hint || - var demandhints = ''; + demandhints = ''; xml = xml.replace(/(^\s*\|\|.*?\|\|\s*$\n?)+/gm, function(match) { // $\n - var options = match.split('\n'); + var inner, + options = match.split('\n'); for (i = 0; i < options.length; i += 1) { - var inner = /\s*\|\|(.*?)\|\|/.exec(options[i]); + inner = /\s*\|\|(.*?)\|\|/.exec(options[i]); if (inner) { - //safe-lint: disable=javascript-concat-html + // safe-lint: disable=javascript-concat-html demandhints += ' ' + inner[1].trim() + '\n'; } } @@ -336,16 +362,18 @@ // Returns a little hash with various parts of the hint: // hint: the hint or empty, nothint: the rest // labelassign: javascript assignment of label attribute, or empty - extractHint = function(text, detectParens) { - var curly = /\s*{{(.*?)}}/.exec(text); - var hint = ''; - var label = ''; - var parens = false; - var labelassign = ''; + extractHint = function(inputText, detectParens) { + var text = inputText, + curly = /\s*{{(.*?)}}/.exec(text), + hint = '', + label = '', + parens = false, + labelassign = '', + labelmatch; if (curly) { text = text.replace(curly[0], ''); hint = curly[1].trim(); - var labelmatch = /^(.*?)::/.exec(hint); + labelmatch = /^(.*?)::/.exec(hint); if (labelmatch) { hint = hint.replace(labelmatch[0], '').trim(); label = labelmatch[1].trim(); @@ -353,19 +381,19 @@ } } if (detectParens) { - if (text.length >= 2 && text[0] == '(' && text[text.length - 1] == ')') { - text = text.substring(1, text.length - 1) + if (text.length >= 2 && text[0] === '(' && text[text.length - 1] === ')') { + text = text.substring(1, text.length - 1); parens = true; } } return { - 'nothint': text, - 'hint': hint, - 'label': label, - 'parens': parens, - 'labelassign': labelassign + nothint: text, + hint: hint, + label: label, + parens: parens, + labelassign: labelassign }; - } + }; // replace selects @@ -377,18 +405,22 @@ // ]] // // - // \n' + optionlines += ' ' + textHint.nothint + hintstr + + '\n'; } } - return '\n\n \n' + optionlines + ' \n\n\n'; + return '\n\n \n' + optionlines + + ' \n\n\n'; }); - //_____________________________________________________________________ - // // multiple choice questions // - xml = xml.replace(/(^\s*\(.{0,3}\).*?$\n*)+/gm, function(match, p) { - var choices = ''; - var shuffle = false; - var options = match.split('\n'); - for (var i = 0; i < options.length; i++) { + xml = xml.replace(/(^\s*\(.{0,3}\).*?$\n*)+/gm, function(match) { + var choices = '', + shuffle = false, + options = match.split('\n'), + value, inparens, correct, + fixed, hint, result; + for (i = 0; i < options.length; i++) { options[i] = options[i].trim(); // trim off leading/trailing whitespace if (options[i].length > 0) { - var value = options[i].split(/^\s*\(.{0,3}\)\s*/)[1]; - var inparens = /^\s*\((.{0,3})\)\s*/.exec(options[i])[1]; - var correct = /x/i.test(inparens); - var fixed = ''; + value = options[i].split(/^\s*\(.{0,3}\)\s*/)[1]; + inparens = /^\s*\((.{0,3})\)\s*/.exec(options[i])[1]; + correct = /x/i.test(inparens); + fixed = ''; if (/@/.test(inparens)) { fixed = ' fixed="true"'; } @@ -440,7 +474,7 @@ shuffle = true; } - var hint = extractHint(value); + hint = extractHint(value); if (hint.hint) { value = hint.nothint; value = value + ' ' + hint.hint + ''; @@ -448,7 +482,7 @@ choices += ' ' + value + '\n'; } } - var result = '\n'; + result = '\n'; if (shuffle) { result += ' \n'; } else { @@ -464,11 +498,11 @@ // [.] with {{...}} lines mixed in xml = xml.replace(/(^\s*((\[.?\])|({{.*?}})).*?$\n*)+/gm, function(match) { var groupString = '\n', - options, value, correct; + options = match.split('\n'), + value, correct, abhint, endHints, hintbody, + hint, inner, select, hints; groupString += ' \n'; - options = match.split('\n'); - endHints = ''; // save these up to emit at the end for (i = 0; i < options.length; i += 1) { @@ -476,31 +510,37 @@ // detect the {{ ((A*B)) ...}} case first // emits: AB hint - var abhint = /^\s*{{\s*\(\((.*?)\)\)(.*?)}}/.exec(options[i]); + abhint = /^\s*{{\s*\(\((.*?)\)\)(.*?)}}/.exec(options[i]); if (abhint) { // lone case of hint text processing outside of extractHint, since syntax here is unique - var hintbody = abhint[2]; - hintbody = hintbody.replace('&lf;', '\n').trim() - endHints += ' ' + hintbody + '\n'; + hintbody = abhint[2]; + hintbody = hintbody.replace('&lf;', '\n').trim(); + endHints += ' ' + hintbody + + '\n'; continue; // bail } value = options[i].split(/^\s*\[.?\]\s*/)[1]; correct = /^\s*\[x\]/i.test(options[i]); hints = ''; - // {{ selected: You’re right that apple is a fruit. }, {unselected: Remember that apple is also a fruit.}} - var hint = extractHint(value); + // {{ selected: You’re right that apple is a fruit. }, + // {unselected: Remember that apple is also a fruit.}} + hint = extractHint(value); if (hint.hint) { - var inner = '{' + hint.hint + '}'; // parsing is easier if we put outer { } back - var select = /{\s*(s|selected):((.|\n)*?)}/i.exec(inner); // include \n since we are downstream of extractHint() + inner = '{' + hint.hint + '}'; // parsing is easier if we put outer { } back + + // include \n since we are downstream of extractHint() + select = /{\s*(s|selected):((.|\n)*?)}/i.exec(inner); // checkbox choicehints get their own line, since there can be two of them // You’re right that apple is a fruit. if (select) { - hints += '\n ' + select[2].trim() + ''; + hints += '\n ' + select[2].trim() + + ''; } - var select = /{\s*(u|unselected):((.|\n)*?)}/i.exec(inner); + select = /{\s*(u|unselected):((.|\n)*?)}/i.exec(inner); if (select) { - hints += '\n ' + select[2].trim() + ''; + hints += '\n ' + select[2].trim() + + ''; } // Blank out the original text only if the specific "selected" syntax is found @@ -527,16 +567,17 @@ // Line split here, trim off leading xxx= in each function var answersList = p.split('\n'), - processNumericalResponse = function(value) { + processNumericalResponse = function(val) { + var params, answer, string, textHint, hintLine, value; // Numeric case is just a plain leading = with a single answer - value = value.replace(/^\=\s*/, ''); - var params, answer, string; + value = val.replace(/^\=\s*/, ''); - var textHint = extractHint(value); - var hintLine = ''; + textHint = extractHint(value); + hintLine = ''; if (textHint.hint) { value = textHint.nothint; - hintLine = ' ' + textHint.hint + '\n' + hintLine = ' ' + textHint.hint + + '\n'; } if (_.contains(['[', '('], value[0]) && _.contains([']', ')'], value[value.length - 1])) { @@ -573,35 +614,39 @@ }, processStringResponse = function(values) { + var firstAnswer, textHint, typ, string, orMatch, notMatch; // First string case is s?= - var firstAnswer = values.shift(), string; + firstAnswer = values.shift(); firstAnswer = firstAnswer.replace(/^s?\=\s*/, ''); - var textHint = extractHint(firstAnswer); + textHint = extractHint(firstAnswer); firstAnswer = textHint.nothint; - var typ = ' type="ci"'; - if (firstAnswer[0] == '|') { // this is regexp case + typ = ' type="ci"'; + if (firstAnswer[0] === '|') { // this is regexp case typ = ' type="ci regexp"'; firstAnswer = firstAnswer.slice(1).trim(); } string = '\n'; if (textHint.hint) { - string += ' ' + textHint.hint + '\n'; + string += ' ' + + textHint.hint + '\n'; } // Subsequent cases are not= or or= for (i = 0; i < values.length; i += 1) { - var textHint = extractHint(values[i]); - var notMatch = /^not\=\s*(.*)/.exec(textHint.nothint); + textHint = extractHint(values[i]); + notMatch = /^not\=\s*(.*)/.exec(textHint.nothint); if (notMatch) { - string += ' ' + textHint.hint + '\n'; + string += ' ' + textHint.hint + '\n'; continue; } - var orMatch = /^or\=\s*(.*)/.exec(textHint.nothint); + orMatch = /^or\=\s*(.*)/.exec(textHint.nothint); if (orMatch) { // additional_answer with answer= attribute string += ' '; if (textHint.hint) { - string += '' + textHint.hint + ''; + string += '' + + textHint.hint + ''; } string += '\n'; } @@ -618,16 +663,13 @@ // replace explanations xml = xml.replace(/\[explanation\]\n?([^\]]*)\[\/?explanation\]/gmi, function(match, p1) { - var selectString = '\n
\n' + gettext('Explanation') + '\n\n' + p1 + '\n
\n
'; - - return selectString; + return '\n
\n' + + gettext('Explanation') + '\n\n' + p1 + '\n
\n
'; }); // replace code blocks xml = xml.replace(/\[code\]\n?([^\]]*)\[\/?code\]/gmi, function(match, p1) { - var selectString = '
' + p1 + '
'; - - return selectString; + return '
' + p1 + '
'; }); // split scripts and preformatted sections, and wrap paragraphs @@ -662,20 +704,20 @@ } // make selector to search responsetypes in xml - var responseTypesSelector = responseTypes.join(', '); + responseTypesSelector = responseTypes.join(', '); // make temporary xml // safe-lint: disable=javascript-concat-html - var $xml = $($.parseXML('' + xml + '')); + $xml = $($.parseXML('' + xml + '')); responseType = $xml.find(responseTypesSelector); // convert if there is only one responsetype if (responseType.length === 1) { - var inputtype = responseType[0].firstElementChild + inputtype = responseType[0].firstElementChild; // used to decide whether an element should be placed before or after an inputtype - var beforeInputtype = true; + beforeInputtype = true; - _.each($xml.find('prob').children(), function(child, index) { + _.each($xml.find('prob').children(), function(child) { // we don't want to add the responsetype again into new xml if (responseType[0].nodeName === child.nodeName) { beforeInputtype = false; @@ -688,8 +730,8 @@ } else { responseType[0].appendChild(child); } - }) - var serializer = new XMLSerializer(); + }); + serializer = new XMLSerializer(); xml = serializer.serializeToString(responseType[0]); @@ -707,21 +749,22 @@ }; responseTypesXML = []; responseTypesMarkdown = markdown.split(/\n\s*---\s*\n/g); - _.each(responseTypesMarkdown, function(responseTypeMarkdown, index) { + _.each(responseTypesMarkdown, function(responseTypeMarkdown) { if (responseTypeMarkdown.trim().length > 0) { - return responseTypesXML.push(toXml(responseTypeMarkdown)); + responseTypesXML.push(toXml(responseTypeMarkdown)); } }); - demandHints = ''; + finalDemandHints = ''; if (demandHintTags.length) { - demandHints = '\n\n' + demandHintTags.join('') + ''; + // safe-lint: disable=javascript-concat-html + finalDemandHints = '\n\n' + demandHintTags.join('') + ''; } - finalXml = '' + responseTypesXML.join('\n\n') + demandHints + ''; + // make all responsetypes descendants of a single problem element + // safe-lint: disable=javascript-concat-html + finalXml = '' + responseTypesXML.join('\n\n') + finalDemandHints + ''; return PrettyPrint.xml(finalXml); }; return MarkdownEditingDescriptor; - - })(XModule.Descriptor); - + }(XModule.Descriptor)); }).call(this);