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
79f5e98d
Commit
79f5e98d
authored
Jan 16, 2013
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 21, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drag and Drop: refactoring + preparing for reuse of draggables.
parent
e47f0e45
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
20 deletions
+145
-20
common/static/js/capa/drag_and_drop/base_image.js
+3
-3
common/static/js/capa/drag_and_drop/config_parser.js
+0
-0
common/static/js/capa/drag_and_drop/draggables.js
+137
-12
common/static/js/capa/drag_and_drop/main.js
+3
-3
common/static/js/capa/drag_and_drop/targets.js
+2
-2
common/static/js/capa/drag_and_drop/update_input.js
+0
-0
No files found.
common/static/js/capa/drag_and_drop/base_image.js
View file @
79f5e98d
...
@@ -26,7 +26,7 @@ define(['logme'], function (logme) {
...
@@ -26,7 +26,7 @@ define(['logme'], function (logme) {
state
.
baseImageEl
.
attr
(
state
.
baseImageEl
.
attr
(
'src'
,
'src'
,
state
.
config
.
base
_i
mage
state
.
config
.
base
I
mage
);
);
state
.
baseImageEl
.
load
(
function
()
{
state
.
baseImageEl
.
load
(
function
()
{
baseImageElContainer
.
css
(
'width'
,
this
.
width
);
baseImageElContainer
.
css
(
'width'
,
this
.
width
);
...
@@ -43,11 +43,11 @@ define(['logme'], function (logme) {
...
@@ -43,11 +43,11 @@ define(['logme'], function (logme) {
});
});
state
.
baseImageEl
.
error
(
function
()
{
state
.
baseImageEl
.
error
(
function
()
{
logme
(
logme
(
'ERROR: Image "'
+
state
.
config
.
base
_i
mage
+
'" was not found!'
'ERROR: Image "'
+
state
.
config
.
base
I
mage
+
'" was not found!'
);
);
baseImageElContainer
.
html
(
baseImageElContainer
.
html
(
'<span style="color: red;">'
+
'<span style="color: red;">'
+
'ERROR: Image "'
+
state
.
config
.
base
_i
mage
+
'" was not found!'
+
'ERROR: Image "'
+
state
.
config
.
base
I
mage
+
'" was not found!'
+
'</span>'
'</span>'
);
);
baseImageElContainer
.
appendTo
(
state
.
containerEl
);
baseImageElContainer
.
appendTo
(
state
.
containerEl
);
...
...
common/static/js/capa/drag_and_drop/config_parser.js
View file @
79f5e98d
This diff is collapsed.
Click to expand it.
common/static/js/capa/drag_and_drop/draggables.js
View file @
79f5e98d
...
@@ -10,8 +10,6 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -10,8 +10,6 @@ define(['logme', 'update_input'], function (logme, updateInput) {
};
};
function
init
(
state
)
{
function
init
(
state
)
{
logme
(
'Draggables.init; state = '
,
state
);
state
.
draggables
=
[];
state
.
draggables
=
[];
state
.
numDraggablesInSlider
=
0
;
state
.
numDraggablesInSlider
=
0
;
state
.
currentMovingDraggable
=
null
;
state
.
currentMovingDraggable
=
null
;
...
@@ -65,12 +63,136 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -65,12 +63,136 @@ define(['logme', 'update_input'], function (logme, updateInput) {
}
}
}
}
function
processDraggable
(
state
,
obj
,
objIndex
)
{
function
moveDraggableToXY
(
newPosition
)
{
var
draggableObj
;
var
self
,
offset
;
if
(
this
.
hasLoaded
===
false
)
{
self
=
this
;
setTimeout
(
function
()
{
self
.
moveDraggableToXY
(
newPosition
);
},
50
);
return
;
}
offset
=
0
;
if
(
this
.
state
.
config
.
targetOutline
===
true
)
{
offset
=
1
;
}
this
.
inContainer
=
false
;
this
.
containerEl
.
hide
();
this
.
iconEl
.
detach
();
this
.
iconEl
.
css
(
'background-color'
,
this
.
iconElBGColor
);
this
.
iconEl
.
css
(
'padding-left'
,
this
.
iconElPadding
);
this
.
iconEl
.
css
(
'padding-right'
,
this
.
iconElPadding
);
this
.
iconEl
.
css
(
'border'
,
this
.
iconElBorder
);
this
.
iconEl
.
css
(
'width'
,
this
.
iconWidth
);
this
.
iconEl
.
css
(
'height'
,
this
.
iconHeight
);
this
.
iconEl
.
css
(
'left'
,
newPosition
.
x
-
this
.
iconWidth
*
0.5
+
offset
-
this
.
iconElLeftOffset
);
this
.
iconEl
.
css
(
'top'
,
newPosition
.
y
-
this
.
iconHeight
*
0.5
+
offset
);
this
.
iconEl
.
appendTo
(
this
.
state
.
baseImageEl
.
parent
());
if
(
this
.
labelEl
!==
null
)
{
this
.
labelEl
.
detach
();
this
.
labelEl
.
css
(
'background-color'
,
this
.
state
.
config
.
labelBgColor
);
this
.
labelEl
.
css
(
'padding-left'
,
8
);
this
.
labelEl
.
css
(
'padding-right'
,
8
);
this
.
labelEl
.
css
(
'border'
,
'1px solid black'
);
this
.
labelEl
.
css
(
'left'
,
newPosition
.
x
-
this
.
labelWidth
*
0.5
+
offset
-
9
// Account for padding, border.
);
this
.
labelEl
.
css
(
'top'
,
newPosition
.
y
-
this
.
iconHeight
*
0.5
+
this
.
iconHeight
+
5
+
offset
);
this
.
labelEl
.
appendTo
(
this
.
state
.
baseImageEl
.
parent
());
}
this
.
x
=
newPosition
.
x
;
this
.
y
=
newPosition
.
y
;
this
.
state
.
numDraggablesInSlider
-=
1
;
this
.
state
.
updateArrowOpacity
();
}
function
moveDraggableToTarget
(
target
)
{
var
self
,
offset
;
logme
(
'processDraggable; state = '
,
state
);
if
(
this
.
hasLoaded
===
false
)
{
self
=
this
;
logme
(
'Processing draggable #'
+
objIndex
);
setTimeout
(
function
()
{
self
.
moveDraggableToTarget
(
target
);
},
50
);
return
;
}
offset
=
0
;
if
(
this
.
state
.
config
.
targetOutline
===
true
)
{
offset
=
1
;
}
this
.
inContainer
=
false
;
this
.
containerEl
.
hide
();
this
.
iconEl
.
detach
();
this
.
iconEl
.
css
(
'background-color'
,
this
.
iconElBGColor
);
this
.
iconEl
.
css
(
'padding-left'
,
this
.
iconElPadding
);
this
.
iconEl
.
css
(
'padding-right'
,
this
.
iconElPadding
);
this
.
iconEl
.
css
(
'border'
,
this
.
iconElBorder
);
this
.
iconEl
.
css
(
'width'
,
this
.
iconWidth
);
this
.
iconEl
.
css
(
'height'
,
this
.
iconHeight
);
this
.
iconEl
.
css
(
'left'
,
target
.
offset
.
left
+
0.5
*
target
.
w
-
this
.
iconWidth
*
0.5
+
offset
-
this
.
iconElLeftOffset
);
this
.
iconEl
.
css
(
'top'
,
target
.
offset
.
top
+
0.5
*
target
.
h
-
this
.
iconHeight
*
0.5
+
offset
);
this
.
iconEl
.
appendTo
(
this
.
state
.
baseImageEl
.
parent
());
if
(
this
.
labelEl
!==
null
)
{
this
.
labelEl
.
detach
();
this
.
labelEl
.
css
(
'background-color'
,
this
.
state
.
config
.
labelBgColor
);
this
.
labelEl
.
css
(
'padding-left'
,
8
);
this
.
labelEl
.
css
(
'padding-right'
,
8
);
this
.
labelEl
.
css
(
'border'
,
'1px solid black'
);
this
.
labelEl
.
css
(
'left'
,
target
.
offset
.
left
+
0.5
*
target
.
w
-
this
.
labelWidth
*
0.5
+
offset
-
9
// Account for padding, border.
);
this
.
labelEl
.
css
(
'top'
,
target
.
offset
.
top
+
0.5
*
target
.
h
+
this
.
iconHeight
*
0.5
+
5
+
offset
);
this
.
labelEl
.
appendTo
(
this
.
state
.
baseImageEl
.
parent
());
}
this
.
onTarget
=
target
;
target
.
draggable
.
push
(
this
.
id
);
if
(
target
.
numTextEl
!==
null
)
{
target
.
updateNumTextEl
();
}
this
.
state
.
numDraggablesInSlider
-=
1
;
this
.
state
.
updateArrowOpacity
();
}
function
processDraggable
(
state
,
obj
,
objIndex
)
{
var
draggableObj
;
draggableObj
=
{
draggableObj
=
{
'zIndex'
:
objIndex
,
'zIndex'
:
objIndex
,
...
@@ -91,7 +213,10 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -91,7 +213,10 @@ define(['logme', 'update_input'], function (logme, updateInput) {
'checkIfOnTarget'
:
checkIfOnTarget
,
'checkIfOnTarget'
:
checkIfOnTarget
,
'snapToTarget'
:
snapToTarget
,
'snapToTarget'
:
snapToTarget
,
'correctZIndexes'
:
correctZIndexes
,
'correctZIndexes'
:
correctZIndexes
,
'moveBackToSlider'
:
moveBackToSlider
'moveBackToSlider'
:
moveBackToSlider
,
'moveDraggableToTarget'
:
moveDraggableToTarget
,
'moveDraggableToXY'
:
moveDraggableToXY
};
};
draggableObj
.
containerEl
=
$
(
draggableObj
.
containerEl
=
$
(
...
@@ -334,7 +459,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -334,7 +459,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
this
.
iconHeight
*
0.5
this
.
iconHeight
*
0.5
);
);
this
.
iconEl
.
appendTo
(
this
.
iconEl
.
appendTo
(
state
.
baseImageEl
.
parent
()
this
.
state
.
baseImageEl
.
parent
()
);
);
if
(
this
.
labelEl
!==
null
)
{
if
(
this
.
labelEl
!==
null
)
{
...
@@ -447,7 +572,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -447,7 +572,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
this
.
mousePressed
=
false
;
this
.
mousePressed
=
false
;
positionIE
=
this
.
iconEl
.
position
();
positionIE
=
this
.
iconEl
.
position
();
if
(
this
.
state
.
individualTargets
===
true
)
{
if
(
this
.
state
.
config
.
individualTargets
===
true
)
{
if
(
this
.
checkIfOnTarget
(
positionIE
)
===
true
)
{
if
(
this
.
checkIfOnTarget
(
positionIE
)
===
true
)
{
this
.
correctZIndexes
();
this
.
correctZIndexes
();
}
else
{
}
else
{
...
@@ -486,7 +611,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -486,7 +611,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
}
}
this
.
state
.
updateArrowOpacity
();
this
.
state
.
updateArrowOpacity
();
updateInput
(
this
.
state
);
updateInput
.
update
(
this
.
state
);
}
}
function
removeObjIdFromTarget
()
{
function
removeObjIdFromTarget
()
{
...
@@ -532,7 +657,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -532,7 +657,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
// (with an ID different from the one we are checking
// (with an ID different from the one we are checking
// against), then go to next target.
// against), then go to next target.
if
(
if
(
(
this
.
state
.
config
.
one
_per_t
arget
===
true
)
&&
(
this
.
state
.
config
.
one
PerT
arget
===
true
)
&&
(
target
.
draggable
.
length
===
1
)
&&
(
target
.
draggable
.
length
===
1
)
&&
(
target
.
draggable
[
0
]
!==
this
.
id
)
(
target
.
draggable
[
0
]
!==
this
.
id
)
)
{
)
{
...
@@ -652,7 +777,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
...
@@ -652,7 +777,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
function
correctZIndexes
()
{
function
correctZIndexes
()
{
var
draggablesInMe
,
c1
,
c2
,
highestZIndex
;
var
draggablesInMe
,
c1
,
c2
,
highestZIndex
;
if
(
this
.
state
.
individualTargets
===
true
)
{
if
(
this
.
state
.
config
.
individualTargets
===
true
)
{
if
(
this
.
onTarget
.
draggable
.
length
>
0
)
{
if
(
this
.
onTarget
.
draggable
.
length
>
0
)
{
draggablesInMe
=
[];
draggablesInMe
=
[];
...
...
common/static/js/capa/drag_and_drop/main.js
View file @
79f5e98d
...
@@ -65,11 +65,11 @@ define(
...
@@ -65,11 +65,11 @@ define(
Scroller
(
state
);
Scroller
(
state
);
Draggables
.
init
(
state
);
Draggables
.
init
(
state
);
logme
(
'After Draggables.init(state); state = '
,
state
);
// Update the input element, checking first that it is not filled with
// Update the input element, checking first that it is not filled with
// an answer from the server.
// an answer from the server.
updateInput
(
state
,
true
);
if
(
updateInput
.
check
(
state
)
===
false
)
{
updateInput
.
update
(
state
);
}
}());
}());
}
}
});
});
...
...
common/static/js/capa/drag_and_drop/targets.js
View file @
79f5e98d
...
@@ -45,7 +45,7 @@ define(['logme'], function (logme) {
...
@@ -45,7 +45,7 @@ define(['logme'], function (logme) {
event
.
preventDefault
();
event
.
preventDefault
();
});
});
if
(
state
.
config
.
one
_per_t
arget
===
false
)
{
if
(
state
.
config
.
one
PerT
arget
===
false
)
{
numTextEl
=
$
(
numTextEl
=
$
(
'<div '
+
'<div '
+
'style=" '
+
'style=" '
+
...
@@ -86,7 +86,7 @@ define(['logme'], function (logme) {
...
@@ -86,7 +86,7 @@ define(['logme'], function (logme) {
'updateNumTextEl'
:
updateNumTextEl
'updateNumTextEl'
:
updateNumTextEl
};
};
if
(
state
.
config
.
one
_per_t
arget
===
false
)
{
if
(
state
.
config
.
one
PerT
arget
===
false
)
{
numTextEl
.
appendTo
(
state
.
baseImageEl
.
parent
());
numTextEl
.
appendTo
(
state
.
baseImageEl
.
parent
());
numTextEl
.
mousedown
(
function
(
event
)
{
numTextEl
.
mousedown
(
function
(
event
)
{
event
.
preventDefault
();
event
.
preventDefault
();
...
...
common/static/js/capa/drag_and_drop/update_input.js
View file @
79f5e98d
This diff is collapsed.
Click to expand it.
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