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
2c1f3bd4
Commit
2c1f3bd4
authored
Feb 06, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1449 from MITx/fix/rocha/7012x-clean
Fix/rocha/7012x clean
parents
31b8f0ce
536333cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
58 deletions
+76
-58
common/lib/capa/capa/templates/editamolecule.html
+4
-2
common/static/js/capa/editamolecule.js
+72
-56
No files found.
common/lib/capa/capa/templates/editamolecule.html
View file @
2c1f3bd4
<section
id=
"editamoleculeinput_${id}"
class=
"editamoleculeinput"
>
<div
class=
"script_placeholder"
data-src=
"/static/js/capa/jsmolcalc/jsmolcalc.nocache.js"
/>
<div
class=
"script_placeholder"
data-src=
"/static/js/capa/jsme/jsme_export.nocache.js"
/>
<div
class=
"script_placeholder"
data-src=
"${applet_loader}"
/>
% if status == 'unsubmitted':
...
...
@@ -35,6 +33,10 @@
incomplete
% endif
</p>
<br/>
<br/>
<div
class=
"error_message"
style=
"padding: 5px 5px 5px 5px; background-color:#FA6666; height:60px;width:400px; display: none"
></div>
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
</div>
% endif
...
...
common/static/js/capa/editamolecule.js
View file @
2c1f3bd4
...
...
@@ -2,23 +2,53 @@
var
timeout
=
100
;
// Simple "lock" to prevent applets from being initialized more than once
if
(
typeof
(
_editamolecule_lock
)
==
'undefined'
||
_editamolecule_lock
==
false
)
{
_editamolecule_lock
=
true
;
if
(
typeof
(
_editamolecule_loaded
)
==
'undefined'
||
_editamolecule_loaded
==
false
)
{
_editamolecule_loaded
=
true
;
loadGWTScripts
();
waitForGWT
();
}
else
{
return
;
}
// FIXME: [rocha] jsme and jsmolcalc are not initialized automatically by
// the GWT script loader. To fix this, wait for the scripts to load, initialize
// them manually and wait until they are ready
function
loadScript
(
src
)
{
var
script
=
document
.
createElement
(
'script'
);
script
.
setAttribute
(
'type'
,
'text/javascript'
);
script
.
setAttribute
(
'src'
,
src
);
$
(
'head'
)[
0
].
appendChild
(
script
);
}
function
loadGWTScripts
()
{
// The names of the script are split to prevent them from
// being rewritten by LMS. GWT uses the filename of the script
// to find the URL path in which the script lives. If the name
// of the file is changed, GWT won't load correctly
var
jsmolcalc_src
=
'/sta'
+
'tic/js/capa/jsmolcalc/jsmolcalc.nocache.js'
;
var
jsme_src
=
'/sta'
+
'tic/js/capa/jsme/jsme_export.nocache.js'
;
// Make sure we don't request the scripts twice
if
(
typeof
(
_jsmolcalc
)
==
'undefined'
)
{
_jsmolcalc
=
true
;
loadScript
(
jsmolcalc_src
);
}
if
(
typeof
(
_jsme
)
==
'undefined'
)
{
_jsme
=
true
;
loadScript
(
jsme_src
);
}
}
function
waitForGWT
()
{
if
(
typeof
(
jsmolcalc
)
!=
"undefined"
&&
jsmolcalc
)
// jsme and jsmolcalc are not initialized automatically by the GWT
// script loader. To fix this, wait for the scripts to load,
// initialize them manually and wait until they are ready
if
(
typeof
(
jsmolcalc
)
!=
'undefined'
&&
jsmolcalc
)
{
jsmolcalc
.
onInjectionDone
(
'jsmolcalc'
);
}
if
(
typeof
(
jsme_export
)
!=
"undefined"
&&
jsme_export
)
if
(
typeof
(
jsme_export
)
!=
'undefined'
&&
jsme_export
)
{
// dummy function called by jsme_export
window
.
jsmeOnLoad
=
function
()
{};
...
...
@@ -29,7 +59,7 @@
if
(
typeof
(
jsmol
)
!=
'undefined'
&&
typeof
(
JavaScriptApplet
)
!=
'undefined'
)
{
// ready, initialize applets
initializeApplets
();
_editamolecule_lo
ck
=
false
;
// release lock, for reloading
_editamolecule_lo
aded
=
false
;
// for reloading when checking is pressed
}
else
{
setTimeout
(
waitForGWT
,
timeout
);
}
...
...
@@ -57,12 +87,7 @@
var
parent
=
$
(
element
).
parent
();
var
input_field
=
parent
.
find
(
'input[type=hidden]'
);
var
reset_button
=
parent
.
find
(
'button.reset'
);
// Add div for error messages
$
(
'<br/> <br/> <div class="errormsgs" style="padding: 5px 5px 5px 5px;
\
visibility:hidden; background-color:#FA6666; height:60px;
\
width:400px;"> </div>'
).
appendTo
(
parent
);
var
message_field
=
parent
.
find
(
'.error_message'
);
// Applet options
applet
.
setAntialias
(
true
);
...
...
@@ -78,31 +103,27 @@
reset_button
.
on
(
'click'
,
function
()
{
requestAppletData
(
element
,
applet
,
input_field
);
// Make sure remaining error messages are cleared
var
errordiv
=
$
(
element
).
parent
().
find
(
'.errormsgs'
)[
0
];
errordiv
.
style
.
visibility
=
'hidden'
;
message_field
.
html
(
''
).
hide
();
// clear messages
});
// Update the input element everytime the is an interaction
// with the applet (click, drag, etc)
$
(
element
).
on
(
'mouseup'
,
function
()
{
updateInput
(
applet
,
input_field
,
element
);
var
values
=
updateInput
(
applet
,
input_field
);
updateMessages
(
message_field
,
values
);
});
}
function
requestAppletData
(
element
,
applet
,
input_field
)
{
var
molFile
=
$
(
element
).
data
(
'molfile-src'
);
jQuery
.
ajax
({
url
:
molFile
,
dataType
:
"text"
,
success
:
function
(
data
)
{
//console.log("Done.");
loadAppletData
(
applet
,
data
,
input_field
);
},
error
:
function
()
{
console
.
error
(
"Cannot load mol data
."
);
console
.
error
(
"Cannot load mol data
from: "
+
molFile
);
}
});
}
...
...
@@ -112,58 +133,53 @@
updateInput
(
applet
,
input_field
);
}
function
updateInput
(
applet
,
input_field
,
element
)
{
function
updateInput
(
applet
,
input_field
)
{
var
mol
=
applet
.
molFile
();
var
smiles
=
applet
.
smiles
();
var
jme
=
applet
.
jmeFile
();
var
info
=
formatInfo
(
jsmol
.
API
.
getInfo
(
mol
,
smiles
,
jme
).
toString
(),
input_field
,
element
);
var
value
=
{
mol
:
mol
,
info
:
info
};
//console.log("Molecule info:");
//console.log(info);
var
raw_info
=
jsmol
.
API
.
getInfo
(
mol
,
smiles
,
jme
).
toString
();
var
info
=
formatInfo
(
raw_info
);
var
error
=
formatError
(
raw_info
);
var
value
=
{
mol
:
mol
,
info
:
info
,
error
:
error
};
input_field
.
val
(
JSON
.
stringify
(
value
));
return
value
;
}
function
formatInfo
(
info
,
input_field
,
element
)
{
function
formatInfo
(
raw_info
)
{
var
results
=
[];
//console.log("element parent is"+$(element).parent())
var
errordiv
=
$
(
element
).
parent
().
find
(
'.errormsgs'
)[
0
];
//console.log(errordiv);
if
(
!
errordiv
)
{
// This is a bit hackish, but works.
// There are situations where formatInfo is called but no div yet exists
// to my knowledge (blame John Hess) this is always followed by a call to
// this function once the div does exist
//console.log("There is no errordiv loaded yet. trying again soon");
return
[]
}
if
(
info
.
search
(
"It is not possible"
)
==
-
1
)
{
errordiv
.
innerHTML
=
''
;
errordiv
.
style
.
visibility
=
'hidden'
;
var
fragment
=
$
(
'<div>'
).
append
(
info
);
if
(
raw_info
.
search
(
"It is not possible"
)
==
-
1
)
{
var
fragment
=
$
(
'<div>'
).
append
(
raw_info
);
fragment
.
find
(
'font'
).
each
(
function
()
{
results
.
push
(
$
(
this
).
html
());
});
}
else
{
//console.log("err");
// remove Brian's html tags
return
results
;
}
function
formatError
(
raw_info
)
{
var
error
=
''
;
if
(
raw_info
.
search
(
"It is not possible"
)
!=
-
1
)
{
var
tags
=
/<
((\/)?\w{1,7})
>/g
;
var
errmsg
=
info
.
replace
(
tags
,
' '
);
//console.log(errmsg);
errordiv
.
innerHTML
=
errmsg
;
errordiv
.
style
.
visibility
=
'visible'
;
}
error
=
raw_info
.
replace
(
tags
,
' '
);
return
results
;
}
return
error
;
}
function
updateMessages
(
message_field
,
values
)
{
var
error
=
values
[
'error'
];
if
(
error
)
{
message_field
.
html
(
error
).
show
();
}
else
{
// Clear messages
message_field
.
html
(
''
).
hide
();
}
}
}).
call
(
this
);
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