Commit 14b4b6a2 by Brian Talbot Committed by cahrens

Adds in minimally revised drag and drop styling.

Add CSS classes and fix drop destination bug.
parent 85be9b42
...@@ -167,10 +167,11 @@ describe "Course Overview", -> ...@@ -167,10 +167,11 @@ describe "Course Overview", ->
null null
) )
expect(CMS.Views.Draggabilly.dragState).toEqual( expect(CMS.Views.Draggabilly.dragState).toEqual(
offset: $('#unit-1').offset()
dropDestination: null, dropDestination: null,
expandTimer: null, expandTimer: null,
toExpand: null toExpand: null,
attachMethod: '',
parentList: null
) )
describe "onDragMove", -> describe "onDragMove", ->
......
...@@ -77,14 +77,16 @@ CMS.Views.Draggabilly = { ...@@ -77,14 +77,16 @@ CMS.Views.Draggabilly = {
onDragStart: function(draggie, event, pointer) { onDragStart: function(draggie, event, pointer) {
var ele = $(draggie.element); var ele = $(draggie.element);
this.dragState = { this.dragState = {
// Where we started, in case of a failed drag
offset: ele.offset(),
// Which element will be dropped into/onto on success // Which element will be dropped into/onto on success
dropDestination: null, dropDestination: null,
// Timer if we're hovering over a collapsed section // Timer if we're hovering over a collapsed section
expandTimer: null, expandTimer: null,
// The list which will be expanded on hover // The list which will be expanded on hover
toExpand: null toExpand: null,
// How we attach to the destination: 'before', 'after', 'prepend'
attachMethod: '',
// If dragging to an empty section, the parent section
parentList: null
}; };
}, },
...@@ -92,7 +94,7 @@ CMS.Views.Draggabilly = { ...@@ -92,7 +94,7 @@ CMS.Views.Draggabilly = {
var ele = $(draggie.element); var ele = $(draggie.element);
var destinationInfo = this.findDestination(ele); var destinationInfo = this.findDestination(ele);
var destinationEle = destinationInfo.ele; var destinationEle = destinationInfo.ele;
var parentList = destinationInfo.parentList; var parentList = this.dragState.parentList = destinationInfo.parentList;
// Clear the timer if we're not hovering over any element // Clear the timer if we're not hovering over any element
if(!parentList) { if(!parentList) {
clearTimeout(this.dragState.expandTimer); clearTimeout(this.dragState.expandTimer);
...@@ -113,27 +115,33 @@ CMS.Views.Draggabilly = { ...@@ -113,27 +115,33 @@ CMS.Views.Draggabilly = {
} }
// Mark the new destination // Mark the new destination
if(destinationEle) { if(destinationEle) {
ele.addClass('valid-drop');
destinationEle.addClass('drop-target drop-target-' + destinationInfo.attachMethod); destinationEle.addClass('drop-target drop-target-' + destinationInfo.attachMethod);
this.dragState.attachMethod = destinationInfo.attachMethod;
this.dragState.dropDestination = destinationEle; this.dragState.dropDestination = destinationEle;
} }
}, },
onDragEnd: function(draggie, event, pointer) { onDragEnd: function(draggie, event, pointer) {
var ele = $(draggie.element); var ele = $(draggie.element);
var destination = this.dragState.dropDestination;
var destinationInfo = this.findDestination(ele);
var destination = destinationInfo.ele;
// If the drag succeeded, rearrange the DOM and send the result. // If the drag succeeded, rearrange the DOM and send the result.
if(destination && pointer.x >= ele.offset().left if(destination && pointer.x >= ele.offset().left
&& pointer.x < ele.offset().left + ele.width()) { && pointer.x < ele.offset().left + ele.width()) {
// Make sure we don't drop into a collapsed element // Make sure we don't drop into a collapsed element
if(destinationInfo.parentList) { if(this.dragState.parentList) {
destinationInfo.parentList.removeClass('collapsed'); this.dragState.parentList.removeClass('collapsed');
} }
var method = destinationInfo.attachMethod; var method = this.dragState.attachMethod;
destination[method](ele); destination[method](ele);
this.handleReorder(ele); this.handleReorder(ele);
ele.removeClass('valid-drop');
}
// If the drag failed, send it back
else {
$('.was-dragging').removeClass('was-dragging');
ele.addClass('was-dragging');
} }
// Everything in its right place // Everything in its right place
......
...@@ -675,35 +675,36 @@ ...@@ -675,35 +675,36 @@
color: $darkGrey; color: $darkGrey;
} }
// sort/drag and drop // ====================
.ui-droppable {
@include transition (padding 0.5s ease-in-out 0s);
min-height: 20px;
padding: 0;
&.dropover { // UI: drag handles
padding: 15px 0; .section-drag-handle, .draggable {
}
}
.ui-draggable-dragging { &:hover, &:focus {
box-shadow: 0 1px 2px rgba(0, 0, 0, .3); cursor: move;
border: 1px solid $darkGrey; }
opacity : 0.2; }
&:hover {
opacity : 1.0;
.section-item {
background: $yellow !important;
}
}
// hiding unit button - temporary fix until this semantically corrected // UI: drag states
.new-unit-item { .is-dragging {
display: none; @extend .ui-depth4;
} box-shadow: 0 1px 2px 0 $blue-t2;
cursor: move;
opacity: 0.80;
border-color: $blue;
} }
ol.ui-droppable .branch:first-child .section-item { // UI: drag target
border-top: none; .drop-target {
background: $blue-t0 !important;
&.drop-target-before {
border-top: ($baseline/5) solid $blue;
}
&.drop-target-after {
border-bottom: ($baseline/5) solid $blue;
}
} }
} }
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