-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QOLOE-797 back to top set default text
- Loading branch information
Showing
2 changed files
with
29 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
export function backToTop() { | ||
// Get the Back To Top object: | ||
// The offset is the number of pixels after which the button is displayed | ||
// The dynamic attribute is used to determine if the buttons CSS uses Relitive or Fixed positioning | ||
// Get the Back To Top object: | ||
// The offset is the number of pixels after which the button is displayed | ||
// The dynamic attribute is used to determine if the buttons CSS uses Relitive or Fixed positioning | ||
|
||
let mybutton = document.getElementById("backToTop"); | ||
let btnIsDynamic = mybutton.getAttribute("data-dynamic"); | ||
let mybutton = document.getElementById("backToTop"); | ||
let btnIsDynamic = mybutton.getAttribute("data-dynamic"); | ||
|
||
mybutton.addEventListener("click", goToTop); | ||
mybutton.addEventListener("click", goToTop); | ||
|
||
if (btnIsDynamic == "true") { | ||
mybutton.classList.remove("show"); | ||
window.onscroll = function() {scrollFunction()}; | ||
} | ||
if (btnIsDynamic == "true") { | ||
mybutton.classList.remove("show"); | ||
window.onscroll = function() {scrollFunction()}; | ||
} | ||
|
||
function scrollFunction() { | ||
if (btnIsDynamic == "true") { | ||
let offset = mybutton.getAttribute("data-offset"); | ||
if (document.body.scrollTop > offset || document.documentElement.scrollTop > offset) { | ||
mybutton.classList.add("show"); | ||
mybutton.setAttribute("aria-hidden", false); | ||
} else { | ||
mybutton.classList.remove("show"); | ||
mybutton.setAttribute("aria-hidden", true); | ||
} | ||
} | ||
function scrollFunction() { | ||
if (btnIsDynamic == "true") { | ||
let offset = mybutton.getAttribute("data-offset"); | ||
if (document.body.scrollTop > offset || document.documentElement.scrollTop > offset) { | ||
mybutton.classList.add("show"); | ||
mybutton.setAttribute("aria-hidden", false); | ||
} else { | ||
mybutton.classList.remove("show"); | ||
mybutton.setAttribute("aria-hidden", true); | ||
} | ||
} | ||
} | ||
|
||
function goToTop() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
event.preventDefault(); | ||
} | ||
} | ||
function goToTop() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
event.preventDefault(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{{#unless hide_back_to_top}} | ||
<div class="qld__widgets {{#if dynamic}}fixed{{/if}}"> | ||
<a href="#" id="backToTop" class="qld__btn qld__btn--floating qld__btn--back-to-top show" data-offset="{{offset}}" data-dynamic="{{dynamic}}" aria-label="{{text}}"> | ||
<span>{{text}}</span> | ||
<a href="#" id="backToTop" class="qld__btn qld__btn--floating qld__btn--back-to-top show" data-offset="{{offset}}" data-dynamic="{{dynamic}}" aria-label="{{#if text}}{{text}}{{else}}Back to top{{/if}}"> | ||
<span>{{#if text}}{{text}}{{else}}Back to top{{/if}}</span> | ||
</a> | ||
</div> | ||
{{/unless}} |