Browse Source

Fixed the touch and release events being fired twice each time. Fixed a bug with dragging in the InteractionHandler

flowchartTest
jos 9 years ago
parent
commit
28f8367f11
5 changed files with 36 additions and 5 deletions
  1. +20
    -2
      lib/hammerUtil.js
  2. +2
    -2
      lib/network/modules/InteractionHandler.js
  3. +5
    -0
      lib/timeline/Core.js
  4. +1
    -1
      lib/timeline/component/ItemSet.js
  5. +8
    -0
      test/timeline.html

+ 20
- 2
lib/hammerUtil.js View File

@ -7,14 +7,23 @@ var Hammer = require('./module/hammer');
*/ */
exports.onTouch = function (hammer, callback) { exports.onTouch = function (hammer, callback) {
callback.inputHandler = function (event) { callback.inputHandler = function (event) {
if (event.isFirst) {
if (event.isFirst && !isTouching) {
callback(event); callback(event);
isTouching = true;
setTimeout(function () {
isTouching = false;
}, 0);
} }
}; };
hammer.on('hammer.input', callback.inputHandler); hammer.on('hammer.input', callback.inputHandler);
}; };
// isTouching is true while a touch action is being emitted
// this is a hack to prevent `touch` from being fired twice
var isTouching = false;
/** /**
* Register a release event, taking place after a gesture * Register a release event, taking place after a gesture
* @param {Hammer} hammer A hammer instance * @param {Hammer} hammer A hammer instance
@ -22,13 +31,22 @@ exports.onTouch = function (hammer, callback) {
*/ */
exports.onRelease = function (hammer, callback) { exports.onRelease = function (hammer, callback) {
callback.inputHandler = function (event) { callback.inputHandler = function (event) {
if (event.isFinal) {
if (event.isFinal && !isReleasing) {
callback(event); callback(event);
isReleasing = true;
setTimeout(function () {
isReleasing = false;
}, 0);
} }
}; };
return hammer.on('hammer.input', callback.inputHandler); return hammer.on('hammer.input', callback.inputHandler);
}; };
// isReleasing is true while a release action is being emitted
// this is a hack to prevent `release` from being fired twice
var isReleasing = false;
/** /**
* Unregister a touch event, taking place before a gesture * Unregister a touch event, taking place before a gesture

+ 2
- 2
lib/network/modules/InteractionHandler.js View File

@ -217,7 +217,7 @@ class InteractionHandler {
this.drag.translation = util.extend({},this.body.view.translation); // copy the object this.drag.translation = util.extend({},this.body.view.translation); // copy the object
this.drag.nodeId = undefined; this.drag.nodeId = undefined;
this.selectionHandler._generateClickEvent('dragStart',pointer);
this.selectionHandler._generateClickEvent('dragStart', this.drag.pointer);
if (node !== undefined && this.options.dragNodes === true) { if (node !== undefined && this.options.dragNodes === true) {
this.drag.nodeId = node.id; this.drag.nodeId = node.id;
@ -324,7 +324,7 @@ class InteractionHandler {
else { else {
this.body.emitter.emit('_requestRedraw'); this.body.emitter.emit('_requestRedraw');
} }
this.selectionHandler._generateClickEvent('dragEnd',pointer);
this.selectionHandler._generateClickEvent('dragEnd',this.drag.pointer);
} }

+ 5
- 0
lib/timeline/Core.js View File

@ -140,6 +140,11 @@ Core.prototype._create = function (container) {
me.emit('touch', event); me.emit('touch', event);
}.bind(this)); }.bind(this));
// emulate a release event (emitted after a pan, pinch, tap, or press)
hammerUtil.onRelease(this.hammer, function (event) {
me.emit('release', event);
}.bind(this));
function onMouseWheel(event) { function onMouseWheel(event) {
if (me.isActive()) { if (me.isActive()) {
me.emit('mousewheel', event); me.emit('mousewheel', event);

+ 1
- 1
lib/timeline/component/ItemSet.js View File

@ -1546,7 +1546,7 @@ ItemSet.prototype.groupFromTarget = function(event) {
//} //}
// //
var clientY = event.gesture.center.clientY;
var clientY = event.center.clientY;
for (var i = 0; i < this.groupIds.length; i++) { for (var i = 0; i < this.groupIds.length; i++) {
var groupId = this.groupIds[i]; var groupId = this.groupIds[i];
var group = this.groups[groupId]; var group = this.groups[groupId];

+ 8
- 0
test/timeline.html View File

@ -151,6 +151,14 @@
console.log('select', selection); console.log('select', selection);
}); });
// timeline.on('touch', function (event) {
// console.log('touch', event, Object.keys(event));
// });
//
// timeline.on('release', function (event) {
// console.log('release', event, Object.keys(event));
// });
/* /*
timeline.on('rangechange', function (range) { timeline.on('rangechange', function (range) {
console.log('rangechange', range); console.log('rangechange', range);

Loading…
Cancel
Save