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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
12 deletions
+27
-12
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
+18
-10
docs/en_us/developers/source/extending_platform/javascript.rst
+4
-2
No files found.
common/lib/capa/capa/inputtypes.py
View file @
58ca939b
...
...
@@ -580,6 +580,7 @@ class JSInput(InputTypeBase):
Attribute
(
'gradefn'
,
"gradefn"
),
Attribute
(
'get_statefn'
,
None
),
# Function to call in iframe
# 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
# set state
Attribute
(
'width'
,
"400"
),
# iframe width
...
...
common/lib/capa/capa/templates/jsinput.html
View file @
58ca939b
...
...
@@ -3,6 +3,9 @@
%
if
saved_state:
data-stored=
"${saved_state|x}"
%
endif
%
if
initial_state:
data-initial-state=
"${initial_state|x}"
%
endif
%
if
get_statefn:
data-getstate=
"${get_statefn}"
%
endif
...
...
common/lib/xmodule/xmodule/templates/problem/jsinput_response.yaml
View file @
58ca939b
...
...
@@ -38,6 +38,7 @@ data: |
<jsinput gradefn="WebGLDemo.getGrade"
get_statefn="WebGLDemo.getState"
set_statefn="WebGLDemo.setState"
initial_state='{"selectedObjects":{"cube":true,"cylinder":false}}'
width="400"
height="400"
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) {
stateSetter
=
sectionAttr
(
"data-setstate"
),
// Get stored state
storedState
=
sectionAttr
(
"data-stored"
),
// Get initial state
initialState
=
sectionAttr
(
"data-initial-state"
),
// Bypass single-origin policy only if this attribute is "false"
// In that case, use JSChannel to do so.
sop
=
sectionAttr
(
"data-sop"
),
...
...
@@ -132,19 +134,25 @@ var JSInput = (function ($, undefined) {
// state to give it. If stateSetter is specified but calling it
// fails, wait and try again, since the iframe might still be
// loading.
if
(
stateSetter
&&
storedState
)
{
if
(
stateSetter
&&
(
storedState
||
initialState
)
)
{
var
stateValue
,
jsonValue
;
try
{
jsonValue
=
JSON
.
parse
(
storedState
);
}
catch
(
err
)
{
jsonValue
=
storedState
;
}
if
(
storedState
)
{
try
{
jsonValue
=
JSON
.
parse
(
storedState
);
}
catch
(
err
)
{
jsonValue
=
storedState
;
}
if
(
typeof
(
jsonValue
)
===
"object"
)
{
stateValue
=
jsonValue
[
"state"
];
}
else
{
stateValue
=
jsonValue
;
if
(
typeof
(
jsonValue
)
===
"object"
)
{
stateValue
=
jsonValue
[
"state"
];
}
else
{
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,
...
...
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.
- The function in your JavaScript application that saves the state of the
objects.
- ``JSObject.setState``
* - initial_state
- A JSON string representing the initial state, if any, of the objects.
- '{"selectedObjects":{"cube":true,"cylinder":false}}'
* - width
- The width of the IFrame in which your JavaScript application will be
displayed, in pixels.
...
...
@@ -309,4 +312,4 @@ The following table describes the attributes of the ``jsinput`` element.
* - sop
- The same-origin policy (SOP), meaning that all elements have the same
protocol, host, and port. To bypass the SOP, set to ``true``.
- false
\ No newline at end of file
- false
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