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