Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-drag-and-drop-v2
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
OpenEdx
xblock-drag-and-drop-v2
Commits
c08357d0
Commit
c08357d0
authored
Dec 14, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backwards compatibility with old user item state format
parent
e7711643
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
drag_and_drop_v2/public/js/drag_and_drop.js
+35
-0
No files found.
drag_and_drop_v2/public/js/drag_and_drop.js
View file @
c08357d0
...
@@ -28,6 +28,7 @@ function DragAndDropBlock(runtime, element, configuration) {
...
@@ -28,6 +28,7 @@ function DragAndDropBlock(runtime, element, configuration) {
computeZoneDimension
(
zone
,
bgImg
.
width
,
bgImg
.
height
);
computeZoneDimension
(
zone
,
bgImg
.
width
,
bgImg
.
height
);
});
});
state
=
stateResult
[
0
];
// stateResult is an array of [data, statusText, jqXHR]
state
=
stateResult
[
0
];
// stateResult is an array of [data, statusText, jqXHR]
migrateState
(
bgImg
.
width
,
bgImg
.
height
);
applyState
();
applyState
();
initDroppable
();
initDroppable
();
...
@@ -340,5 +341,39 @@ function DragAndDropBlock(runtime, element, configuration) {
...
@@ -340,5 +341,39 @@ function DragAndDropBlock(runtime, element, configuration) {
return
DragAndDropBlock
.
renderView
(
context
);
return
DragAndDropBlock
.
renderView
(
context
);
};
};
/**
* migrateState: Apply any changes necessary to support the 'state' format used by older
* versions of this XBlock.
* We have to do this in JS, not python, since some migrations depend on the image size,
* which is not known in Python-land.
*/
var
migrateState
=
function
(
bg_image_width
,
bg_image_height
)
{
Object
.
keys
(
state
.
items
).
forEach
(
function
(
item_id
)
{
var
item
=
state
.
items
[
item_id
];
if
(
item
.
x_percent
===
undefined
)
{
// Find the matching item in the configuration
var
width
=
190
;
var
height
=
44
;
for
(
var
i
in
configuration
.
items
)
{
if
(
configuration
.
items
[
i
].
id
===
+
item_id
)
{
var
size
=
configuration
.
items
[
i
].
size
;
// size is an object like '{width: "50px", height: "auto"}'
if
(
parseInt
(
size
.
width
)
>
0
)
{
width
=
parseInt
(
size
.
width
);
}
if
(
parseInt
(
size
.
height
)
>
0
)
{
height
=
parseInt
(
size
.
height
);
}
break
;
}
}
// Update the user's item state to use centered relative coordinates
var
left_px
=
parseFloat
(
item
.
left
)
-
220
;
// 220 px for the items container that used to be on the left
var
top_px
=
parseFloat
(
item
.
top
);
item
.
x_percent
=
(
left_px
+
width
/
2
)
/
bg_image_width
*
100
;
item
.
y_percent
=
(
top_px
+
height
/
2
)
/
bg_image_height
*
100
;
delete
item
.
left
;
delete
item
.
top
;
delete
item
.
absolute
;
}
});
};
init
();
init
();
}
}
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