From 0f497e57c817f0bb128b6e67be0f3f0291f4e585 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sat, 6 Jan 2024 17:35:31 +0100 Subject: [PATCH] Use window.requestAnimationFrame w/o fallback https://caniuse.com/requestanimationframe --- assets/javascripts/lib/util.js | 21 ------------------- assets/javascripts/vendor/prism.js | 4 ++-- assets/javascripts/vendor/raven.js | 2 +- assets/javascripts/views/list/list_focus.js | 2 +- assets/javascripts/views/pages/base.js | 6 ++---- assets/javascripts/views/search/search.js | 2 +- .../javascripts/views/sidebar/doc_picker.js | 2 +- assets/javascripts/views/sidebar/sidebar.js | 2 +- 8 files changed, 9 insertions(+), 32 deletions(-) diff --git a/assets/javascripts/lib/util.js b/assets/javascripts/lib/util.js index 97d4e733..9e25bc0c 100644 --- a/assets/javascripts/lib/util.js +++ b/assets/javascripts/lib/util.js @@ -379,11 +379,6 @@ let smoothScroll = null); $.smoothScroll = function (el, end) { - if (!window.requestAnimationFrame) { - el.scrollTop = end; - return; - } - smoothEnd = end; if (smoothScroll) { @@ -472,22 +467,6 @@ $.classify = function (string) { 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 // diff --git a/assets/javascripts/vendor/prism.js b/assets/javascripts/vendor/prism.js index 1f0b732a..8eda8d21 100644 --- a/assets/javascripts/vendor/prism.js +++ b/assets/javascripts/vendor/prism.js @@ -1255,8 +1255,8 @@ var Prism = (function (_self) { highlightAutomaticallyCallback, ); } else { - if (window.requestAnimationFrame) { - window.requestAnimationFrame(highlightAutomaticallyCallback); + if (requestAnimationFrame) { + requestAnimationFrame(highlightAutomaticallyCallback); } else { window.setTimeout(highlightAutomaticallyCallback, 16); } diff --git a/assets/javascripts/vendor/raven.js b/assets/javascripts/vendor/raven.js index 0b91cd9b..a4d42a9b 100644 --- a/assets/javascripts/vendor/raven.js +++ b/assets/javascripts/vendor/raven.js @@ -1290,7 +1290,7 @@ fill(_window, "setTimeout", wrapTimeFn, wrappedBuiltIns); fill(_window, "setInterval", wrapTimeFn, wrappedBuiltIns); - if (_window.requestAnimationFrame) { + if (_requestAnimationFrame) { fill( _window, "requestAnimationFrame", diff --git a/assets/javascripts/views/list/list_focus.js b/assets/javascripts/views/list/list_focus.js index 394aec99..0c4cdcfe 100644 --- a/assets/javascripts/views/list/list_focus.js +++ b/assets/javascripts/views/list/list_focus.js @@ -14,7 +14,7 @@ app.views.ListFocus = class ListFocus extends app.View { constructor(el) { super(el); - this.focusOnNextFrame = $.framify(this.focus, this); + this.focusOnNextFrame = (el) => requestAnimationFrame(() => this.focus(el)); } focus(el, options) { diff --git a/assets/javascripts/views/pages/base.js b/assets/javascripts/views/pages/base.js index 40716785..1e04b5a0 100644 --- a/assets/javascripts/views/pages/base.js +++ b/assets/javascripts/views/pages/base.js @@ -28,9 +28,7 @@ app.views.BasePage = class BasePage extends app.View { this.delay(this.afterRender); } 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) { - $.requestAnimationFrame(() => this.paintCode()); + requestAnimationFrame(() => this.paintCode()); } this.previousTiming = timing; } diff --git a/assets/javascripts/views/search/search.js b/assets/javascripts/views/search/search.js index 6cfcb4cb..74d81a7c 100644 --- a/assets/javascripts/views/search/search.js +++ b/assets/javascripts/views/search/search.js @@ -203,7 +203,7 @@ app.views.Search = class Search extends app.View { if (context.hash) { this.delay(this.searchUrl); } - $.requestAnimationFrame(() => this.autoFocus()); + requestAnimationFrame(() => this.autoFocus()); } extractHashValue() { diff --git a/assets/javascripts/views/sidebar/doc_picker.js b/assets/javascripts/views/sidebar/doc_picker.js index 9e532ee3..194e234a 100644 --- a/assets/javascripts/views/sidebar/doc_picker.js +++ b/assets/javascripts/views/sidebar/doc_picker.js @@ -50,7 +50,7 @@ app.views.DocPicker = class DocPicker extends app.View { this.html(html + this.tmpl("docPickerNote")); - $.requestAnimationFrame(() => this.findByTag("input")?.focus()); + requestAnimationFrame(() => this.findByTag("input")?.focus()); } renderVersions(docs) { diff --git a/assets/javascripts/views/sidebar/sidebar.js b/assets/javascripts/views/sidebar/sidebar.js index 9028c9a2..eaab03fa 100644 --- a/assets/javascripts/views/sidebar/sidebar.js +++ b/assets/javascripts/views/sidebar/sidebar.js @@ -64,7 +64,7 @@ app.views.Sidebar = class Sidebar extends app.View { resetHoverOnMouseMove() { $.off(window, "mousemove", this.resetHoverOnMouseMove); - return $.requestAnimationFrame(() => this.resetHover()); + return requestAnimationFrame(() => this.resetHover()); } resetHover() {