From 619d8422628c76bdea99ba6ffe672b647b38cf73 Mon Sep 17 00:00:00 2001
From: Thibaud Guillot <thibaud.guillot@biblibre.com>
Date: Mon, 15 Jan 2024 11:19:51 +0100
Subject: [PATCH] Bug 35810: Add back to top button on staff pages

Test plan:

1) Apply this patch and rebuild css with 'yarn build'
2) For example, perform a search from catalogue
3) Scroll down to see the button appear and scroll up to see it
   disappear

Note that it's works also on patron search etc..

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
---
 .../intranet-tmpl/prog/css/src/staff-global.scss  |  8 ++++++++
 koha-tmpl/intranet-tmpl/prog/js/staff-global.js   | 15 ++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
index 0723e230690..9e806a81bc2 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
@@ -4775,3 +4775,11 @@ div .suggestion_note {
         border-bottom-right-radius: 5px;
     }
 }
+
+#backtotop {
+    font-size: 140%;
+    position: fixed;
+    bottom: 40px;
+    right: 40px;
+    z-index: 1000;
+}
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
index ab24a9304e2..b4752191649 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
@@ -243,7 +243,20 @@ $(document).ready(function() {
     $("#bookbag_form a[href*='detail.pl?']").click(function(){
         resetSearchContext();
     });
-
+    // add back to top button on each staff page
+    $("body").append('<button id="backtotop" class="btn btn-default"><i class="fa fa-arrow-up" aria-hidden="true"></i></button>');
+    $("#backtotop").hide();
+    $(window).scroll(function(){
+        if ( $(window).scrollTop() < 300 ) {
+            $("#backtotop").fadeOut();
+        } else {
+            $("#backtotop").fadeIn();
+        }
+    });
+    $("#backtotop").click(function(e) {
+        e.preventDefault();
+        $("html,body").animate({scrollTop: 0}, "slow");
+    });
 });
 
 function removeLastBorrower(){
-- 
2.30.2