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
7ebeccd4
Commit
7ebeccd4
authored
Dec 12, 2013
by
Valera Rozuvan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating ImageInput JS code base.
parent
a78400a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
37 deletions
+99
-37
common/lib/capa/capa/templates/imageinput.html
+57
-21
common/lib/xmodule/xmodule/js/src/capa/imageinput.js
+42
-16
No files found.
common/lib/capa/capa/templates/imageinput.html
View file @
7ebeccd4
<span>
<input
type=
"hidden"
class=
"imageinput"
src=
"${src}"
name=
"input_${id}"
id=
"input_${id}"
value=
"${value}"
/>
<div
id=
"imageinput_${id}"
onclick=
"image_input_click('${id}',event);"
style =
"background-image:url('${src}');width:${width}px;height:${height}px;position: relative; left: 0; top: 0;"
>
<img
src=
"${STATIC_URL}green-pointer.png"
id=
"cross_${id}"
style=
"position: absolute;top: ${gy}px;left: ${gx}px;"
/>
</div>
<input
type=
"hidden"
class=
"imageinput"
src=
"${src}"
name=
"input_${id}"
id=
"input_${id}"
value=
"${value}"
/>
% if status == 'unsubmitted':
<span
class=
"unanswered"
style=
"display:inline-block;"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: unanswered
</span>
</span>
% elif status == 'correct':
<span
class=
"correct"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: correct
</span>
</span>
% elif status == 'incorrect':
<span
class=
"incorrect"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: incorrect
</span>
</span>
% elif status == 'incomplete':
<span
class=
"incorrect"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: incorrect
</span>
</span>
% endif
<div
id=
"imageinput_${id}"
style=
"background-image: url('${src}'); width: ${width}px; height: ${height}px; position: relative; left: 0; top: 0;"
>
<img
src=
"${STATIC_URL}green-pointer.png"
id=
"cross_${id}"
style=
"position: absolute; top: ${gy}px; left: ${gx}px;"
/>
</div>
<script
type=
"text/javascript"
charset=
"utf-8"
>
(
new
ImageInput
(
'${id}'
));
</script>
% if status == 'unsubmitted':
<span
class=
"unanswered"
style=
"display: inline-block;"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: unanswered
</span>
</span>
% elif status == 'correct':
<span
class=
"correct"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: correct
</span>
</span>
% elif status == 'incorrect':
<span
class=
"incorrect"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: incorrect
</span>
</span>
% elif status == 'incomplete':
<span
class=
"incorrect"
id=
"status_${id}"
aria-describedby=
"input_${id}"
>
<span
class=
"sr"
>
Status: incorrect
</span>
</span>
% endif
</span>
common/lib/xmodule/xmodule/js/src/capa/imageinput.js
View file @
7ebeccd4
...
...
@@ -13,24 +13,50 @@
* ~ Chinese Proverb
*/
window
.
image_input_click
=
function
(
id
,
event
)
{
var
iiDiv
=
document
.
getElementById
(
'imageinput_'
+
id
),
window
.
ImageInput
=
(
function
(
$
,
undefined
)
{
var
ImageInput
=
ImageInputConstructor
;
posX
=
event
.
offsetX
?
event
.
offsetX
:
event
.
pageX
-
iiDiv
.
offsetLeft
,
posY
=
event
.
offsetY
?
event
.
offsetY
:
event
.
pageY
-
iiDiv
.
offsetTop
,
ImageInput
.
prototype
=
{
constructor
:
ImageInputConstructor
,
clickHandler
:
clickHandler
};
cross
=
document
.
getElementById
(
'cross_'
+
id
),
return
ImageInput
;
// To reduce differences between values returned by different kinds of
// browsers, we round `posX` and `posY`.
//
// IE10: `posX` and `posY` - float.
// Chrome, FF: `posX` and `posY` - integers.
result
=
'['
+
Math
.
round
(
posX
)
+
','
+
Math
.
round
(
posY
)
+
']'
;
function
ImageInputConstructor
(
elementId
)
{
var
_this
=
this
;
cross
.
style
.
left
=
(
posX
-
15
)
+
'px'
;
cross
.
style
.
top
=
(
posY
-
15
)
+
'px'
;
cross
.
style
.
visibility
=
'visible'
;
this
.
elementId
=
elementId
;
this
.
el
=
$
(
'#imageinput_'
+
elementId
);
document
.
getElementById
(
'input_'
+
id
).
value
=
result
;
};
this
.
el
.
on
(
'click'
,
function
(
event
)
{
_this
.
clickHandler
(
event
);
});
}
function
clickHandler
(
event
)
{
var
iiDiv
=
document
.
getElementById
(
'imageinput_'
+
this
.
elementId
),
posX
=
event
.
offsetX
?
event
.
offsetX
:
event
.
pageX
-
iiDiv
.
offsetLeft
,
posY
=
event
.
offsetY
?
event
.
offsetY
:
event
.
pageY
-
iiDiv
.
offsetTop
,
cross
=
document
.
getElementById
(
'cross_'
+
this
.
elementId
),
// To reduce differences between values returned by different kinds
// of browsers, we round `posX` and `posY`.
//
// IE10: `posX` and `posY` - float.
// Chrome, FF: `posX` and `posY` - integers.
result
=
'['
+
Math
.
round
(
posX
)
+
','
+
Math
.
round
(
posY
)
+
']'
;
console
.
log
(
'[image_input_click]: event = '
,
event
);
cross
.
style
.
left
=
(
posX
-
15
)
+
'px'
;
cross
.
style
.
top
=
(
posY
-
15
)
+
'px'
;
cross
.
style
.
visibility
=
'visible'
;
document
.
getElementById
(
'input_'
+
this
.
elementId
).
value
=
result
;
}
}).
call
(
this
,
window
.
jQuery
);
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