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
58ca939b
Commit
58ca939b
authored
Jul 30, 2014
by
jmclaus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4292 from terman/jsinput
Supply initial_state attribute for jsinput tag
parents
ac5f8d94
d3149f66
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
1 deletions
+17
-1
common/lib/capa/capa/inputtypes.py
+1
-0
common/lib/capa/capa/templates/jsinput.html
+3
-0
common/lib/xmodule/xmodule/templates/problem/jsinput_response.yaml
+1
-0
common/static/js/capa/src/jsinput.js
+9
-1
docs/en_us/developers/source/extending_platform/javascript.rst
+3
-0
No files found.
common/lib/capa/capa/inputtypes.py
View file @
58ca939b
...
@@ -580,6 +580,7 @@ class JSInput(InputTypeBase):
...
@@ -580,6 +580,7 @@ class JSInput(InputTypeBase):
Attribute
(
'gradefn'
,
"gradefn"
),
Attribute
(
'gradefn'
,
"gradefn"
),
Attribute
(
'get_statefn'
,
None
),
# Function to call in iframe
Attribute
(
'get_statefn'
,
None
),
# Function to call in iframe
# to get current state.
# to get current state.
Attribute
(
'initial_state'
,
None
),
# JSON string to be used as initial state
Attribute
(
'set_statefn'
,
None
),
# Function to call iframe to
Attribute
(
'set_statefn'
,
None
),
# Function to call iframe to
# set state
# set state
Attribute
(
'width'
,
"400"
),
# iframe width
Attribute
(
'width'
,
"400"
),
# iframe width
...
...
common/lib/capa/capa/templates/jsinput.html
View file @
58ca939b
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
%
if
saved_state:
%
if
saved_state:
data-stored=
"${saved_state|x}"
data-stored=
"${saved_state|x}"
%
endif
%
endif
%
if
initial_state:
data-initial-state=
"${initial_state|x}"
%
endif
%
if
get_statefn:
%
if
get_statefn:
data-getstate=
"${get_statefn}"
data-getstate=
"${get_statefn}"
%
endif
%
endif
...
...
common/lib/xmodule/xmodule/templates/problem/jsinput_response.yaml
View file @
58ca939b
...
@@ -38,6 +38,7 @@ data: |
...
@@ -38,6 +38,7 @@ data: |
<jsinput gradefn="WebGLDemo.getGrade"
<jsinput gradefn="WebGLDemo.getGrade"
get_statefn="WebGLDemo.getState"
get_statefn="WebGLDemo.getState"
set_statefn="WebGLDemo.setState"
set_statefn="WebGLDemo.setState"
initial_state='{"selectedObjects":{"cube":true,"cylinder":false}}'
width="400"
width="400"
height="400"
height="400"
html_file="https://studio.edx.org/c4x/edX/DemoX/asset/webGLDemo.html"
html_file="https://studio.edx.org/c4x/edX/DemoX/asset/webGLDemo.html"
...
...
common/static/js/capa/src/jsinput.js
View file @
58ca939b
...
@@ -54,6 +54,8 @@ var JSInput = (function ($, undefined) {
...
@@ -54,6 +54,8 @@ var JSInput = (function ($, undefined) {
stateSetter
=
sectionAttr
(
"data-setstate"
),
stateSetter
=
sectionAttr
(
"data-setstate"
),
// Get stored state
// Get stored state
storedState
=
sectionAttr
(
"data-stored"
),
storedState
=
sectionAttr
(
"data-stored"
),
// Get initial state
initialState
=
sectionAttr
(
"data-initial-state"
),
// Bypass single-origin policy only if this attribute is "false"
// Bypass single-origin policy only if this attribute is "false"
// In that case, use JSChannel to do so.
// In that case, use JSChannel to do so.
sop
=
sectionAttr
(
"data-sop"
),
sop
=
sectionAttr
(
"data-sop"
),
...
@@ -132,9 +134,10 @@ var JSInput = (function ($, undefined) {
...
@@ -132,9 +134,10 @@ var JSInput = (function ($, undefined) {
// state to give it. If stateSetter is specified but calling it
// state to give it. If stateSetter is specified but calling it
// fails, wait and try again, since the iframe might still be
// fails, wait and try again, since the iframe might still be
// loading.
// loading.
if
(
stateSetter
&&
storedState
)
{
if
(
stateSetter
&&
(
storedState
||
initialState
)
)
{
var
stateValue
,
jsonValue
;
var
stateValue
,
jsonValue
;
if
(
storedState
)
{
try
{
try
{
jsonValue
=
JSON
.
parse
(
storedState
);
jsonValue
=
JSON
.
parse
(
storedState
);
}
catch
(
err
)
{
}
catch
(
err
)
{
...
@@ -146,6 +149,11 @@ var JSInput = (function ($, undefined) {
...
@@ -146,6 +149,11 @@ var JSInput = (function ($, undefined) {
}
else
{
}
else
{
stateValue
=
jsonValue
;
stateValue
=
jsonValue
;
}
}
}
else
{
// use initial_state string as the JSON string for stateValue.
stateValue
=
initialState
;
}
// Try calling setstate every 200ms while it throws an exception,
// Try calling setstate every 200ms while it throws an exception,
// up to five times; give up after that.
// up to five times; give up after that.
...
...
docs/en_us/developers/source/extending_platform/javascript.rst
View file @
58ca939b
...
@@ -294,6 +294,9 @@ The following table describes the attributes of the ``jsinput`` element.
...
@@ -294,6 +294,9 @@ The following table describes the attributes of the ``jsinput`` element.
- The function in your JavaScript application that saves the state of the
- The function in your JavaScript application that saves the state of the
objects.
objects.
- ``JSObject.setState``
- ``JSObject.setState``
* - initial_state
- A JSON string representing the initial state, if any, of the objects.
- '{"selectedObjects":{"cube":true,"cylinder":false}}'
* - width
* - width
- The width of the IFrame in which your JavaScript application will be
- The width of the IFrame in which your JavaScript application will be
displayed, in pixels.
displayed, in pixels.
...
...
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