Commit 25fca016 by dragonfi

Properly scope variables in javascript

parent dde46032
...@@ -49,10 +49,10 @@ function AnswerBlock(runtime, element) { ...@@ -49,10 +49,10 @@ function AnswerBlock(runtime, element) {
if (blockquote_ro.length > 0) if (blockquote_ro.length > 0)
return true; return true;
var input = $(':input', element), var input = $(':input', element);
input_value = input.val().replace(/^\s+|\s+$/gm,''), var input_value = input.val().replace(/^\s+|\s+$/gm,'');
answer_length = input_value.length, var answer_length = input_value.length;
data = input.data(); var data = input.data();
// an answer cannot be empty event if min_characters is 0 // an answer cannot be empty event if min_characters is 0
if (_.isNumber(data.min_characters)) { if (_.isNumber(data.min_characters)) {
...@@ -61,8 +61,7 @@ function AnswerBlock(runtime, element) { ...@@ -61,8 +61,7 @@ function AnswerBlock(runtime, element) {
return false; return false;
} }
} }
return true; return true;
} }
} };
} }
...@@ -5,5 +5,5 @@ function MentoringTableBlock(runtime, element) { ...@@ -5,5 +5,5 @@ function MentoringTableBlock(runtime, element) {
lessText: 'less', lessText: 'less',
showChars: '500' showChars: '500'
}); });
return {} return {};
} }
...@@ -14,8 +14,8 @@ function MentoringBlock(runtime, element) { ...@@ -14,8 +14,8 @@ function MentoringBlock(runtime, element) {
} }
$(document).on("click", function(event, ui) { $(document).on("click", function(event, ui) {
target = $(event.target); var target = $(event.target);
feedback_box = ".mentoring .feedback"; var feedback_box = ".mentoring .feedback";
if (target.is(feedback_box)) { if (target.is(feedback_box)) {
return; return;
} }
...@@ -60,8 +60,8 @@ function MentoringBlock(runtime, element) { ...@@ -60,8 +60,8 @@ function MentoringBlock(runtime, element) {
} }
function renderDependency() { function renderDependency() {
var warning_dom = $('.missing-dependency', element), var warning_dom = $('.missing-dependency', element);
data = warning_dom.data(); var data = warning_dom.data();
if (data.missing === 'True') { if (data.missing === 'True') {
warning_dom.show(); warning_dom.show();
...@@ -72,8 +72,8 @@ function MentoringBlock(runtime, element) { ...@@ -72,8 +72,8 @@ function MentoringBlock(runtime, element) {
var doms = $('.xblock-light-child', element); var doms = $('.xblock-light-child', element);
$.each(doms, function(index, child_dom) { $.each(doms, function(index, child_dom) {
var child_type = $(child_dom).attr('data-type'), var child_type = $(child_dom).attr('data-type');
child = window[child_type]; var child = window[child_type];
children_dom.push(child_dom); children_dom.push(child_dom);
children.push(child); children.push(child);
if (typeof child !== 'undefined') { if (typeof child !== 'undefined') {
......
...@@ -23,8 +23,8 @@ function MentoringAssessmentView(runtime, element, mentoring) { ...@@ -23,8 +23,8 @@ function MentoringAssessmentView(runtime, element, mentoring) {
var data = $('.grade', element).data(); var data = $('.grade', element).data();
cleanAll(); cleanAll();
$('.grade', element).html(gradeTemplate(data)); $('.grade', element).html(gradeTemplate(data));
reviewDOM.hide() reviewDOM.hide();
submitDOM.hide() submitDOM.hide();
nextDOM.hide(); nextDOM.hide();
tryAgainDOM.show(); tryAgainDOM.show();
...@@ -192,7 +192,7 @@ function MentoringAssessmentView(runtime, element, mentoring) { ...@@ -192,7 +192,7 @@ function MentoringAssessmentView(runtime, element, mentoring) {
} }
if (isLastChild()) { if (isLastChild()) {
nextDOM.hide() nextDOM.hide();
reviewDOM.show(); reviewDOM.show();
} }
......
function MentoringStandardView(runtime, element, mentoring) { function MentoringStandardView(runtime, element, mentoring) {
var submitXHR; var submitXHR;
var submitDOM; var submitDOM, messagesDOM;
var callIfExists = mentoring.callIfExists; var callIfExists = mentoring.callIfExists;
...@@ -8,13 +8,13 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -8,13 +8,13 @@ function MentoringStandardView(runtime, element, mentoring) {
messagesDOM.empty().hide(); messagesDOM.empty().hide();
$.each(results.submitResults || [], function(index, submitResult) { $.each(results.submitResults || [], function(index, submitResult) {
var input = submitResult[0], var input = submitResult[0];
result = submitResult[1], var result = submitResult[1];
child = mentoring.getChildByName(element, input); var child = mentoring.getChildByName(element, input);
var options = { var options = {
max_attempts: results.max_attempts, max_attempts: results.max_attempts,
num_attempts: results.num_attempts num_attempts: results.num_attempts
} };
callIfExists(child, 'handleSubmit', result, options); callIfExists(child, 'handleSubmit', result, options);
}); });
......
...@@ -17,15 +17,15 @@ function MessageView(element, mentoring) { ...@@ -17,15 +17,15 @@ function MessageView(element, mentoring) {
var tip = $('.tip', popupDOM)[0]; var tip = $('.tip', popupDOM)[0];
var data = $(tip).data(); var data = $(tip).data();
if (data && data.width) { if (data && data.width) {
popupDOM.css('width', data.width) popupDOM.css('width', data.width);
} else { } else {
popupDOM.css('width', '') popupDOM.css('width', '');
} }
if (data && data.height) { if (data && data.height) {
popupDOM.css('height', data.height); popupDOM.css('height', data.height);
} else { } else {
popupDOM.css('height', '') popupDOM.css('height', '');
} }
popupDOM.show(); popupDOM.show();
...@@ -45,7 +45,7 @@ function MessageView(element, mentoring) { ...@@ -45,7 +45,7 @@ function MessageView(element, mentoring) {
}, },
showMessage: function(message) { showMessage: function(message) {
if (_.isString(message)) { if (_.isString(message)) {
mentoring.setContent(this.messageDOM, message) mentoring.setContent(this.messageDOM, message);
this.showPopup(this.messageDOM); this.showPopup(this.messageDOM);
} }
else { else {
...@@ -58,7 +58,7 @@ function MessageView(element, mentoring) { ...@@ -58,7 +58,7 @@ function MessageView(element, mentoring) {
'checkmark-incorrect icon-exclamation fa-exclamation checkmark-correct icon-ok fa-check' 'checkmark-incorrect icon-exclamation fa-exclamation checkmark-correct icon-ok fa-check'
); );
} }
} };
} }
function MCQBlock(runtime, element, mentoring) { function MCQBlock(runtime, element, mentoring) {
...@@ -88,11 +88,11 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -88,11 +88,11 @@ function MCQBlock(runtime, element, mentoring) {
var choiceInputs = $('.choice input', element); var choiceInputs = $('.choice input', element);
$.each(choiceInputs, function(index, choiceInput) { $.each(choiceInputs, function(index, choiceInput) {
var choiceInputDOM = $(choiceInput), var choiceInputDOM = $(choiceInput);
choiceDOM = choiceInputDOM.closest('.choice'), var choiceDOM = choiceInputDOM.closest('.choice');
choiceResultDOM = $('.choice-result', choiceDOM), var choiceResultDOM = $('.choice-result', choiceDOM);
choiceTipsDOM = $('.choice-tips', choiceDOM), var choiceTipsDOM = $('.choice-tips', choiceDOM);
choiceTipsCloseDOM; var choiceTipsCloseDOM;
if (result.completed && choiceInputDOM.val() === result.submission) { if (result.completed && choiceInputDOM.val() === result.submission) {
choiceResultDOM.addClass('checkmark-correct icon-ok fa-check'); choiceResultDOM.addClass('checkmark-correct icon-ok fa-check');
...@@ -107,7 +107,7 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -107,7 +107,7 @@ function MCQBlock(runtime, element, mentoring) {
choiceTipsCloseDOM = $('.close', choiceTipsDOM); choiceTipsCloseDOM = $('.close', choiceTipsDOM);
choiceResultDOM.off('click').on('click', function() { choiceResultDOM.off('click').on('click', function() {
if (choiceTipsDOM.html() != '') { if (choiceTipsDOM.html() !== '') {
messageView.showMessage(choiceTipsDOM); messageView.showMessage(choiceTipsDOM);
} }
}); });
...@@ -128,10 +128,7 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -128,10 +128,7 @@ function MCQBlock(runtime, element, mentoring) {
validate: function(){ validate: function(){
var checked = $('input[type=radio]:checked', element); var checked = $('input[type=radio]:checked', element);
if (checked.length) { return Boolean(checked.length);
return true;
}
return false;
} }
}; };
} }
...@@ -145,8 +142,8 @@ function MRQBlock(runtime, element, mentoring) { ...@@ -145,8 +142,8 @@ function MRQBlock(runtime, element, mentoring) {
}, },
submit: function() { submit: function() {
var checkedCheckboxes = $('input[type=checkbox]:checked', element), var checkedCheckboxes = $('input[type=checkbox]:checked', element);
checkedValues = []; var checkedValues = [];
$.each(checkedCheckboxes, function(index, checkedCheckbox) { $.each(checkedCheckboxes, function(index, checkedCheckbox) {
checkedValues.push($(checkedCheckbox).val()); checkedValues.push($(checkedCheckbox).val());
...@@ -165,16 +162,16 @@ function MRQBlock(runtime, element, mentoring) { ...@@ -165,16 +162,16 @@ function MRQBlock(runtime, element, mentoring) {
'<div class="close icon-remove-sign fa-times-circle"></div>'); '<div class="close icon-remove-sign fa-times-circle"></div>');
} }
var questionnaireDOM = $('fieldset.questionnaire', element), var questionnaireDOM = $('fieldset.questionnaire', element);
data = questionnaireDOM.data(), var data = questionnaireDOM.data();
hide_results = (data.hide_results === 'True') ? true : false; var hide_results = (data.hide_results === 'True') ? true : false;
$.each(result.choices, function(index, choice) { $.each(result.choices, function(index, choice) {
var choiceInputDOM = $('.choice input[value='+choice.value+']', element), var choiceInputDOM = $('.choice input[value='+choice.value+']', element);
choiceDOM = choiceInputDOM.closest('.choice'), var choiceDOM = choiceInputDOM.closest('.choice');
choiceResultDOM = $('.choice-result', choiceDOM), var choiceResultDOM = $('.choice-result', choiceDOM);
choiceTipsDOM = $('.choice-tips', choiceDOM), var choiceTipsDOM = $('.choice-tips', choiceDOM);
choiceTipsCloseDOM; var choiceTipsCloseDOM;
/* show hint if checked or max_attempts is disabled */ /* show hint if checked or max_attempts is disabled */
if (!hide_results && if (!hide_results &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment