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
4594986b
Commit
4594986b
authored
Dec 25, 2012
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 21, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client side drag and drop. Work in progress. Part 4.
parent
de954a41
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
9 deletions
+106
-9
common/static/js/capa/drag_and_drop/container.js
+1
-1
common/static/js/capa/drag_and_drop/draggables.js
+101
-6
common/static/js/capa/drag_and_drop/scroller.js
+2
-2
common/static/js/capa/drag_and_drop/target.js
+2
-0
No files found.
common/static/js/capa/drag_and_drop/container.js
View file @
4594986b
...
@@ -12,7 +12,7 @@ define(['logme'], function (logme) {
...
@@ -12,7 +12,7 @@ define(['logme'], function (logme) {
'<div '
+
'<div '
+
'style=" '
+
'style=" '
+
'border: 1px solid black; '
+
'border: 1px solid black; '
+
'overflow: hidden; '
+
//
'overflow: hidden; ' +
'clear: both; '
+
'clear: both; '
+
'" '
+
'" '
+
'></div>'
'></div>'
...
...
common/static/js/capa/drag_and_drop/draggables.js
View file @
4594986b
...
@@ -10,15 +10,14 @@ define(['logme'], function (logme) {
...
@@ -10,15 +10,14 @@ define(['logme'], function (logme) {
function
Draggables
(
state
)
{
function
Draggables
(
state
)
{
(
function
(
i
)
{
(
function
(
i
)
{
while
(
i
<
state
.
config
.
draggable
.
length
)
{
while
(
i
<
state
.
config
.
draggable
.
length
)
{
processDraggable
(
state
.
config
.
draggable
[
i
]);
processDraggable
(
state
.
config
.
draggable
[
i
]
,
i
+
1
);
i
+=
1
;
i
+=
1
;
}
}
}(
0
));
}(
0
));
function
processDraggable
(
obj
)
{
function
processDraggable
(
obj
,
index
)
{
var
draggableContainerEl
;
var
draggableContainerEl
,
imgEl
,
inContainer
,
mouseDown
;
logme
(
obj
);
draggableContainerEl
=
$
(
draggableContainerEl
=
$
(
'<div '
+
'<div '
+
...
@@ -27,17 +26,113 @@ define(['logme'], function (logme) {
...
@@ -27,17 +26,113 @@ define(['logme'], function (logme) {
'height: 100px; '
+
'height: 100px; '
+
'display: inline; '
+
'display: inline; '
+
'float: left; '
+
'float: left; '
+
'overflow: hidden; '
+
'" '
+
'" '
+
'data-draggable-position-index="'
+
index
+
'" '
+
'></div>'
'></div>'
);
);
if
(
obj
.
icon
.
length
>
0
)
{
if
(
obj
.
icon
.
length
>
0
)
{
imgEl
=
$
(
'<img '
+
'src="'
+
state
.
config
.
imageDir
+
'/'
+
obj
.
icon
+
'" '
+
'/>'
);
draggableContainerEl
.
append
(
imgEl
);
}
if
(
obj
.
label
.
length
>
0
)
{
draggableContainerEl
.
append
(
draggableContainerEl
.
append
(
$
(
'<
img src="'
+
state
.
config
.
imageDir
+
'/'
+
obj
.
icon
+
'" /
>'
)
$
(
'<
div style="clear: both; text-align: center;">'
+
obj
.
label
+
'</div
>'
)
);
);
}
}
draggableContainerEl
.
appendTo
(
state
.
sliderEl
);
draggableContainerEl
.
appendTo
(
state
.
sliderEl
);
inContainer
=
true
;
mouseDown
=
false
;
draggableContainerEl
.
mousedown
(
function
(
event
)
{
if
(
mouseDown
===
false
)
{
if
(
inContainer
===
true
)
{
draggableContainerEl
.
detach
();
draggableContainerEl
.
css
(
'position'
,
'absolute'
);
draggableContainerEl
.
css
(
'left'
,
(
event
.
pageX
-
50
));
draggableContainerEl
.
css
(
'top'
,
(
event
.
pageY
-
50
));
draggableContainerEl
.
appendTo
(
state
.
containerEl
);
inContainer
=
false
;
}
mouseDown
=
true
;
event
.
preventDefault
();
}
});
draggableContainerEl
.
mouseup
(
function
(
event
)
{
if
(
mouseDown
===
true
)
{
mouseDown
=
false
;
checkLandingElement
(
event
);
event
.
preventDefault
();
}
});
draggableContainerEl
.
mousemove
(
function
(
event
)
{
if
(
mouseDown
===
true
)
{
draggableContainerEl
.
css
(
'left'
,
(
event
.
pageX
-
50
));
draggableContainerEl
.
css
(
'top'
,
(
event
.
pageY
-
50
));
event
.
preventDefault
();
}
});
draggableContainerEl
.
mouseleave
(
function
(
event
)
{
if
(
mouseDown
===
true
)
{
mouseDown
=
false
;
checkLandingElement
(
event
);
event
.
preventDefault
();
}
});
return
;
function
checkLandingElement
(
event
)
{
var
offsetDE
,
children
;
offsetDE
=
draggableContainerEl
.
offset
();
if
(
(
offsetDE
.
left
<
state
.
targetEl
.
offset
().
left
)
||
(
offsetDE
.
left
+
100
>
state
.
targetEl
.
offset
().
left
+
state
.
targetEl
.
width
())
||
(
offsetDE
.
top
<
state
.
targetEl
.
offset
().
top
)
||
(
offsetDE
.
top
+
100
>
state
.
targetEl
.
offset
().
top
+
state
.
targetEl
.
height
())
)
{
draggableContainerEl
.
detach
();
draggableContainerEl
.
css
(
'position'
,
'static'
);
children
=
state
.
sliderEl
.
children
();
if
(
children
.
length
===
0
)
{
draggableContainerEl
.
appendTo
(
state
.
sliderEl
);
}
else
{
state
.
sliderEl
.
children
().
each
(
function
(
index
,
value
)
{
if
(
inContainer
===
false
)
{
if
(
parseInt
(
$
(
value
).
attr
(
'data-draggable-position-index'
),
10
)
+
1
===
parseInt
(
draggableContainerEl
.
attr
(
'data-draggable-position-index'
),
10
))
{
$
(
value
).
after
(
draggableContainerEl
);
inContainer
=
true
;
}
else
if
(
parseInt
(
$
(
value
).
attr
(
'data-draggable-position-index'
),
10
)
-
1
===
parseInt
(
draggableContainerEl
.
attr
(
'data-draggable-position-index'
),
10
))
{
$
(
value
).
before
(
draggableContainerEl
);
inContainer
=
true
;
}
}
});
}
if
(
inContainer
===
false
)
{
draggableContainerEl
.
appendTo
(
state
.
sliderEl
);
}
}
}
}
}
}
}
...
...
common/static/js/capa/drag_and_drop/scroller.js
View file @
4594986b
...
@@ -37,7 +37,7 @@ define(['logme'], function (logme) {
...
@@ -37,7 +37,7 @@ define(['logme'], function (logme) {
moveLeftEl
.
appendTo
(
parentEl
);
moveLeftEl
.
appendTo
(
parentEl
);
moveLeftEl
.
click
(
function
()
{
moveLeftEl
.
click
(
function
()
{
state
.
showElLeftMargin
-
=
100
;
state
.
showElLeftMargin
+
=
100
;
state
.
sliderEl
.
animate
({
state
.
sliderEl
.
animate
({
'margin-left'
:
state
.
showElLeftMargin
+
'px'
'margin-left'
:
state
.
showElLeftMargin
+
'px'
});
});
...
@@ -82,7 +82,7 @@ define(['logme'], function (logme) {
...
@@ -82,7 +82,7 @@ define(['logme'], function (logme) {
moveRightEl
.
appendTo
(
parentEl
);
moveRightEl
.
appendTo
(
parentEl
);
moveRightEl
.
click
(
function
()
{
moveRightEl
.
click
(
function
()
{
state
.
showElLeftMargin
+
=
100
;
state
.
showElLeftMargin
-
=
100
;
state
.
sliderEl
.
animate
({
state
.
sliderEl
.
animate
({
'margin-left'
:
state
.
showElLeftMargin
+
'px'
'margin-left'
:
state
.
showElLeftMargin
+
'px'
});
});
...
...
common/static/js/capa/drag_and_drop/target.js
View file @
4594986b
...
@@ -48,6 +48,8 @@ define(['logme'], function (logme) {
...
@@ -48,6 +48,8 @@ define(['logme'], function (logme) {
mouseMoveDiv
.
appendTo
(
targetElContainer
);
mouseMoveDiv
.
appendTo
(
targetElContainer
);
targetElContainer
.
appendTo
(
state
.
containerEl
);
targetElContainer
.
appendTo
(
state
.
containerEl
);
state
.
targetElOffset
=
state
.
targetEl
.
offset
();
}
}
});
});
...
...
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