Browse Source

Fixed #1455: allow vertical panning of the web page on touch devices

codeClimate
jos 8 years ago
parent
commit
311ea1eef5
6 changed files with 31 additions and 6 deletions
  1. +1
    -0
      HISTORY.md
  2. +17
    -0
      lib/hammerUtil.js
  3. +1
    -1
      lib/network/modules/Canvas.js
  4. +9
    -2
      lib/timeline/Core.js
  5. +1
    -1
      lib/timeline/component/CustomTime.js
  6. +2
    -2
      lib/timeline/component/ItemSet.js

+ 1
- 0
HISTORY.md View File

@ -20,6 +20,7 @@ http://visjs.org
- Implemented `currentTimeTick` event (see #1683). - Implemented `currentTimeTick` event (see #1683).
- Fixed #1630: method `getItemRange` missing in docs. - Fixed #1630: method `getItemRange` missing in docs.
- Fixed #1455: allow vertical panning of the web page on touch devices.
### Graph2d ### Graph2d

+ 17
- 0
lib/hammerUtil.js View File

@ -46,3 +46,20 @@ exports.offTouch = function (hammer, callback) {
* @param {function} callback Callback, called as callback(event) * @param {function} callback Callback, called as callback(event)
*/ */
exports.offRelease = exports.offTouch; exports.offRelease = exports.offTouch;
/**
* Hack the PinchRecognizer such that it doesn't prevent default behavior
* for vertical panning.
* @param {Hammer.Pinch} pinchRecognizer
* @return {Hammer.Pinch} returns the pinchRecognizer
*/
exports.disablePreventDefaultVertically = function (pinchRecognizer) {
var TOUCH_ACTION_PAN_Y = 'pan-y';
pinchRecognizer.getTouchAction = function() {
// default method returns [TOUCH_ACTION_NONE]
return [TOUCH_ACTION_PAN_Y];
};
return pinchRecognizer;
};

+ 1
- 1
lib/network/modules/Canvas.js View File

@ -222,7 +222,7 @@ class Canvas {
this.hammer = new Hammer(this.frame.canvas); this.hammer = new Hammer(this.frame.canvas);
this.hammer.get('pinch').set({enable: true}); this.hammer.get('pinch').set({enable: true});
// enable to get better response, todo: test on mobile. // enable to get better response, todo: test on mobile.
this.hammer.get('pan').set({threshold:5, direction:30}); // 30 is ALL_DIRECTIONS in hammer.
this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_ALL});
hammerUtil.onTouch(this.hammer, (event) => {this.body.eventListeners.onTouch(event)}); hammerUtil.onTouch(this.hammer, (event) => {this.body.eventListeners.onTouch(event)});
this.hammer.on('tap', (event) => {this.body.eventListeners.onTap(event)}); this.hammer.on('tap', (event) => {this.body.eventListeners.onTap(event)});

+ 9
- 2
lib/timeline/Core.js View File

@ -118,8 +118,9 @@ Core.prototype._create = function (container) {
// create event listeners for all interesting events, these events will be // create event listeners for all interesting events, these events will be
// emitted via emitter // emitted via emitter
this.hammer = new Hammer(this.dom.root); this.hammer = new Hammer(this.dom.root);
this.hammer.get('pinch').set({enable: true});
this.hammer.get('pan').set({threshold:5, direction:30}); // 30 is ALL_DIRECTIONS in hammer.
var pinchRecognizer = this.hammer.get('pinch').set({enable: true});
hammerUtil.disablePreventDefaultVertically(pinchRecognizer);
this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
this.listeners = {}; this.listeners = {};
var events = [ var events = [
@ -768,6 +769,12 @@ Core.prototype._redraw = function() {
dom.shadowTopRight.style.visibility = visibilityTop; dom.shadowTopRight.style.visibility = visibilityTop;
dom.shadowBottomRight.style.visibility = visibilityBottom; dom.shadowBottomRight.style.visibility = visibilityBottom;
// enable/disable vertical panning
var contentsOverflow = this.props.center.height > this.props.centerContainer.height;
this.hammer.get('pan').set({
direction: contentsOverflow ? Hammer.DIRECTION_ALL : Hammer.DIRECTION_HORIZONTAL
});
// redraw all components // redraw all components
this.components.forEach(function (component) { this.components.forEach(function (component) {
resized = component.redraw() || resized; resized = component.redraw() || resized;

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

@ -84,7 +84,7 @@ CustomTime.prototype._create = function() {
this.hammer.on('panstart', this._onDragStart.bind(this)); this.hammer.on('panstart', this._onDragStart.bind(this));
this.hammer.on('panmove', this._onDrag.bind(this)); this.hammer.on('panmove', this._onDrag.bind(this));
this.hammer.on('panend', this._onDragEnd.bind(this)); this.hammer.on('panend', this._onDragEnd.bind(this));
this.hammer.get('pan').set({threshold:5, direction:30}); // 30 is ALL_DIRECTIONS in hammer.
this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
}; };
/** /**

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

@ -220,7 +220,7 @@ ItemSet.prototype._create = function(){
this.hammer.on('panstart', this._onDragStart.bind(this)); this.hammer.on('panstart', this._onDragStart.bind(this));
this.hammer.on('panmove', this._onDrag.bind(this)); this.hammer.on('panmove', this._onDrag.bind(this));
this.hammer.on('panend', this._onDragEnd.bind(this)); this.hammer.on('panend', this._onDragEnd.bind(this));
this.hammer.get('pan').set({threshold:5, direction:30}); // 30 is ALL_DIRECTIONS in hammer.
this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
// single select (or unselect) when tapping an item // single select (or unselect) when tapping an item
this.hammer.on('tap', this._onSelectItem.bind(this)); this.hammer.on('tap', this._onSelectItem.bind(this));
@ -235,7 +235,7 @@ ItemSet.prototype._create = function(){
this.groupHammer.on('panstart', this._onGroupDragStart.bind(this)); this.groupHammer.on('panstart', this._onGroupDragStart.bind(this));
this.groupHammer.on('panmove', this._onGroupDrag.bind(this)); this.groupHammer.on('panmove', this._onGroupDrag.bind(this));
this.groupHammer.on('panend', this._onGroupDragEnd.bind(this)); this.groupHammer.on('panend', this._onGroupDragEnd.bind(this));
this.groupHammer.get('pan').set({threshold:5, direction:30});
this.groupHammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
// attach to the DOM // attach to the DOM
this.show(); this.show();

Loading…
Cancel
Save