Faster javascript and usability enchancements in book reader.
[wolnelektury.git] / wolnelektury / media / js / book.js
1 $(function() {
2     $.highlightFade.defaults.speed = 3000;
3     
4     $('#toc').hide();
5     $.scrollTo('-=50px');
6     
7     if ($('#toc li').length == 0) {
8         $('#menu li a[href="#toc"]').remove();
9     }
10     
11     $('body').delegate('click', '#toc a, #themes a, .anchor, .annotation', function(event) {
12         event.preventDefault();
13         $('#menu li a.selected').click();
14         if ($(this).attr('href')) {
15             var name = $(this).attr('href').slice(1);
16             $.scrollTo('a[name="' + name + '"]', 500, {offset: {top: -50, left: 0}});
17             $('a[name="' + name + '"]').highlightFade('yellow');
18         }
19     });
20     
21     $('#menu li a').toggle(function() {
22         $('#menu li a.selected').click();
23         $(this).addClass('selected');
24         $($(this).attr('href')).slideDown('fast');
25     }, function() {
26         $(this).removeClass('selected');
27         $($(this).attr('href')).slideUp('fast');
28     });
29 });