-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.ui.rotatable.min.js
155 lines (155 loc) · 6.24 KB
/
jquery.ui.rotatable.min.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
(function(c, d) {
c.widget("ui.rotatable", c.ui.mouse, {
options: {
handle: !1,
angle: !1,
snap: !1,
step: 22.5,
rotationCenterX: !1,
rotationCenterY: !1,
start: null,
rotate: null,
stop: null
},
rotationCenterX: function(a) {
if (a === d)
return this.options.rotationCenterX;
this.options.rotationCenterX = a
},
rotationCenterY: function(a) {
if (a === d)
return this.options.rotationCenterY;
this.options.rotationCenterY = a
},
handle: function(a) {
if (a === d)
return this.options.handle;
this.options.handle = a
},
angle: function(a) {
if (a === d)
return this.options.angle;
this.elementCurrentAngle = this.options.angle = a;
this.performRotation(this.options.angle)
},
_create: function() {
var a;
this.options.handle ? a = this.options.handle : (a = c(document.createElement("div")),
a.addClass("ui-rotatable-handle"));
this.listeners = {
rotateElement: c.proxy(this.rotateElement, this),
startRotate: c.proxy(this.startRotate, this),
stopRotate: c.proxy(this.stopRotate, this),
wheelRotate: c.proxy(this.wheelRotate, this)
};
//this.element.bind("wheel",this.listeners.wheelRotate);
a.draggable({
helper: "clone",
start: this.dragStart,
handle: a
});
a.bind("mousedown", this.listeners.startRotate);
a.appendTo(this.element);
0 != this.options.angle ? (this.elementCurrentAngle = this.options.angle,
this.performRotation(this.elementCurrentAngle)) : this.elementCurrentAngle = 0
},
_destroy: function() {
this.element.removeClass("ui-rotatable");
this.element.find(".ui-rotatable-handle").remove();
//this.element.unbind("wheel",this.listeners.wheelRotate)
},
performRotation: function(a) {
this.element.css("transform-origin", this.options.rotationCenterX + "% " + this.options.rotationCenterY + "%");
this.element.css("-ms-transform-origin", this.options.rotationCenterX + "% " + this.options.rotationCenterY + "%");
this.element.css("-webkit-transform-origin", this.options.rotationCenterX + "% " + this.options.rotationCenterY + "%");
this.element.css("transform", "rotate(" + a + "rad)");
this.element.css("-moz-transform", "rotate(" + a + "rad)");
this.element.css("-webkit-transform", "rotate(" + a + "rad)");
this.element.css("-o-transform", "rotate(" + a + "rad)")
},
getElementOffset: function() {
this.performRotation(0);
var a = this.element.offset();
this.performRotation(this.elementCurrentAngle);
return a
},
getElementCenter: function() {
var a = this.getElementOffset();
if (!1 === this.options.rotationCenterX)
var b = a.left + this.element.width() / 2
, a = a.top + this.element.height() / 2;
else
b = a.left + this.element.width() / 100 * this.options.rotationCenterX,
a = a.top + this.element.height() / 100 * this.options.rotationCenterY;
return [b, a]
},
dragStart: function(a) {
if (this.element)
return !1
},
startRotate: function(a) {
var b = this.getElementCenter();
this.mouseStartAngle = Math.atan2(a.pageY - b[1], a.pageX - b[0]);
this.elementStartAngle = this.elementCurrentAngle;
this.hasRotated = !1;
this._propagate("start", a);
c(document).bind("mousemove", this.listeners.rotateElement);
c(document).bind("mouseup", this.listeners.stopRotate);
return !1
},
rotateElement: function(a) {
if (!this.element || this.element.disabled)
return !1;
var b = this.getRotateAngle(a);
this.performRotation(b);
var c = this.elementCurrentAngle;
this.elementCurrentAngle = b;
this._propagate("rotate", a);
c != b && (this._trigger("rotate", a, this.ui()),
this.hasRotated = !0);
return !1
},
stopRotate: function(a) {
if (this.element && !this.element.disabled)
return c(document).unbind("mousemove", this.listeners.rotateElement),
c(document).unbind("mouseup", this.listeners.stopRotate),
this.elementStopAngle = this.elementCurrentAngle,
this.hasRotated && this._propagate("stop", a),
setTimeout(function() {
this.element = !1
}, 10),
!1
},
getRotateAngle: function(a) {
var b = this.getElementCenter();
a = Math.atan2(a.pageY - b[1], a.pageX - b[0]) - this.mouseStartAngle + this.elementStartAngle;
this.options.snap && (a = a / Math.PI * 180,
a = Math.round(a / this.options.step) * this.options.step,
a = a * Math.PI / 180);
return a
},
wheelRotate: function(a) {
var b = Math.round(a.originalEvent.deltaY / 10) * Math.PI / 180
, b = this.elementCurrentAngle + b;
this.angle(b);
this._trigger("rotate", a, this.ui())
},
_propagate: function(a, b) {
c.ui.plugin.call(this, a, [b, this.ui()]);
"rotate" !== a && this._trigger(a, b, this.ui())
},
plugins: {},
ui: function() {
return {
api: this,
element: this.element,
angle: {
start: this.elementStartAngle,
current: this.elementCurrentAngle,
stop: this.elementStopAngle
}
}
}
})
}
)(jQuery);