Skip to content

Commit f1fb6b3

Browse files
authored
editor-animations -- invert speed and make options dynamic (1/2)
1 parent b8b381a commit f1fb6b3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/addons/addons/editor-animations/userscript.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default async function({ addon }) {
118118
animateButtons = addon.settings.get("animateButtons");
119119

120120
const oldSpeed = animationSpeed;
121-
animationSpeed = Number(addon.settings.get("animateSpeed")) / 100;
121+
animationSpeed = 5 - (Number(addon.settings.get("animateSpeed")) / 100);
122122
if (oldSpeed !== animationSpeed) styleElement.textContent = genStyles();
123123
}
124124

@@ -158,7 +158,6 @@ export default async function({ addon }) {
158158
}
159159

160160
function handleOpenAnimation(elementName) {
161-
requestAddonState();
162161
const type = elementName.endsWith("Library") ? "library" : elementName.endsWith("Menu") ? "menu" : "modal";
163162

164163
if (!animateLibraries && type === "library") return;
@@ -190,7 +189,7 @@ export default async function({ addon }) {
190189

191190
const animation = element.animate(
192191
[{ height: "0px", opacity: 0 }, { height: `${ogHeight}px`, opacity: 1 }],
193-
{ duration: animTime, easing: cubicAnimation }
192+
{ duration: animTime * animationSpeed, easing: cubicAnimation }
194193
);
195194
animation.onfinish = () => {
196195
element.style.overflow = "hidden";
@@ -208,12 +207,11 @@ export default async function({ addon }) {
208207

209208
element.animate(
210209
[{ transform: "scale(0)", opacity: 0 }, { transform: "scale(1)", opacity: 1 }],
211-
{ duration: animTime, easing: cubicAnimation }
210+
{ duration: animTime * animationSpeed, easing: cubicAnimation }
212211
);
213212
}
214213

215214
function attachCloseHijack(elementName) {
216-
requestAddonState();
217215
const type = elementName.endsWith("Library") ? "library" : elementName.endsWith("Menu") ? "menu" : "modal";
218216
if (type === "menu" || patchedBody) return;
219217

@@ -228,7 +226,6 @@ export default async function({ addon }) {
228226

229227
let animTime = 200;
230228
patchedBody = true;
231-
232229
if (child === element) {
233230
const child = element.firstChild;
234231
if (child) {
@@ -247,11 +244,11 @@ export default async function({ addon }) {
247244

248245
animClone.animate(
249246
[{ opacity: 1 }, { opacity: 0 }],
250-
{ duration: animTime, easing: cubicAnimation }
247+
{ duration: animTime * animationSpeed, easing: cubicAnimation }
251248
);
252249
const animation = animClone.firstChild.animate(
253250
[{ transform: "scale(1)", opacity: 1 }, { transform: "scale(0)", opacity: 0 }],
254-
{ duration: animTime, easing: cubicAnimation }
251+
{ duration: animTime * animationSpeed, easing: cubicAnimation }
255252
);
256253
animation.onfinish = () => {
257254
animClone.remove();
@@ -267,7 +264,6 @@ export default async function({ addon }) {
267264
}
268265

269266
function compileClasses(optLibrary) {
270-
requestAddonState();
271267
if (!animateButtons) return;
272268
const classMapper = new Map();
273269

@@ -458,4 +454,16 @@ export default async function({ addon }) {
458454
}
459455

460456
if (typeof scaffolding === "undefined") startListenerWorker();
457+
458+
addon.settings.addEventListener("change", requestAddonState);
459+
addon.self.addEventListener("disabled", () => {
460+
animateModals = false;
461+
animateLibraries = false;
462+
animateButtons = false;
463+
});
464+
addon.self.addEventListener("reenabled", () => {
465+
animateModals = true;
466+
animateLibraries = true;
467+
animateButtons = true;
468+
});
461469
}

0 commit comments

Comments
 (0)