Additional index styling
[exim-website.git] / templates / web / doc / chapter.js
1 // Sidebar table of contents
2 (function ($) {
3
4     var click_func = function (e) {
5         if ($('#toc').data('opened')) {
6             $('#toc > *').animate({
7                 left: '-=' + $('#toc > ul').width() + 'px'
8             }, 'fast');
9             $('#toc').removeData('opened');
10         } else {
11             $('#toc > *').animate({
12                 left: '+=' + $('#toc > ul').width() + 'px'
13             }, 'fast');
14             $('#toc').data('opened', 1);
15         }
16     };
17
18     var type = document.location.pathname.match(/\/doc\/html\/spec_html\/filter/) ? 'filter' : 'spec';
19
20     // Get the relevant table of contents
21     $.get(type === 'spec' ? 'index_toc.xml' : 'filter_toc.xml', function (xml) {
22
23         // Remove the main list from the DOM for performance
24         var $ul = $('#toc > ul').remove();
25
26         // Traverse chapters
27         var chapter_id = 0;
28         $(xml).find('c').each(function () {
29             ++chapter_id;
30             var chapter_title = $(this).children('t').text();
31             var chapter_url = $(this).children('u').text();
32
33             var chapter_li = $('<li/>').append(
34             $('<a/>').attr({
35                 href: chapter_url,
36                 title: chapter_title
37             }).text(chapter_id + '. ' + chapter_title), $('<ul/>').hide()).appendTo($ul);
38         });
39
40         $('#toc img').fadeIn('slow', function () {
41             // Add the main list back to the DOM
42             $ul.removeClass('hidden').css('visibility', 'hidden').appendTo('#toc').css('left', '-' + $ul.width() + 'px').css('visibility', 'visible');
43             $('#toc > img').mousedown(click_func);
44             $('#toc > ul').click(click_func);
45             $('#toc a').click(function (e) {
46                 e.stopPropagation()
47             });
48         });
49     });
50 })(jQuery);