From 6db272cdb367187394dbb01e93e2e03dab14f9ab Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 5 Feb 2024 09:22:59 +0100 Subject: [PATCH 1/1] fix --- .../static/js/book_text/progress.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/wolnelektury/static/js/book_text/progress.js diff --git a/src/wolnelektury/static/js/book_text/progress.js b/src/wolnelektury/static/js/book_text/progress.js new file mode 100644 index 000000000..8175de666 --- /dev/null +++ b/src/wolnelektury/static/js/book_text/progress.js @@ -0,0 +1,33 @@ +(function($){$(function(){ + + t = $('#global-progress').data('t'); + function upd_t() { + $text = $('#main-text #book-text'); + texttop = $text.offset().top; + + $footnotes = $('#footnotes', $text); + if ($footnotes.length) { + textbottom = $footnotes.offset().top; + } else { + textbottom = texttop + $text.height(); + } + + textlen = textbottom - texttop; + progress = (window.scrollY - texttop) / textlen; + progress = Math.max(0, Math.min(progress, 1)) + console.log('SCROLL BODY', progress); + + $('#global-progress .filled').css('right', (1 - progress) * 100 + '%'); + tleft = Math.round((1 - progress) * t / 60); + tt = ''; + if (tleft > 60) { + h = Math.floor(tleft / 60); + tt = h + ' h '; + tleft -= h * 60; + } + tt += tleft + ' min'; + $('#global-progress .progress-text-value').text(tt); + } + upd_t(); + $(window).scroll(upd_t); +})})(jQuery); -- 2.20.1