From 5dc2ae649cf41889d57d6f2d40562616cfb4de3c Mon Sep 17 00:00:00 2001 From: Fengyuan Chen Date: Wed, 11 Oct 2017 21:35:35 +0800 Subject: [PATCH] build: release 3.1.1 --- CHANGELOG.md | 4 ++ dist/cropper.common.js | 108 ++++++++++++++++++++--------------------- dist/cropper.css | 6 +-- dist/cropper.esm.js | 108 ++++++++++++++++++++--------------------- dist/cropper.js | 108 ++++++++++++++++++++--------------------- dist/cropper.min.css | 6 +-- dist/cropper.min.js | 8 +-- docs/css/cropper.css | 6 +-- docs/index.html | 4 +- docs/js/cropper.js | 108 ++++++++++++++++++++--------------------- package-lock.json | 2 +- package.json | 6 +-- 12 files changed, 239 insertions(+), 235 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 699485b8..79a92ebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.1.1 (Oct 11, 2017) + +- Supports to load in node environment. + ## 3.1.0 (Oct 8, 2017) - Added 4 new options to `getCroppedCanvas` method: `minWidth`, `minHeight`, `maxWidth` and `maxHeight`. diff --git a/dist/cropper.common.js b/dist/cropper.common.js index 4bd03946..42d59940 100644 --- a/dist/cropper.common.js +++ b/dist/cropper.common.js @@ -1,11 +1,11 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:38.353Z + * Date: 2017-10-11T13:34:24.201Z */ 'use strict'; @@ -14,9 +14,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var $ = _interopDefault(require('jquery')); -var _window = window; -var PointerEvent = _window.PointerEvent; - +var global = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'cropper'; @@ -60,9 +58,9 @@ var EVENT_CROP_START = 'cropstart'; var EVENT_DBLCLICK = 'dblclick'; var EVENT_ERROR = 'error'; var EVENT_LOAD = 'load'; -var EVENT_POINTER_DOWN = PointerEvent ? 'pointerdown' : 'touchstart mousedown'; -var EVENT_POINTER_MOVE = PointerEvent ? 'pointermove' : 'touchmove mousemove'; -var EVENT_POINTER_UP = PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; +var EVENT_POINTER_DOWN = global.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; +var EVENT_POINTER_MOVE = global.PointerEvent ? 'pointermove' : 'touchmove mousemove'; +var EVENT_POINTER_UP = global.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; var EVENT_READY = 'ready'; var EVENT_RESIZE = 'resize'; var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll'; @@ -184,7 +182,7 @@ function isString(value) { /** * Check if the given value is not a number. */ -var isNaN = Number.isNaN || window.isNaN; +var isNaN = Number.isNaN || global.isNaN; /** * Check if the given value is a number. @@ -240,8 +238,7 @@ var objectKeys = Object.keys || function objectKeys(obj) { return keys; }; -var _window$1 = window; -var location = _window$1.location; +var location = global.location; var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i; @@ -305,6 +302,8 @@ function getTransformValues(_ref) { return values.length ? values.join(' ') : 'none'; } +var navigator = global.navigator; + var IS_SAFARI_OR_UIWEBVIEW = navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent); /** @@ -416,7 +415,7 @@ function getPointersCenter(pointers) { /** * Check if the given value is a finite number. */ -var isFinite = Number.isFinite || window.isFinite; +var isFinite = Number.isFinite || global.isFinite; /** * Get the max sizes in a rectangle under the given aspect ratio. @@ -564,9 +563,6 @@ function getStringFromCharCode(dataView, start, length) { return str; } -var _window2 = window; -var atob = _window2.atob; - var REGEXP_DATA_URL_HEAD = /^data:.*,/; /** @@ -1300,7 +1296,7 @@ var events = { $(document).on(EVENT_POINTER_MOVE, this.onCropMove = proxy(this.cropMove, this)).on(EVENT_POINTER_UP, this.onCropEnd = proxy(this.cropEnd, this)); if (options.responsive) { - $(window).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); + $(global).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); } }, unbind: function unbind() { @@ -1342,7 +1338,7 @@ var events = { $(document).off(EVENT_POINTER_MOVE, this.onCropMove).off(EVENT_POINTER_UP, this.onCropEnd); if (options.responsive) { - $(window).off(EVENT_RESIZE, this.onResize); + $(global).off(EVENT_RESIZE, this.onResize); } } }; @@ -2582,7 +2578,7 @@ var methods = { getCroppedCanvas: function getCroppedCanvas() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - if (!this.ready || !window.HTMLCanvasElement) { + if (!this.ready || !global.HTMLCanvasElement) { return null; } @@ -2806,7 +2802,7 @@ var Cropper = function () { this.isImg = true; // Should use `$.fn.attr` here. e.g.: "img/picture.jpg" - url = $element.attr('src'); + url = $element.attr('src') || ''; this.originalUrl = url; // Stop when it's a blank image @@ -2816,7 +2812,7 @@ var Cropper = function () { // Should use `$.fn.prop` here. e.g.: "http://example.com/img/picture.jpg" url = $element.prop('src'); - } else if ($element.is('canvas') && window.HTMLCanvasElement) { + } else if ($element.is('canvas') && global.HTMLCanvasElement) { url = $element[0].toDataURL(); } @@ -2850,7 +2846,7 @@ var Cropper = function () { options = this.options; - if (!options.checkOrientation || !window.ArrayBuffer) { + if (!options.checkOrientation || !global.ArrayBuffer) { this.clone(); return; } @@ -3144,47 +3140,51 @@ var Cropper = function () { return Cropper; }(); -$.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +if ($.extend) { + $.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +} -var AnotherCropper = $.fn.cropper; +if ($.fn) { + var AnotherCropper = $.fn.cropper; -$.fn.cropper = function jQueryCropper(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } + $.fn.cropper = function jQueryCropper(option) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } - var result = void 0; + var result = void 0; - this.each(function (i, element) { - var $element = $(element); - var data = $element.data(NAMESPACE); + this.each(function (i, element) { + var $element = $(element); + var data = $element.data(NAMESPACE); - if (!data) { - if (/destroy/.test(option)) { - return; - } + if (!data) { + if (/destroy/.test(option)) { + return; + } - var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); + var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - data = new Cropper(element, options); - $element.data(NAMESPACE, data); - } + data = new Cropper(element, options); + $element.data(NAMESPACE, data); + } - if (isString(option)) { - var fn = data[option]; + if (isString(option)) { + var fn = data[option]; - if ($.isFunction(fn)) { - result = fn.apply(data, args); + if ($.isFunction(fn)) { + result = fn.apply(data, args); + } } - } - }); + }); - return isUndefined(result) ? this : result; -}; + return isUndefined(result) ? this : result; + }; -$.fn.cropper.Constructor = Cropper; -$.fn.cropper.setDefaults = Cropper.setDefaults; -$.fn.cropper.noConflict = function noConflict() { - $.fn.cropper = AnotherCropper; - return this; -}; + $.fn.cropper.Constructor = Cropper; + $.fn.cropper.setDefaults = Cropper.setDefaults; + $.fn.cropper.noConflict = function noConflict() { + $.fn.cropper = AnotherCropper; + return this; + }; +} diff --git a/dist/cropper.css b/dist/cropper.css index 6789ffe2..31257dc7 100644 --- a/dist/cropper.css +++ b/dist/cropper.css @@ -1,11 +1,11 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:31.177Z + * Date: 2017-10-11T13:34:16.708Z */ .cropper-container { diff --git a/dist/cropper.esm.js b/dist/cropper.esm.js index 766b3644..a4d1074b 100644 --- a/dist/cropper.esm.js +++ b/dist/cropper.esm.js @@ -1,18 +1,16 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:38.353Z + * Date: 2017-10-11T13:34:24.201Z */ import $ from 'jquery'; -var _window = window; -var PointerEvent = _window.PointerEvent; - +var global = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'cropper'; @@ -56,9 +54,9 @@ var EVENT_CROP_START = 'cropstart'; var EVENT_DBLCLICK = 'dblclick'; var EVENT_ERROR = 'error'; var EVENT_LOAD = 'load'; -var EVENT_POINTER_DOWN = PointerEvent ? 'pointerdown' : 'touchstart mousedown'; -var EVENT_POINTER_MOVE = PointerEvent ? 'pointermove' : 'touchmove mousemove'; -var EVENT_POINTER_UP = PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; +var EVENT_POINTER_DOWN = global.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; +var EVENT_POINTER_MOVE = global.PointerEvent ? 'pointermove' : 'touchmove mousemove'; +var EVENT_POINTER_UP = global.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; var EVENT_READY = 'ready'; var EVENT_RESIZE = 'resize'; var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll'; @@ -180,7 +178,7 @@ function isString(value) { /** * Check if the given value is not a number. */ -var isNaN = Number.isNaN || window.isNaN; +var isNaN = Number.isNaN || global.isNaN; /** * Check if the given value is a number. @@ -236,8 +234,7 @@ var objectKeys = Object.keys || function objectKeys(obj) { return keys; }; -var _window$1 = window; -var location = _window$1.location; +var location = global.location; var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i; @@ -301,6 +298,8 @@ function getTransformValues(_ref) { return values.length ? values.join(' ') : 'none'; } +var navigator = global.navigator; + var IS_SAFARI_OR_UIWEBVIEW = navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent); /** @@ -412,7 +411,7 @@ function getPointersCenter(pointers) { /** * Check if the given value is a finite number. */ -var isFinite = Number.isFinite || window.isFinite; +var isFinite = Number.isFinite || global.isFinite; /** * Get the max sizes in a rectangle under the given aspect ratio. @@ -560,9 +559,6 @@ function getStringFromCharCode(dataView, start, length) { return str; } -var _window2 = window; -var atob = _window2.atob; - var REGEXP_DATA_URL_HEAD = /^data:.*,/; /** @@ -1296,7 +1292,7 @@ var events = { $(document).on(EVENT_POINTER_MOVE, this.onCropMove = proxy(this.cropMove, this)).on(EVENT_POINTER_UP, this.onCropEnd = proxy(this.cropEnd, this)); if (options.responsive) { - $(window).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); + $(global).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); } }, unbind: function unbind() { @@ -1338,7 +1334,7 @@ var events = { $(document).off(EVENT_POINTER_MOVE, this.onCropMove).off(EVENT_POINTER_UP, this.onCropEnd); if (options.responsive) { - $(window).off(EVENT_RESIZE, this.onResize); + $(global).off(EVENT_RESIZE, this.onResize); } } }; @@ -2578,7 +2574,7 @@ var methods = { getCroppedCanvas: function getCroppedCanvas() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - if (!this.ready || !window.HTMLCanvasElement) { + if (!this.ready || !global.HTMLCanvasElement) { return null; } @@ -2802,7 +2798,7 @@ var Cropper = function () { this.isImg = true; // Should use `$.fn.attr` here. e.g.: "img/picture.jpg" - url = $element.attr('src'); + url = $element.attr('src') || ''; this.originalUrl = url; // Stop when it's a blank image @@ -2812,7 +2808,7 @@ var Cropper = function () { // Should use `$.fn.prop` here. e.g.: "http://example.com/img/picture.jpg" url = $element.prop('src'); - } else if ($element.is('canvas') && window.HTMLCanvasElement) { + } else if ($element.is('canvas') && global.HTMLCanvasElement) { url = $element[0].toDataURL(); } @@ -2846,7 +2842,7 @@ var Cropper = function () { options = this.options; - if (!options.checkOrientation || !window.ArrayBuffer) { + if (!options.checkOrientation || !global.ArrayBuffer) { this.clone(); return; } @@ -3140,47 +3136,51 @@ var Cropper = function () { return Cropper; }(); -$.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +if ($.extend) { + $.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +} -var AnotherCropper = $.fn.cropper; +if ($.fn) { + var AnotherCropper = $.fn.cropper; -$.fn.cropper = function jQueryCropper(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } + $.fn.cropper = function jQueryCropper(option) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } - var result = void 0; + var result = void 0; - this.each(function (i, element) { - var $element = $(element); - var data = $element.data(NAMESPACE); + this.each(function (i, element) { + var $element = $(element); + var data = $element.data(NAMESPACE); - if (!data) { - if (/destroy/.test(option)) { - return; - } + if (!data) { + if (/destroy/.test(option)) { + return; + } - var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); + var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - data = new Cropper(element, options); - $element.data(NAMESPACE, data); - } + data = new Cropper(element, options); + $element.data(NAMESPACE, data); + } - if (isString(option)) { - var fn = data[option]; + if (isString(option)) { + var fn = data[option]; - if ($.isFunction(fn)) { - result = fn.apply(data, args); + if ($.isFunction(fn)) { + result = fn.apply(data, args); + } } - } - }); + }); - return isUndefined(result) ? this : result; -}; + return isUndefined(result) ? this : result; + }; -$.fn.cropper.Constructor = Cropper; -$.fn.cropper.setDefaults = Cropper.setDefaults; -$.fn.cropper.noConflict = function noConflict() { - $.fn.cropper = AnotherCropper; - return this; -}; + $.fn.cropper.Constructor = Cropper; + $.fn.cropper.setDefaults = Cropper.setDefaults; + $.fn.cropper.noConflict = function noConflict() { + $.fn.cropper = AnotherCropper; + return this; + }; +} diff --git a/dist/cropper.js b/dist/cropper.js index 843a202d..86e7c826 100644 --- a/dist/cropper.js +++ b/dist/cropper.js @@ -1,11 +1,11 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:38.353Z + * Date: 2017-10-11T13:34:24.201Z */ (function (global, factory) { @@ -16,9 +16,7 @@ $ = $ && $.hasOwnProperty('default') ? $['default'] : $; -var _window = window; -var PointerEvent = _window.PointerEvent; - +var global = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'cropper'; @@ -62,9 +60,9 @@ var EVENT_CROP_START = 'cropstart'; var EVENT_DBLCLICK = 'dblclick'; var EVENT_ERROR = 'error'; var EVENT_LOAD = 'load'; -var EVENT_POINTER_DOWN = PointerEvent ? 'pointerdown' : 'touchstart mousedown'; -var EVENT_POINTER_MOVE = PointerEvent ? 'pointermove' : 'touchmove mousemove'; -var EVENT_POINTER_UP = PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; +var EVENT_POINTER_DOWN = global.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; +var EVENT_POINTER_MOVE = global.PointerEvent ? 'pointermove' : 'touchmove mousemove'; +var EVENT_POINTER_UP = global.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; var EVENT_READY = 'ready'; var EVENT_RESIZE = 'resize'; var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll'; @@ -186,7 +184,7 @@ function isString(value) { /** * Check if the given value is not a number. */ -var isNaN = Number.isNaN || window.isNaN; +var isNaN = Number.isNaN || global.isNaN; /** * Check if the given value is a number. @@ -242,8 +240,7 @@ var objectKeys = Object.keys || function objectKeys(obj) { return keys; }; -var _window$1 = window; -var location = _window$1.location; +var location = global.location; var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i; @@ -307,6 +304,8 @@ function getTransformValues(_ref) { return values.length ? values.join(' ') : 'none'; } +var navigator = global.navigator; + var IS_SAFARI_OR_UIWEBVIEW = navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent); /** @@ -418,7 +417,7 @@ function getPointersCenter(pointers) { /** * Check if the given value is a finite number. */ -var isFinite = Number.isFinite || window.isFinite; +var isFinite = Number.isFinite || global.isFinite; /** * Get the max sizes in a rectangle under the given aspect ratio. @@ -566,9 +565,6 @@ function getStringFromCharCode(dataView, start, length) { return str; } -var _window2 = window; -var atob = _window2.atob; - var REGEXP_DATA_URL_HEAD = /^data:.*,/; /** @@ -1302,7 +1298,7 @@ var events = { $(document).on(EVENT_POINTER_MOVE, this.onCropMove = proxy(this.cropMove, this)).on(EVENT_POINTER_UP, this.onCropEnd = proxy(this.cropEnd, this)); if (options.responsive) { - $(window).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); + $(global).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); } }, unbind: function unbind() { @@ -1344,7 +1340,7 @@ var events = { $(document).off(EVENT_POINTER_MOVE, this.onCropMove).off(EVENT_POINTER_UP, this.onCropEnd); if (options.responsive) { - $(window).off(EVENT_RESIZE, this.onResize); + $(global).off(EVENT_RESIZE, this.onResize); } } }; @@ -2584,7 +2580,7 @@ var methods = { getCroppedCanvas: function getCroppedCanvas() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - if (!this.ready || !window.HTMLCanvasElement) { + if (!this.ready || !global.HTMLCanvasElement) { return null; } @@ -2808,7 +2804,7 @@ var Cropper = function () { this.isImg = true; // Should use `$.fn.attr` here. e.g.: "img/picture.jpg" - url = $element.attr('src'); + url = $element.attr('src') || ''; this.originalUrl = url; // Stop when it's a blank image @@ -2818,7 +2814,7 @@ var Cropper = function () { // Should use `$.fn.prop` here. e.g.: "http://example.com/img/picture.jpg" url = $element.prop('src'); - } else if ($element.is('canvas') && window.HTMLCanvasElement) { + } else if ($element.is('canvas') && global.HTMLCanvasElement) { url = $element[0].toDataURL(); } @@ -2852,7 +2848,7 @@ var Cropper = function () { options = this.options; - if (!options.checkOrientation || !window.ArrayBuffer) { + if (!options.checkOrientation || !global.ArrayBuffer) { this.clone(); return; } @@ -3146,49 +3142,53 @@ var Cropper = function () { return Cropper; }(); -$.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +if ($.extend) { + $.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +} -var AnotherCropper = $.fn.cropper; +if ($.fn) { + var AnotherCropper = $.fn.cropper; -$.fn.cropper = function jQueryCropper(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } + $.fn.cropper = function jQueryCropper(option) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } - var result = void 0; + var result = void 0; - this.each(function (i, element) { - var $element = $(element); - var data = $element.data(NAMESPACE); + this.each(function (i, element) { + var $element = $(element); + var data = $element.data(NAMESPACE); - if (!data) { - if (/destroy/.test(option)) { - return; - } + if (!data) { + if (/destroy/.test(option)) { + return; + } - var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); + var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - data = new Cropper(element, options); - $element.data(NAMESPACE, data); - } + data = new Cropper(element, options); + $element.data(NAMESPACE, data); + } - if (isString(option)) { - var fn = data[option]; + if (isString(option)) { + var fn = data[option]; - if ($.isFunction(fn)) { - result = fn.apply(data, args); + if ($.isFunction(fn)) { + result = fn.apply(data, args); + } } - } - }); + }); - return isUndefined(result) ? this : result; -}; + return isUndefined(result) ? this : result; + }; -$.fn.cropper.Constructor = Cropper; -$.fn.cropper.setDefaults = Cropper.setDefaults; -$.fn.cropper.noConflict = function noConflict() { - $.fn.cropper = AnotherCropper; - return this; -}; + $.fn.cropper.Constructor = Cropper; + $.fn.cropper.setDefaults = Cropper.setDefaults; + $.fn.cropper.noConflict = function noConflict() { + $.fn.cropper = AnotherCropper; + return this; + }; +} }))); diff --git a/dist/cropper.min.css b/dist/cropper.min.css index 8d57e466..86806461 100644 --- a/dist/cropper.min.css +++ b/dist/cropper.min.css @@ -1,10 +1,10 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:31.177Z + * Date: 2017-10-11T13:34:16.708Z */.cropper-container{direction:ltr;font-size:0;line-height:0;position:relative;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.cropper-container img{display:block;height:100%;image-orientation:0deg;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}.cropper-canvas,.cropper-crop-box,.cropper-drag-box,.cropper-modal,.cropper-wrap-box{bottom:0;left:0;position:absolute;right:0;top:0}.cropper-canvas,.cropper-wrap-box{overflow:hidden}.cropper-drag-box{background-color:#fff;opacity:0}.cropper-modal{background-color:#000;opacity:.5}.cropper-view-box{display:block;height:100%;outline-color:rgba(51,153,255,.75);outline:1px solid #39f;overflow:hidden;width:100%}.cropper-dashed{border:0 dashed #eee;display:block;opacity:.5;position:absolute}.cropper-dashed.dashed-h{border-bottom-width:1px;border-top-width:1px;height:33.33333%;left:0;top:33.33333%;width:100%}.cropper-dashed.dashed-v{border-left-width:1px;border-right-width:1px;height:100%;left:33.33333%;top:0;width:33.33333%}.cropper-center{display:block;height:0;left:50%;opacity:.75;position:absolute;top:50%;width:0}.cropper-center:after,.cropper-center:before{background-color:#eee;content:" ";display:block;position:absolute}.cropper-center:before{height:1px;left:-3px;top:0;width:7px}.cropper-center:after{height:7px;left:0;top:-3px;width:1px}.cropper-face,.cropper-line,.cropper-point{display:block;height:100%;opacity:.1;position:absolute;width:100%}.cropper-face{background-color:#fff;left:0;top:0}.cropper-line{background-color:#39f}.cropper-line.line-e{cursor:e-resize;right:-3px;top:0;width:5px}.cropper-line.line-n{cursor:n-resize;height:5px;left:0;top:-3px}.cropper-line.line-w{cursor:w-resize;left:-3px;top:0;width:5px}.cropper-line.line-s{bottom:-3px;cursor:s-resize;height:5px;left:0}.cropper-point{background-color:#39f;height:5px;opacity:.75;width:5px}.cropper-point.point-e{cursor:e-resize;margin-top:-3px;right:-3px;top:50%}.cropper-point.point-n{cursor:n-resize;left:50%;margin-left:-3px;top:-3px}.cropper-point.point-w{cursor:w-resize;left:-3px;margin-top:-3px;top:50%}.cropper-point.point-s{bottom:-3px;cursor:s-resize;left:50%;margin-left:-3px}.cropper-point.point-ne{cursor:ne-resize;right:-3px;top:-3px}.cropper-point.point-nw{cursor:nw-resize;left:-3px;top:-3px}.cropper-point.point-sw{bottom:-3px;cursor:sw-resize;left:-3px}.cropper-point.point-se{bottom:-3px;cursor:se-resize;height:20px;opacity:1;right:-3px;width:20px}@media (min-width:768px){.cropper-point.point-se{height:15px;width:15px}}@media (min-width:992px){.cropper-point.point-se{height:10px;width:10px}}@media (min-width:1200px){.cropper-point.point-se{height:5px;opacity:.75;width:5px}}.cropper-point.point-se:before{background-color:#39f;bottom:-50%;content:" ";display:block;height:200%;opacity:0;position:absolute;right:-50%;width:200%}.cropper-invisible{opacity:0}.cropper-bg{background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC")}.cropper-hide{display:block;height:0;position:absolute;width:0}.cropper-hidden{display:none!important}.cropper-move{cursor:move}.cropper-crop{cursor:crosshair}.cropper-disabled .cropper-drag-box,.cropper-disabled .cropper-face,.cropper-disabled .cropper-line,.cropper-disabled .cropper-point{cursor:not-allowed} /*# sourceMappingURL=cropper.min.css.map */ \ No newline at end of file diff --git a/dist/cropper.min.js b/dist/cropper.min.js index 2413244f..84094a8b 100644 --- a/dist/cropper.min.js +++ b/dist/cropper.min.js @@ -1,10 +1,10 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:38.353Z + * Date: 2017-10-11T13:34:24.201Z */ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],i):i(t.jQuery)}(this,function(t){"use strict";function i(t){return"string"==typeof t}function e(t){return"number"==typeof t&&!Y(t)}function a(t){return void 0===t}function o(t,i){for(var e=arguments.length,a=Array(e>2?e-2:0),o=2;o0};return o(a)&&o(e)?e*i>a?e=a/i:a=e*i:o(a)?e=a/i:o(e)&&(a=e*i),{width:a,height:e}}function m(t){var i=t.width,e=t.height,a=t.degree;if((a=Math.abs(a))%180==90)return{width:e,height:i};var o=a%90*Math.PI/180,n=Math.sin(o),h=Math.cos(o);return{width:i*h+e*n,height:i*n+e*h}}function g(t,i,e,a){var o=i.naturalWidth,n=i.naturalHeight,h=i.rotate,s=i.scaleX,r=i.scaleY,c=e.aspectRatio,d=e.naturalWidth,l=e.naturalHeight,m=a.fillColor,g=void 0===m?"transparent":m,u=a.imageSmoothingEnabled,f=void 0===u||u,v=a.imageSmoothingQuality,w=void 0===v?"low":v,x=a.maxWidth,b=void 0===x?1/0:x,y=a.maxHeight,M=void 0===y?1/0:y,C=a.minWidth,$=void 0===C?0:C,B=a.minHeight,k=void 0===B?0:B,W=p({aspectRatio:c,width:b,height:M}),T=p({aspectRatio:c,width:$,height:k}),D=Math.min(W.width,Math.max(T.width,d)),H=Math.min(W.height,Math.max(T.height,l)),Y=document.createElement("canvas"),X=Y.getContext("2d");return Y.width=D,Y.height=H,X.fillStyle=g,X.fillRect(0,0,D,H),X.save(),X.translate(D/2,H/2),X.rotate(h*Math.PI/180),X.scale(s,r),X.imageSmoothingEnabled=!!f,X.imageSmoothingQuality=w,X.drawImage(t,Math.floor(-o/2),Math.floor(-n/2),Math.floor(o),Math.floor(n)),X.restore(),Y}function u(t,i,e){var a="",o=void 0;for(e+=i,o=i;o=8&&(n=r+d)}}}if(n){var l=i.getUint16(n,a),p=void 0,m=void 0;for(m=0;mi.width?3===a?r=i.height*s:c=i.width/s:3===a?c=i.width/s:r=i.height*s;var d={aspectRatio:s,naturalWidth:n,naturalHeight:h,width:r,height:c};d.left=(i.width-r)/2,d.top=(i.height-c)/2,d.oldLeft=d.left,d.oldTop=d.top,this.canvas=d,this.limited=1===a||2===a,this.limitCanvas(!0,!0),this.initialImage=t.extend({},e),this.initialCanvas=t.extend({},d)},limitCanvas:function(t,i){var e=this.options,a=this.container,o=this.canvas,n=this.cropBox,h=e.viewMode,s=o.aspectRatio,r=this.cropped&&n;if(t){var c=Number(e.minCanvasWidth)||0,d=Number(e.minCanvasHeight)||0;h>0&&(h>1?(c=Math.max(c,a.width),d=Math.max(d,a.height),3===h&&(d*s>c?c=d*s:d=c/s)):c?c=Math.max(c,r?n.width:0):d?d=Math.max(d,r?n.height:0):r&&(c=n.width,(d=n.height)*s>c?c=d*s:d=c/s));var l=p({aspectRatio:s,width:c,height:d});c=l.width,d=l.height,o.minWidth=c,o.minHeight=d,o.maxWidth=1/0,o.maxHeight=1/0}if(i)if(h>0){var m=a.width-o.width,g=a.height-o.height;o.minLeft=Math.min(0,m),o.minTop=Math.min(0,g),o.maxLeft=Math.max(0,m),o.maxTop=Math.max(0,g),r&&this.limited&&(o.minLeft=Math.min(n.left,n.left+n.width-o.width),o.minTop=Math.min(n.top,n.top+n.height-o.height),o.maxLeft=n.left,o.maxTop=n.top,2===h&&(o.width>=a.width&&(o.minLeft=Math.min(0,m),o.maxLeft=Math.max(0,m)),o.height>=a.height&&(o.minTop=Math.min(0,g),o.maxTop=Math.max(0,g))))}else o.minLeft=-o.width,o.minTop=-o.height,o.maxLeft=a.width,o.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvas,a=this.image;if(i){var o=m({width:a.naturalWidth*Math.abs(a.scaleX),height:a.naturalHeight*Math.abs(a.scaleY),degree:a.rotate}),n=o.width,h=o.height,r=e.width*(n/e.naturalWidth),c=e.height*(h/e.naturalHeight);e.left-=(r-e.width)/2,e.top-=(c-e.height)/2,e.width=r,e.height=c,e.aspectRatio=n/h,e.naturalWidth=n,e.naturalHeight=h,this.limitCanvas(!0,!1)}(e.width>e.maxWidth||e.widthe.maxHeight||e.heighte.width?n.height=n.width/a:n.width=n.height*a),this.cropBox=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*o),n.height=Math.max(n.minHeight,n.height*o),n.left=e.left+(e.width-n.width)/2,n.top=e.top+(e.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBox=t.extend({},n)},limitCropBox:function(t,i){var e=this.options,a=this.container,o=this.canvas,n=this.cropBox,h=this.limited,s=e.aspectRatio;if(t){var r=Number(e.minCropBoxWidth)||0,c=Number(e.minCropBoxHeight)||0,d=Math.min(a.width,h?o.width:a.width),l=Math.min(a.height,h?o.height:a.height);r=Math.min(r,a.width),c=Math.min(c,a.height),s&&(r&&c?c*s>r?c=r/s:r=c*s:r?c=r/s:c&&(r=c*s),l*s>d?l=d/s:d=l*s),n.minWidth=Math.min(r,d),n.minHeight=Math.min(c,l),n.maxWidth=d,n.maxHeight=l}i&&(h?(n.minLeft=Math.max(0,o.left),n.minTop=Math.max(0,o.top),n.maxLeft=Math.min(a.width,o.left+o.width)-n.width,n.maxTop=Math.min(a.height,o.top+o.height)-n.height):(n.minLeft=0,n.minTop=0,n.maxLeft=a.width-n.width,n.maxTop=a.height-n.height))},renderCropBox:function(){var t=this.options,i=this.container,e=this.cropBox;(e.width>e.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?"move":"all"),this.$cropBox.css({width:e.width,height:e.height,transform:s({translateX:e.left,translateY:e.top})}),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),this.completed&&this.trigger("crop",this.getData())}},U={initPreview:function(){var i=this.crossOrigin,e=i?this.crossOriginUrl:this.url,a=document.createElement("img");i&&(a.crossOrigin=i),a.src=e;var o=t(a);this.$preview=t(this.options.preview),this.$clone2=o,this.$viewBox.html(o),this.$preview.each(function(a,o){var n=t(o),h=document.createElement("img");n.data("preview",{width:n.width(),height:n.height(),html:n.html()}),i&&(h.crossOrigin=i),h.src=e,h.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',n.html(h)})},resetPreview:function(){this.$preview.each(function(i,e){var a=t(e),o=a.data("preview");a.css({width:o.width,height:o.height}).html(o.html).removeData("preview")})},preview:function(){var i=this.image,e=this.canvas,a=this.cropBox,o=a.width,n=a.height,h=i.width,r=i.height,c=a.left-e.left-i.left,d=a.top-e.top-i.top;this.cropped&&!this.disabled&&(this.$clone2.css({width:h,height:r,transform:s(t.extend({translateX:-c,translateY:-d},i))}),this.$preview.each(function(e,a){var l=t(a),p=l.data("preview"),m=p.width,g=p.height,u=m,f=g,v=1;o&&(f=n*(v=m/o)),n&&f>g&&(u=o*(v=g/n),f=g),l.css({width:u,height:f}).find("img").css({width:h*v,height:r*v,transform:s(t.extend({translateX:-c*v,translateY:-d*v},i))})}))}},F={bind:function(){var i=this.$element,e=this.options,a=this.$cropper;t.isFunction(e.cropstart)&&i.on("cropstart",e.cropstart),t.isFunction(e.cropmove)&&i.on("cropmove",e.cropmove),t.isFunction(e.cropend)&&i.on("cropend",e.cropend),t.isFunction(e.crop)&&i.on("crop",e.crop),t.isFunction(e.zoom)&&i.on("zoom",e.zoom),a.on(C,o(this.cropStart,this)),e.zoomable&&e.zoomOnWheel&&a.on("wheel mousewheel DOMMouseScroll",o(this.wheel,this)),e.toggleDragModeOnDblclick&&a.on("dblclick",o(this.dblclick,this)),t(document).on($,this.onCropMove=o(this.cropMove,this)).on(B,this.onCropEnd=o(this.cropEnd,this)),e.responsive&&t(window).on("resize",this.onResize=o(this.resize,this))},unbind:function(){var i=this.$element,e=this.options,a=this.$cropper;t.isFunction(e.cropstart)&&i.off("cropstart",e.cropstart),t.isFunction(e.cropmove)&&i.off("cropmove",e.cropmove),t.isFunction(e.cropend)&&i.off("cropend",e.cropend),t.isFunction(e.crop)&&i.off("crop",e.crop),t.isFunction(e.zoom)&&i.off("zoom",e.zoom),a.off(C,this.cropStart),e.zoomable&&e.zoomOnWheel&&a.off("wheel mousewheel DOMMouseScroll",this.wheel),e.toggleDragModeOnDblclick&&a.off("dblclick",this.dblclick),t(document).off($,this.onCropMove).off(B,this.onCropEnd),e.responsive&&t(window).off("resize",this.onResize)}},S={resize:function(){var i=this.options,e=this.$container,a=this.container,o=Number(i.minContainerWidth)||200,n=Number(i.minContainerHeight)||100;if(!(this.disabled||a.width<=o||a.height<=n)){var h=e.width()/a.width;if(1!==h||e.height()!==a.height){var s=void 0,r=void 0;i.restore&&(s=this.getCanvasData(),r=this.getCropBoxData()),this.render(),i.restore&&(this.setCanvasData(t.each(s,function(t,i){s[t]=i*h})),this.setCropBoxData(t.each(r,function(t,i){r[t]=i*h})))}}},dblclick:function(){this.disabled||"none"===this.options.dragMode||this.setDragMode(this.$dragBox.hasClass("cropper-crop")?"move":"crop")},wheel:function(t){var i=this,e=t.originalEvent||t,a=Number(this.options.wheelZoomRatio)||.1;if(!this.disabled&&(t.preventDefault(),!this.wheeling)){this.wheeling=!0,setTimeout(function(){i.wheeling=!1},50);var o=1;e.deltaY?o=e.deltaY>0?1:-1:e.wheelDelta?o=-e.wheelDelta/120:e.detail&&(o=e.detail>0?1:-1),this.zoom(-o*a,t)}},cropStart:function(i){if(!this.disabled){var e=this.options,a=this.pointers,o=i.originalEvent,n=void 0;o&&o.changedTouches?t.each(o.changedTouches,function(t,i){a[i.identifier]=d(i)}):a[o&&o.pointerId||0]=d(o||i),n=X(a).length>1&&e.zoomable&&e.zoomOnTouch?"zoom":t(i.target).data("action"),k.test(n)&&(this.trigger("cropstart",{originalEvent:o,action:n}).isDefaultPrevented()||(i.preventDefault(),this.action=n,this.cropping=!1,"crop"===n&&(this.cropping=!0,this.$dragBox.addClass("cropper-modal"))))}},cropMove:function(i){var e=this.action;if(!this.disabled&&e){var a=this.pointers,o=i.originalEvent;i.preventDefault(),this.trigger("cropmove",{originalEvent:o,action:e}).isDefaultPrevented()||(o&&o.changedTouches?t.each(o.changedTouches,function(i,e){t.extend(a[e.identifier],d(e,!0))}):t.extend(a[o&&o.pointerId||0],d(o||i,!0)),this.change(i))}},cropEnd:function(i){if(!this.disabled){var e=this.action,a=this.pointers,o=i.originalEvent;o&&o.changedTouches?t.each(o.changedTouches,function(t,i){delete a[i.identifier]}):delete a[o&&o.pointerId||0],e&&(i.preventDefault(),X(a).length||(this.action=""),this.cropping&&(this.cropping=!1,this.$dragBox.toggleClass("cropper-modal",this.cropped&&this.options.modal)),this.trigger("cropend",{originalEvent:o,action:e}))}}},j={change:function(i){var e=this.options,a=this.pointers,o=this.container,n=this.canvas,h=this.cropBox,s=this.action,r=e.aspectRatio,d=h.left,l=h.top,p=h.width,m=h.height,g=d+p,u=l+m,f=0,v=0,w=o.width,x=o.height,b=!0,y=void 0;!r&&i.shiftKey&&(r=p&&m?p/m:1),this.limited&&(f=h.minLeft,v=h.minTop,w=f+Math.min(o.width,n.width,n.left+n.width),x=v+Math.min(o.height,n.height,n.top+n.height));var C=a[X(a)[0]],$={x:C.endX-C.startX,y:C.endY-C.startY},B=function(t){switch(t){case"e":g+$.x>w&&($.x=w-g);break;case"w":d+$.xx&&($.y=x-u)}};switch(s){case"all":d+=$.x,l+=$.y;break;case"e":if($.x>=0&&(g>=w||r&&(l<=v||u>=x))){b=!1;break}B("e"),p+=$.x,r&&(m=p/r,l-=$.x/r/2),p<0&&(s="w",p=0);break;case"n":if($.y<=0&&(l<=v||r&&(d<=f||g>=w))){b=!1;break}B("n"),m-=$.y,l+=$.y,r&&(p=m*r,d+=$.y*r/2),m<0&&(s="s",m=0);break;case"w":if($.x<=0&&(d<=f||r&&(l<=v||u>=x))){b=!1;break}B("w"),p-=$.x,d+=$.x,r&&(m=p/r,l+=$.x/r/2),p<0&&(s="e",p=0);break;case"s":if($.y>=0&&(u>=x||r&&(d<=f||g>=w))){b=!1;break}B("s"),m+=$.y,r&&(p=m*r,d-=$.y*r/2),m<0&&(s="n",m=0);break;case"ne":if(r){if($.y<=0&&(l<=v||g>=w)){b=!1;break}B("n"),m-=$.y,l+=$.y,p=m*r}else B("n"),B("e"),$.x>=0?gv&&(m-=$.y,l+=$.y):(m-=$.y,l+=$.y);p<0&&m<0?(s="sw",m=0,p=0):p<0?(s="nw",p=0):m<0&&(s="se",m=0);break;case"nw":if(r){if($.y<=0&&(l<=v||d<=f)){b=!1;break}B("n"),m-=$.y,l+=$.y,p=m*r,d+=$.y*r}else B("n"),B("w"),$.x<=0?d>f?(p-=$.x,d+=$.x):$.y<=0&&l<=v&&(b=!1):(p-=$.x,d+=$.x),$.y<=0?l>v&&(m-=$.y,l+=$.y):(m-=$.y,l+=$.y);p<0&&m<0?(s="se",m=0,p=0):p<0?(s="ne",p=0):m<0&&(s="sw",m=0);break;case"sw":if(r){if($.x<=0&&(d<=f||u>=x)){b=!1;break}B("w"),p-=$.x,d+=$.x,m=p/r}else B("s"),B("w"),$.x<=0?d>f?(p-=$.x,d+=$.x):$.y>=0&&u>=x&&(b=!1):(p-=$.x,d+=$.x),$.y>=0?u=0&&(g>=w||u>=x)){b=!1;break}B("e"),m=(p+=$.x)/r}else B("s"),B("e"),$.x>=0?g=0&&u>=x&&(b=!1):p+=$.x,$.y>=0?u0?s=$.y>0?"se":"ne":$.x<0&&(d-=p,s=$.y>0?"sw":"nw"),$.y<0&&(l-=m),this.cropped||(this.$cropBox.removeClass(M),this.cropped=!0,this.limited&&this.limitCropBox(!0,!0))}b&&(h.width=p,h.height=m,h.left=d,h.top=l,this.action=s,this.renderCropBox()),t.each(a,function(t,i){i.startX=i.endX,i.startY=i.endY})}},A={crop:function(){this.ready&&!this.disabled&&(this.cropped||(this.cropped=!0,this.limitCropBox(!0,!0),this.options.modal&&this.$dragBox.addClass("cropper-modal"),this.$cropBox.removeClass(M)),this.setCropBoxData(this.initialCropBox))},reset:function(){this.ready&&!this.disabled&&(this.image=t.extend({},this.initialImage),this.canvas=t.extend({},this.initialCanvas),this.cropBox=t.extend({},this.initialCropBox),this.renderCanvas(),this.cropped&&this.renderCropBox())},clear:function(){this.cropped&&!this.disabled&&(t.extend(this.cropBox,{left:0,top:0,width:0,height:0}),this.cropped=!1,this.renderCropBox(),this.limitCanvas(!0,!0),this.renderCanvas(),this.$dragBox.removeClass("cropper-modal"),this.$cropBox.addClass(M))},replace:function(t,i){!this.disabled&&t&&(this.isImg&&this.$element.attr("src",t),i?(this.url=t,this.$clone.attr("src",t),this.ready&&this.$preview.find("img").add(this.$clone2).attr("src",t)):(this.isImg&&(this.replaced=!0),this.options.data=null,this.load(t)))},enable:function(){this.ready&&(this.disabled=!1,this.$cropper.removeClass("cropper-disabled"))},disable:function(){this.ready&&(this.disabled=!0,this.$cropper.addClass("cropper-disabled"))},destroy:function(){var t=this.$element;this.loaded?(this.isImg&&this.replaced&&t.attr("src",this.originalUrl),this.unbuild(),t.removeClass(M)):this.isImg?t.off("load",this.start):this.$clone&&this.$clone.remove(),t.removeData("cropper")},move:function(t,i){var e=this.canvas,o=e.left,n=e.top;this.moveTo(a(t)?t:o+Number(t),a(i)?i:n+Number(i))},moveTo:function(t,i){var o=this.canvas,n=!1;a(i)&&(i=t),t=Number(t),i=Number(i),this.ready&&!this.disabled&&this.options.movable&&(e(t)&&(o.left=t,n=!0),e(i)&&(o.top=i,n=!0),n&&this.renderCanvas(!0))},zoom:function(t,i){var e=this.canvas;t=(t=Number(t))<0?1/(1-t):1+t,this.zoomTo(e.width*t/e.naturalWidth,i)},zoomTo:function(t,i){var e=this.options,a=this.pointers,o=this.canvas,n=o.width,h=o.height,s=o.naturalWidth,r=o.naturalHeight;if((t=Number(t))>=0&&this.ready&&!this.disabled&&e.zoomable){var c=s*t,d=r*t,p=void 0;if(i&&(p=i.originalEvent),this.trigger("zoom",{originalEvent:p,oldRatio:n/s,ratio:c/s}).isDefaultPrevented())return;if(p){var m=this.$cropper.offset(),g=a&&X(a).length?l(a):{pageX:i.pageX||p.pageX||0,pageY:i.pageY||p.pageY||0};o.left-=(c-n)*((g.pageX-m.left-o.left)/n),o.top-=(d-h)*((g.pageY-m.top-o.top)/h)}else o.left-=(c-n)/2,o.top-=(d-h)/2;o.width=c,o.height=d,this.renderCanvas(!0)}},rotate:function(t){this.rotateTo((this.image.rotate||0)+Number(t))},rotateTo:function(t){e(t=Number(t))&&this.ready&&!this.disabled&&this.options.rotatable&&(this.image.rotate=t%360,this.renderCanvas(!0,!0))},scaleX:function(t){var i=this.image.scaleY;this.scale(t,e(i)?i:1)},scaleY:function(t){var i=this.image.scaleX;this.scale(e(i)?i:1,t)},scale:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,a=this.image,o=!1;t=Number(t),i=Number(i),this.ready&&!this.disabled&&this.options.scalable&&(e(t)&&(a.scaleX=t,o=!0),e(i)&&(a.scaleY=i,o=!0),o&&this.renderCanvas(!0,!0))},getData:function(){var i=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.options,a=this.image,o=this.canvas,n=this.cropBox,h=void 0;if(this.ready&&this.cropped){h={x:n.left-o.left,y:n.top-o.top,width:n.width,height:n.height};var s=a.width/a.naturalWidth;t.each(h,function(t,e){e/=s,h[t]=i?Math.round(e):e})}else h={x:0,y:0,width:0,height:0};return e.rotatable&&(h.rotate=a.rotate||0),e.scalable&&(h.scaleX=a.scaleX||1,h.scaleY=a.scaleY||1),h},setData:function(i){var a=this.options,o=this.image,n=this.canvas,h={};if(t.isFunction(i)&&(i=i.call(this.element)),this.ready&&!this.disabled&&t.isPlainObject(i)){var s=!1;a.rotatable&&e(i.rotate)&&i.rotate!==o.rotate&&(o.rotate=i.rotate,s=!0),a.scalable&&(e(i.scaleX)&&i.scaleX!==o.scaleX&&(o.scaleX=i.scaleX,s=!0),e(i.scaleY)&&i.scaleY!==o.scaleY&&(o.scaleY=i.scaleY,s=!0)),s&&this.renderCanvas(!0,!0);var r=o.width/o.naturalWidth;e(i.x)&&(h.left=i.x*r+n.left),e(i.y)&&(h.top=i.y*r+n.top),e(i.width)&&(h.width=i.width*r),e(i.height)&&(h.height=i.height*r),this.setCropBoxData(h)}},getContainerData:function(){return this.ready?t.extend({},this.container):{}},getImageData:function(){return this.loaded?t.extend({},this.image):{}},getCanvasData:function(){var i=this.canvas,e={};return this.ready&&t.each(["left","top","width","height","naturalWidth","naturalHeight"],function(t,a){e[a]=i[a]}),e},setCanvasData:function(i){var a=this.canvas,o=a.aspectRatio;t.isFunction(i)&&(i=i.call(this.$element)),this.ready&&!this.disabled&&t.isPlainObject(i)&&(e(i.left)&&(a.left=i.left),e(i.top)&&(a.top=i.top),e(i.width)?(a.width=i.width,a.height=i.width/o):e(i.height)&&(a.height=i.height,a.width=i.height*o),this.renderCanvas(!0))},getCropBoxData:function(){var t=this.cropBox;return this.ready&&this.cropped?{left:t.left,top:t.top,width:t.width,height:t.height}:{}},setCropBoxData:function(i){var a=this.cropBox,o=this.options.aspectRatio,n=void 0,h=void 0;t.isFunction(i)&&(i=i.call(this.$element)),this.ready&&this.cropped&&!this.disabled&&t.isPlainObject(i)&&(e(i.left)&&(a.left=i.left),e(i.top)&&(a.top=i.top),e(i.width)&&i.width!==a.width&&(n=!0,a.width=i.width),e(i.height)&&i.height!==a.height&&(h=!0,a.height=i.height),o&&(n?a.height=a.width/o:h&&(a.width=a.height*o)),this.renderCropBox())},getCroppedCanvas:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.ready||!window.HTMLCanvasElement)return null;var i=this.canvas,e=g(this.$clone[0],this.image,i,t);if(!this.cropped)return e;var a=this.getData(),o=a.x,n=a.y,h=a.width,s=a.height,r=h/s,c=p({aspectRatio:r,width:t.maxWidth||1/0,height:t.maxHeight||1/0}),d=p({aspectRatio:r,width:t.minWidth||0,height:t.minHeight||0}),l=p({aspectRatio:r,width:t.width||h,height:t.height||s}),m=l.width,u=l.height;m=Math.min(c.width,Math.max(d.width,m)),u=Math.min(c.height,Math.max(d.height,u));var f=document.createElement("canvas"),v=f.getContext("2d");f.width=m,f.height=u,v.fillStyle=t.fillColor||"transparent",v.fillRect(0,0,m,u);var w=t.imageSmoothingEnabled,x=void 0===w||w,b=t.imageSmoothingQuality;v.imageSmoothingEnabled=x,b&&(v.imageSmoothingQuality=b);var y=e.width,M=e.height,C=o,$=n,B=void 0,k=void 0,W=void 0,T=void 0,D=void 0,H=void 0;C<=-h||C>y?(C=0,B=0,W=0,D=0):C<=0?(W=-C,C=0,D=B=Math.min(y,h+C)):C<=y&&(W=0,D=B=Math.min(h,y-C)),B<=0||$<=-s||$>M?($=0,k=0,T=0,H=0):$<=0?(T=-$,$=0,H=k=Math.min(M,s+$)):$<=M&&(T=0,H=k=Math.min(s,M-$));var Y=[Math.floor(C),Math.floor($),Math.floor(B),Math.floor(k)];if(D>0&&H>0){var X=m/h;Y.push(Math.floor(W*X),Math.floor(T*X),Math.floor(D*X),Math.floor(H*X))}return v.drawImage.apply(v,[e].concat(Y)),f},setAspectRatio:function(t){var i=this.options;this.disabled||a(t)||(i.aspectRatio=Math.max(0,t)||NaN,this.ready&&(this.initCropBox(),this.cropped&&this.renderCropBox()))},setDragMode:function(t){var i=this.options,e=void 0,a=void 0;this.loaded&&!this.disabled&&(e="crop"===t,a=i.movable&&"move"===t,t=e||a?t:"none",this.$dragBox.data("action",t).toggleClass("cropper-crop",e).toggleClass("cropper-move",a),i.cropBoxMovable||this.$face.data("action",t).toggleClass("cropper-crop",e).toggleClass("cropper-move",a))}},q=function(){function t(t,i){for(var e=0;e1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,i),!e||!D.test(e.tagName))throw new Error("The first argument is required and must be an or element.");this.element=e,this.$element=t(e),this.options=t.extend({},H,t.isPlainObject(a)&&a),this.completed=!1,this.cropped=!1,this.disabled=!1,this.isImg=!1,this.limited=!1,this.loaded=!1,this.ready=!1,this.replaced=!1,this.wheeling=!1,this.originalUrl="",this.canvas=null,this.cropBox=null,this.pointers={},this.init()}return q(i,[{key:"init",value:function(){var t=this.$element,i=void 0;if(t.is("img")){if(this.isImg=!0,i=t.attr("src"),this.originalUrl=i,!i)return;i=t.prop("src")}else t.is("canvas")&&window.HTMLCanvasElement&&(i=t[0].toDataURL());this.load(i)}},{key:"trigger",value:function(i,e){var a=t.Event(i,e);return this.$element.trigger(a),a}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.image={};var e=this.$element,a=this.options;if(a.checkOrientation&&window.ArrayBuffer)if(W.test(t))T.test(t)?this.read(f(t)):this.clone();else{var o=new XMLHttpRequest;o.onerror=function(){i.clone()},o.onload=function(){i.read(o.response)},a.checkCrossOrigin&&n(t)&&e.prop("crossOrigin")&&(t=h(t)),o.open("get",t),o.responseType="arraybuffer",o.withCredentials="use-credentials"===e.prop("crossOrigin"),o.send()}else this.clone()}}},{key:"read",value:function(t){var i=this.options,e=this.image,a=w(t),o=0,n=1,h=1;if(a>1){this.url=v(t,"image/jpeg");var s=x(a);o=s.rotate,n=s.scaleX,h=s.scaleY}i.rotatable&&(e.rotate=o),i.scalable&&(e.scaleX=n,e.scaleY=h),this.clone()}},{key:"clone",value:function(){var i=this.$element,e=this.options,a=this.url,o="",s=void 0;e.checkCrossOrigin&&n(a)&&((o=i.prop("crossOrigin"))?s=a:(o="anonymous",s=h(a))),this.crossOrigin=o,this.crossOriginUrl=s;var r=document.createElement("img");o&&(r.crossOrigin=o),r.src=s||a;var c=t(r);this.$clone=c,this.isImg?this.element.complete?this.start():i.one("load",t.proxy(this.start,this)):c.one("load",t.proxy(this.start,this)).one("error",t.proxy(this.stop,this)).addClass("cropper-hide").insertAfter(i)}},{key:"start",value:function(){var i=this,e=this.$clone,a=this.$element;this.isImg||(e.off("error",this.stop),a=e),r(a[0],function(e,a){t.extend(i.image,{naturalWidth:e,naturalHeight:a,aspectRatio:e/a}),i.loaded=!0,i.build()})}},{key:"stop",value:function(){this.$clone.remove(),this.$clone=null}},{key:"build",value:function(){var i=this;if(this.loaded){this.ready&&this.unbuild();var e=this.$element,a=this.options,o=this.$clone,n=t('
'),h=n.find(".cropper-crop-box"),s=h.find(".cropper-face");this.$container=e.parent(),this.$cropper=n,this.$canvas=n.find(".cropper-canvas").append(o),this.$dragBox=n.find(".cropper-drag-box"),this.$cropBox=h,this.$viewBox=n.find(".cropper-view-box"),this.$face=s,e.addClass(M).after(n),this.isImg||o.removeClass("cropper-hide"),this.initPreview(),this.bind(),a.aspectRatio=Math.max(0,a.aspectRatio)||NaN,a.viewMode=Math.max(0,Math.min(3,Math.round(a.viewMode)))||0,this.cropped=a.autoCrop,a.autoCrop?a.modal&&this.$dragBox.addClass("cropper-modal"):h.addClass(M),a.guides||h.find(".cropper-dashed").addClass(M),a.center||h.find(".cropper-center").addClass(M),a.cropBoxMovable&&s.addClass("cropper-move").data("action","all"),a.highlight||s.addClass("cropper-invisible"),a.background&&n.addClass("cropper-bg"),a.cropBoxResizable||h.find(".cropper-line,.cropper-point").addClass(M),this.setDragMode(a.dragMode),this.render(),this.ready=!0,this.setData(a.data),this.completing=setTimeout(function(){t.isFunction(a.ready)&&e.one("ready",a.ready),i.trigger("ready"),i.trigger("crop",i.getData()),i.completed=!0},0)}}},{key:"unbuild",value:function(){this.ready&&(this.completed||clearTimeout(this.completing),this.ready=!1,this.completed=!1,this.initialImage=null,this.initialCanvas=null,this.initialCropBox=null,this.container=null,this.canvas=null,this.cropBox=null,this.unbind(),this.resetPreview(),this.$preview=null,this.$viewBox=null,this.$cropBox=null,this.$dragBox=null,this.$canvas=null,this.$container=null,this.$cropper.remove(),this.$cropper=null)}}],[{key:"setDefaults",value:function(i){t.extend(H,t.isPlainObject(i)&&i)}}]),i}();t.extend(Q.prototype,P,U,F,S,j,A);var K=t.fn.cropper;t.fn.cropper=function(e){for(var o=arguments.length,n=Array(o>1?o-1:0),h=1;h2?e-2:0),o=2;o0};return o(a)&&o(e)?e*i>a?e=a/i:a=e*i:o(a)?e=a/i:o(e)&&(a=e*i),{width:a,height:e}}function m(t){var i=t.width,e=t.height,a=t.degree;if((a=Math.abs(a))%180==90)return{width:e,height:i};var o=a%90*Math.PI/180,n=Math.sin(o),h=Math.cos(o);return{width:i*h+e*n,height:i*n+e*h}}function g(t,i,e,a){var o=i.naturalWidth,n=i.naturalHeight,h=i.rotate,s=i.scaleX,r=i.scaleY,c=e.aspectRatio,d=e.naturalWidth,l=e.naturalHeight,m=a.fillColor,g=void 0===m?"transparent":m,u=a.imageSmoothingEnabled,f=void 0===u||u,v=a.imageSmoothingQuality,w=void 0===v?"low":v,x=a.maxWidth,b=void 0===x?1/0:x,y=a.maxHeight,M=void 0===y?1/0:y,C=a.minWidth,$=void 0===C?0:C,B=a.minHeight,k=void 0===B?0:B,W=p({aspectRatio:c,width:b,height:M}),T=p({aspectRatio:c,width:$,height:k}),D=Math.min(W.width,Math.max(T.width,d)),H=Math.min(W.height,Math.max(T.height,l)),Y=document.createElement("canvas"),X=Y.getContext("2d");return Y.width=D,Y.height=H,X.fillStyle=g,X.fillRect(0,0,D,H),X.save(),X.translate(D/2,H/2),X.rotate(h*Math.PI/180),X.scale(s,r),X.imageSmoothingEnabled=!!f,X.imageSmoothingQuality=w,X.drawImage(t,Math.floor(-o/2),Math.floor(-n/2),Math.floor(o),Math.floor(n)),X.restore(),Y}function u(t,i,e){var a="",o=void 0;for(e+=i,o=i;o=8&&(n=r+d)}}}if(n){var l=i.getUint16(n,a),p=void 0,m=void 0;for(m=0;mi.width?3===a?r=i.height*s:c=i.width/s:3===a?c=i.width/s:r=i.height*s;var d={aspectRatio:s,naturalWidth:n,naturalHeight:h,width:r,height:c};d.left=(i.width-r)/2,d.top=(i.height-c)/2,d.oldLeft=d.left,d.oldTop=d.top,this.canvas=d,this.limited=1===a||2===a,this.limitCanvas(!0,!0),this.initialImage=t.extend({},e),this.initialCanvas=t.extend({},d)},limitCanvas:function(t,i){var e=this.options,a=this.container,o=this.canvas,n=this.cropBox,h=e.viewMode,s=o.aspectRatio,r=this.cropped&&n;if(t){var c=Number(e.minCanvasWidth)||0,d=Number(e.minCanvasHeight)||0;h>0&&(h>1?(c=Math.max(c,a.width),d=Math.max(d,a.height),3===h&&(d*s>c?c=d*s:d=c/s)):c?c=Math.max(c,r?n.width:0):d?d=Math.max(d,r?n.height:0):r&&(c=n.width,(d=n.height)*s>c?c=d*s:d=c/s));var l=p({aspectRatio:s,width:c,height:d});c=l.width,d=l.height,o.minWidth=c,o.minHeight=d,o.maxWidth=1/0,o.maxHeight=1/0}if(i)if(h>0){var m=a.width-o.width,g=a.height-o.height;o.minLeft=Math.min(0,m),o.minTop=Math.min(0,g),o.maxLeft=Math.max(0,m),o.maxTop=Math.max(0,g),r&&this.limited&&(o.minLeft=Math.min(n.left,n.left+n.width-o.width),o.minTop=Math.min(n.top,n.top+n.height-o.height),o.maxLeft=n.left,o.maxTop=n.top,2===h&&(o.width>=a.width&&(o.minLeft=Math.min(0,m),o.maxLeft=Math.max(0,m)),o.height>=a.height&&(o.minTop=Math.min(0,g),o.maxTop=Math.max(0,g))))}else o.minLeft=-o.width,o.minTop=-o.height,o.maxLeft=a.width,o.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvas,a=this.image;if(i){var o=m({width:a.naturalWidth*Math.abs(a.scaleX),height:a.naturalHeight*Math.abs(a.scaleY),degree:a.rotate}),n=o.width,h=o.height,r=e.width*(n/e.naturalWidth),c=e.height*(h/e.naturalHeight);e.left-=(r-e.width)/2,e.top-=(c-e.height)/2,e.width=r,e.height=c,e.aspectRatio=n/h,e.naturalWidth=n,e.naturalHeight=h,this.limitCanvas(!0,!1)}(e.width>e.maxWidth||e.widthe.maxHeight||e.heighte.width?n.height=n.width/a:n.width=n.height*a),this.cropBox=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*o),n.height=Math.max(n.minHeight,n.height*o),n.left=e.left+(e.width-n.width)/2,n.top=e.top+(e.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBox=t.extend({},n)},limitCropBox:function(t,i){var e=this.options,a=this.container,o=this.canvas,n=this.cropBox,h=this.limited,s=e.aspectRatio;if(t){var r=Number(e.minCropBoxWidth)||0,c=Number(e.minCropBoxHeight)||0,d=Math.min(a.width,h?o.width:a.width),l=Math.min(a.height,h?o.height:a.height);r=Math.min(r,a.width),c=Math.min(c,a.height),s&&(r&&c?c*s>r?c=r/s:r=c*s:r?c=r/s:c&&(r=c*s),l*s>d?l=d/s:d=l*s),n.minWidth=Math.min(r,d),n.minHeight=Math.min(c,l),n.maxWidth=d,n.maxHeight=l}i&&(h?(n.minLeft=Math.max(0,o.left),n.minTop=Math.max(0,o.top),n.maxLeft=Math.min(a.width,o.left+o.width)-n.width,n.maxTop=Math.min(a.height,o.top+o.height)-n.height):(n.minLeft=0,n.minTop=0,n.maxLeft=a.width-n.width,n.maxTop=a.height-n.height))},renderCropBox:function(){var t=this.options,i=this.container,e=this.cropBox;(e.width>e.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?"move":"all"),this.$cropBox.css({width:e.width,height:e.height,transform:s({translateX:e.left,translateY:e.top})}),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),this.completed&&this.trigger("crop",this.getData())}},U={initPreview:function(){var i=this.crossOrigin,e=i?this.crossOriginUrl:this.url,a=document.createElement("img");i&&(a.crossOrigin=i),a.src=e;var o=t(a);this.$preview=t(this.options.preview),this.$clone2=o,this.$viewBox.html(o),this.$preview.each(function(a,o){var n=t(o),h=document.createElement("img");n.data("preview",{width:n.width(),height:n.height(),html:n.html()}),i&&(h.crossOrigin=i),h.src=e,h.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',n.html(h)})},resetPreview:function(){this.$preview.each(function(i,e){var a=t(e),o=a.data("preview");a.css({width:o.width,height:o.height}).html(o.html).removeData("preview")})},preview:function(){var i=this.image,e=this.canvas,a=this.cropBox,o=a.width,n=a.height,h=i.width,r=i.height,c=a.left-e.left-i.left,d=a.top-e.top-i.top;this.cropped&&!this.disabled&&(this.$clone2.css({width:h,height:r,transform:s(t.extend({translateX:-c,translateY:-d},i))}),this.$preview.each(function(e,a){var l=t(a),p=l.data("preview"),m=p.width,g=p.height,u=m,f=g,v=1;o&&(f=n*(v=m/o)),n&&f>g&&(u=o*(v=g/n),f=g),l.css({width:u,height:f}).find("img").css({width:h*v,height:r*v,transform:s(t.extend({translateX:-c*v,translateY:-d*v},i))})}))}},F={bind:function(){var i=this.$element,e=this.options,a=this.$cropper;t.isFunction(e.cropstart)&&i.on("cropstart",e.cropstart),t.isFunction(e.cropmove)&&i.on("cropmove",e.cropmove),t.isFunction(e.cropend)&&i.on("cropend",e.cropend),t.isFunction(e.crop)&&i.on("crop",e.crop),t.isFunction(e.zoom)&&i.on("zoom",e.zoom),a.on(C,o(this.cropStart,this)),e.zoomable&&e.zoomOnWheel&&a.on("wheel mousewheel DOMMouseScroll",o(this.wheel,this)),e.toggleDragModeOnDblclick&&a.on("dblclick",o(this.dblclick,this)),t(document).on($,this.onCropMove=o(this.cropMove,this)).on(B,this.onCropEnd=o(this.cropEnd,this)),e.responsive&&t(y).on("resize",this.onResize=o(this.resize,this))},unbind:function(){var i=this.$element,e=this.options,a=this.$cropper;t.isFunction(e.cropstart)&&i.off("cropstart",e.cropstart),t.isFunction(e.cropmove)&&i.off("cropmove",e.cropmove),t.isFunction(e.cropend)&&i.off("cropend",e.cropend),t.isFunction(e.crop)&&i.off("crop",e.crop),t.isFunction(e.zoom)&&i.off("zoom",e.zoom),a.off(C,this.cropStart),e.zoomable&&e.zoomOnWheel&&a.off("wheel mousewheel DOMMouseScroll",this.wheel),e.toggleDragModeOnDblclick&&a.off("dblclick",this.dblclick),t(document).off($,this.onCropMove).off(B,this.onCropEnd),e.responsive&&t(y).off("resize",this.onResize)}},S={resize:function(){var i=this.options,e=this.$container,a=this.container,o=Number(i.minContainerWidth)||200,n=Number(i.minContainerHeight)||100;if(!(this.disabled||a.width<=o||a.height<=n)){var h=e.width()/a.width;if(1!==h||e.height()!==a.height){var s=void 0,r=void 0;i.restore&&(s=this.getCanvasData(),r=this.getCropBoxData()),this.render(),i.restore&&(this.setCanvasData(t.each(s,function(t,i){s[t]=i*h})),this.setCropBoxData(t.each(r,function(t,i){r[t]=i*h})))}}},dblclick:function(){this.disabled||"none"===this.options.dragMode||this.setDragMode(this.$dragBox.hasClass("cropper-crop")?"move":"crop")},wheel:function(t){var i=this,e=t.originalEvent||t,a=Number(this.options.wheelZoomRatio)||.1;if(!this.disabled&&(t.preventDefault(),!this.wheeling)){this.wheeling=!0,setTimeout(function(){i.wheeling=!1},50);var o=1;e.deltaY?o=e.deltaY>0?1:-1:e.wheelDelta?o=-e.wheelDelta/120:e.detail&&(o=e.detail>0?1:-1),this.zoom(-o*a,t)}},cropStart:function(i){if(!this.disabled){var e=this.options,a=this.pointers,o=i.originalEvent,n=void 0;o&&o.changedTouches?t.each(o.changedTouches,function(t,i){a[i.identifier]=d(i)}):a[o&&o.pointerId||0]=d(o||i),n=X(a).length>1&&e.zoomable&&e.zoomOnTouch?"zoom":t(i.target).data("action"),k.test(n)&&(this.trigger("cropstart",{originalEvent:o,action:n}).isDefaultPrevented()||(i.preventDefault(),this.action=n,this.cropping=!1,"crop"===n&&(this.cropping=!0,this.$dragBox.addClass("cropper-modal"))))}},cropMove:function(i){var e=this.action;if(!this.disabled&&e){var a=this.pointers,o=i.originalEvent;i.preventDefault(),this.trigger("cropmove",{originalEvent:o,action:e}).isDefaultPrevented()||(o&&o.changedTouches?t.each(o.changedTouches,function(i,e){t.extend(a[e.identifier],d(e,!0))}):t.extend(a[o&&o.pointerId||0],d(o||i,!0)),this.change(i))}},cropEnd:function(i){if(!this.disabled){var e=this.action,a=this.pointers,o=i.originalEvent;o&&o.changedTouches?t.each(o.changedTouches,function(t,i){delete a[i.identifier]}):delete a[o&&o.pointerId||0],e&&(i.preventDefault(),X(a).length||(this.action=""),this.cropping&&(this.cropping=!1,this.$dragBox.toggleClass("cropper-modal",this.cropped&&this.options.modal)),this.trigger("cropend",{originalEvent:o,action:e}))}}},j={change:function(i){var e=this.options,a=this.pointers,o=this.container,n=this.canvas,h=this.cropBox,s=this.action,r=e.aspectRatio,d=h.left,l=h.top,p=h.width,m=h.height,g=d+p,u=l+m,f=0,v=0,w=o.width,x=o.height,b=!0,y=void 0;!r&&i.shiftKey&&(r=p&&m?p/m:1),this.limited&&(f=h.minLeft,v=h.minTop,w=f+Math.min(o.width,n.width,n.left+n.width),x=v+Math.min(o.height,n.height,n.top+n.height));var C=a[X(a)[0]],$={x:C.endX-C.startX,y:C.endY-C.startY},B=function(t){switch(t){case"e":g+$.x>w&&($.x=w-g);break;case"w":d+$.xx&&($.y=x-u)}};switch(s){case"all":d+=$.x,l+=$.y;break;case"e":if($.x>=0&&(g>=w||r&&(l<=v||u>=x))){b=!1;break}B("e"),p+=$.x,r&&(m=p/r,l-=$.x/r/2),p<0&&(s="w",p=0);break;case"n":if($.y<=0&&(l<=v||r&&(d<=f||g>=w))){b=!1;break}B("n"),m-=$.y,l+=$.y,r&&(p=m*r,d+=$.y*r/2),m<0&&(s="s",m=0);break;case"w":if($.x<=0&&(d<=f||r&&(l<=v||u>=x))){b=!1;break}B("w"),p-=$.x,d+=$.x,r&&(m=p/r,l+=$.x/r/2),p<0&&(s="e",p=0);break;case"s":if($.y>=0&&(u>=x||r&&(d<=f||g>=w))){b=!1;break}B("s"),m+=$.y,r&&(p=m*r,d-=$.y*r/2),m<0&&(s="n",m=0);break;case"ne":if(r){if($.y<=0&&(l<=v||g>=w)){b=!1;break}B("n"),m-=$.y,l+=$.y,p=m*r}else B("n"),B("e"),$.x>=0?gv&&(m-=$.y,l+=$.y):(m-=$.y,l+=$.y);p<0&&m<0?(s="sw",m=0,p=0):p<0?(s="nw",p=0):m<0&&(s="se",m=0);break;case"nw":if(r){if($.y<=0&&(l<=v||d<=f)){b=!1;break}B("n"),m-=$.y,l+=$.y,p=m*r,d+=$.y*r}else B("n"),B("w"),$.x<=0?d>f?(p-=$.x,d+=$.x):$.y<=0&&l<=v&&(b=!1):(p-=$.x,d+=$.x),$.y<=0?l>v&&(m-=$.y,l+=$.y):(m-=$.y,l+=$.y);p<0&&m<0?(s="se",m=0,p=0):p<0?(s="ne",p=0):m<0&&(s="sw",m=0);break;case"sw":if(r){if($.x<=0&&(d<=f||u>=x)){b=!1;break}B("w"),p-=$.x,d+=$.x,m=p/r}else B("s"),B("w"),$.x<=0?d>f?(p-=$.x,d+=$.x):$.y>=0&&u>=x&&(b=!1):(p-=$.x,d+=$.x),$.y>=0?u=0&&(g>=w||u>=x)){b=!1;break}B("e"),m=(p+=$.x)/r}else B("s"),B("e"),$.x>=0?g=0&&u>=x&&(b=!1):p+=$.x,$.y>=0?u0?s=$.y>0?"se":"ne":$.x<0&&(d-=p,s=$.y>0?"sw":"nw"),$.y<0&&(l-=m),this.cropped||(this.$cropBox.removeClass(M),this.cropped=!0,this.limited&&this.limitCropBox(!0,!0))}b&&(h.width=p,h.height=m,h.left=d,h.top=l,this.action=s,this.renderCropBox()),t.each(a,function(t,i){i.startX=i.endX,i.startY=i.endY})}},A={crop:function(){this.ready&&!this.disabled&&(this.cropped||(this.cropped=!0,this.limitCropBox(!0,!0),this.options.modal&&this.$dragBox.addClass("cropper-modal"),this.$cropBox.removeClass(M)),this.setCropBoxData(this.initialCropBox))},reset:function(){this.ready&&!this.disabled&&(this.image=t.extend({},this.initialImage),this.canvas=t.extend({},this.initialCanvas),this.cropBox=t.extend({},this.initialCropBox),this.renderCanvas(),this.cropped&&this.renderCropBox())},clear:function(){this.cropped&&!this.disabled&&(t.extend(this.cropBox,{left:0,top:0,width:0,height:0}),this.cropped=!1,this.renderCropBox(),this.limitCanvas(!0,!0),this.renderCanvas(),this.$dragBox.removeClass("cropper-modal"),this.$cropBox.addClass(M))},replace:function(t,i){!this.disabled&&t&&(this.isImg&&this.$element.attr("src",t),i?(this.url=t,this.$clone.attr("src",t),this.ready&&this.$preview.find("img").add(this.$clone2).attr("src",t)):(this.isImg&&(this.replaced=!0),this.options.data=null,this.load(t)))},enable:function(){this.ready&&(this.disabled=!1,this.$cropper.removeClass("cropper-disabled"))},disable:function(){this.ready&&(this.disabled=!0,this.$cropper.addClass("cropper-disabled"))},destroy:function(){var t=this.$element;this.loaded?(this.isImg&&this.replaced&&t.attr("src",this.originalUrl),this.unbuild(),t.removeClass(M)):this.isImg?t.off("load",this.start):this.$clone&&this.$clone.remove(),t.removeData("cropper")},move:function(t,i){var e=this.canvas,o=e.left,n=e.top;this.moveTo(a(t)?t:o+Number(t),a(i)?i:n+Number(i))},moveTo:function(t,i){var o=this.canvas,n=!1;a(i)&&(i=t),t=Number(t),i=Number(i),this.ready&&!this.disabled&&this.options.movable&&(e(t)&&(o.left=t,n=!0),e(i)&&(o.top=i,n=!0),n&&this.renderCanvas(!0))},zoom:function(t,i){var e=this.canvas;t=(t=Number(t))<0?1/(1-t):1+t,this.zoomTo(e.width*t/e.naturalWidth,i)},zoomTo:function(t,i){var e=this.options,a=this.pointers,o=this.canvas,n=o.width,h=o.height,s=o.naturalWidth,r=o.naturalHeight;if((t=Number(t))>=0&&this.ready&&!this.disabled&&e.zoomable){var c=s*t,d=r*t,p=void 0;if(i&&(p=i.originalEvent),this.trigger("zoom",{originalEvent:p,oldRatio:n/s,ratio:c/s}).isDefaultPrevented())return;if(p){var m=this.$cropper.offset(),g=a&&X(a).length?l(a):{pageX:i.pageX||p.pageX||0,pageY:i.pageY||p.pageY||0};o.left-=(c-n)*((g.pageX-m.left-o.left)/n),o.top-=(d-h)*((g.pageY-m.top-o.top)/h)}else o.left-=(c-n)/2,o.top-=(d-h)/2;o.width=c,o.height=d,this.renderCanvas(!0)}},rotate:function(t){this.rotateTo((this.image.rotate||0)+Number(t))},rotateTo:function(t){e(t=Number(t))&&this.ready&&!this.disabled&&this.options.rotatable&&(this.image.rotate=t%360,this.renderCanvas(!0,!0))},scaleX:function(t){var i=this.image.scaleY;this.scale(t,e(i)?i:1)},scaleY:function(t){var i=this.image.scaleX;this.scale(e(i)?i:1,t)},scale:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,a=this.image,o=!1;t=Number(t),i=Number(i),this.ready&&!this.disabled&&this.options.scalable&&(e(t)&&(a.scaleX=t,o=!0),e(i)&&(a.scaleY=i,o=!0),o&&this.renderCanvas(!0,!0))},getData:function(){var i=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.options,a=this.image,o=this.canvas,n=this.cropBox,h=void 0;if(this.ready&&this.cropped){h={x:n.left-o.left,y:n.top-o.top,width:n.width,height:n.height};var s=a.width/a.naturalWidth;t.each(h,function(t,e){e/=s,h[t]=i?Math.round(e):e})}else h={x:0,y:0,width:0,height:0};return e.rotatable&&(h.rotate=a.rotate||0),e.scalable&&(h.scaleX=a.scaleX||1,h.scaleY=a.scaleY||1),h},setData:function(i){var a=this.options,o=this.image,n=this.canvas,h={};if(t.isFunction(i)&&(i=i.call(this.element)),this.ready&&!this.disabled&&t.isPlainObject(i)){var s=!1;a.rotatable&&e(i.rotate)&&i.rotate!==o.rotate&&(o.rotate=i.rotate,s=!0),a.scalable&&(e(i.scaleX)&&i.scaleX!==o.scaleX&&(o.scaleX=i.scaleX,s=!0),e(i.scaleY)&&i.scaleY!==o.scaleY&&(o.scaleY=i.scaleY,s=!0)),s&&this.renderCanvas(!0,!0);var r=o.width/o.naturalWidth;e(i.x)&&(h.left=i.x*r+n.left),e(i.y)&&(h.top=i.y*r+n.top),e(i.width)&&(h.width=i.width*r),e(i.height)&&(h.height=i.height*r),this.setCropBoxData(h)}},getContainerData:function(){return this.ready?t.extend({},this.container):{}},getImageData:function(){return this.loaded?t.extend({},this.image):{}},getCanvasData:function(){var i=this.canvas,e={};return this.ready&&t.each(["left","top","width","height","naturalWidth","naturalHeight"],function(t,a){e[a]=i[a]}),e},setCanvasData:function(i){var a=this.canvas,o=a.aspectRatio;t.isFunction(i)&&(i=i.call(this.$element)),this.ready&&!this.disabled&&t.isPlainObject(i)&&(e(i.left)&&(a.left=i.left),e(i.top)&&(a.top=i.top),e(i.width)?(a.width=i.width,a.height=i.width/o):e(i.height)&&(a.height=i.height,a.width=i.height*o),this.renderCanvas(!0))},getCropBoxData:function(){var t=this.cropBox;return this.ready&&this.cropped?{left:t.left,top:t.top,width:t.width,height:t.height}:{}},setCropBoxData:function(i){var a=this.cropBox,o=this.options.aspectRatio,n=void 0,h=void 0;t.isFunction(i)&&(i=i.call(this.$element)),this.ready&&this.cropped&&!this.disabled&&t.isPlainObject(i)&&(e(i.left)&&(a.left=i.left),e(i.top)&&(a.top=i.top),e(i.width)&&i.width!==a.width&&(n=!0,a.width=i.width),e(i.height)&&i.height!==a.height&&(h=!0,a.height=i.height),o&&(n?a.height=a.width/o:h&&(a.width=a.height*o)),this.renderCropBox())},getCroppedCanvas:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.ready||!y.HTMLCanvasElement)return null;var i=this.canvas,e=g(this.$clone[0],this.image,i,t);if(!this.cropped)return e;var a=this.getData(),o=a.x,n=a.y,h=a.width,s=a.height,r=h/s,c=p({aspectRatio:r,width:t.maxWidth||1/0,height:t.maxHeight||1/0}),d=p({aspectRatio:r,width:t.minWidth||0,height:t.minHeight||0}),l=p({aspectRatio:r,width:t.width||h,height:t.height||s}),m=l.width,u=l.height;m=Math.min(c.width,Math.max(d.width,m)),u=Math.min(c.height,Math.max(d.height,u));var f=document.createElement("canvas"),v=f.getContext("2d");f.width=m,f.height=u,v.fillStyle=t.fillColor||"transparent",v.fillRect(0,0,m,u);var w=t.imageSmoothingEnabled,x=void 0===w||w,b=t.imageSmoothingQuality;v.imageSmoothingEnabled=x,b&&(v.imageSmoothingQuality=b);var M=e.width,C=e.height,$=o,B=n,k=void 0,W=void 0,T=void 0,D=void 0,H=void 0,Y=void 0;$<=-h||$>M?($=0,k=0,T=0,H=0):$<=0?(T=-$,$=0,H=k=Math.min(M,h+$)):$<=M&&(T=0,H=k=Math.min(h,M-$)),k<=0||B<=-s||B>C?(B=0,W=0,D=0,Y=0):B<=0?(D=-B,B=0,Y=W=Math.min(C,s+B)):B<=C&&(D=0,Y=W=Math.min(s,C-B));var X=[Math.floor($),Math.floor(B),Math.floor(k),Math.floor(W)];if(H>0&&Y>0){var O=m/h;X.push(Math.floor(T*O),Math.floor(D*O),Math.floor(H*O),Math.floor(Y*O))}return v.drawImage.apply(v,[e].concat(X)),f},setAspectRatio:function(t){var i=this.options;this.disabled||a(t)||(i.aspectRatio=Math.max(0,t)||NaN,this.ready&&(this.initCropBox(),this.cropped&&this.renderCropBox()))},setDragMode:function(t){var i=this.options,e=void 0,a=void 0;this.loaded&&!this.disabled&&(e="crop"===t,a=i.movable&&"move"===t,t=e||a?t:"none",this.$dragBox.data("action",t).toggleClass("cropper-crop",e).toggleClass("cropper-move",a),i.cropBoxMovable||this.$face.data("action",t).toggleClass("cropper-crop",e).toggleClass("cropper-move",a))}},q=function(){function t(t,i){for(var e=0;e1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,i),!e||!D.test(e.tagName))throw new Error("The first argument is required and must be an or element.");this.element=e,this.$element=t(e),this.options=t.extend({},H,t.isPlainObject(a)&&a),this.completed=!1,this.cropped=!1,this.disabled=!1,this.isImg=!1,this.limited=!1,this.loaded=!1,this.ready=!1,this.replaced=!1,this.wheeling=!1,this.originalUrl="",this.canvas=null,this.cropBox=null,this.pointers={},this.init()}return q(i,[{key:"init",value:function(){var t=this.$element,i=void 0;if(t.is("img")){if(this.isImg=!0,i=t.attr("src")||"",this.originalUrl=i,!i)return;i=t.prop("src")}else t.is("canvas")&&y.HTMLCanvasElement&&(i=t[0].toDataURL());this.load(i)}},{key:"trigger",value:function(i,e){var a=t.Event(i,e);return this.$element.trigger(a),a}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.image={};var e=this.$element,a=this.options;if(a.checkOrientation&&y.ArrayBuffer)if(W.test(t))T.test(t)?this.read(f(t)):this.clone();else{var o=new XMLHttpRequest;o.onerror=function(){i.clone()},o.onload=function(){i.read(o.response)},a.checkCrossOrigin&&n(t)&&e.prop("crossOrigin")&&(t=h(t)),o.open("get",t),o.responseType="arraybuffer",o.withCredentials="use-credentials"===e.prop("crossOrigin"),o.send()}else this.clone()}}},{key:"read",value:function(t){var i=this.options,e=this.image,a=w(t),o=0,n=1,h=1;if(a>1){this.url=v(t,"image/jpeg");var s=x(a);o=s.rotate,n=s.scaleX,h=s.scaleY}i.rotatable&&(e.rotate=o),i.scalable&&(e.scaleX=n,e.scaleY=h),this.clone()}},{key:"clone",value:function(){var i=this.$element,e=this.options,a=this.url,o="",s=void 0;e.checkCrossOrigin&&n(a)&&((o=i.prop("crossOrigin"))?s=a:(o="anonymous",s=h(a))),this.crossOrigin=o,this.crossOriginUrl=s;var r=document.createElement("img");o&&(r.crossOrigin=o),r.src=s||a;var c=t(r);this.$clone=c,this.isImg?this.element.complete?this.start():i.one("load",t.proxy(this.start,this)):c.one("load",t.proxy(this.start,this)).one("error",t.proxy(this.stop,this)).addClass("cropper-hide").insertAfter(i)}},{key:"start",value:function(){var i=this,e=this.$clone,a=this.$element;this.isImg||(e.off("error",this.stop),a=e),r(a[0],function(e,a){t.extend(i.image,{naturalWidth:e,naturalHeight:a,aspectRatio:e/a}),i.loaded=!0,i.build()})}},{key:"stop",value:function(){this.$clone.remove(),this.$clone=null}},{key:"build",value:function(){var i=this;if(this.loaded){this.ready&&this.unbuild();var e=this.$element,a=this.options,o=this.$clone,n=t('
'),h=n.find(".cropper-crop-box"),s=h.find(".cropper-face");this.$container=e.parent(),this.$cropper=n,this.$canvas=n.find(".cropper-canvas").append(o),this.$dragBox=n.find(".cropper-drag-box"),this.$cropBox=h,this.$viewBox=n.find(".cropper-view-box"),this.$face=s,e.addClass(M).after(n),this.isImg||o.removeClass("cropper-hide"),this.initPreview(),this.bind(),a.aspectRatio=Math.max(0,a.aspectRatio)||NaN,a.viewMode=Math.max(0,Math.min(3,Math.round(a.viewMode)))||0,this.cropped=a.autoCrop,a.autoCrop?a.modal&&this.$dragBox.addClass("cropper-modal"):h.addClass(M),a.guides||h.find(".cropper-dashed").addClass(M),a.center||h.find(".cropper-center").addClass(M),a.cropBoxMovable&&s.addClass("cropper-move").data("action","all"),a.highlight||s.addClass("cropper-invisible"),a.background&&n.addClass("cropper-bg"),a.cropBoxResizable||h.find(".cropper-line,.cropper-point").addClass(M),this.setDragMode(a.dragMode),this.render(),this.ready=!0,this.setData(a.data),this.completing=setTimeout(function(){t.isFunction(a.ready)&&e.one("ready",a.ready),i.trigger("ready"),i.trigger("crop",i.getData()),i.completed=!0},0)}}},{key:"unbuild",value:function(){this.ready&&(this.completed||clearTimeout(this.completing),this.ready=!1,this.completed=!1,this.initialImage=null,this.initialCanvas=null,this.initialCropBox=null,this.container=null,this.canvas=null,this.cropBox=null,this.unbind(),this.resetPreview(),this.$preview=null,this.$viewBox=null,this.$cropBox=null,this.$dragBox=null,this.$canvas=null,this.$container=null,this.$cropper.remove(),this.$cropper=null)}}],[{key:"setDefaults",value:function(i){t.extend(H,t.isPlainObject(i)&&i)}}]),i}();if(t.extend&&t.extend(Q.prototype,I,U,F,S,j,A),t.fn){var K=t.fn.cropper;t.fn.cropper=function(e){for(var o=arguments.length,n=Array(o>1?o-1:0),h=1;h - + Cropper @@ -49,7 +49,7 @@
-

Cropper v3.1.0

+

Cropper v3.1.1

A simple jQuery image cropping plugin.

diff --git a/docs/js/cropper.js b/docs/js/cropper.js index 843a202d..86e7c826 100644 --- a/docs/js/cropper.js +++ b/docs/js/cropper.js @@ -1,11 +1,11 @@ /*! - * Cropper v3.1.0 + * Cropper v3.1.1 * https://github.com/fengyuanchen/cropper * - * Copyright (c) 2014-2017 Fengyuan Chen + * Copyright (c) 2014-2017 Chen Fengyuan * Released under the MIT license * - * Date: 2017-10-08T08:56:38.353Z + * Date: 2017-10-11T13:34:24.201Z */ (function (global, factory) { @@ -16,9 +16,7 @@ $ = $ && $.hasOwnProperty('default') ? $['default'] : $; -var _window = window; -var PointerEvent = _window.PointerEvent; - +var global = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'cropper'; @@ -62,9 +60,9 @@ var EVENT_CROP_START = 'cropstart'; var EVENT_DBLCLICK = 'dblclick'; var EVENT_ERROR = 'error'; var EVENT_LOAD = 'load'; -var EVENT_POINTER_DOWN = PointerEvent ? 'pointerdown' : 'touchstart mousedown'; -var EVENT_POINTER_MOVE = PointerEvent ? 'pointermove' : 'touchmove mousemove'; -var EVENT_POINTER_UP = PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; +var EVENT_POINTER_DOWN = global.PointerEvent ? 'pointerdown' : 'touchstart mousedown'; +var EVENT_POINTER_MOVE = global.PointerEvent ? 'pointermove' : 'touchmove mousemove'; +var EVENT_POINTER_UP = global.PointerEvent ? ' pointerup pointercancel' : 'touchend touchcancel mouseup'; var EVENT_READY = 'ready'; var EVENT_RESIZE = 'resize'; var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll'; @@ -186,7 +184,7 @@ function isString(value) { /** * Check if the given value is not a number. */ -var isNaN = Number.isNaN || window.isNaN; +var isNaN = Number.isNaN || global.isNaN; /** * Check if the given value is a number. @@ -242,8 +240,7 @@ var objectKeys = Object.keys || function objectKeys(obj) { return keys; }; -var _window$1 = window; -var location = _window$1.location; +var location = global.location; var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i; @@ -307,6 +304,8 @@ function getTransformValues(_ref) { return values.length ? values.join(' ') : 'none'; } +var navigator = global.navigator; + var IS_SAFARI_OR_UIWEBVIEW = navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent); /** @@ -418,7 +417,7 @@ function getPointersCenter(pointers) { /** * Check if the given value is a finite number. */ -var isFinite = Number.isFinite || window.isFinite; +var isFinite = Number.isFinite || global.isFinite; /** * Get the max sizes in a rectangle under the given aspect ratio. @@ -566,9 +565,6 @@ function getStringFromCharCode(dataView, start, length) { return str; } -var _window2 = window; -var atob = _window2.atob; - var REGEXP_DATA_URL_HEAD = /^data:.*,/; /** @@ -1302,7 +1298,7 @@ var events = { $(document).on(EVENT_POINTER_MOVE, this.onCropMove = proxy(this.cropMove, this)).on(EVENT_POINTER_UP, this.onCropEnd = proxy(this.cropEnd, this)); if (options.responsive) { - $(window).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); + $(global).on(EVENT_RESIZE, this.onResize = proxy(this.resize, this)); } }, unbind: function unbind() { @@ -1344,7 +1340,7 @@ var events = { $(document).off(EVENT_POINTER_MOVE, this.onCropMove).off(EVENT_POINTER_UP, this.onCropEnd); if (options.responsive) { - $(window).off(EVENT_RESIZE, this.onResize); + $(global).off(EVENT_RESIZE, this.onResize); } } }; @@ -2584,7 +2580,7 @@ var methods = { getCroppedCanvas: function getCroppedCanvas() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - if (!this.ready || !window.HTMLCanvasElement) { + if (!this.ready || !global.HTMLCanvasElement) { return null; } @@ -2808,7 +2804,7 @@ var Cropper = function () { this.isImg = true; // Should use `$.fn.attr` here. e.g.: "img/picture.jpg" - url = $element.attr('src'); + url = $element.attr('src') || ''; this.originalUrl = url; // Stop when it's a blank image @@ -2818,7 +2814,7 @@ var Cropper = function () { // Should use `$.fn.prop` here. e.g.: "http://example.com/img/picture.jpg" url = $element.prop('src'); - } else if ($element.is('canvas') && window.HTMLCanvasElement) { + } else if ($element.is('canvas') && global.HTMLCanvasElement) { url = $element[0].toDataURL(); } @@ -2852,7 +2848,7 @@ var Cropper = function () { options = this.options; - if (!options.checkOrientation || !window.ArrayBuffer) { + if (!options.checkOrientation || !global.ArrayBuffer) { this.clone(); return; } @@ -3146,49 +3142,53 @@ var Cropper = function () { return Cropper; }(); -$.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +if ($.extend) { + $.extend(Cropper.prototype, render, preview, events, handlers, change, methods); +} -var AnotherCropper = $.fn.cropper; +if ($.fn) { + var AnotherCropper = $.fn.cropper; -$.fn.cropper = function jQueryCropper(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } + $.fn.cropper = function jQueryCropper(option) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } - var result = void 0; + var result = void 0; - this.each(function (i, element) { - var $element = $(element); - var data = $element.data(NAMESPACE); + this.each(function (i, element) { + var $element = $(element); + var data = $element.data(NAMESPACE); - if (!data) { - if (/destroy/.test(option)) { - return; - } + if (!data) { + if (/destroy/.test(option)) { + return; + } - var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); + var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - data = new Cropper(element, options); - $element.data(NAMESPACE, data); - } + data = new Cropper(element, options); + $element.data(NAMESPACE, data); + } - if (isString(option)) { - var fn = data[option]; + if (isString(option)) { + var fn = data[option]; - if ($.isFunction(fn)) { - result = fn.apply(data, args); + if ($.isFunction(fn)) { + result = fn.apply(data, args); + } } - } - }); + }); - return isUndefined(result) ? this : result; -}; + return isUndefined(result) ? this : result; + }; -$.fn.cropper.Constructor = Cropper; -$.fn.cropper.setDefaults = Cropper.setDefaults; -$.fn.cropper.noConflict = function noConflict() { - $.fn.cropper = AnotherCropper; - return this; -}; + $.fn.cropper.Constructor = Cropper; + $.fn.cropper.setDefaults = Cropper.setDefaults; + $.fn.cropper.noConflict = function noConflict() { + $.fn.cropper = AnotherCropper; + return this; + }; +} }))); diff --git a/package-lock.json b/package-lock.json index b44fd02d..933e8aeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cropper", - "version": "3.1.0", + "version": "3.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1253bc3c..b8937c81 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cropper", "description": "A simple jQuery image cropping plugin.", - "version": "3.1.0", + "version": "3.1.1", "main": "dist/cropper.common.js", "module": "dist/cropper.esm.js", "browser": "dist/cropper.js", @@ -9,7 +9,7 @@ "repository": "fengyuanchen/cropper", "homepage": "https://fengyuanchen.github.io/cropper", "author": { - "name": "Fengyuan Chen", + "name": "Chen Fengyuan", "url": "http://chenfengyuan.com" }, "keywords": [ @@ -40,7 +40,7 @@ "compress:js": "uglifyjs dist/cropper.js -o dist/cropper.min.js -c -m --comments /^!/", "copy": "cpy dist/cropper.css docs/css", "lint": "eslint src/js --fix", - "postbuild": "npm test && npm run compress && npm run copy", + "postbuild": "npm run compress && npm run copy && npm test", "prebuild": "npm run lint", "start": "npm-run-all --parallel watch:*", "test": "node-qunit-phantomjs test/index.html --timeout 10",