Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasramo committed Jul 14, 2019
1 parent 0eed781 commit 1a81026
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
15 changes: 8 additions & 7 deletions dist/muuri.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,10 @@
cancel: 'cancel'
};

var hasTouchEvents = !!(
'ontouchstart' in window ||
window.TouchEvent ||
(window.DocumentTouch && window.document instanceof DocumentTouch)
);
var hasTouchEvents = !!('ontouchstart' in window || window.TouchEvent);
var hasPointerEvents = !!window.PointerEvent;
var hasMsPointerEvents = !!window.navigator.msPointerEnabled;
var isAndroid = /(android)/i.test(navigator.userAgent);
var isAndroid = /(android)/i.test(window.navigator.userAgent);
var listenerOptions = isPassiveEventsSupported ? { passive: true } : false;

var taProp = 'touchAction';
Expand Down Expand Up @@ -864,7 +860,12 @@
this._pointerId = Dragger._getEventPointerId(e);
if (this._pointerId === null) return;

// Store the start event and trigger start (async or sync).
// Store the start event and trigger start (async or sync). Pointer events
// are emitted before touch events if the browser supports both of them. And
// if you try to move an element before `touchstart` is emitted the pointer
// events for that element will be canceled. The fix is to delay the emitted
// pointer events in such a scenario by one frame so that `touchstart` has
// time to be emitted before the element is (potentially) moved.
this._startEvent = e;
if (hasTouchEvents && (hasPointerEvents || hasMsPointerEvents)) {
// Special cancelable check for Android to prevent drag procedure from
Expand Down
2 changes: 1 addition & 1 deletion dist/muuri.min.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/Dragger/Dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ var events = {
cancel: 'cancel'
};

var hasTouchEvents = !!(
'ontouchstart' in window ||
window.TouchEvent ||
(window.DocumentTouch && window.document instanceof DocumentTouch)
);
var hasTouchEvents = !!('ontouchstart' in window || window.TouchEvent);
var hasPointerEvents = !!window.PointerEvent;
var hasMsPointerEvents = !!window.navigator.msPointerEnabled;
var isAndroid = /(android)/i.test(navigator.userAgent);
var isAndroid = /(android)/i.test(window.navigator.userAgent);
var listenerOptions = isPassiveEventsSupported ? { passive: true } : false;

var taProp = 'touchAction';
Expand Down Expand Up @@ -351,7 +347,12 @@ Dragger.prototype._preStartCheck = function(e) {
this._pointerId = Dragger._getEventPointerId(e);
if (this._pointerId === null) return;

// Store the start event and trigger start (async or sync).
// Store the start event and trigger start (async or sync). Pointer events
// are emitted before touch events if the browser supports both of them. And
// if you try to move an element before `touchstart` is emitted the pointer
// events for that element will be canceled. The fix is to delay the emitted
// pointer events in such a scenario by one frame so that `touchstart` has
// time to be emitted before the element is (potentially) moved.
this._startEvent = e;
if (hasTouchEvents && (hasPointerEvents || hasMsPointerEvents)) {
// Special cancelable check for Android to prevent drag procedure from
Expand Down

0 comments on commit 1a81026

Please sign in to comment.