Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

Commit

Permalink
v0.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Fengyuan Chen committed Dec 20, 2014
1 parent 01c7d41 commit 7e16f7c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cropper",
"description": "A simple jQuery image cropping plugin.",
"version": "0.7.6-beta",
"version": "0.7.6",
"main": "dist/cropper.js",
"keywords": [
"image",
Expand Down
2 changes: 1 addition & 1 deletion dist/cropper.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Cropper v0.7.6-beta
* Cropper v0.7.6
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down
99 changes: 65 additions & 34 deletions dist/cropper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Cropper v0.7.6-beta
* Cropper v0.7.6
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down Expand Up @@ -66,6 +66,25 @@
return typeof n === "number";
},

toArray = function (obj, offset) {
var args = [];

if (typeof offset === "number") { // It's necessary for IE8
args.push(offset);
}

return args.slice.apply(obj, args);
},

// Custom proxy to avoid jQuery's guid
proxy = function (fn, context) {
var args = toArray(arguments, 2);

return function () {
return fn.apply(context, args.concat(toArray(arguments)));
};
},

// Constructor
Cropper = function (element, options) {
this.element = element;
Expand All @@ -82,7 +101,6 @@
},

// Others
round = Math.round,
sqrt = Math.sqrt,
min = Math.min,
max = Math.max,
Expand Down Expand Up @@ -244,8 +262,6 @@
!defaults.movable && this.$dragger.find(".cropper-face").data(STRING_DIRECTIVE, "move");
!defaults.resizable && this.$dragger.find(".cropper-line, .cropper-point").addClass(CLASS_HIDDEN);

this.$scope = defaults.multiple ? this.$cropper : $document;

this.addListeners();
this.initPreview();

Expand Down Expand Up @@ -303,21 +319,21 @@
top = dragger.top - image.top;

this.$viewer.find("img").css({
width: round(width),
height: round(height),
marginLeft: -round(left),
marginTop: -round(top)
width: width,
height: height,
marginLeft: -left,
marginTop: -top
});

this.$preview.each(function () {
var $this = $(this),
ratio = $this.width() / dragger.width;

$this.find("img").css({
width: round(width * ratio),
height: round(height * ratio),
marginLeft: -round(left * ratio),
marginTop: -round(top * ratio)
width: width * ratio,
height: height * ratio,
marginLeft: -left * ratio,
marginTop: -top * ratio
});
});
},
Expand All @@ -326,20 +342,36 @@
var defaults = this.defaults;

this.$element.on(EVENT_DRAG_START, defaults.dragstart).on(EVENT_DRAG_MOVE, defaults.dragmove).on(EVENT_DRAG_END, defaults.dragend);
this.$cropper.on(EVENT_MOUSE_DOWN, (this._dragstart = $.proxy(this.dragstart, this))).on(EVENT_DBLCLICK, (this._dblclick = $.proxy(this.dblclick, this)));
defaults.zoomable && this.$cropper.on(EVENT_WHEEL, (this._wheel = $.proxy(this.wheel, this)));
this.$scope.on(EVENT_MOUSE_MOVE, (this._dragmove = $.proxy(this.dragmove, this))).on(EVENT_MOUSE_UP, (this._dragend = $.proxy(this.dragend, this)));
this.$cropper.on(EVENT_MOUSE_DOWN, $.proxy(this.dragstart, this)).on(EVENT_DBLCLICK, $.proxy(this.dblclick, this));

$window.on(EVENT_RESIZE, (this._resize = $.proxy(this.resize, this)));
if (defaults.zoomable) {
this.$cropper.on(EVENT_WHEEL, $.proxy(this.wheel, this));
}

if (defaults.multiple) {
this.$cropper.on(EVENT_MOUSE_MOVE, $.proxy(this.dragmove, this)).on(EVENT_MOUSE_UP, $.proxy(this.dragend, this));
} else {
$document.on(EVENT_MOUSE_MOVE, (this._dragmove = proxy(this.dragmove, this))).on(EVENT_MOUSE_UP, (this._dragend = proxy(this.dragend, this)));
}

$window.on(EVENT_RESIZE, (this._resize = proxy(this.resize, this)));
},

removeListeners: function () {
var defaults = this.defaults;

this.$element.off(EVENT_DRAG_START, defaults.dragstart).off(EVENT_DRAG_MOVE, defaults.dragmove).off(EVENT_DRAG_END, defaults.dragend);
this.$cropper.off(EVENT_MOUSE_DOWN, this._dragstart).off(EVENT_DBLCLICK, this._dblclick);
defaults.zoomable && this.$cropper.off(EVENT_WHEEL, this._wheel);
this.$scope.off(EVENT_MOUSE_MOVE, this._dragmove).off(EVENT_MOUSE_UP, this._dragend);
this.$cropper.off(EVENT_MOUSE_DOWN, this.dragstart).off(EVENT_DBLCLICK, this.dblclick);

if (defaults.zoomable) {
this.$cropper.off(EVENT_WHEEL, this.wheel);
}

if (defaults.multiple) {
this.$cropper.off(EVENT_MOUSE_MOVE, this.dragmove).off(EVENT_MOUSE_UP, this.dragend);
} else {
$document.off(EVENT_MOUSE_MOVE, this._dragmove).off(EVENT_MOUSE_UP, this._dragend);
}

$window.off(EVENT_RESIZE, this._resize);
},
Expand Down Expand Up @@ -385,10 +417,10 @@
}

this.$cropper.css({
width: round(cropper.width),
height: round(cropper.height),
left: round(cropper.left),
top: round(cropper.top)
width: cropper.width,
height: cropper.height,
left: cropper.left,
top: cropper.top
});

this.cropper = cropper;
Expand Down Expand Up @@ -437,10 +469,10 @@
image.top = min(max(image.top, image._height - image.height), 0);

this.$clone.css({
width: round(image.width),
height: round(image.height),
marginLeft: round(image.left),
marginTop: round(image.top)
width: image.width,
height: image.height,
marginLeft: image.left,
marginTop: image.top
});

if (mode) {
Expand Down Expand Up @@ -552,10 +584,10 @@
}

this.$dragger.css({
width: round(dragger.width),
height: round(dragger.height),
left: round(dragger.left),
top: round(dragger.top)
width: dragger.width,
height: dragger.height,
left: dragger.left,
top: dragger.top
});

this.preview();
Expand Down Expand Up @@ -718,8 +750,7 @@
n = num(n);

if (REGEXP_OPTIONS.test(i) && !isNaN(n)) {
// Not round when set data.
result[i] = reversed ? (rounded ? round(n / ratio) : n / ratio) : n * ratio;
result[i] = reversed ? (rounded ? Math.round(n / ratio) : n / ratio) : n * ratio;
}
});

Expand Down Expand Up @@ -1515,7 +1546,7 @@

// Register as jQuery plugin
$.fn.cropper = function (options) {
var args = [].slice.call(arguments, 1),
var args = toArray(arguments, 1),
result;

this.each(function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/cropper.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7e16f7c

Please sign in to comment.