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