Commit 672aa8c0 by Tim Krones

Address review comments.

parent 48b9846b
...@@ -72,10 +72,12 @@ ...@@ -72,10 +72,12 @@
border-radius: 3px; border-radius: 3px;
margin: 5px; margin: 5px;
padding: 10px; padding: 10px;
background-color: #2872b2; background-color: #1d5280;
font-size: 14px; font-size: 14px;
color: #fff; color: #fff;
opacity: 1; opacity: 1;
outline-color: #fff;
outline-style: none;
/* Some versions of the drag and drop library try to fiddle with this */ /* Some versions of the drag and drop library try to fiddle with this */
z-index: 10 !important; z-index: 10 !important;
} }
...@@ -115,7 +117,8 @@ ...@@ -115,7 +117,8 @@
/* Focused option */ /* Focused option */
.xblock--drag-and-drop .drag-container .item-bank .option:focus, .xblock--drag-and-drop .drag-container .item-bank .option:focus,
.xblock--drag-and-drop .drag-container .item-bank .option:hover { .xblock--drag-and-drop .drag-container .item-bank .option:hover {
outline: 2px solid #fff; outline-width: 2px;
outline-style: solid;
outline-offset: -4px; outline-offset: -4px;
} }
......
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
/** Buttons **/ /** Buttons **/
.xblock--drag-and-drop--editor .btn { .xblock--drag-and-drop--editor .btn {
background: #2872b2; background: #1d5280;
color: #fff; color: #fff;
border: 1px solid #156ab4; border: 1px solid #156ab4;
border-radius: 6px; border-radius: 6px;
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
.xblock--drag-and-drop--editor .add-element { .xblock--drag-and-drop--editor .add-element {
text-decoration: none; text-decoration: none;
color: #236299; color: #1d5280;
} }
.xblock--drag-and-drop--editor .remove-zone { .xblock--drag-and-drop--editor .remove-zone {
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
width: 14px; width: 14px;
height: 14px; height: 14px;
border-radius: 7px; border-radius: 7px;
background: #236299; background: #1d5280;
position: relative; position: relative;
float: left; float: left;
margin: 0 5px 0 0; margin: 0 5px 0 0;
...@@ -325,9 +325,9 @@ ...@@ -325,9 +325,9 @@
.xblock--drag-and-drop--editor .remove-item .icon.remove { .xblock--drag-and-drop--editor .remove-item .icon.remove {
background: #fff; background: #fff;
color: #0072a7; color: #0072a7; /* Override default color from Studio to ensure contrast is large enough */
} }
.xblock--drag-and-drop--editor .remove-item .icon.remove:before, .xblock--drag-and-drop--editor .remove-item .icon.remove:before,
.xblock--drag-and-drop--editor .remove-item .icon.remove:after { .xblock--drag-and-drop--editor .remove-item .icon.remove:after {
background: #236299; background: #1d5280;
} }
...@@ -167,16 +167,18 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -167,16 +167,18 @@ function DragAndDropBlock(runtime, element, configuration) {
revert: 'invalid', revert: 'invalid',
revertDuration: 150, revertDuration: 150,
start: function(evt, ui) { start: function(evt, ui) {
var $item = $(this); var item_id = $(this).data('value');
$item.attr('aria-grabbed', true); setGrabbedState(item_id, true);
var item_id = $item.data('value'); updateDOM();
publishEvent({ publishEvent({
event_type: 'xblock.drag-and-drop-v2.item.picked-up', event_type: 'xblock.drag-and-drop-v2.item.picked-up',
item_id: item_id item_id: item_id
}); });
}, },
stop: function(evt, ui) { stop: function(evt, ui) {
$(this).attr('aria-grabbed', false); var item_id = $(this).data('value');
setGrabbedState(item_id, false);
updateDOM();
} }
}); });
} catch (e) { } catch (e) {
...@@ -186,6 +188,14 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -186,6 +188,14 @@ function DragAndDropBlock(runtime, element, configuration) {
}); });
}; };
var setGrabbedState = function(item_id, grabbed) {
for (var i = 0; i < configuration.items.length; i++) {
if (configuration.items[i].id === item_id) {
configuration.items[i].grabbed = grabbed;
}
}
};
var destroyDraggable = function() { var destroyDraggable = function() {
$root.find('.item-bank .option[data-drag-disabled=true]').each(function() { $root.find('.item-bank .option[data-drag-disabled=true]').each(function() {
try { try {
...@@ -317,6 +327,10 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -317,6 +327,10 @@ function DragAndDropBlock(runtime, element, configuration) {
} }
} }
var imageURL = item.imageURL || item.backgroundImage; // Fall back on "backgroundImage" to be backward-compatible var imageURL = item.imageURL || item.backgroundImage; // Fall back on "backgroundImage" to be backward-compatible
var grabbed = false;
if (item.grabbed !== undefined) {
grabbed = item.grabbed;
}
var itemProperties = { var itemProperties = {
value: item.id, value: item.id,
drag_disabled: Boolean(item_user_state || state.finished), drag_disabled: Boolean(item_user_state || state.finished),
...@@ -327,6 +341,7 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -327,6 +341,7 @@ function DragAndDropBlock(runtime, element, configuration) {
imageURL: imageURL, imageURL: imageURL,
imageDescription: item.imageDescription, imageDescription: item.imageDescription,
has_image: !!imageURL, has_image: !!imageURL,
grabbed: grabbed,
}; };
if (item_user_state) { if (item_user_state) {
itemProperties.is_placed = true; itemProperties.is_placed = true;
......
...@@ -61,6 +61,9 @@ ...@@ -61,6 +61,9 @@
} }
if (item.color) { if (item.color) {
style.color = item.color; style.color = item.color;
// Ensure contrast between outline-color and background color
// matches contrast between text color and background color:
style['outline-color'] = item.color;
} }
if (item.is_placed) { if (item.is_placed) {
style.left = item.x_percent + "%"; style.left = item.x_percent + "%";
...@@ -82,8 +85,8 @@ ...@@ -82,8 +85,8 @@
className: className, className: className,
attributes: { attributes: {
'tabindex': tabindex, 'tabindex': tabindex,
'draggable': true, 'draggable': !item.drag_disabled,
'aria-grabbed': false, 'aria-grabbed': item.grabbed,
'data-value': item.value, 'data-value': item.value,
'data-drag-disabled': item.drag_disabled 'data-drag-disabled': item.drag_disabled
}, },
......
...@@ -7,7 +7,7 @@ from .test_base import BaseIntegrationTest ...@@ -7,7 +7,7 @@ from .test_base import BaseIntegrationTest
class Colors(object): class Colors(object):
WHITE = 'rgb(255, 255, 255)' WHITE = 'rgb(255, 255, 255)'
BLUE = 'rgb(40, 114, 178)' BLUE = 'rgb(29, 82, 128)'
GREY = 'rgb(237, 237, 237)' GREY = 'rgb(237, 237, 237)'
CORAL = '#ff7f50' CORAL = '#ff7f50'
CORNFLOWERBLUE = 'cornflowerblue' CORNFLOWERBLUE = 'cornflowerblue'
...@@ -69,6 +69,7 @@ class TestDragAndDropRender(BaseIntegrationTest): ...@@ -69,6 +69,7 @@ class TestDragAndDropRender(BaseIntegrationTest):
def _test_item_style(self, item_element, style_settings): def _test_item_style(self, item_element, style_settings):
item_val = item_element.get_attribute('data-value') item_val = item_element.get_attribute('data-value')
item_selector = '.item-bank .option[data-value=' + item_val + ']'
style = item_element.get_attribute('style') style = item_element.get_attribute('style')
# Check background color # Check background color
background_color_property = 'background-color' background_color_property = 'background-color'
...@@ -77,7 +78,7 @@ class TestDragAndDropRender(BaseIntegrationTest): ...@@ -77,7 +78,7 @@ class TestDragAndDropRender(BaseIntegrationTest):
expected_background_color = Colors.BLUE expected_background_color = Colors.BLUE
else: else:
expected_background_color = Colors.rgb(style_settings['background-color']) expected_background_color = Colors.rgb(style_settings['background-color'])
background_color = self._get_style('.item-bank .option[data-value='+item_val+']', 'backgroundColor') background_color = self._get_style(item_selector, 'backgroundColor')
self.assertEquals(background_color, expected_background_color) self.assertEquals(background_color, expected_background_color)
# Check text color # Check text color
...@@ -88,9 +89,18 @@ class TestDragAndDropRender(BaseIntegrationTest): ...@@ -88,9 +89,18 @@ class TestDragAndDropRender(BaseIntegrationTest):
expected_color = Colors.WHITE expected_color = Colors.WHITE
else: else:
expected_color = Colors.rgb(style_settings['color']) expected_color = Colors.rgb(style_settings['color'])
color = self._get_style('.item-bank .option[data-value='+item_val+']', 'color') color = self._get_style(item_selector, 'color')
self.assertEquals(color, expected_color) self.assertEquals(color, expected_color)
# Check outline color
outline_color_property = 'outline-color'
if outline_color_property not in style_settings:
self.assertNotIn(outline_color_property, style)
# Outline color should match text color to ensure it does not meld into background color:
expected_outline_color = expected_color
outline_color = self._get_style(item_selector, 'outlineColor')
self.assertEquals(outline_color, expected_outline_color)
def test_items_default_colors(self): def test_items_default_colors(self):
self.load_scenario() self.load_scenario()
self._test_items() self._test_items()
...@@ -109,6 +119,7 @@ class TestDragAndDropRender(BaseIntegrationTest): ...@@ -109,6 +119,7 @@ class TestDragAndDropRender(BaseIntegrationTest):
color_settings['background-color'] = item_background_color color_settings['background-color'] = item_background_color
if item_text_color: if item_text_color:
color_settings['color'] = item_text_color color_settings['color'] = item_text_color
color_settings['outline-color'] = item_text_color
self._test_items(color_settings=color_settings) self._test_items(color_settings=color_settings)
......
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