Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally require hammer.js #658

Merged
merged 2 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/utils/events/event-manager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import {Manager} from 'hammerjs';
import WheelInput from './wheel-input';
import MoveInput from './move-input';
import {isBrowser} from '../../controllers/globals';

// Hammer.js directly references `document` and `window`,
// which means that importing it in environments without
// those objects throws errors. Therefore, instead of
// directly `import`ing 'hammerjs' and './constants'
// (which imports Hammer.js) we conditionally require it
// depending on support for those globals.
function ManagerMock(m) {
const noop = () => {};
return {
on: noop,
off: noop,
destroy: noop,
emit: noop
};
}

import {
const Manager = isBrowser ? require('hammerjs').Manager : ManagerMock;
const {
BASIC_EVENT_ALIASES,
EVENT_RECOGNIZER_MAP,
RECOGNIZERS,
GESTURE_EVENT_ALIASES
} from './constants';
import WheelInput from './wheel-input';
import MoveInput from './move-input';
} = isBrowser ? require('./constants') : {};

/**
* Single API for subscribing to events about both
Expand Down
3 changes: 2 additions & 1 deletion src/utils/events/wheel-input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global window:false */
import window from '../../lib/utils/globals';

const ua = typeof window.navigator !== 'undefined' ?
window.navigator.userAgent.toLowerCase() : '';
const firefox = ua.indexOf('firefox') !== -1;
Expand Down