|
|
@ -51,8 +51,7 @@ function Range(body, options) { |
|
|
|
this.body.emitter.on('press', this._onHold.bind(this)); |
|
|
|
|
|
|
|
// mouse wheel for zooming
|
|
|
|
this.body.emitter.on('mousewheel', this._onMouseWheel.bind(this)); |
|
|
|
this.body.emitter.on('DOMMouseScroll', this._onMouseWheel.bind(this)); // For FF
|
|
|
|
this.body.emitter.on('mousewheel', this._onMouseWheel.bind(this)); |
|
|
|
|
|
|
|
// pinch to zoom
|
|
|
|
this.body.emitter.on('touch', this._onTouch.bind(this)); |
|
|
@ -374,14 +373,15 @@ Range.prototype._onDragStart = function(event) { |
|
|
|
Range.prototype._onDrag = function (event) { |
|
|
|
// only allow dragging when configured as movable
|
|
|
|
if (!this.options.moveable) return; |
|
|
|
|
|
|
|
// TODO: this may be redundant in hammerjs2
|
|
|
|
// refuse to drag when we where pinching to prevent the timeline make a jump
|
|
|
|
// when releasing the fingers in opposite order from the touch screen
|
|
|
|
if (!this.props.touch.allowDragging) return; |
|
|
|
|
|
|
|
var direction = this.options.direction; |
|
|
|
validateDirection(direction); |
|
|
|
|
|
|
|
var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY; |
|
|
|
var delta = (direction == 'horizontal') ? event.deltaX : event.deltaY; |
|
|
|
delta -= this.deltaDifference; |
|
|
|
var interval = (this.props.touch.end - this.props.touch.start); |
|
|
|
|
|
|
@ -394,7 +394,6 @@ Range.prototype._onDrag = function (event) { |
|
|
|
var newStart = this.props.touch.start + diffRange; |
|
|
|
var newEnd = this.props.touch.end + diffRange; |
|
|
|
|
|
|
|
|
|
|
|
// snapping times away from hidden zones
|
|
|
|
var safeStart = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newStart, this.previousDelta-delta, true); |
|
|
|
var safeEnd = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newEnd, this.previousDelta-delta, true); |
|
|
@ -425,6 +424,7 @@ Range.prototype._onDragEnd = function (event) { |
|
|
|
// only allow dragging when configured as movable
|
|
|
|
if (!this.options.moveable) return; |
|
|
|
|
|
|
|
// TODO: this may be redundant in hammerjs2
|
|
|
|
// refuse to drag when we where pinching to prevent the timeline make a jump
|
|
|
|
// when releasing the fingers in opposite order from the touch screen
|
|
|
|
if (!this.props.touch.allowDragging) return; |
|
|
@ -478,9 +478,8 @@ Range.prototype._onMouseWheel = function(event) { |
|
|
|
} |
|
|
|
|
|
|
|
// calculate center, the date to zoom around
|
|
|
|
var gesture = hammerUtil.fakeGesture(this, event), |
|
|
|
pointer = getPointer(gesture.center, this.body.dom.center), |
|
|
|
pointerDate = this._pointerToDate(pointer); |
|
|
|
var pointer = getPointer({x: event.pageX, y: event.pageY}, this.body.dom.center); |
|
|
|
var pointerDate = this._pointerToDate(pointer); |
|
|
|
|
|
|
|
this.zoom(scale, pointerDate, delta); |
|
|
|
} |
|
|
@ -522,12 +521,12 @@ Range.prototype._onPinch = function (event) { |
|
|
|
|
|
|
|
this.props.touch.allowDragging = false; |
|
|
|
|
|
|
|
if (event.gesture.touches.length > 1) { |
|
|
|
if (event.touches.length > 1) { |
|
|
|
if (!this.props.touch.center) { |
|
|
|
this.props.touch.center = getPointer(event.gesture.center, this.body.dom.center); |
|
|
|
this.props.touch.center = getPointer(event.center, this.body.dom.center); |
|
|
|
} |
|
|
|
|
|
|
|
var scale = 1 / (event.gesture.scale + this.scaleOffset); |
|
|
|
var scale = 1 / (event.scale + this.scaleOffset); |
|
|
|
var centerDate = this._pointerToDate(this.props.touch.center); |
|
|
|
|
|
|
|
var hiddenDuration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, this.start, this.end); |
|
|
@ -547,7 +546,7 @@ Range.prototype._onPinch = function (event) { |
|
|
|
if (safeStart != newStart || safeEnd != newEnd) { |
|
|
|
this.props.touch.start = safeStart; |
|
|
|
this.props.touch.end = safeEnd; |
|
|
|
this.scaleOffset = 1 - event.gesture.scale; |
|
|
|
this.scaleOffset = 1 - event.scale; |
|
|
|
newStart = safeStart; |
|
|
|
newEnd = safeEnd; |
|
|
|
} |
|
|
@ -583,15 +582,15 @@ Range.prototype._pointerToDate = function (pointer) { |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the pointer location relative to the location of the dom element |
|
|
|
* @param {{pageX: Number, pageY: Number}} touch |
|
|
|
* @param {{x: Number, y: Number}} touch |
|
|
|
* @param {Element} element HTML DOM element |
|
|
|
* @return {{x: Number, y: Number}} pointer |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
function getPointer (touch, element) { |
|
|
|
return { |
|
|
|
x: touch.pageX - util.getAbsoluteLeft(element), |
|
|
|
y: touch.pageY - util.getAbsoluteTop(element) |
|
|
|
x: touch.x - util.getAbsoluteLeft(element), |
|
|
|
y: touch.y - util.getAbsoluteTop(element) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|