* @param {jQuery} drag the item being moved.
*/
DragDropOntoImageQuestion.prototype.dragMove = function(pageX, pageY, drag) {
- var thisQ = this;
+ var thisQ = this,
+ highlighted = false;
this.getRoot().find('.dropzone.group' + this.getGroup(drag)).each(function(i, dropNode) {
var drop = $(dropNode);
- if (thisQ.isPointInDrop(pageX, pageY, drop)) {
+ if (thisQ.isPointInDrop(pageX, pageY, drop) && !highlighted) {
+ highlighted = true;
drop.addClass('valid-drag-over-drop');
} else {
drop.removeClass('valid-drag-over-drop');
});
this.getRoot().find('.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, dropNode) {
var drop = $(dropNode);
- if (thisQ.isPointInDrop(pageX, pageY, drop) && !highlighted) {
- if (thisQ.isPointInDrop(pageX, pageY, drop) && !thisQ.isDragSameAsDrop(drag, drop)) {
++ if (thisQ.isPointInDrop(pageX, pageY, drop) && !highlighted && !thisQ.isDragSameAsDrop(drag, drop)) {
+ highlighted = true;
drop.addClass('valid-drag-over-drop');
} else {
drop.removeClass('valid-drag-over-drop');
var thisQ = this,
root = this.getRoot(),
placed = false;
+
+ // Looking for drag that was dropped on a dropzone.
root.find('.dropzone.group' + this.getGroup(drag)).each(function(i, dropNode) {
var drop = $(dropNode);
if (!thisQ.isPointInDrop(pageX, pageY, drop)) {
return false; // Stop the each() here.
});
- root.find('.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, placedNode) {
- var placedDrag = $(placedNode);
- if (!thisQ.isPointInDrop(pageX, pageY, placedDrag) || thisQ.isDragSameAsDrop(drag, placedDrag)) {
- // Not this placed drag.
- return true;
- }
+ if (!placed) {
+ // Looking for drag that was dropped on a placed drag.
+ root.find('.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, placedNode) {
+ var placedDrag = $(placedNode);
- if (!thisQ.isPointInDrop(pageX, pageY, placedDrag)) {
++ if (!thisQ.isPointInDrop(pageX, pageY, placedDrag) || thisQ.isDragSameAsDrop(drag, placedDrag)) {
+ // Not this placed drag.
+ return true;
+ }
- // Now put this drag into the drop.
- placedDrag.removeClass('valid-drag-over-drop');
- var currentPlace = thisQ.getClassnameNumericSuffix(placedDrag, 'inplace');
- var drop = thisQ.getDrop(drag, currentPlace);
- thisQ.sendDragToDrop(drag, drop);
- placed = true;
- return false; // Stop the each() here.
- });
+ // Now put this drag into the drop.
+ placedDrag.removeClass('valid-drag-over-drop');
+ var currentPlace = thisQ.getClassnameNumericSuffix(placedDrag, 'inplace');
+ var drop = thisQ.getDrop(drag, currentPlace);
+ thisQ.sendDragToDrop(drag, drop);
+ placed = true;
+ return false; // Stop the each() here.
+ });
+ }
if (!placed) {
this.sendDragHome(drag);
return zIndex;
};
+ /**
+ * Check that the drag is drop to it's clone.
+ *
+ * @param {jQuery} drag The drag.
+ * @param {jQuery} drop The drop.
+ * @returns {boolean}
+ */
+ DragDropOntoImageQuestion.prototype.isDragSameAsDrop = function(drag, drop) {
+ return this.getChoice(drag) === this.getChoice(drop) && this.getGroup(drag) === this.getGroup(drop);
+ };
+
/**
* Singleton object that handles all the DragDropOntoImageQuestions
* on the page, and deals with event dispatching.
* @param {jQuery} element Element to bind the event
*/
addEventHandlersToDrag: function(element) {
+ // Unbind all the mousedown and touchstart events to prevent double binding.
+ element.unbind('mousedown touchstart');
element.on('mousedown touchstart', questionManager.handleDragStart);
},