- Added librarian as a submodule.
[wolnelektury.git] / wolnelektury / static / js / book.js
1 $(function() {
2     function scrollToAnchor(anchor) {
3         if (anchor) {
4             var element = $('a[name="' + anchor.slice(1) + '"]');
5             if (element.length > 0) {
6                 $.scrollTo(element, 500, {offset: {top: -50, left: 0}});
7                 $(element).highlightFade('yellow');
8                 window.location.hash = anchor;
9             }
10         }
11     }
12
13     $.highlightFade.defaults.speed = 3000;
14     $('#toc').hide();
15     if ($('#toc li').length == 0) {
16         $('#menu li a[href="#toc"]').remove();
17     }
18
19     // On page load, scroll to anchor
20     scrollToAnchor(window.location.hash)
21
22     $('#toc, #themes, #book-text').delegate('click', 'a', function(event) {
23         event.preventDefault();
24         $('#menu li a.selected').click();
25         scrollToAnchor($(this).attr('href'));
26     });
27
28     $('#menu li a').toggle(function() {
29         $('#menu li a.selected').click();
30         $(this).addClass('selected');
31         $($(this).attr('href')).slideDown('fast');
32     }, function() {
33         $(this).removeClass('selected');
34         $($(this).attr('href')).slideUp('fast');
35     });
36 });