CropAnimator.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* CropAnimator
* manages smooth cropping animation
*
* This object is called internally to manage animation.
* An in-memory div is animated and a progress callback
* is used to update the selection coordinates of the
* visible selection in realtime.
*/
// var CropAnimator = function(selection){{{
var CropAnimator = function(selection){
this.selection = selection;
this.core = selection.core;
};
// }}}
CropAnimator.prototype = {
getElement: function(){
var b = this.selection.get();
return $('<div />')
.css({
position: 'absolute',
top: b.y+'px',
left: b.x+'px',
width: b.w+'px',
height: b.h+'px'
});
},
animate: function(x,y,w,h,cb){
var t = this;
t.selection.allowResize(false);
t.getElement().animate({
top: y+'px',
left: x+'px',
width: w+'px',
height: h+'px'
},{
easing: t.core.opt.animEasing,
duration: t.core.opt.animDuration,
complete: function(){
t.selection.allowResize(true);
cb && cb.call(this);
},
progress: function(anim){
var props = {}, i, tw = anim.tweens;
for(i=0;i<tw.length;i++){
props[tw[i].prop] = tw[i].now; }
var b = {
x: parseInt(props.left),
y: parseInt(props.top),
w: parseInt(props.width),
h: parseInt(props.height)
};
b.x2 = b.x + b.w;
b.y2 = b.y + b.h;
t.selection.updateRaw(b,'se');
}
});
}
};
Jcrop.registerComponent('Animator',CropAnimator);