From aaf1afe30448af73d46650d123c320303037a471 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 10 Sep 2014 10:11:26 +0200 Subject: [PATCH] Fixed an error thrown when calling timeline.destroy() (see #294) --- lib/timeline/Core.js | 2 +- lib/timeline/Range.js | 12 ++++++++---- lib/timeline/component/ItemSet.js | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index c4a2f2f5..01204584 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -100,7 +100,7 @@ Core.prototype._create = function (container) { // create event listeners for all interesting events, these events will be // emitted via emitter this.hammer = Hammer(this.dom.root, { - prevent_default: true + preventDefault: true }); this.listeners = {}; diff --git a/lib/timeline/Range.js b/lib/timeline/Range.js index a9924b7e..f4dcf4ce 100644 --- a/lib/timeline/Range.js +++ b/lib/timeline/Range.js @@ -360,14 +360,18 @@ Range.prototype._onDrag = function (event) { if (!this.options.moveable) return; var direction = this.options.direction; validateDirection(direction); + // 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 delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY, - interval = (this.props.touch.end - this.props.touch.start), - width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height, - diffRange = -delta / width * interval; + + var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY; + var interval = (this.props.touch.end - this.props.touch.start); + var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height; + var diffRange = -delta / width * interval; this._applyRange(this.props.touch.start + diffRange, this.props.touch.end + diffRange); + + // fire a rangechange event this.body.emitter.emit('rangechange', { start: new Date(this.start), end: new Date(this.end) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 9675637b..6feb7e2c 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -48,10 +48,10 @@ function ItemSet(body, options) { onMove: function (item, callback) { callback(item); }, - onMoving: null, onRemove: function (item, callback) { callback(item); }, + onMoving: null, // onMoving is null by default for better performance (other on* functions do not support null) margin: { item: { @@ -299,8 +299,8 @@ ItemSet.prototype.setOptions = function(options) { // callback functions var addCallback = (function (name) { - if (name in options) { - var fn = options[name]; + var fn = options[name]; + if (fn) { if (!(fn instanceof Function)) { throw new Error('option ' + name + ' must be a function ' + name + '(item, callback)'); } @@ -1157,6 +1157,7 @@ ItemSet.prototype._onDrag = function (event) { * @private */ ItemSet.prototype._updateItemProps = function(item, props) { + // TODO: copy all properties from props to item? (also new ones) if ('start' in props) item.data.start = props.start; if ('end' in props) item.data.end = props.end; if ('group' in props && item.data.group != props.group) {