Skip to content

Commit

Permalink
Update topbar.js to v3.0.0 (#6051)
Browse files Browse the repository at this point in the history
Changes:
- Removes polyfill for requestAnimationFrame as it's no longer needed for modern browsers
- Improves DOM manipulation by only appending canvas when showing
- Updates copyright year and version numbers
  • Loading branch information
rayere authored Jan 26, 2025
1 parent 1934500 commit 300cfb1
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions installer/templates/phx_assets/topbar.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
/**
* @license MIT
* topbar 2.0.0, 2023-02-04
* https://buunguyen.github.io/topbar
* Copyright (c) 2021 Buu Nguyen
* topbar 3.0.0
* http://buunguyen.github.io/topbar
* Copyright (c) 2024 Buu Nguyen
*/
(function (window, document) {
"use strict";

// https://gist.github.com/paulirish/1579671
(function () {
var lastTime = 0;
var vendors = ["ms", "moz", "webkit", "o"];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame =
window[vendors[x] + "RequestAnimationFrame"];
window.cancelAnimationFrame =
window[vendors[x] + "CancelAnimationFrame"] ||
window[vendors[x] + "CancelRequestAnimationFrame"];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function (callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function () {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
})();

var canvas,
currentProgress,
showing,
Expand Down Expand Up @@ -88,7 +61,6 @@
style.zIndex = 100001;
style.display = "none";
if (options.className) canvas.classList.add(options.className);
document.body.appendChild(canvas);
addEvent(window, "resize", repaint);
},
topbar = {
Expand All @@ -101,10 +73,11 @@
if (delay) {
if (delayTimerId) return;
delayTimerId = setTimeout(() => topbar.show(), delay);
} else {
} else {
showing = true;
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
if (!canvas) createCanvas();
if (!canvas.parentElement) document.body.appendChild(canvas);
canvas.style.opacity = 1;
canvas.style.display = "block";
topbar.progress(0);
Expand Down

0 comments on commit 300cfb1

Please sign in to comment.