From e08215e62aa2938d767b4058bc7f5c4aed0d429c Mon Sep 17 00:00:00 2001 From: Julian Arni Date: Wed, 15 May 2013 14:05:31 -0400 Subject: [PATCH] JSinput input type --- common/lib/capa/capa/inputtypes.py | 62 ++++++ common/lib/capa/capa/responsetypes.py | 2 +- common/lib/capa/capa/templates/jsinput.html | 64 ++++++ .../xmodule/js/src/capa/display.coffee | 5 + common/static/css/capa/jsinput_css.css | 0 common/static/js/capa/jsinput.js | 197 ++++++++++++++++++ common/static/js/test/jsinput/jsinput.js | 16 ++ .../static/js/test/jsinput/mainfixture.html | 103 +++++++++ .../src/pip-delete-this-directory.txt | 5 + 9 files changed, 453 insertions(+), 1 deletion(-) create mode 100644 common/lib/capa/capa/templates/jsinput.html create mode 100644 common/static/css/capa/jsinput_css.css create mode 100644 common/static/js/capa/jsinput.js create mode 100644 common/static/js/test/jsinput/jsinput.js create mode 100644 common/static/js/test/jsinput/mainfixture.html create mode 100644 requirements/src/pip-delete-this-directory.txt diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 65280d6d29..963062a263 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -451,6 +451,68 @@ class JavascriptInput(InputTypeBase): registry.register(JavascriptInput) + +#----------------------------------------------------------------------------- + + +class JSInput(InputTypeBase): + """ + DO NOT USE! HAS NOT BEEN TESTED BEYOND 700X PROBLEMS, AND MAY CHANGE IN + BACKWARDS-INCOMPATIBLE WAYS. + Inputtype for general javascript inputs. Intended to be used with + customresponse. + Loads in a sandboxed iframe to help prevent css and js conflicts between + frame and top-level window. + + iframe sandbox whitelist: + - allow-scripts + - allow-popups + - allow-forms + - allow-pointer-lock + + This in turn means that the iframe cannot directly access the top-level + window elements. + Example: + + + + See the documentation in the /doc/public folder for more information. + """ + + template = "jsinput.html" + tags = ['jsinput'] + + @classmethod + def get_attributes(cls): + """ + Register the attributes. + """ + return [Attribute('params', None), # extra iframe params + Attribute('html_file', None), + Attribute('gradefn', "gradefn"), + Attribute('get_statefn', None), # Function to call in iframe + # to get current state. + Attribute('set_statefn', None), # Function to call iframe to + # set state + Attribute('width', "400"), # iframe width + Attribute('height', "300")] # iframe height + + + + def _extra_context(self): + context = { + 'applet_loader': '/static/js/capa/jsinput.js', + 'saved_state': self.value + } + + return context + + + +registry.register(JSInput) #----------------------------------------------------------------------------- class TextLine(InputTypeBase): diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 0fa50079de..f5c15260de 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -929,7 +929,7 @@ class CustomResponse(LoncapaResponse): 'chemicalequationinput', 'vsepr_input', 'drag_and_drop_input', 'editamoleculeinput', 'designprotein2dinput', 'editageneinput', - 'annotationinput'] + 'annotationinput', 'jsinput'] def setup_response(self): xml = self.xml diff --git a/common/lib/capa/capa/templates/jsinput.html b/common/lib/capa/capa/templates/jsinput.html new file mode 100644 index 0000000000..ec5d32b5c2 --- /dev/null +++ b/common/lib/capa/capa/templates/jsinput.html @@ -0,0 +1,64 @@ +
+ + +
+ % if status == 'unsubmitted': +
+ % elif status == 'correct': +
+ % elif status == 'incorrect': +
+ % elif status == 'incomplete': +
+ % endif + + + + +
+ +

+ +

+

+

+ + + +
+
+
+ +
+ + + +
+ +

+ +

+

+

+ + + +
+
+ + diff --git a/requirements/src/pip-delete-this-directory.txt b/requirements/src/pip-delete-this-directory.txt new file mode 100644 index 0000000000..c8883ea99f --- /dev/null +++ b/requirements/src/pip-delete-this-directory.txt @@ -0,0 +1,5 @@ +This file is placed here by pip to indicate the source was put +here by pip. + +Once this package is successfully installed this source code will be +deleted (unless you remove this file).