|
@ -17,6 +17,7 @@ function Range(body, options) { |
|
|
this.end = now.clone().add(4, 'days').valueOf(); // Number
|
|
|
this.end = now.clone().add(4, 'days').valueOf(); // Number
|
|
|
|
|
|
|
|
|
this.body = body; |
|
|
this.body = body; |
|
|
|
|
|
this.deltaDifference = 0; |
|
|
|
|
|
|
|
|
// default options
|
|
|
// default options
|
|
|
this.defaultOptions = { |
|
|
this.defaultOptions = { |
|
@ -77,7 +78,7 @@ Range.prototype = new Component(); |
|
|
Range.prototype.setOptions = function (options) { |
|
|
Range.prototype.setOptions = function (options) { |
|
|
if (options) { |
|
|
if (options) { |
|
|
// copy the options that we know
|
|
|
// copy the options that we know
|
|
|
var fields = ['direction', 'min', 'max', 'zoomMin', 'zoomMax', 'moveable', 'zoomable', 'activate']; |
|
|
|
|
|
|
|
|
var fields = ['direction', 'min', 'max', 'zoomMin', 'zoomMax', 'moveable', 'zoomable', 'activate','hide']; |
|
|
util.selectiveExtend(fields, this.options, options); |
|
|
util.selectiveExtend(fields, this.options, options); |
|
|
|
|
|
|
|
|
if ('start' in options || 'end' in options) { |
|
|
if ('start' in options || 'end' in options) { |
|
@ -301,8 +302,8 @@ Range.prototype.getRange = function() { |
|
|
* @param {Number} width |
|
|
* @param {Number} width |
|
|
* @returns {{offset: number, scale: number}} conversion |
|
|
* @returns {{offset: number, scale: number}} conversion |
|
|
*/ |
|
|
*/ |
|
|
Range.prototype.conversion = function (width) { |
|
|
|
|
|
return Range.conversion(this.start, this.end, width); |
|
|
|
|
|
|
|
|
Range.prototype.conversion = function (width, totalHidden) { |
|
|
|
|
|
return Range.conversion(this.start, this.end, width, totalHidden); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -313,11 +314,14 @@ Range.prototype.conversion = function (width) { |
|
|
* @param {Number} width |
|
|
* @param {Number} width |
|
|
* @returns {{offset: number, scale: number}} conversion |
|
|
* @returns {{offset: number, scale: number}} conversion |
|
|
*/ |
|
|
*/ |
|
|
Range.conversion = function (start, end, width) { |
|
|
|
|
|
|
|
|
Range.conversion = function (start, end, width, totalHidden) { |
|
|
|
|
|
if (totalHidden === undefined) { |
|
|
|
|
|
totalHidden = 0; |
|
|
|
|
|
} |
|
|
if (width != 0 && (end - start != 0)) { |
|
|
if (width != 0 && (end - start != 0)) { |
|
|
return { |
|
|
return { |
|
|
offset: start, |
|
|
offset: start, |
|
|
scale: width / (end - start) |
|
|
|
|
|
|
|
|
scale: width / (end - start - totalHidden) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
@ -334,6 +338,8 @@ Range.conversion = function (start, end, width) { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
Range.prototype._onDragStart = function(event) { |
|
|
Range.prototype._onDragStart = function(event) { |
|
|
|
|
|
this.deltaDifference = 0; |
|
|
|
|
|
this.previousDelta = 0; |
|
|
// only allow dragging when configured as movable
|
|
|
// only allow dragging when configured as movable
|
|
|
if (!this.options.moveable) return; |
|
|
if (!this.options.moveable) return; |
|
|
|
|
|
|
|
@ -366,10 +372,54 @@ Range.prototype._onDrag = function (event) { |
|
|
if (!this.props.touch.allowDragging) return; |
|
|
if (!this.props.touch.allowDragging) return; |
|
|
|
|
|
|
|
|
var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY; |
|
|
var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY; |
|
|
|
|
|
delta -= this.deltaDifference; |
|
|
var interval = (this.props.touch.end - this.props.touch.start); |
|
|
var interval = (this.props.touch.end - this.props.touch.start); |
|
|
|
|
|
|
|
|
|
|
|
// normalize dragging speed if cutout is in between.
|
|
|
|
|
|
var startDate = new Date(this.options.hide.start).getTime(); |
|
|
|
|
|
var endDate = new Date(this.options.hide.end).getTime(); |
|
|
|
|
|
var duration = endDate - startDate; |
|
|
|
|
|
if (startDate >= this.start && endDate < this.end) { |
|
|
|
|
|
interval -= duration; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height; |
|
|
var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height; |
|
|
var diffRange = -delta / width * interval; |
|
|
var diffRange = -delta / width * interval; |
|
|
this._applyRange(this.props.touch.start + diffRange, this.props.touch.end + diffRange); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// snapping times away from hidden zones
|
|
|
|
|
|
var start = this.props.touch.start + diffRange; |
|
|
|
|
|
var end = this.props.touch.end + diffRange; |
|
|
|
|
|
if (start >= startDate && start < endDate && this.previousDelta - delta > 0) { // if the start is entering the zone from the left
|
|
|
|
|
|
this.deltaDifference += delta; |
|
|
|
|
|
this.props.touch.start = endDate + 1; |
|
|
|
|
|
this.props.touch.end = end + duration; // to cancel the time subtraction events;
|
|
|
|
|
|
this._onDrag(event); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
else if (start >= startDate && start < endDate && this.previousDelta - delta < 0) { // if the start is entering the zone from the right
|
|
|
|
|
|
this.deltaDifference += delta; |
|
|
|
|
|
this.props.touch.start = startDate - 1; |
|
|
|
|
|
this.props.touch.end = end - duration; // to cancel the time subtraction events;
|
|
|
|
|
|
this._onDrag(event); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
else if (end >= startDate && end < endDate && this.previousDelta - delta > 0) { // if the start is entering the zone from the right
|
|
|
|
|
|
this.deltaDifference += delta; |
|
|
|
|
|
this.props.touch.end = endDate + 1; |
|
|
|
|
|
this.props.touch.start = start; // to cancel the time subtraction events;
|
|
|
|
|
|
this._onDrag(event); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
else if (end >= startDate && end < endDate && this.previousDelta - delta < 0) { // if the start is entering the zone from the right
|
|
|
|
|
|
this.deltaDifference += delta; |
|
|
|
|
|
this.props.touch.end = startDate-1; |
|
|
|
|
|
this.props.touch.start = start; // to cancel the time subtraction events;
|
|
|
|
|
|
this._onDrag(event); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
this.previousDelta = delta; |
|
|
|
|
|
|
|
|
|
|
|
this._applyRange(start, end); |
|
|
|
|
|
|
|
|
// fire a rangechange event
|
|
|
// fire a rangechange event
|
|
|
this.body.emitter.emit('rangechange', { |
|
|
this.body.emitter.emit('rangechange', { |
|
|