Skip to content

Commit

Permalink
Do not throw error if imported in nodeJS context
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-m1 committed Oct 1, 2019
1 parent 5fccf71 commit 576e335
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/BrowserInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function userAgent(pattern) {
return !!/*@__PURE__*/navigator.userAgent.match(pattern);
if (typeof window !== 'undefined' && window.navigator) {
return !!/*@__PURE__*/navigator.userAgent.match(pattern);
}
}

export const IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
Expand Down
43 changes: 24 additions & 19 deletions src/Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @license MIT
*/

import './windowCheck.js'; // Always import first

import { version } from '../package.json';

import { IE11OrLess, Edge, FireFox, Safari, IOS, ChromeForAndroid } from './BrowserInfo.js';
Expand Down Expand Up @@ -140,14 +138,17 @@ let dragEl,
savedInputChecked = [];

/** @const */
const PositionGhostAbsolutely = IOS,
const documentExists = typeof document !== 'undefined',

PositionGhostAbsolutely = IOS,

CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',

// This will not pass for IE9, because IE9 DnD only works on anchors
supportDraggable = !ChromeForAndroid && !IOS && ('draggable' in document.createElement('div')),
supportDraggable = documentExists && !ChromeForAndroid && !IOS && ('draggable' in document.createElement('div')),

supportCssPointerEvents = (function() {
if (!documentExists) return;
// false when <= IE11
if (IE11OrLess) {
return false;
Expand Down Expand Up @@ -297,15 +298,17 @@ let dragEl,


// #1184 fix - Prevent click event on fallback if dragged but item not changed position
document.addEventListener('click', function(evt) {
if (ignoreNextClick) {
evt.preventDefault();
evt.stopPropagation && evt.stopPropagation();
evt.stopImmediatePropagation && evt.stopImmediatePropagation();
ignoreNextClick = false;
return false;
}
}, true);
if (documentExists) {
document.addEventListener('click', function(evt) {
if (ignoreNextClick) {
evt.preventDefault();
evt.stopPropagation && evt.stopPropagation();
evt.stopImmediatePropagation && evt.stopImmediatePropagation();
ignoreNextClick = false;
return false;
}
}, true);
}

let nearestEmptyInsertDetectEvent = function(evt) {
if (dragEl) {
Expand Down Expand Up @@ -1613,7 +1616,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
return options[name];
} else {
let modifiedValue = PluginManager.modifyOption(this, name, value);
if (typeof(modifiedValue) !== 'undefined') {
if (typeof modifiedValue !== 'undefined') {
options[name] = modifiedValue;
} else {
options[name] = value;
Expand Down Expand Up @@ -1884,11 +1887,13 @@ function _cancelNextTick(id) {
}

// Fixed #973:
on(document, 'touchmove', function(evt) {
if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
evt.preventDefault();
}
});
if (documentExists) {
on(document, 'touchmove', function(evt) {
if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
evt.preventDefault();
}
});
}


// Export utils
Expand Down
3 changes: 0 additions & 3 deletions src/windowCheck.js

This file was deleted.

0 comments on commit 576e335

Please sign in to comment.