Use window.requestAnimationFrame w/o fallback

https://caniuse.com/requestanimationframe
pull/1441/head
Simon Legner 1 year ago
parent ff7a10c003
commit 0f497e57c8

@ -379,11 +379,6 @@ let smoothScroll =
null); null);
$.smoothScroll = function (el, end) { $.smoothScroll = function (el, end) {
if (!window.requestAnimationFrame) {
el.scrollTop = end;
return;
}
smoothEnd = end; smoothEnd = end;
if (smoothScroll) { if (smoothScroll) {
@ -472,22 +467,6 @@ $.classify = function (string) {
return string.join(""); return string.join("");
}; };
$.framify = function (fn, obj) {
if (window.requestAnimationFrame) {
return (...args) => requestAnimationFrame(fn.bind(obj, ...args));
} else {
return fn;
}
};
$.requestAnimationFrame = function (fn) {
if (window.requestAnimationFrame) {
requestAnimationFrame(fn);
} else {
setTimeout(fn, 0);
}
};
// //
// Miscellaneous // Miscellaneous
// //

@ -1255,8 +1255,8 @@ var Prism = (function (_self) {
highlightAutomaticallyCallback, highlightAutomaticallyCallback,
); );
} else { } else {
if (window.requestAnimationFrame) { if (requestAnimationFrame) {
window.requestAnimationFrame(highlightAutomaticallyCallback); requestAnimationFrame(highlightAutomaticallyCallback);
} else { } else {
window.setTimeout(highlightAutomaticallyCallback, 16); window.setTimeout(highlightAutomaticallyCallback, 16);
} }

@ -1290,7 +1290,7 @@
fill(_window, "setTimeout", wrapTimeFn, wrappedBuiltIns); fill(_window, "setTimeout", wrapTimeFn, wrappedBuiltIns);
fill(_window, "setInterval", wrapTimeFn, wrappedBuiltIns); fill(_window, "setInterval", wrapTimeFn, wrappedBuiltIns);
if (_window.requestAnimationFrame) { if (_requestAnimationFrame) {
fill( fill(
_window, _window,
"requestAnimationFrame", "requestAnimationFrame",

@ -14,7 +14,7 @@ app.views.ListFocus = class ListFocus extends app.View {
constructor(el) { constructor(el) {
super(el); super(el);
this.focusOnNextFrame = $.framify(this.focus, this); this.focusOnNextFrame = (el) => requestAnimationFrame(() => this.focus(el));
} }
focus(el, options) { focus(el, options) {

@ -28,9 +28,7 @@ app.views.BasePage = class BasePage extends app.View {
this.delay(this.afterRender); this.delay(this.afterRender);
} }
if (this.highlightNodes.length > 0) { if (this.highlightNodes.length > 0) {
$.requestAnimationFrame(() => requestAnimationFrame(() => this.paintCode());
$.requestAnimationFrame(() => this.paintCode()),
);
} }
} }
@ -68,7 +66,7 @@ app.views.BasePage = class BasePage extends app.View {
} }
if (this.highlightNodes.length > 0) { if (this.highlightNodes.length > 0) {
$.requestAnimationFrame(() => this.paintCode()); requestAnimationFrame(() => this.paintCode());
} }
this.previousTiming = timing; this.previousTiming = timing;
} }

@ -203,7 +203,7 @@ app.views.Search = class Search extends app.View {
if (context.hash) { if (context.hash) {
this.delay(this.searchUrl); this.delay(this.searchUrl);
} }
$.requestAnimationFrame(() => this.autoFocus()); requestAnimationFrame(() => this.autoFocus());
} }
extractHashValue() { extractHashValue() {

@ -50,7 +50,7 @@ app.views.DocPicker = class DocPicker extends app.View {
this.html(html + this.tmpl("docPickerNote")); this.html(html + this.tmpl("docPickerNote"));
$.requestAnimationFrame(() => this.findByTag("input")?.focus()); requestAnimationFrame(() => this.findByTag("input")?.focus());
} }
renderVersions(docs) { renderVersions(docs) {

@ -64,7 +64,7 @@ app.views.Sidebar = class Sidebar extends app.View {
resetHoverOnMouseMove() { resetHoverOnMouseMove() {
$.off(window, "mousemove", this.resetHoverOnMouseMove); $.off(window, "mousemove", this.resetHoverOnMouseMove);
return $.requestAnimationFrame(() => this.resetHover()); return requestAnimationFrame(() => this.resetHover());
} }
resetHover() { resetHover() {

Loading…
Cancel
Save