Mini Shell
{"version":3,"file":"backtotopbutton.min.js","sources":["../src/backtotopbutton.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Theme LearnR - JS code back to top button\n *\n * @module theme_learnr/backtotopbutton\n * @copyright 2022 Alexander Bias, lern.link GmbH <[email protected]>\n * @copyright on behalf of Zurich University of Applied Sciences (ZHAW)\n * @copyright based on code from theme_boost_campus by Kathrin Osswald.\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/str', 'core/notification'], function($, str, Notification) {\n \"use strict\";\n\n // Remember if the back to top button is shown currently.\n let buttonShown = false;\n\n /**\n * Initializing.\n */\n function initBackToTop() {\n // Get the string backtotop from language file.\n let stringsPromise = str.get_string('backtotop', 'theme_learnr');\n\n // If the string has arrived, add backtotop button to DOM and add scroll and click handlers.\n $.when(stringsPromise).then(function(string) {\n // Add a fontawesome icon after the footer as the back to top button.\n $('#page-footer').after('<button id=\"back-to-top\" ' +\n 'class=\"btn btn-icon bg-secondary icon-no-margin d-print-none\"' +\n 'aria-label=\"' + string + '\">' +\n '<i aria-hidden=\"true\" class=\"fa fa-chevron-up fa-fw \"></i></button>');\n\n // This function fades the button in when the page is scrolled down or fades it out\n // if the user is at the top of the page again.\n // Please note that Boost in Moodle 4.0 does not scroll the window object / whole body tag anymore,\n // it scrolls the #page element instead.\n $('#page').on('scroll', function() {\n if ($('#page').scrollTop() > 220) {\n checkAndShow();\n } else {\n checkAndHide();\n }\n });\n\n // This function scrolls the page to top with a duration of 500ms.\n $('#back-to-top').on('click', function(event) {\n event.preventDefault();\n $('#page').animate({scrollTop: 0}, 500);\n $('#back-to-top').blur();\n });\n\n return true;\n }).fail(Notification.exception);\n }\n\n /**\n * Helper function to handle the button visibility when the page is scrolling up.\n */\n function checkAndHide() {\n // Check if the button is still shown.\n if (buttonShown === true) {\n // Fade it out and remember the status in the end.\n // To be precise, the faceOut() function will be called multiple times as buttonShown is not set until the button is\n // really faded out. However, as soon as it is faded out, it won't be called until the button is shown again.\n $('#back-to-top').fadeOut(100, function() {\n buttonShown = false;\n });\n }\n }\n\n /**\n * Helper function to handle the button visibility when the page is scrolling down.\n */\n function checkAndShow() {\n // Check if the button is not yet shown.\n if (buttonShown === false) {\n // Fade it in and remember the status in the end.\n $('#back-to-top').fadeIn(300, function() {\n buttonShown = true;\n });\n }\n }\n\n return {\n init: function() {\n initBackToTop();\n }\n };\n});\n"],"names":["define","$","str","Notification","buttonShown","initBackToTop","stringsPromise","get_string","when","then","string","after","on","scrollTop","fadeIn","fadeOut","event","preventDefault","animate","blur","fail","exception","init"],"mappings":";;;;;;;;;AAyBAA,2CAAO,CAAC,SAAU,WAAY,sBAAsB,SAASC,EAAGC,IAAKC,kBAI7DC,aAAc,WAKTC,oBAEDC,eAAiBJ,IAAIK,WAAW,YAAa,qBAGjDN,EAAEO,KAAKF,gBAAgBG,MAAK,SAASC,eAEjCT,EAAE,gBAAgBU,MAAM,qGAECD,OAFD,yEASxBT,EAAE,SAASW,GAAG,UAAU,WAChBX,EAAE,SAASY,YAAc,KAsCjB,IAAhBT,aAEAH,EAAE,gBAAgBa,OAAO,KAAK,WAC1BV,aAAc,MAlBF,IAAhBA,aAIAH,EAAE,gBAAgBc,QAAQ,KAAK,WAC3BX,aAAc,QApBlBH,EAAE,gBAAgBW,GAAG,SAAS,SAASI,OACnCA,MAAMC,iBACNhB,EAAE,SAASiB,QAAQ,CAACL,UAAW,GAAI,KACnCZ,EAAE,gBAAgBkB,WAGf,KACRC,KAAKjB,aAAakB,iBA+BlB,CACHC,KAAM,WACFjB"}
Zerion Mini Shell 1.0