History

Use window.requestAnimationFrame w/o fallback

https://caniuse.com/requestanimationframe

Simon Legner committed 2 years ago

Commit 0f497e51 parent ff7a10c8 files · +9 −32Browse files

Unified · Split

8 files
  1. assets/javascripts/lib/util.js +0 −21
  2. assets/javascripts/vendor/prism.js +2 −2
  3. assets/javascripts/vendor/raven.js +1 −1
  4. assets/javascripts/views/list/list_focus.js +1 −1
  5. assets/javascripts/views/pages/base.js +2 −4
  6. assets/javascripts/views/search/search.js +1 −1
  7. assets/javascripts/views/sidebar/doc_picker.js +1 −1
  8. assets/javascripts/views/sidebar/sidebar.js +1 −1
assets/javascripts/lib/util.js+0−21
@@ -379,11 +379,6 @@ let smoothScroll = · 378 unmodified lines
379379 null);
380380
381381 $.smoothScroll = function (el, end) {
382− if (!window.requestAnimationFrame) {
383− el.scrollTop = end;
384− return;
385− }
386−
387382 smoothEnd = end;
388383
389384 if (smoothScroll) {
@@ -472,22 +467,6 @@ $.classify = function (string) { · 82 unmodified lines
472467 return string.join("");
473468 };
474469
475−$.framify = function (fn, obj) {
476− if (window.requestAnimationFrame) {
477− return (...args) => requestAnimationFrame(fn.bind(obj, ...args));
478− } else {
479− return fn;
480− }
481−};
482−
483−$.requestAnimationFrame = function (fn) {
484− if (window.requestAnimationFrame) {
485− requestAnimationFrame(fn);
486− } else {
487− setTimeout(fn, 0);
488− }
489−};
490−
491470 //
492471 // Miscellaneous
493472 //
assets/javascripts/vendor/prism.js+2−2
@@ -1255,8 +1255,8 @@ var Prism = (function (_self) { · 1254 unmodified lines
12551255 highlightAutomaticallyCallback,
12561256 );
12571257 } else {
1258− if (window.requestAnimationFrame) {
1259− window.requestAnimationFrame(highlightAutomaticallyCallback);
1258+ if (requestAnimationFrame) {
1259+ requestAnimationFrame(highlightAutomaticallyCallback);
12601260 } else {
12611261 window.setTimeout(highlightAutomaticallyCallback, 16);
12621262 }
assets/javascripts/vendor/raven.js+1−1
@@ -1290,7 +1290,7 @@ · 1289 unmodified lines
12901290
12911291 fill(_window, "setTimeout", wrapTimeFn, wrappedBuiltIns);
12921292 fill(_window, "setInterval", wrapTimeFn, wrappedBuiltIns);
1293− if (_window.requestAnimationFrame) {
1293+ if (_requestAnimationFrame) {
12941294 fill(
12951295 _window,
12961296 "requestAnimationFrame",
assets/javascripts/views/list/list_focus.js+1−1
@@ -14,7 +14,7 @@ app.views.ListFocus = class ListFocus extends app.View { · 13 unmodified lines
1414
1515 constructor(el) {
1616 super(el);
17− this.focusOnNextFrame = $.framify(this.focus, this);
17+ this.focusOnNextFrame = (el) => requestAnimationFrame(() => this.focus(el));
1818 }
1919
2020 focus(el, options) {
assets/javascripts/views/pages/base.js+2−4
@@ -28,9 +28,7 @@ app.views.BasePage = class BasePage extends app.View { · 27 unmodified lines
2828 this.delay(this.afterRender);
2929 }
3030 if (this.highlightNodes.length > 0) {
31− $.requestAnimationFrame(() =>
32− $.requestAnimationFrame(() => this.paintCode()),
33− );
31+ requestAnimationFrame(() => this.paintCode());
3432 }
3533 }
3634
@@ -68,7 +66,7 @@ app.views.BasePage = class BasePage extends app.View { · 31 unmodified lines
6866 }
6967
7068 if (this.highlightNodes.length > 0) {
71− $.requestAnimationFrame(() => this.paintCode());
69+ requestAnimationFrame(() => this.paintCode());
7270 }
7371 this.previousTiming = timing;
7472 }
assets/javascripts/views/search/search.js+1−1
@@ -203,7 +203,7 @@ app.views.Search = class Search extends app.View { · 202 unmodified lines
203203 if (context.hash) {
204204 this.delay(this.searchUrl);
205205 }
206− $.requestAnimationFrame(() => this.autoFocus());
206+ requestAnimationFrame(() => this.autoFocus());
207207 }
208208
209209 extractHashValue() {
assets/javascripts/views/sidebar/doc_picker.js+1−1
@@ -50,7 +50,7 @@ app.views.DocPicker = class DocPicker extends app.View { · 49 unmodified lines
5050
5151 this.html(html + this.tmpl("docPickerNote"));
5252
53− $.requestAnimationFrame(() => this.findByTag("input")?.focus());
53+ requestAnimationFrame(() => this.findByTag("input")?.focus());
5454 }
5555
5656 renderVersions(docs) {
assets/javascripts/views/sidebar/sidebar.js+1−1
@@ -64,7 +64,7 @@ app.views.Sidebar = class Sidebar extends app.View { · 63 unmodified lines
6464
6565 resetHoverOnMouseMove() {
6666 $.off(window, "mousemove", this.resetHoverOnMouseMove);
67− return $.requestAnimationFrame(() => this.resetHover());
67+ return requestAnimationFrame(() => this.resetHover());
6868 }
6969
7070 resetHover() {