How to use the hammerjs.Manager function in hammerjs

To help you get started, we’ve selected a few hammerjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpmn-io / diagram-js / lib / features / touch / TouchInteractionEvents.js View on Github external
setTimeout(function() {
      forEach(mouseEvents, function(e) {
        domEvent.unbind(node, e, stopEvent, true);
      });
    }, 500);
  }

  domEvent.bind(node, 'touchstart', stopMouse, true);
  domEvent.bind(node, 'touchend', allowMouse, true);
  domEvent.bind(node, 'touchcancel', allowMouse, true);

  // A touch event recognizer that handles
  // touch events only (we know, we can already handle
  // mouse events out of the box)

  var recognizer = new Hammer.Manager(node, {
    inputClass: Hammer.TouchInput,
    recognizers: []
  });


  var tap = new Hammer.Tap();
  var pan = new Hammer.Pan({ threshold: 10 });
  var press = new Hammer.Press();
  var pinch = new Hammer.Pinch();

  var doubleTap = new Hammer.Tap({ event: 'doubletap', taps: 2 });

  pinch.requireFailure(pan);
  pinch.requireFailure(press);

  recognizer.add([ pan, press, pinch, doubleTap, tap ]);
github gajus / swing / src / Card.js View on Github external
/* Mapping directions to event names */
    throwDirectionToEventName = {};
    throwDirectionToEventName[Direction.LEFT] = 'throwoutleft';
    throwDirectionToEventName[Direction.RIGHT] = 'throwoutright';
    throwDirectionToEventName[Direction.UP] = 'throwoutup';
    throwDirectionToEventName[Direction.DOWN] = 'throwoutdown';

    springThrowIn.setRestSpeedThreshold(0.05);
    springThrowIn.setRestDisplacementThreshold(0.05);

    springThrowOut.setRestSpeedThreshold(0.05);
    springThrowOut.setRestDisplacementThreshold(0.05);

    throwOutDistance = config.throwOutDistance(config.minThrowOutDistance, config.maxThrowOutDistance);

    mc = new Hammer.Manager(targetElement, {
      recognizers: [
        [
          Hammer.Pan,
          {
            threshold: 2
          }
        ]
      ]
    });

    if (prepend) {
      Card.prependToParent(targetElement);
    } else {
      Card.appendToParent(targetElement);
    }
