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
39243a1b
Commit
39243a1b
authored
Aug 02, 2012
by
John Hess
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added display.coffee to js/survey
parent
5d403493
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
+112
-0
common/lib/xmodule/xmodule/js/src/survey/display.coffee
+112
-0
No files found.
common/lib/xmodule/xmodule/js/src/survey/display.coffee
0 → 100644
View file @
39243a1b
class
@
Problem
constructor
:
(
element
)
->
@
el
=
$
(
element
).
find
(
'.problems-wrapper'
)
@
id
=
@
el
.
data
(
'problem-id'
)
@
element_id
=
@
el
.
attr
(
'id'
)
@
url
=
@
el
.
data
(
'url'
)
@
render
()
$
:
(
selector
)
->
$
(
selector
,
@
el
)
bind
:
=>
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
]
window
.
update_schematics
()
@
$
(
'section.action input:button'
).
click
@
refreshAnswers
@
$
(
'section.action input.check'
).
click
@
check
@
$
(
'section.action input.reset'
).
click
@
reset
@
$
(
'section.action input.show'
).
click
@
show
@
$
(
'section.action input.save'
).
click
@
save
@
$
(
'input.math'
).
keyup
(
@
refreshMath
).
each
(
@
refreshMath
)
updateProgress
:
(
response
)
=>
if
response
.
progress_changed
@
el
.
attr
progress
:
response
.
progress_status
@
el
.
trigger
(
'progressChanged'
)
render
:
(
content
)
->
if
content
@
el
.
html
(
content
)
@
bind
()
else
$
.
postWithPrefix
"
#{
@
url
}
/problem_get"
,
(
response
)
=>
@
el
.
html
(
response
.
html
)
@
executeProblemScripts
()
@
bind
()
executeProblemScripts
:
->
@
el
.
find
(
".script_placeholder"
).
each
(
index
,
placeholder
)
->
s
=
$
(
"<script>"
)
s
.
attr
(
"type"
,
"text/javascript"
)
s
.
attr
(
"src"
,
$
(
placeholder
).
attr
(
"data-src"
))
# Need to use the DOM elements directly or the scripts won't execute
# properly.
$
(
'head'
)[
0
].
appendChild
(
s
[
0
])
$
(
placeholder
).
remove
()
check
:
=>
Logger
.
log
'problem_check'
,
@
answers
$
.
postWithPrefix
"
#{
@
url
}
/problem_check"
,
@
answers
,
(
response
)
=>
switch
response
.
success
when
'incorrect'
,
'correct'
@
render
(
response
.
contents
)
@
updateProgress
response
else
alert
(
response
.
success
)
reset
:
=>
Logger
.
log
'problem_reset'
,
@
answers
$
.
postWithPrefix
"
#{
@
url
}
/problem_reset"
,
id
:
@
id
,
(
response
)
=>
@
render
(
response
.
html
)
@
updateProgress
response
show
:
=>
if
!
@
el
.
hasClass
'showed'
Logger
.
log
'problem_show'
,
problem
:
@
id
$
.
postWithPrefix
"
#{
@
url
}
/problem_show"
,
(
response
)
=>
answers
=
response
.
answers
$
.
each
answers
,
(
key
,
value
)
=>
if
$
.
isArray
(
value
)
for
choice
in
value
@
$
(
"label[for='input_
#{
key
}
_
#{
choice
}
']"
).
attr
correct_answer
:
'true'
else
@
$
(
"#answer_
#{
key
}
, #solution_
#{
key
}
"
).
html
(
value
)
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
]
@
$
(
'.show'
).
val
'Hide Answer'
@
el
.
addClass
'showed'
@
updateProgress
response
else
@
$
(
'[id^=answer_], [id^=solution_]'
).
text
''
@
$
(
'[correct_answer]'
).
attr
correct_answer
:
null
@
el
.
removeClass
'showed'
@
$
(
'.show'
).
val
'Show Answer'
save
:
=>
Logger
.
log
'problem_save'
,
@
answers
$
.
postWithPrefix
"
#{
@
url
}
/problem_save"
,
@
answers
,
(
response
)
=>
if
response
.
success
alert
'Saved'
@
updateProgress
response
refreshMath
:
(
event
,
element
)
=>
element
=
event
.
target
unless
element
target
=
"display_
#{
element
.
id
.
replace
(
/^input_/
,
''
)
}
"
if
jax
=
MathJax
.
Hub
.
getAllJax
(
target
)[
0
]
MathJax
.
Hub
.
Queue
[
'Text'
,
jax
,
$
(
element
).
val
()],
[
@
updateMathML
,
jax
,
element
]
updateMathML
:
(
jax
,
element
)
=>
try
$
(
"#
#{
element
.
id
}
_dynamath"
).
val
(
jax
.
root
.
toMathML
''
)
catch
exception
throw
exception
unless
exception
.
restart
MathJax
.
Callback
.
After
[
@
refreshMath
,
jax
],
exception
.
restart
refreshAnswers
:
=>
@
$
(
'input.schematic'
).
each
(
index
,
element
)
->
element
.
schematic
.
update_value
()
@
$
(
".CodeMirror"
).
each
(
index
,
element
)
->
element
.
CodeMirror
.
save
()
if
element
.
CodeMirror
.
save
@
answers
=
@
$
(
"[id^=input_
#{
@
element_id
.
replace
(
/problem_/
,
''
)
}
_]"
).
serialize
()
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