-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate.js
150 lines (131 loc) · 4.81 KB
/
rotate.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
/*
Modifed from: Modifed from https://bl.ocks.org/joyrexus/7207044
Written By:
Logan C.
Inspired By / Replicating:
https://www.wonder-tonic.com/steamtube/
With help from:
Logan C.'s Dad
The good people of Stack Overflow.
w3schools.com
The Caret text editor
Microsoft Visual Studio Code
Pop-Tarts.
Mio-Water.
The JPEXS Flash .swf decomplier.
Notepad.
The Desmos Graphing Calculator.
*/
// Generated by CoffeeScript 1.6.3
var audioQualityControl = document.getElementById("audioQualityControl");
var videoQualityControl = document.getElementById("videoQualityControl");
// Active is if the user is actively turning the control.
audioQualityControl.dataset.active = false;
audioQualityControl.dataset.angle = 0;
videoQualityControl.dataset.active = false;
videoQualityControl.dataset.angle = 0;
// DragObject is a function modifed from the original script that handles the dragging and rotation of the object.
// springBack handles ensuring the angle of rotation for the controls never exceeds 360 degrees.
// The name "springBack" is holdover from when I had the wheel spin back to it's starting locaton.
DragObject(audioQualityControl);
DragObject(videoQualityControl);
// Check the rotation of the controls every ~1/30 of a second.
setInterval(springBack, 33, audioQualityControl);
setInterval(springBack, 33, videoQualityControl);
// Code I have a hard time understanding.
// Someone else, please explain this.
function DragObject(target) {
var R2D, center, init, rotate, rotation, start, startAngle, stop;
var active = false;
var angle, rotation, startAngle = 0;
var center = {
x: 0,
y: 0
};
init = function() {
if (mobile === false) {
target.addEventListener("mousedown", start, false);
target.addEventListener("mousemove", rotate, false);
return document.addEventListener("mouseup", stop, false);
} else {
target.addEventListener("touchstart", start, false);
target.addEventListener("touchmove", rotate, false);
return target.addEventListener("touchend", stop, false);
}
};
R2D = 180 / Math.PI;
start = function(e) {
var height, left, top, width, x, y, _ref;
e.preventDefault();
_ref = this.getBoundingClientRect(), top = _ref.top, left = _ref.left, height = _ref.height, width = _ref.width;
center = {
x: left + (width / 2),
y: top + (height / 2)
};
if (mobile === false) {
x = e.clientX - center.x;
y = e.clientY - center.y;
} else {
/* WHY CAN'T YOU SEARCH THROUGH A TOUCH LIST LIKE A NORMAL ARRAY?!?!
JAVASCRIPPPPPPPT! */
var touchArray = [];
// This is to convert the touchlist into a normal array so it can be searched through.
for (var loops = 0; loops < e.touches.length; loops++) {
touchArray.push(e.touches[loops]);
}
var touchIndex = touchArray.findIndex((element) => element.target == e.target);
x = e.touches[touchIndex].clientX - center.x;
y = e.touches[touchIndex].clientY - center.y;
}
startAngle = R2D * Math.atan2(y, x);
target.dataset.active = true;
return active = true;
};
rotate = function(e) {
angle = parseFloat(this.dataset.angle);
var d, x, y;
e.preventDefault();
if (mobile === false) {
x = e.clientX - center.x;
y = e.clientY - center.y;
} else {
/* WHY CAN'T YOU SEARCH THROUGH A TOUCH LIST LIKE A NORMAL ARRAY?!?!
JAVASCRIPPPPPPPT! */
var touchArray = [];
// This is to convert the touchlist into a normal array so it can be searched through.
for (var loops = 0; loops < e.touches.length; loops++) {
touchArray.push(e.touches[loops]);
}
var touchIndex = touchArray.findIndex((element) => element.target == e.target);
x = e.touches[touchIndex].clientX - center.x;
y = e.touches[touchIndex].clientY - center.y;
}
d = R2D * Math.atan2(y, x);
rotation = d - startAngle;
// Because active is a global variable, we need to get the active state for this specific target.
active = target.dataset.active;
if (active == "true") {
var dropShadow = getRotationPoint(20, 20, (angle + rotation));
this.style.filter = "drop-shadow(" + dropShadow[0] + "px " + dropShadow[1] + "px 3px rgba(0,0,0,0.7)";
return this.style.transform = "rotate(" + (angle + rotation) + "deg)";
}
};
stop = function() {
angle += rotation;
target.dataset.angle = angle;
target.dataset.active = false;
return active = false;
};
init();
}
function springBack(target) {
var angle = parseFloat(target.dataset.angle);
// If the angle is negative, make it positive again.
if (angle < 0) {
angle += 360;
}
if (angle > 360) {
angle -= 360;
}
target.dataset.angle = angle;
}