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