Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.each((i, element) => {
const $element = $(element);
const isDestroy = option === 'destroy';
let cropper = $element.data(NAMESPACE);
if (!cropper) {
if (isDestroy) {
return;
}
const options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
cropper = new Cropper(element, options);
$element.data(NAMESPACE, cropper);
}
if (typeof option === 'string') {
const fn = cropper[option];
if ($.isFunction(fn)) {
result = fn.apply(cropper, args);
if (result === cropper) {
result = undefined;
}
if (isDestroy) {
$element.removeData(NAMESPACE);
}
setCropper() {
const { x, y, w, h } = this.value || {},
data = { x, y, width: w, height: h },
[variationWidth, variationHeight] = this.variation,
aspectRatio =
variationWidth > 0 && variationHeight > 0
? variationWidth / variationHeight
: undefined;
this.destroyCropper();
const scale = this.$refs.cropper.clientWidth / this.imageSize.width;
this.cropper = new Cropper(this.$refs.image, {
viewMode: 2,
dragMode: "none",
autoCrop: true,
data,
aspectRatio,
guides: true,
movable: false,
rotatable: false,
guides: false,
center: false,
zoomable: false,
scalable: true,
minCropBoxWidth: 50,
minCropBoxHeight: 50,
crop: this.handleCrop,
preview: this.$refs.preview