Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d3a467d3
Commit
d3a467d3
authored
Mar 09, 2016
by
Adam Palay
Committed by
Qubad786
Mar 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only add event listener if it hasn't been added yet
parent
7eb079df
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
common/static/js/capa/spec/formula_equation_preview_spec.js
+21
-0
common/static/js/capa/src/formula_equation_preview.js
+8
-0
No files found.
common/static/js/capa/spec/formula_equation_preview_spec.js
View file @
d3a467d3
...
...
@@ -115,6 +115,27 @@ describe("Formula Equation Preview", function () {
]);
});
it
(
'does not request again if the initial request has already been made'
,
function
()
{
// jshint undef:false
expect
(
Problem
.
inputAjax
.
callCount
).
toEqual
(
1
);
// Reset the spy in order to check calls again.
Problem
.
inputAjax
.
reset
();
// Enabling the formulaEquationPreview again to see if this will
// reinitialize input request once again.
formulaEquationPreview
.
enable
();
// This part may be asynchronous, so wait.
waitsFor
(
function
()
{
return
!
Problem
.
inputAjax
.
wasCalled
;
},
"times out in case of AJAX call"
,
1000
);
// Expect Problem.inputAjax was not called as input request was
// initialized before.
expect
(
Problem
.
inputAjax
).
not
.
toHaveBeenCalled
();
});
it
(
'makes a request on user input'
,
function
()
{
Problem
.
inputAjax
.
reset
();
$
(
'#input_THE_ID'
).
val
(
'user_input'
).
trigger
(
'input'
);
...
...
common/static/js/capa/src/formula_equation_preview.js
View file @
d3a467d3
...
...
@@ -58,9 +58,17 @@ formulaEquationPreview.enable = function () {
throttledRequest
(
inputData
,
this
.
value
);
};
if
(
!
$this
.
data
(
"inputInitialized"
))
{
// Hack alert: since this javascript file is loaded every time a
// problem with mathjax preview is loaded, we wrap this step in this
// condition to make sure we don't attach multiple event listeners
// per math input if multiple such problems are loaded on a page.
$this
.
on
(
"input"
,
initializeRequest
);
// Ask for initial preview.
initializeRequest
.
call
(
this
);
// indicates that the initial preview is done for current $this!
$this
.
data
(
"inputInitialized"
,
true
);
}
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment