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
d5317462
Commit
d5317462
authored
Jan 04, 2013
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 21, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed reliance on imageDir config setting. Now we expect the correct path to tbe set in XML.
parent
533a1693
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
44 deletions
+46
-44
common/static/js/capa/drag_and_drop/base_image.js
+3
-5
common/static/js/capa/drag_and_drop/config_parser.js
+1
-2
common/static/js/capa/drag_and_drop/draggables.js
+40
-28
common/static/js/capa/drag_and_drop/main.js
+2
-9
No files found.
common/static/js/capa/drag_and_drop/base_image.js
View file @
d5317462
...
...
@@ -26,7 +26,7 @@ define(['logme'], function (logme) {
state
.
baseImageEl
.
attr
(
'src'
,
state
.
config
.
imageDir
+
'/'
+
state
.
config
.
base_image
state
.
config
.
base_image
);
state
.
baseImageEl
.
load
(
function
()
{
baseImageElContainer
.
css
(
'width'
,
this
.
width
);
...
...
@@ -39,13 +39,11 @@ define(['logme'], function (logme) {
});
state
.
baseImageEl
.
error
(
function
()
{
logme
(
'ERROR: Image "'
+
state
.
config
.
imageDir
+
'/'
+
state
.
config
.
base_image
+
'" was not found!'
'ERROR: Image "'
+
state
.
config
.
base_image
+
'" was not found!'
);
baseImageElContainer
.
html
(
'<span style="color: red;">'
+
'ERROR: Image "'
+
state
.
config
.
imageDir
+
'/'
+
state
.
config
.
base_image
+
'" was not found!'
+
'ERROR: Image "'
+
state
.
config
.
base_image
+
'" was not found!'
+
'</span>'
);
baseImageElContainer
.
appendTo
(
state
.
containerEl
);
...
...
common/static/js/capa/drag_and_drop/config_parser.js
View file @
d5317462
...
...
@@ -7,13 +7,12 @@
define
([
'logme'
],
function
(
logme
)
{
return
configParser
;
function
configParser
(
config
,
imageDir
,
state
)
{
function
configParser
(
config
,
state
)
{
var
returnStatus
;
returnStatus
=
true
;
state
.
config
=
{
'imageDir'
:
'/static/'
+
imageDir
+
'/images'
,
'draggables'
:
[],
'targets'
:
[],
'base_image'
:
''
...
...
common/static/js/capa/drag_and_drop/draggables.js
View file @
d5317462
...
...
@@ -89,7 +89,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
draggableObj
.
iconEl
=
$
(
'<img />'
);
draggableObj
.
iconEl
.
attr
(
'src'
,
state
.
config
.
imageDir
+
'/'
+
obj
.
icon
obj
.
icon
);
draggableObj
.
iconEl
.
load
(
function
()
{
draggableObj
.
iconWidth
=
this
.
width
;
...
...
@@ -358,11 +358,10 @@ define(['logme', 'update_input'], function (logme, updateInput) {
// the input with the user's answer (X-Y position of the draggable,
// or the ID of the target where it landed.
function
checkLandingElement
()
{
var
offset
IE
,
targetFound
;
var
position
IE
,
targetFound
;
mousePressed
=
false
;
offsetIE
=
draggableObj
.
iconEl
.
position
();
positionIE
=
draggableObj
.
iconEl
.
position
();
if
(
state
.
individualTargets
===
true
)
{
targetFound
=
false
;
...
...
@@ -378,20 +377,15 @@ define(['logme', 'update_input'], function (logme, updateInput) {
state
.
numDraggablesInSlider
+=
1
;
}
}
else
{
logme
(
'baseImageEl.width = '
+
state
.
baseImageEl
.
width
()
+
'; '
+
'baseImageEl.height = '
+
state
.
baseImageEl
.
height
()
);
if
(
(
offset
IE
.
left
<
0
)
||
(
position
IE
.
left
<
0
)
||
(
offset
IE
.
left
+
draggableObj
.
iconWidth
>
position
IE
.
left
+
draggableObj
.
iconWidth
>
state
.
baseImageEl
.
width
()
)
||
(
offset
IE
.
top
<
0
)
||
(
position
IE
.
top
<
0
)
||
(
offset
IE
.
top
+
draggableObj
.
iconHeight
>
position
IE
.
top
+
draggableObj
.
iconHeight
>
state
.
baseImageEl
.
height
()
)
)
{
...
...
@@ -405,9 +399,9 @@ define(['logme', 'update_input'], function (logme, updateInput) {
correctZIndexes
();
draggableObj
.
x
=
offset
IE
.
left
+
draggableObj
.
iconWidth
*
0.5
;
position
IE
.
left
+
draggableObj
.
iconWidth
*
0.5
;
draggableObj
.
y
=
offset
IE
.
top
+
draggableObj
.
iconHeight
*
0.5
;
position
IE
.
top
+
draggableObj
.
iconHeight
*
0.5
;
}
}
...
...
@@ -432,49 +426,63 @@ define(['logme', 'update_input'], function (logme, updateInput) {
}
}
//
// Determine if a draggable, after it was relased, ends up on a
// target. We do this by iterating over all of the targets, and
// for each one we check whether the draggable's center is
// within the target's dimensions.
//
// positionIE is the object as returned by
//
// draggableObj.iconEl.position()
//
function
checkIfOnTarget
()
{
var
c1
,
target
;
for
(
c1
=
0
;
c1
<
state
.
targets
.
length
;
c1
+=
1
)
{
target
=
state
.
targets
[
c1
];
// If only one draggable per target is allowed, and
// the current target already has a draggable on it
// (with an ID different from the one we are checking
// against), then go to next target.
if
(
offsetIE
.
top
+
draggableObj
.
iconHeight
*
0.5
<
target
.
offset
.
top
(
state
.
config
.
one_per_target
===
true
)
&&
(
target
.
draggable
.
length
===
1
)
&&
(
target
.
draggable
[
0
]
!==
draggableObj
.
id
)
)
{
continue
;
}
// Check if the draggable's center coordinate is within
// the target's dimensions. If not, go to next target.
if
(
offsetIE
.
top
+
draggableObj
.
iconHeight
*
0.5
>
target
.
offset
.
top
+
target
.
h
positionIE
.
top
+
draggableObj
.
iconHeight
*
0.5
<
target
.
offset
.
top
)
{
continue
;
}
if
(
offsetIE
.
left
+
draggableObj
.
iconWidth
*
0.5
<
target
.
offset
.
left
positionIE
.
top
+
draggableObj
.
iconHeight
*
0.5
>
target
.
offset
.
top
+
target
.
h
)
{
continue
;
}
if
(
offsetIE
.
left
+
draggableObj
.
iconWidth
*
0.5
>
target
.
offset
.
left
+
target
.
w
positionIE
.
left
+
draggableObj
.
iconWidth
*
0.5
<
target
.
offset
.
left
)
{
continue
;
}
if
(
(
state
.
config
.
one_per_target
===
true
)
&&
(
target
.
draggable
.
length
===
1
)
&&
(
target
.
draggable
[
0
]
!==
draggableObj
.
id
)
positionIE
.
left
+
draggableObj
.
iconWidth
*
0.5
>
target
.
offset
.
left
+
target
.
w
)
{
continue
;
}
// If we got here, then our draggable is on top of a
// target.
targetFound
=
true
;
// If the draggable was moved from one target to
...
...
@@ -488,7 +496,11 @@ define(['logme', 'update_input'], function (logme, updateInput) {
removeObjIdFromTarget
();
onTarget
=
target
;
target
.
draggable
.
push
(
draggableObj
.
id
);
}
else
if
(
onTarget
===
null
)
{
}
// If the draggable was moved from the slider to a
// target, remember the target, and add ID to the
// target's draggables list.
else
if
(
onTarget
===
null
)
{
onTarget
=
target
;
target
.
draggable
.
push
(
draggableObj
.
id
);
}
...
...
common/static/js/capa/drag_and_drop/main.js
View file @
d5317462
...
...
@@ -17,7 +17,7 @@ define(
// $(value) - get the element of the entire problem
function
processProblem
(
index
,
value
)
{
var
problemId
,
imageDir
,
config
,
state
;
var
problemId
,
config
,
state
;
if
(
$
(
value
).
attr
(
'data-problem-processed'
)
===
'true'
)
{
// This problem was already processed by us before, so we will
...
...
@@ -43,16 +43,9 @@ define(
return
;
}
imageDir
=
$
(
value
).
attr
(
'data-course-folder'
);
if
(
typeof
imageDir
!==
'string'
)
{
logme
(
'ERROR: Could not find the name of the image directory.'
);
return
;
}
state
=
State
(
problemId
);
if
(
configParser
(
config
,
imageDir
,
state
)
!==
true
)
{
if
(
configParser
(
config
,
state
)
!==
true
)
{
logme
(
'ERROR: Could not make sense of the JSON configuration options.'
);
return
;
...
...
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