Skip to content

Commit

Permalink
QOLOE-797 back to top set default text
Browse files Browse the repository at this point in the history
  • Loading branch information
SenChung committed Jan 15, 2025
1 parent 08a6ac2 commit 2bb5b73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
54 changes: 27 additions & 27 deletions src/components/bs5/backToTop/backToTop.functions.js
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();
}
}
4 changes: 2 additions & 2 deletions src/components/bs5/backToTop/backToTop.hbs
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}}

0 comments on commit 2bb5b73

Please sign in to comment.