Adding the ability for javascript from problems to execute more intelligently; for example, errors from javascript included in the returned html will show up in the console when using this mechanism.

This commit is contained in:
Arjun Singh
2012-07-26 16:34:40 -04:00
parent 6afe1709e7
commit c4c8bc2fbe

View File

@@ -31,8 +31,20 @@ class @Problem
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) =>