Skip to content

Commit

Permalink
Correcting progressbar following al-folio's alshedivat#934
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana Carolina Richter authored and Ana Carolina Richter committed Oct 31, 2022
1 parent cf91c45 commit c77834d
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Metadata, OpenGraph and Schema.org -->
{% include metadata.html %}

<!-- Favicon???s -->
<!-- [*Added* by Ana: Favicon] -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
Expand Down
1 change: 1 addition & 0 deletions _includes/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- [*Edited* on 31.10.2022 following pull request #934] -->

<header>

Expand Down
83 changes: 83 additions & 0 deletions _includes/scripts/progressBar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!-- [*Added* on 31.10.2022 following pull request #934] -->


{% if site.enable_progressbar %}

<!-- Scrolling Progress Bar -->
<script type="text/javascript">
/*
* This JavaScript code has been adapted from the article
* https://css-tricks.com/reading-position-indicator/ authored by Pankaj Parashar,
* published on the website https://css-tricks.com on the 7th of May, 2014.
* Couple of changes were made to the original code to make it compatible
* with the `al-foio` theme.
*/
const progressBar = $("#progress");
/*
* We set up the bar after all elements are done loading.
* In some cases, if the images in the page are larger than the intended
* size they'll have on the page, they'll be resized via CSS to accomodate
* the desired size. This mistake, however, breaks the computations as the
* scroll size is computed as soon as the elements finish loading.
* To account for this, a minimal delay was introduced before computing the
* values.
*/
window.onload = function () {
setTimeout(progressBarSetup, 50);
};
/*
* We set up the bar according to the browser.
* If the browser supports the progress element we use that.
* Otherwise, we resize the bar thru CSS styling
*/
function progressBarSetup() {
if ("max" in document.createElement("progress")) {
initializeProgressElement();
$(document).on("scroll", function() {
progressBar.attr({ value: getCurrentScrollPosition() });
});
$(window).on("resize", initializeProgressElement);
} else {
resizeProgressBar();
$(document).on("scroll", resizeProgressBar);
$(window).on("resize", resizeProgressBar);
}
}
/*
* The vertical scroll position is the same as the number of pixels that
* are hidden from view above the scrollable area. Thus, a value > 0 is
* how much the user has scrolled from the top
*/
function getCurrentScrollPosition() {
return $(window).scrollTop();
}

function initializeProgressElement() {
let navbarHeight = $("#navbar").outerHeight(true);
$("body").css({ "padding-top": navbarHeight });
$("progress-container").css({ "padding-top": navbarHeight });
progressBar.css({ top: navbarHeight });
progressBar.attr({
max: getDistanceToScroll(),
value: getCurrentScrollPosition(),
});
}
/*
* The offset between the html document height and the browser viewport
* height will be greater than zero if vertical scroll is possible.
* This is the distance the user can scroll
*/
function getDistanceToScroll() {
return $(document).height() - $(window).height();
}

function resizeProgressBar() {
progressBar.css({ width: getWidthPercentage() + "%" });
}
// The scroll ratio equals the percentage to resize the bar
function getWidthPercentage() {
return (getCurrentScrollPosition() / getDistanceToScroll()) * 100;
}
</script>

{%- endif %}
6 changes: 4 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!-- [*Edited* on 31.10.2022 following pull request #934] -->

<!DOCTYPE html>
<html lang="{{ site.lang }}">

<!-- Head -->
<head>

{%- if page.redirect -%}
<meta http-equiv="refresh" content="3; url={{ site.baseurl }}/" />
{%- endif -%}
Expand Down Expand Up @@ -31,5 +32,6 @@
{% include scripts/misc.html %}
{% include scripts/mathjax.html %}
{% include scripts/analytics.html %}
{% include scripts/progressBar.html %}
</body>
</html>
</html>
5 changes: 4 additions & 1 deletion _layouts/distill.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- [*Edited* on 31.10.2022 following pull request #934] -->

<!DOCTYPE html>
<!-- _layouts/distill.html -->
<html>
Expand Down Expand Up @@ -105,5 +107,6 @@ <h3>Contents</h3>

{% include scripts/bootstrap.html %}
{% include scripts/analytics.html %}
{% include scripts/progressBar.html %}
</body>
</html>
</html>
58 changes: 58 additions & 0 deletions _sass/_base.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// *Edited* on 31.10.2022 following pull request #934]

/*******************************************************************************
* Styles for the base elements of the theme.
******************************************************************************/
Expand Down Expand Up @@ -308,6 +310,7 @@ footer.sticky-bottom {

.list-group-item {
background-color: inherit;
border-color: var(--global-divider-color);

.badge {
color: var(--global-card-bg-color) !important;
Expand Down Expand Up @@ -656,3 +659,58 @@ html.transition *:after {
}
}
}

progress {
/* Positioning */
position: fixed;
left: 0;
top: 56px;
z-index: 10;

/* Dimensions */
width: 100%;
height: 1px;

/* Reset the appearance */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

/* Get rid of the default border in Firefox/Opera. */
border: none;

/* Progress bar container for Firefox/IE10 */
background-color: transparent;

/* Progress bar value for IE10 */
color: var(--global-theme-color);
}

progress::-webkit-progress-bar {
background-color: transparent;
}

progress::-webkit-progress-value {
background-color: var(--global-theme-color);
}

progress::-moz-progress-bar {
background-color: var(--global-theme-color);
}

.progress-container {
width: 100%;
background-color: transparent;
position: fixed;
top: 56px;
left: 0;
height: 5px;
display: block;
}

.progress-bar {
background-color: var(--global-theme-color);
width: 0%;
display: block;
height: inherit;
}

0 comments on commit c77834d

Please sign in to comment.