Rearrange source to src dir.
[redakcja.git] / src / redakcja / static / js / book_text / book.js
1 $(function() {
2     function scrollToAnchor(anchor) {
3         if (anchor) {
4             var anchor_name = anchor.slice(1);
5             var element = $('a[name="' + anchor_name + '"]');
6             if (element.length > 0) {
7                 $.scrollTo(element, 500, {offset: {top: -50, left: 0}});
8                 foot_elem = $('#footnotes a[name="' + anchor_name + '"]');
9                 if (foot_elem.length > 0) {
10                     $(element).parent().highlightFade('yellow');
11                 }
12                 window.location.hash = anchor;
13             }
14         }
15     }
16
17     $.highlightFade.defaults.speed = 3000;
18     $('#toc').hide();
19     if ($('#toc li').length == 0) {
20         $('#menu li a[href="#toc"]').remove();
21     }
22     if ($('#nota_red').length == 0) {
23         $('#menu li a[href="#nota_red"]').remove();
24     }
25
26     // On page load, scroll to anchor
27     scrollToAnchor(window.location.hash)
28
29     $('#toc, #themes, #book-text').delegate('click', 'a', function(event) {
30         event.preventDefault();
31         $('#menu li a.selected').click();
32         scrollToAnchor($(this).attr('href'));
33     });
34
35     $('#menu li a.menu').toggle(function() {
36         $('#menu li a.selected').click();
37         $(this).addClass('selected');
38         $($(this).attr('href')).slideDown('fast');
39     }, function() {
40         $(this).removeClass('selected');
41         $($(this).attr('href')).slideUp('fast');
42     });
43     
44
45     if (window.getSelection) {
46         $('.theme-begin').click(function() {
47             var selection = window.getSelection();
48             selection.removeAllRanges();
49             var range = document.createRange();
50
51             var e = $(".theme-end[fid='" + $(this).attr('fid') + "']")[0];
52
53             if (e) {
54                 range.setStartAfter(this);
55                 range.setEndBefore(e);
56                 selection.addRange(range);
57             }
58         });
59     }
60
61 });