Fix hearts
[wolnelektury.git] / src / wolnelektury / static / js / book_text / progress.js
1 (function($){$(function(){
2
3     let t = $('#global-progress').data('t');
4
5     function upd_t() {
6         $text = $('#main-text #book-text');
7         if (!$text.length) return;
8
9         texttop = $text.offset().top;
10
11         $footnotes = $('#footnotes', $text);
12         if ($footnotes.length) {
13             textbottom = $footnotes.offset().top;
14         } else {
15             textbottom = texttop + $text.height();
16         }
17
18         textlen = textbottom - texttop;
19         progress = (window.scrollY - texttop) / textlen;
20         progress = Math.max(0, Math.min(progress, 1))
21
22         $('#global-progress .filled').css('right', (1 - progress) * 100 + '%');
23         tleft = Math.round((1 - progress) * t / 60);
24         tt = '';
25         if (tleft > 60) {
26             h = Math.floor(tleft / 60);
27             tt = h + ' h ';
28             tleft -= h * 60;
29         }
30         tt += tleft + ' min';
31         $('#global-progress .progress-text-value').text(tt);
32     }
33     upd_t();
34     $(window).scroll(upd_t);
35 })})(jQuery);