Skip to content

Commit 17a435b

Browse files
committed
release: delay support
1 parent bcef840 commit 17a435b

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface TopbarConfigOptions {
1313

1414
export interface Topbar {
1515
config: (options: TopbarConfigOptions) => void
16-
show: () => void
16+
show: (delay?: number) => void
1717
progress: (to?: number | string) => number
1818
hide: () => void
1919
}

index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
// Delayed Demo
5656
$('#btnStartDelayed').click(function() {
5757
resetToDefaults()
58-
topbar.delayedShow(500)
58+
topbar.show(500)
5959
})
6060
$('#btnStopDelayed').click(function() {
6161
topbar.hide()
@@ -137,12 +137,12 @@ <h4>Basic</h4>
137137
</section>
138138
<h4>Delayed show</h4>
139139
<section class="code">
140-
<p>You can use <code>topbar.delayedShow(microseconds)</code> to delay the progress bar. If the topbar is hidden within the time in microseconds, it does not show up at all. This can make the user experience feel smoother:</p>
140+
<p>You can use <code>topbar.show(delayMillis)</code> to delay the progress bar. If hide() is invoked within the delay period, topbar won't show up at all. This can make the user experience feel smoother in some cases.</p>
141141
<a id="btnStartDelayed" class="button" href="javascript:void(0)">Show Progress</a>
142142
<a id="btnStopDelayed" class="button" href="javascript:void(0)">Hide Progress</a>
143143
<pre class="prettyprint">
144144
$('#btnStartDelayed').click(function() {
145-
topbar.delayedShow(500)
145+
topbar.show(500)
146146
})
147147

148148
$('#btnStopDelayed').click(function() {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"topbar.min.js",
77
"*.d.ts"
88
],
9-
"version": "1.0.1",
9+
"version": "2.0.0",
1010
"description": "Tiny & beautiful site-wide progress indicator",
1111
"homepage": "http://buunguyen.github.io/topbar",
1212
"repository": {

topbar.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license MIT
3-
* topbar 1.0.0, 2021-01-06
3+
* topbar 2.0.0, 2023-02-04
44
* http://buunguyen.github.io/topbar
55
* Copyright (c) 2021 Buu Nguyen
66
*/
@@ -96,26 +96,26 @@
9696
for (var key in opts)
9797
if (options.hasOwnProperty(key)) options[key] = opts[key];
9898
},
99-
delayedShow: function(time) {
99+
show: function (delay) {
100100
if (showing) return;
101-
if (delayTimerId) return;
102-
delayTimerId = setTimeout(() => topbar.show(), time);
103-
},
104-
show: function () {
105-
if (showing) return;
106-
showing = true;
107-
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
108-
if (!canvas) createCanvas();
109-
canvas.style.opacity = 1;
110-
canvas.style.display = "block";
111-
topbar.progress(0);
112-
if (options.autoRun) {
113-
(function loop() {
114-
progressTimerId = window.requestAnimationFrame(loop);
115-
topbar.progress(
116-
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
117-
);
118-
})();
101+
if (delay) {
102+
if (delayTimerId) return;
103+
delayTimerId = setTimeout(() => topbar.show(), delay);
104+
} else {
105+
showing = true;
106+
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
107+
if (!canvas) createCanvas();
108+
canvas.style.opacity = 1;
109+
canvas.style.display = "block";
110+
topbar.progress(0);
111+
if (options.autoRun) {
112+
(function loop() {
113+
progressTimerId = window.requestAnimationFrame(loop);
114+
topbar.progress(
115+
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
116+
);
117+
})();
118+
}
119119
}
120120
},
121121
progress: function (to) {

topbar.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)