From 08a839c5f59574b5f3d96910e2dad1821ece8c77 Mon Sep 17 00:00:00 2001 From: Carlos Morales Date: Mon, 24 Oct 2022 10:38:26 +0100 Subject: [PATCH] Add a progress bar to show the scroll position (#934) This feature adds a horizontal bar under the top menu which tracks the vertical scroll position. Such a feature can be useful to represent how much is left to read on the current page more aesthetically. As this is an optional feature, `enable_progressbar` must be set to `true` in `_config.yml` to activate the functionality. I am not the original author of this code. I just made it compatible with the current version of the template at the time of this commit. The original code was most likely authored by Pankaj Parashar in this [post](https://css-tricks.com/reading-position-indicator/) made a few years before the first inclusion in an `al-folio` site. Then, the code was adapted for compatibility with the template at Anthony Plantanios' site. Finally, I did the last updates to have the code fit the new conventions used in the project. This was discussed in #557 Co-authored-by: rohandebsarkar --- _config.yml | 2 +- _includes/header.html | 10 +++- _includes/scripts/progressBar.html | 80 ++++++++++++++++++++++++++++++ _layouts/default.html | 1 + _layouts/distill.html | 1 + _sass/_base.scss | 55 ++++++++++++++++++++ 6 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 _includes/scripts/progressBar.html diff --git a/_config.yml b/_config.yml index 71597db4f91e..59b1395e98a3 100644 --- a/_config.yml +++ b/_config.yml @@ -308,7 +308,7 @@ enable_navbar_social: false # enables displaying social links in the enable_project_categories: true # enables categorization of projects into # multiple categories enable_medium_zoom: true # enables image zoom feature (as on medium.com) - +enable_progressbar: false # enables a horizontal progress bar linked to the vertical scroll position # ----------------------------------------------------------------------------- # Library versions diff --git a/_includes/header.html b/_includes/header.html index 29bb66c43290..79779f6a44ff 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -108,4 +108,12 @@ - \ No newline at end of file +{% if site.enable_progressbar %} + + +
+ +
+
+{%- endif %} + diff --git a/_includes/scripts/progressBar.html b/_includes/scripts/progressBar.html new file mode 100644 index 000000000000..88bb73cd35e4 --- /dev/null +++ b/_includes/scripts/progressBar.html @@ -0,0 +1,80 @@ +{% if site.enable_progressbar %} + + + + +{%- endif %} diff --git a/_layouts/default.html b/_layouts/default.html index 1d291e406fca..2887107cc95f 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -30,5 +30,6 @@ {% include scripts/misc.html %} {% include scripts/mathjax.html %} {% include scripts/analytics.html %} + {% include scripts/progressBar.html %} diff --git a/_layouts/distill.html b/_layouts/distill.html index 018b2897dd44..b104771aa720 100644 --- a/_layouts/distill.html +++ b/_layouts/distill.html @@ -105,5 +105,6 @@

Contents

{% include scripts/bootstrap.html %} {% include scripts/analytics.html %} + {% include scripts/progressBar.html %} diff --git a/_sass/_base.scss b/_sass/_base.scss index 0efbcb98535b..f507af59a18d 100644 --- a/_sass/_base.scss +++ b/_sass/_base.scss @@ -656,3 +656,58 @@ html.transition *:after { } } } + +progress { + /* Positioning */ + position: fixed; + left: 0; + top: 56px; + z-index: 10; + + /* Dimensions */ + width: 100%; + height: 5px; + + /* 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; + }