diff --git a/src/js/constants.js b/src/js/constants.js index 986571763..47fa736b9 100644 --- a/src/js/constants.js +++ b/src/js/constants.js @@ -1,5 +1,4 @@ -import global from './global'; - +export const WINDOW = typeof window !== 'undefined' ? window : {}; export const NAMESPACE = 'cropper'; // Actions @@ -42,9 +41,9 @@ export const EVENT_CROP_START = 'cropstart'; export const EVENT_DBLCLICK = 'dblclick'; export const EVENT_ERROR = 'error'; export const EVENT_LOAD = 'load'; -export const EVENT_POINTER_DOWN = global.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; -export const EVENT_POINTER_MOVE = global.PointerEvent ? 'pointermove' : 'touchmove mousemove'; -export const EVENT_POINTER_UP = global.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; +export const EVENT_POINTER_DOWN = WINDOW.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; +export const EVENT_POINTER_MOVE = WINDOW.PointerEvent ? 'pointermove' : 'touchmove mousemove'; +export const EVENT_POINTER_UP = WINDOW.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; export const EVENT_READY = 'ready'; export const EVENT_RESIZE = 'resize'; export const EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll'; diff --git a/src/js/cropper.js b/src/js/cropper.js index 447b0b341..813b6ee2d 100644 --- a/src/js/cropper.js +++ b/src/js/cropper.js @@ -1,4 +1,3 @@ -import global from './global'; import DEFAULTS from './defaults'; import TEMPLATE from './template'; import render from './render'; @@ -23,6 +22,7 @@ import { REGEXP_DATA_URL, REGEXP_DATA_URL_JPEG, REGEXP_TAG_NAME, + WINDOW, } from './constants'; import { addClass, @@ -45,7 +45,7 @@ import { setData, } from './utilities'; -const AnotherCropper = global.Cropper; +const AnotherCropper = WINDOW.Cropper; class Cropper { /** @@ -102,7 +102,7 @@ class Cropper { // e.g.: "http://example.com/img/picture.jpg" url = element.src; - } else if (tagName === 'canvas' && global.HTMLCanvasElement) { + } else if (tagName === 'canvas' && window.HTMLCanvasElement) { url = element.toDataURL(); } @@ -119,7 +119,7 @@ class Cropper { const { element, options } = this; - if (!options.checkOrientation || !global.ArrayBuffer) { + if (!options.checkOrientation || !window.ArrayBuffer) { this.clone(); return; } @@ -402,7 +402,7 @@ class Cropper { * @returns {Cropper} The cropper class. */ static noConflict() { - global.Cropper = AnotherCropper; + window.Cropper = AnotherCropper; return Cropper; } diff --git a/src/js/events.js b/src/js/events.js index b30f35cdf..e70c4309a 100644 --- a/src/js/events.js +++ b/src/js/events.js @@ -1,4 +1,3 @@ -import global from './global'; import { EVENT_CROP, EVENT_CROP_END, @@ -57,7 +56,7 @@ export default { addListener(document, EVENT_POINTER_UP, (this.onCropEnd = proxy(this.cropEnd, this))); if (options.responsive) { - addListener(global, EVENT_RESIZE, (this.onResize = proxy(this.resize, this))); + addListener(window, EVENT_RESIZE, (this.onResize = proxy(this.resize, this))); } }, @@ -98,7 +97,7 @@ export default { removeListener(document, EVENT_POINTER_UP, this.onCropEnd); if (options.responsive) { - removeListener(global, EVENT_RESIZE, this.onResize); + removeListener(window, EVENT_RESIZE, this.onResize); } }, }; diff --git a/src/js/global.js b/src/js/global.js deleted file mode 100644 index 4545ba207..000000000 --- a/src/js/global.js +++ /dev/null @@ -1 +0,0 @@ -export default typeof window !== 'undefined' ? window : {}; diff --git a/src/js/methods.js b/src/js/methods.js index 9b6e2a5f0..bdf17f48e 100644 --- a/src/js/methods.js +++ b/src/js/methods.js @@ -1,4 +1,3 @@ -import global from './global'; import { CLASS_CROP, CLASS_DISABLED, @@ -639,7 +638,7 @@ export default { * @returns {HTMLCanvasElement} - The result canvas. */ getCroppedCanvas(options = {}) { - if (!this.ready || !global.HTMLCanvasElement) { + if (!this.ready || !window.HTMLCanvasElement) { return null; } diff --git a/src/js/utilities.js b/src/js/utilities.js index f0033328d..5d43eb8d8 100644 --- a/src/js/utilities.js +++ b/src/js/utilities.js @@ -1,9 +1,11 @@ -import global from './global'; +import { + WINDOW, +} from './constants'; /** * Check if the given value is not a number. */ -export const isNaN = Number.isNaN || global.isNaN; +export const isNaN = Number.isNaN || WINDOW.isNaN; /** * Check if the given value is a number. @@ -442,10 +444,10 @@ export function getOffset(element) { return { left: box.left + ( - (global.scrollX || (doc && doc.scrollLeft) || 0) - ((doc && doc.clientLeft) || 0) + (window.scrollX || (doc && doc.scrollLeft) || 0) - ((doc && doc.clientLeft) || 0) ), top: box.top + ( - (global.scrollY || (doc && doc.scrollTop) || 0) - ((doc && doc.clientTop) || 0) + (window.scrollY || (doc && doc.scrollTop) || 0) - ((doc && doc.clientTop) || 0) ), }; } @@ -460,7 +462,7 @@ export function empty(element) { } } -const { location } = global; +const { location } = WINDOW; const REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i; /** @@ -533,7 +535,7 @@ export function getTransforms({ }; } -const { navigator } = global; +const { navigator } = WINDOW; const IS_SAFARI_OR_UIWEBVIEW = navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent); /** @@ -637,7 +639,7 @@ export function getPointersCenter(pointers) { /** * Check if the given value is a finite number. */ -export const isFinite = Number.isFinite || global.isFinite; +export const isFinite = Number.isFinite || WINDOW.isFinite; /** * Get the max sizes in a rectangle under the given aspect ratio.