Commit 62f09669 by Sven Marnach

Expand static image URLs for item background images.

parent c1a38e41
...@@ -152,6 +152,12 @@ class DragAndDropBlock(XBlock, XBlockWithSettingsMixin, ThemableXBlockMixin): ...@@ -152,6 +152,12 @@ class DragAndDropBlock(XBlock, XBlockWithSettingsMixin, ThemableXBlockMixin):
del item['feedback'] del item['feedback']
del item['zone'] del item['zone']
item['inputOptions'] = 'inputOptions' in item item['inputOptions'] = 'inputOptions' in item
# Fall back on "backgroundImage" to be backward-compatible.
image_url = item.get('imageURL') or item.get('backgroundImage')
if image_url:
item['expandedImageURL'] = self._expand_static_url(image_url)
else:
item['expandedImageURL'] = ''
return items return items
return { return {
......
...@@ -857,7 +857,6 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -857,7 +857,6 @@ function DragAndDropBlock(runtime, element, configuration) {
input.class_name = item_user_state.correct_input ? 'correct' : 'incorrect'; input.class_name = item_user_state.correct_input ? 'correct' : 'incorrect';
} }
} }
var imageURL = item.imageURL || item.backgroundImage; // Fall back on "backgroundImage" to be backward-compatible
var grabbed = false; var grabbed = false;
if (item.grabbed !== undefined) { if (item.grabbed !== undefined) {
grabbed = item.grabbed; grabbed = item.grabbed;
...@@ -870,9 +869,9 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -870,9 +869,9 @@ function DragAndDropBlock(runtime, element, configuration) {
xhr_active: (item_user_state && item_user_state.submitting_location), xhr_active: (item_user_state && item_user_state.submitting_location),
input: input, input: input,
displayName: item.displayName, displayName: item.displayName,
imageURL: imageURL, imageURL: item.expandedImageURL,
imageDescription: item.imageDescription, imageDescription: item.imageDescription,
has_image: !!imageURL, has_image: !!item.expandedImageURL,
grabbed: grabbed, grabbed: grabbed,
widthPercent: item.widthPercent, // widthPercent may be undefined (auto width) widthPercent: item.widthPercent, // widthPercent may be undefined (auto width)
imgNaturalWidth: item.imgNaturalWidth, imgNaturalWidth: item.imgNaturalWidth,
......
...@@ -35,24 +35,28 @@ ...@@ -35,24 +35,28 @@
{ {
"displayName": "<b>1</b>", "displayName": "<b>1</b>",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 0, "id": 0,
"inputOptions": false "inputOptions": false
}, },
{ {
"displayName": "<i>2</i>", "displayName": "<i>2</i>",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 1, "id": 1,
"inputOptions": true "inputOptions": true
}, },
{ {
"displayName": "X", "displayName": "X",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 2, "id": 2,
"inputOptions": false "inputOptions": false
}, },
{ {
"displayName": "", "displayName": "",
"imageURL": "http://placehold.it/100x300", "imageURL": "http://placehold.it/100x300",
"expandedImageURL": "http://placehold.it/100x300",
"id": 3, "id": 3,
"inputOptions": false "inputOptions": false
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
{ {
"displayName": "1", "displayName": "1",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 0, "id": 0,
"inputOptions": false, "inputOptions": false,
"size": {"height": "auto", "width": "190px"} "size": {"height": "auto", "width": "190px"}
...@@ -42,6 +43,7 @@ ...@@ -42,6 +43,7 @@
{ {
"displayName": "2", "displayName": "2",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 1, "id": 1,
"inputOptions": true, "inputOptions": true,
"size": {"height": "auto", "width": "190px"} "size": {"height": "auto", "width": "190px"}
...@@ -49,6 +51,7 @@ ...@@ -49,6 +51,7 @@
{ {
"displayName": "X", "displayName": "X",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 2, "id": 2,
"inputOptions": false, "inputOptions": false,
"size": {"height": "100px", "width": "100px"} "size": {"height": "100px", "width": "100px"}
...@@ -56,6 +59,7 @@ ...@@ -56,6 +59,7 @@
{ {
"displayName": "", "displayName": "",
"imageURL": "http://i1.kym-cdn.com/entries/icons/square/000/006/151/tumblr_lltzgnHi5F1qzib3wo1_400.jpg", "imageURL": "http://i1.kym-cdn.com/entries/icons/square/000/006/151/tumblr_lltzgnHi5F1qzib3wo1_400.jpg",
"expandedImageURL": "http://i1.kym-cdn.com/entries/icons/square/000/006/151/tumblr_lltzgnHi5F1qzib3wo1_400.jpg",
"id": 3, "id": 3,
"inputOptions": false, "inputOptions": false,
"size": {"height": "auto", "width": "190px"} "size": {"height": "auto", "width": "190px"}
......
...@@ -35,24 +35,28 @@ ...@@ -35,24 +35,28 @@
{ {
"displayName": "1", "displayName": "1",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 0, "id": 0,
"inputOptions": false "inputOptions": false
}, },
{ {
"displayName": "2", "displayName": "2",
"imageURL": "", "imageURL": "",
"expandedImageURL": "",
"id": 1, "id": 1,
"inputOptions": true "inputOptions": true
}, },
{ {
"displayName": "X", "displayName": "X",
"imageURL": "", "imageURL": "/static/test_url_expansion",
"expandedImageURL": "/course/test-course/assets/test_url_expansion",
"id": 2, "id": 2,
"inputOptions": false "inputOptions": false
}, },
{ {
"displayName": "", "displayName": "",
"imageURL": "http://placehold.it/200x100", "imageURL": "http://placehold.it/200x100",
"expandedImageURL": "http://placehold.it/200x100",
"id": 3, "id": 3,
"inputOptions": false "inputOptions": false
} }
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
"correct": "" "correct": ""
}, },
"zone": "none", "zone": "none",
"imageURL": "", "imageURL": "/static/test_url_expansion",
"id": 2 "id": 2
}, },
{ {
......
...@@ -45,10 +45,10 @@ class BasicTests(TestCaseMixin, unittest.TestCase): ...@@ -45,10 +45,10 @@ class BasicTests(TestCaseMixin, unittest.TestCase):
self.assertEqual(zones, DEFAULT_DATA["zones"]) self.assertEqual(zones, DEFAULT_DATA["zones"])
# Items should contain no answer data: # Items should contain no answer data:
self.assertEqual(items, [ self.assertEqual(items, [
{"id": 0, "displayName": "Goes to the top", "imageURL": "", "inputOptions": False}, {"id": i, "displayName": display_name, "imageURL": "", "expandedImageURL": "", "inputOptions": False}
{"id": 1, "displayName": "Goes to the middle", "imageURL": "", "inputOptions": False}, for i, display_name in enumerate(
{"id": 2, "displayName": "Goes to the bottom", "imageURL": "", "inputOptions": False}, ["Goes to the top", "Goes to the middle", "Goes to the bottom", "I don't belong anywhere"]
{"id": 3, "displayName": "I don't belong anywhere", "imageURL": "", "inputOptions": False}, )
]) ])
def test_ajax_solve_and_reset(self): def test_ajax_solve_and_reset(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment