|
|
|
@ -3,145 +3,201 @@
|
|
|
|
|
if(typeof VMM != 'undefined' && typeof VMM.DragSlider == 'undefined') { |
|
|
|
|
// VMM.DragSlider.createSlidePanel(drag_object, move_object, w, padding, sticky);
|
|
|
|
|
// VMM.DragSlider.cancelSlide();
|
|
|
|
|
VMM.DragSlider = { |
|
|
|
|
createPanel: function(drag_object, move_object, w, padding, sticky) { |
|
|
|
|
|
|
|
|
|
VMM.DragSlider = function() { |
|
|
|
|
var drag = { |
|
|
|
|
element: "", |
|
|
|
|
element_move: "", |
|
|
|
|
constraint: "", |
|
|
|
|
sliding: false, |
|
|
|
|
pagex: { |
|
|
|
|
start: 0, |
|
|
|
|
end: 0 |
|
|
|
|
}, |
|
|
|
|
left: { |
|
|
|
|
start: 0, |
|
|
|
|
end: 0 |
|
|
|
|
}, |
|
|
|
|
time: { |
|
|
|
|
start: 0, |
|
|
|
|
end: 0 |
|
|
|
|
}, |
|
|
|
|
touch: false |
|
|
|
|
}, |
|
|
|
|
dragevent = { |
|
|
|
|
down: "mousedown", |
|
|
|
|
up: "mouseup", |
|
|
|
|
leave: "mouseleave", |
|
|
|
|
move: "mousemove" |
|
|
|
|
}, |
|
|
|
|
mousedrag = { |
|
|
|
|
down: "mousedown", |
|
|
|
|
up: "mouseup", |
|
|
|
|
leave: "mouseleave", |
|
|
|
|
move: "mousemove" |
|
|
|
|
}, |
|
|
|
|
touchdrag = { |
|
|
|
|
down: "touchstart", |
|
|
|
|
up: "touchend", |
|
|
|
|
leave: "mouseleave", |
|
|
|
|
move: "touchmove" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.createPanel = function(drag_object, move_object, constraint, touch) { |
|
|
|
|
drag.element = drag_object; |
|
|
|
|
drag.element_move = move_object; |
|
|
|
|
|
|
|
|
|
var x = padding; |
|
|
|
|
VMM.DragSlider.width = w; |
|
|
|
|
VMM.DragSlider.makeDraggable(drag_object, move_object); |
|
|
|
|
VMM.DragSlider.drag_elem = drag_object; |
|
|
|
|
/* |
|
|
|
|
if (sticky != null && sticky != "") { |
|
|
|
|
VMM.TouchSlider.sticky = sticky; |
|
|
|
|
if ( constraint != null && constraint != "") { |
|
|
|
|
drag.constraint = constraint; |
|
|
|
|
} else { |
|
|
|
|
VMM.TouchSlider.sticky = false; |
|
|
|
|
drag.constraint = false; |
|
|
|
|
} |
|
|
|
|
if ( touch) { |
|
|
|
|
drag.touch = touch; |
|
|
|
|
} else { |
|
|
|
|
drag.touch = false; |
|
|
|
|
} |
|
|
|
|
trace("TOUCH" + drag.touch); |
|
|
|
|
if (drag.touch) { |
|
|
|
|
dragevent = touchdrag; |
|
|
|
|
} else { |
|
|
|
|
dragevent = mousedrag; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
VMM.DragSlider.sticky = sticky; |
|
|
|
|
}, |
|
|
|
|
makeDraggable: function(drag_object, move_object) { |
|
|
|
|
VMM.bindEvent(drag_object, VMM.DragSlider.onDragStart, "mousedown", {element: move_object, delement: drag_object}); |
|
|
|
|
//VMM.bindEvent(drag_object, VMM.DragSlider.onDragMove, "mousemove", {element: move_object});
|
|
|
|
|
VMM.bindEvent(drag_object, VMM.DragSlider.onDragEnd, "mouseup", {element: move_object, delement: drag_object}); |
|
|
|
|
VMM.bindEvent(drag_object, VMM.DragSlider.onDragLeave, "mouseleave", {element: move_object, delement: drag_object}); |
|
|
|
|
}, |
|
|
|
|
cancelSlide: function(e) { |
|
|
|
|
VMM.unbindEvent(VMM.DragSlider.drag_elem, VMM.DragSlider.onDragMove, "mousemove"); |
|
|
|
|
//VMM.DragSlider.drag_elem.preventDefault();
|
|
|
|
|
//VMM.DragSlider.drag_elem.stopPropagation();
|
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
onDragLeave: function(e) { |
|
|
|
|
|
|
|
|
|
VMM.unbindEvent(e.data.delement, VMM.DragSlider.onDragMove, "mousemove"); |
|
|
|
|
makeDraggable(drag.element, drag.element_move); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.updateConstraint = function(constraint) { |
|
|
|
|
trace("updateConstraint"); |
|
|
|
|
drag.constraint = constraint; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var makeDraggable = function(drag_object, move_object) { |
|
|
|
|
|
|
|
|
|
VMM.bindEvent(drag_object, onDragStart, dragevent.down, {element: move_object, delement: drag_object}); |
|
|
|
|
VMM.bindEvent(drag_object, onDragEnd, dragevent.up, {element: move_object, delement: drag_object}); |
|
|
|
|
VMM.bindEvent(drag_object, onDragLeave, dragevent.leave, {element: move_object, delement: drag_object}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
this.cancelSlide = function(e) { |
|
|
|
|
VMM.unbindEvent(drag.element, onDragMove, dragevent.move); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
var onDragLeave = function(e) { |
|
|
|
|
VMM.unbindEvent(e.data.delement, onDragMove, dragevent.move); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
if (drag.sliding) { |
|
|
|
|
drag.sliding = false; |
|
|
|
|
dragEnd(e.data.element, e.data.delement, e); |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
onDragStart: function(e) { |
|
|
|
|
VMM.DragSlider.dragStart(e.data.element, e.data.delement, e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var onDragStart = function(e) { |
|
|
|
|
dragStart(e.data.element, e.data.delement, e); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
onDragEnd: function(e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var onDragEnd = function(e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
|
|
|
|
|
if (VMM.DragSlider.sliding) { |
|
|
|
|
VMM.DragSlider.sliding = false; |
|
|
|
|
VMM.DragSlider.dragEnd(e.data.element, e.data.delement, e); |
|
|
|
|
if (drag.sliding) { |
|
|
|
|
drag.sliding = false; |
|
|
|
|
dragEnd(e.data.element, e.data.delement, e); |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
onDragMove: function(e) { |
|
|
|
|
VMM.DragSlider.dragMove(e.data.element, e); |
|
|
|
|
} |
|
|
|
|
var onDragMove = function(e) { |
|
|
|
|
dragMove(e.data.element, e); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
return false; |
|
|
|
|
}, |
|
|
|
|
dragStart: function(elem, delem, e) { |
|
|
|
|
|
|
|
|
|
VMM.DragSlider.startX = e.pageX; |
|
|
|
|
|
|
|
|
|
VMM.DragSlider.startLeft = VMM.DragSlider.getLeft(elem); |
|
|
|
|
VMM.DragSlider.dragStartTime = new Date().getTime(); |
|
|
|
|
VMM.DragSlider.dragWidth = VMM.Lib.width(delem); |
|
|
|
|
|
|
|
|
|
// CANCEL CURRENT ANIMATION IF ANIMATING
|
|
|
|
|
var _newx = Math.round(VMM.DragSlider.startX - e.pageX - VMM.DragSlider.startLeft); |
|
|
|
|
} |
|
|
|
|
var dragStart = function(elem, delem, e) { |
|
|
|
|
if (drag.touch) { |
|
|
|
|
trace("IS TOUCH") |
|
|
|
|
VMM.Lib.css(elem, '-webkit-transition-duration', '0'); |
|
|
|
|
drag.pagex.start = e.originalEvent.touches[0].screenX; |
|
|
|
|
} else { |
|
|
|
|
drag.pagex.start = e.pageX; |
|
|
|
|
} |
|
|
|
|
drag.left.start = getLeft(elem); |
|
|
|
|
drag.time.start = new Date().getTime(); |
|
|
|
|
|
|
|
|
|
VMM.Lib.stop(elem); |
|
|
|
|
VMM.bindEvent(delem, VMM.DragSlider.onDragMove, "mousemove", {element: elem}); |
|
|
|
|
VMM.bindEvent(delem, onDragMove, dragevent.move, {element: elem}); |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
dragEnd: function(elem, delem, e) { |
|
|
|
|
VMM.unbindEvent(delem, VMM.DragSlider.onDragMove, "mousemove"); |
|
|
|
|
//VMM.DragSlider.dragMomentum(elem, e);
|
|
|
|
|
if (VMM.DragSlider.getLeft(elem) > 0) { |
|
|
|
|
//(VMM.DragSlider.dragWidth/2)
|
|
|
|
|
//This means they dragged to the right past the first item
|
|
|
|
|
//VMM.Lib.animate(elem, 1000, "linear", {"left": 0});
|
|
|
|
|
|
|
|
|
|
//VMM.fireEvent(elem, "DRAGUPDATE", [0]);
|
|
|
|
|
} else { |
|
|
|
|
//This means they were just dragging within the bounds of the grid and we just need to handle the momentum and snap to the grid.
|
|
|
|
|
VMM.DragSlider.dragMomentum(elem, e); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
dragMove: function(elem, e) { |
|
|
|
|
if (!VMM.DragSlider.sliding) { |
|
|
|
|
//elem.parent().addClass('sliding');
|
|
|
|
|
var dragEnd = function(elem, delem, e) { |
|
|
|
|
VMM.unbindEvent(delem, onDragMove, dragevent.move); |
|
|
|
|
dragMomentum(elem, e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VMM.DragSlider.sliding = true; |
|
|
|
|
if (VMM.DragSlider.startX > e.pageX) { |
|
|
|
|
//Sliding to the left
|
|
|
|
|
VMM.Lib.css(elem, 'left', -(VMM.DragSlider.startX - e.pageX - VMM.DragSlider.startLeft)); |
|
|
|
|
VMM.DragSlider.slidingLeft = true; |
|
|
|
|
var dragMove = function(elem, e) { |
|
|
|
|
drag.sliding = true; |
|
|
|
|
if (drag.touch) { |
|
|
|
|
drag.pagex.end = e.originalEvent.touches[0].screenX; |
|
|
|
|
} else { |
|
|
|
|
//Sliding to the right
|
|
|
|
|
var left = (e.pageX - VMM.DragSlider.startX + VMM.DragSlider.startLeft); |
|
|
|
|
VMM.Lib.css(elem, 'left', -(VMM.DragSlider.startX - e.pageX - VMM.DragSlider.startLeft)); |
|
|
|
|
VMM.DragSlider.slidingLeft = false; |
|
|
|
|
drag.pagex.end = e.pageX; |
|
|
|
|
} |
|
|
|
|
drag.left.end = getLeft(elem); |
|
|
|
|
VMM.Lib.css(elem, 'left', -(drag.pagex.start - drag.pagex.end - drag.left.start)); |
|
|
|
|
} |
|
|
|
|
var dragMomentum = function(elem, e) { |
|
|
|
|
var drag_info = { |
|
|
|
|
left: drag.left.end, |
|
|
|
|
left_adjust: 0, |
|
|
|
|
change: { |
|
|
|
|
x: 0 |
|
|
|
|
}, |
|
|
|
|
time: (new Date().getTime() - drag.time.start) * 10, |
|
|
|
|
time_adjust: (new Date().getTime() - drag.time.start) * 10 |
|
|
|
|
}, |
|
|
|
|
dragMomentum: function(elem, e) { |
|
|
|
|
var slideAdjust = (new Date().getTime() - VMM.DragSlider.dragStartTime) * 10; |
|
|
|
|
var timeAdjust = slideAdjust; |
|
|
|
|
var left = VMM.DragSlider.getLeft(elem); |
|
|
|
|
ease = "easeOutExpo"; |
|
|
|
|
|
|
|
|
|
drag_info.change.x = 6000 * (Math.abs(drag.pagex.end) - Math.abs(drag.pagex.start)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var changeX = 6000 * (Math.abs(VMM.DragSlider.startLeft) - Math.abs(left)); |
|
|
|
|
//var changeX = 6000 * (VMM.DragSlider.startLeft - left);
|
|
|
|
|
slideAdjust = Math.round(changeX / slideAdjust); |
|
|
|
|
drag_info.left_adjust = Math.round(drag_info.change.x / drag_info.time); |
|
|
|
|
|
|
|
|
|
var newLeft = left + slideAdjust; |
|
|
|
|
drag_info.left = Math.min(drag_info.left + drag_info.left_adjust); |
|
|
|
|
|
|
|
|
|
var t = newLeft % VMM.DragSlider.width; |
|
|
|
|
//left: Math.min(0, newLeft),
|
|
|
|
|
var _r_object = { |
|
|
|
|
left: Math.min(newLeft), |
|
|
|
|
time: timeAdjust |
|
|
|
|
if (drag.constraint) { |
|
|
|
|
if (drag_info.left > drag.constraint.left) { |
|
|
|
|
drag_info.left = drag.constraint.left; |
|
|
|
|
if (drag_info.time > 5000) { |
|
|
|
|
drag_info.time = 5000; |
|
|
|
|
} |
|
|
|
|
} else if (drag_info.left < drag.constraint.right) { |
|
|
|
|
drag_info.left = drag.constraint.right; |
|
|
|
|
if (drag_info.time > 5000) { |
|
|
|
|
drag_info.time = 5000; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VMM.fireEvent(elem, "DRAGUPDATE", [_r_object]); |
|
|
|
|
var _ease = "easeOutExpo"; |
|
|
|
|
if (_r_object.time > 0) { |
|
|
|
|
VMM.Lib.animate(elem, _r_object.time, _ease, {"left": _r_object.left}); |
|
|
|
|
}; |
|
|
|
|
VMM.fireEvent(elem, "DRAGUPDATE", [drag_info]); |
|
|
|
|
|
|
|
|
|
if (drag_info.time > 0) { |
|
|
|
|
if (drag.touch) { |
|
|
|
|
VMM.Lib.css(elem, '-webkit-transition-property', 'left'); |
|
|
|
|
VMM.Lib.css(elem, '-webkit-transition-duration', drag_info.time); |
|
|
|
|
VMM.Lib.css(elem, 'left', drag_info.left); |
|
|
|
|
|
|
|
|
|
//VMM.DragSlider.startX = null;
|
|
|
|
|
}, |
|
|
|
|
getLeft: function(elem) { |
|
|
|
|
return parseInt(VMM.Lib.css(elem, 'left').substring(0, VMM.Lib.css(elem, 'left').length - 2), 10); |
|
|
|
|
} else { |
|
|
|
|
VMM.Lib.animate(elem, drag_info.time, ease, {"left": drag_info.left}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
var getLeft = function(elem) { |
|
|
|
|
return parseInt(VMM.Lib.css(elem, 'left').substring(0, VMM.Lib.css(elem, 'left').length - 2), 10); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |