瀏覽代碼

Use window.requestAnimationFrame w/o fallback

https://caniuse.com/requestanimationframe
Simon Legner 1 年之前
父節點
當前提交
0f497e57c8

+ 0 - 21
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
 //

+ 2 - 2
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);
       }

+ 1 - 1
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",

+ 1 - 1
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) {

+ 2 - 4
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;
   }

+ 1 - 1
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() {

+ 1 - 1
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) {

+ 1 - 1
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() {