github mojs / mojs-curve-editor / app / js / tags / point.babel.jsx View on Github external
{point, index} = this.props;

      let y = point.y + e.deltaY,
          returnValue = y;

      if ( y < resize.top - resize.panY ) {
        returnValue = resize.top - resize.panY;
      } else if ( y > C.CURVE_SIZE + resize.bottom - resize.panY ) {
        returnValue = C.CURVE_SIZE + resize.bottom - resize.panY;
      }

      return roundTo( returnValue, 5*C.CURVE_PERCENT, 2*C.CURVE_PERCENT ) - point.y;
    }

    const el = this.base.querySelector('#js-point-touch'),
          mc = propagating(new Hammer.Manager(el));

    mc.add(new Hammer.Pan({ threshold: 0 }));

    mc
      .on('pan', (e) => {
        const {point, index} = this.props;
        store.dispatch({
          type: 'POINT_TRANSLATE',
          data: { x: getTempX(e), y: getTempY(e), index }
        });
        e.stopPropagation();
      })
      .on('panend', (e) => {
        const {point, index} = this.props;
        // fire translate end and save it to the store
        store.dispatch({
github OpenCircuits / OpenCircuits / app / core / ts / utils / Input.ts View on Github external
private setupHammer(): void {
        // Pinch to zoom
        const touchManager = new Hammer.Manager(this.canvas, {recognizers: []});
        let lastScale = 1;

        touchManager.add(new Hammer.Pinch());
        touchManager.on("pinch", (e) => {
            this.callListeners("zoom", lastScale/e.scale, this.mousePos);
            lastScale = e.scale;
        });
        touchManager.on("pinchend", (_) => {
            lastScale = 1;
        });

        touchManager.add(new Hammer.Tap());
        touchManager.on("tap", (e) => {
            if (e.pointerType == "mouse")
                return;
github liqueflies / slideer / src / index.js View on Github external
init() {

        this.hammer = new Hammer.Manager(this.el, { touchAction: 'pan-y' })
        this.hammer.add(new Hammer.Swipe({
            direction: Hammer.DIRECTION_HORIZONTAL
        }))
        this.hammer.on('swipe', this.onSwipe)
    }
github Deathspike / mangarack / src / client / areas / chapter / utilities / pinchZoom.ts View on Github external
export function pinchZoom(el: HTMLElement) {
  let mc = new Hammer.Manager(el);
  let pinch = new Hammer.Pinch();
  let pan = new Hammer.Pan();

  pinch.recognizeWith(pan);
  mc.add([pinch, pan]);

  let adjustScale = 1;
  let adjustDeltaX = 0;
  let adjustDeltaY = 0;

  let currentScale = 0;
  let currentDeltaX = 0;
  let currentDeltaY = 0;
  let panDelay = 0;

  mc.on('pan pinch', ev => {
github tinderjs / tinder-desktop / desktop-app / js / vendor / swing.js View on Github external
eventEmitter = Sister();
      springSystem = stack.springSystem();
      springThrowIn = springSystem.createSpring(250, 10);
      springThrowOut = springSystem.createSpring(500, 20);
      lastThrow = {};
      lastTranslate = {x: 0, y: 0};

      springThrowIn.setRestSpeedThreshold(0.05);
      springThrowIn.setRestDisplacementThreshold(0.05);

      springThrowOut.setRestSpeedThreshold(0.05);
      springThrowOut.setRestDisplacementThreshold(0.05);

      throwOutDistance = config.throwOutDistance(config.minThrowOutDistance, config.maxThrowOutDistance);

      mc = new Hammer.Manager(targetElement, {
        recognizers: [
          [Hammer.Pan, {threshold: 2}]
        ]
      });

      Card.appendToParent(targetElement);

      eventEmitter.on('_panstart', function () {
        Card.appendToParent(targetElement);

        eventEmitter.trigger('dragstart', {
          target: targetElement
        });
      });

      eventEmitter.on('_panmove', function (e) {
github mojs / mojs-curve-editor / app / js / tags / code-button.babel.jsx View on Github external
componentDidMount () {
    const {store} = this.context;
    const mc = propagating(new Hammer.Manager(this.base));
    mc.add(new Hammer.Tap);

    mc.on('tap', (e) => { store.dispatch({ type: 'CODE_TAP' }); });
  }
}
github mojs / mojs-timeline-editor / app / js / components / spot.babel.jsx View on Github external
componentDidMount() {
    const mc  = new Hammer.Manager(this._dot);
    mc.add(new Hammer.Pan);
    mc.add(new Hammer.Tap);
    mc.get('pan').set({ direction: Hammer.DIRECTION_HORIZONTAL });

    mc.on('pan', this._pan);
    mc.on('panend', this._panEnd);
    mc.on('tap', this._tap);
  }
github SilverDecisions / SilverDecisions / src / tree-designer / tree-designer.js View on Github external
this.svg = this.container.selectOrAppend('svg.tree-designer');
        this.svg.attr('width', this.availableWidth).attr('height', this.availableHeight);

        this.mainGroup = this.svg.selectOrAppend('g.main-group');
        this.updateMargin();


        if (!this.config.width) {
            d3.select(window)
                .on("resize.tree-designer", function () {
                    self.updatePlottingRegionSize();
                    self.redrawDiagramTitle();
                });
        }

        var mc = new Hammer.Manager(this.svg.node(), {touchAction : 'auto'});
        mc.add(new Hammer.Press({
            pointerType: 'touch'
        }));

        mc.add(new Hammer.Pinch({
            pointerType: 'touch'
        }));

        var cancel;
        mc.on('pinchstart', function(){
            self.disableBrush();
        })
        mc.on('pinch', function(){
            cancel = Utils.waitForFinalEvent(()=>self.enableBrush(), 'pinchend', 5000)
        })
    }