From fd10fbf725756a12a8c57b8b42fb9a0c086dcf08 Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 5 Jun 2014 12:41:18 -0700 Subject: [PATCH] Fix JSInput scope leak Declare variables locally - The `allSections` variable was leaking into the global scope, due to a typo in the declaration. - `dataProcessed` can be declared more narrowly within the callback. --- common/static/js/capa/src/jsinput.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/static/js/capa/src/jsinput.js b/common/static/js/capa/src/jsinput.js index a10f18fa76..a1ad7e8bc7 100644 --- a/common/static/js/capa/src/jsinput.js +++ b/common/static/js/capa/src/jsinput.js @@ -181,19 +181,15 @@ var JSInput = (function ($, undefined) { } function walkDOM() { - var dataProcessed, all; - - // Find all jsinput elements - allSections = $('section.jsinput'); - + var allSections = $('section.jsinput'); // When a JSInput problem loads, its data-processed attribute is false, // so the jsconstructor will be called for it. // The constructor will not be called again on subsequent reruns of // this file by other JSInput. Only if it is reloaded, either with the // rest of the page or when it is submitted, will this constructor be - // called again. + // called again. allSections.each(function(index, value) { - dataProcessed = ($(value).attr("data-processed") === "true"); + var dataProcessed = ($(value).attr("data-processed") === "true"); if (!dataProcessed) { jsinputConstructor(value); $(value).attr("data-processed", 'true');