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
1e0702f3
Commit
1e0702f3
authored
Jun 25, 2013
by
Julian Arni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow nested object methods for the grade and state functions
parent
74bb976e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
8 deletions
+34
-8
common/static/js/capa/jsinput.js
+26
-3
doc/public/course_data_formats/jsinput.rst
+8
-5
No files found.
common/static/js/capa/jsinput.js
View file @
1e0702f3
...
...
@@ -4,6 +4,29 @@
// most relevantly, jquery). Keep in mind what happens in which context
// when modifying this file.
// _deepKey and _ctxCall are helper functions used to ensure that gradefn
// etc. can be nested objects (e.g., "firepad.getText") and that when
// called they receive the appropriate objects as "this" (e.g., "firepad").
// Take a string and find the nested object that corresponds to it. E.g.:
// deepKey(obj, "an.example") -> obj["an"]["example"]
var
_deepKey
=
function
(
obj
,
path
){
for
(
var
i
=
0
,
path
=
path
.
split
(
'.'
),
len
=
path
.
length
;
i
<
len
;
i
++
){
obj
=
obj
[
path
[
i
]];
}
return
obj
;
};
var
_ctxCall
=
function
(
obj
,
fn
)
{
var
func
=
_deepKey
(
obj
,
fn
);
var
oldthis
=
fn
.
split
(
'.'
);
oldthis
.
pop
();
oldthis
=
oldthis
.
join
();
var
newthis
=
_deepKey
(
obj
,
oldthis
);
return
func
.
apply
(
newthis
);
};
// First time this function was called?
var
isFirst
=
typeof
(
jsinput
.
jsinputarr
)
!=
'undefined'
;
...
...
@@ -70,12 +93,12 @@
var
update
=
function
(
answer
)
{
var
ans
;
ans
=
cWindow
[
gradefn
](
);
ans
=
_ctxCall
(
cWindow
,
gradefn
);
// setstate presumes getstate, so don't getstate unless setstate is
// defined.
if
(
getgetstate
()
&&
getsetstate
())
{
var
state
,
store
;
state
=
cWindow
[
getgetstate
()](
);
state
=
_ctxCall
(
cWindow
,
getgetstate
()
);
store
=
{
answer
:
ans
,
state
:
state
...
...
@@ -131,7 +154,7 @@
function
whileloop
(
n
)
{
if
(
n
<
10
){
try
{
cWindow
[
getsetstate
()](
sval
);
_ctxCall
(
cWindow
,
getsetstate
(),
sval
);
}
catch
(
err
)
{
setTimeout
(
whileloop
(
n
+
1
),
200
);
}
...
...
doc/public/course_data_formats/jsinput.rst
View file @
1e0702f3
...
...
@@ -66,11 +66,14 @@ should be located in the content directory.
The iframe is created using the sandbox attribute; while popups, scripts, and
pointer locks are allowed, the iframe cannot access its parent's attributes.
The html file should contain a top-level function for the gradefn function. To
check whether the gradefn will be accessible to JSInput, check that, in the
console,::
window["`gradefn`"]
Returns the right thing.
The html file should contain an accesible gradefn function. To check whether
the gradefn will be accessible to JSInput, check that, in the console,::
"`gradefn"
Returns the right thing. When used by JSInput, `gradefn` is called with::
`gradefn`.call(`obj`)
Where `obj` is the object-part of `gradefn`. For example, if `gradefn` is
`myprog.myfn`, JSInput will call `myprog.myfun.call(myprog)`. (This is to
ensure "`this`" continues to refer to what `gradefn` expects.)
Aside from that, more or less anything goes. Note that currently there is no
support for inheriting css or javascript from the parent (aside from the
...
...
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