Security release 4.90.1
[exim-website.git] / templates / static / doc / chapter.js
1 // Rewrite chapter urls using the canonical name. e.g ch01.html becomes introduction.html
2 (function ($) {
3     if (document.location.pathname.match(/\/ch\d+\.html$/)) {
4         var url = document.location.href;
5         var canonical = $('link[rel="canonical"]').attr('href');
6         if (canonical) {
7             canonical = canonical.replace(/^[^#]+(\/[^\/#]+).*/,'$1');
8             url = url.replace(/\/ch\d+\.html/, canonical);
9             if ("history" in window && "replaceState" in window.history)
10                 window.history.replaceState("", document.title, url);
11             else
12                 document.location.href = url;
13         }
14     }
15 })(jQuery);
16
17 // Warnings about reading old version of documentation
18 (function ($) {
19     if( $.grep( document.cookie.split(/\s*;\s*/), function(a){return a === 'old_version_warning_removed=true' ? true : false }).length === 0 ){
20         $('#old_version_warning')
21             .show()
22             .find('span.closebar a')
23                 .click(function(e){
24                     $('#old_version_warning').remove();
25                     document.cookie="old_version_warning_removed=true";
26                     e.preventDefault();
27                 });
28     }
29 })(jQuery);
30
31 // Sidebar table of contents
32 (function ($) {
33
34     var click_func = function (e) {
35         e.stopPropagation();
36         if ($('#toc').data('opened')) {
37             $('#toc > *').animate({
38                 left: '-=' + $('#toc > ul').width() + 'px'
39             }, 'fast');
40             $('#toc').removeData('opened');
41         } else {
42             $('#toc > *').animate({
43                 left: '+=' + $('#toc > ul').width() + 'px'
44             }, 'fast');
45             $('#toc').data('opened', 1);
46         }
47     };
48
49     $('body').click(function () {
50         if( $('#toc').data('opened') ) $('#toc > img').mousedown();
51     });
52
53     var type = document.location.pathname.match(/\/doc\/html\/spec_html\/filter/) ? 'filter' : 'spec';
54
55     // Get the relevant table of contents
56     $.get(type === 'spec' ? 'index_toc.xml' : 'filter_toc.xml', function (xml) {
57
58         // Remove the main list from the DOM for performance
59         var $ul = $('#toc > ul').remove();
60
61         // Traverse chapters
62         var chapter_id = 0;
63         $(xml).find('c').each(function () {
64             ++chapter_id;
65             var chapter_title = $(this).children('t').text();
66             var chapter_url = $(this).children('u').text();
67
68             var chapter_li = $('<li/>').append(
69             $('<a/>').attr({
70                 href: chapter_url,
71                 title: chapter_title
72             }).text(chapter_id + '. ' + chapter_title), $('<ul/>').hide()).appendTo($ul);
73         });
74
75         $('#toc img').fadeIn('slow', function () {
76             // Add the main list back to the DOM
77             $ul.removeClass('hidden').css('visibility', 'hidden').appendTo('#toc').css('left', '-' + $ul.width() + 'px').css('visibility', 'visible');
78             $('#toc > img').mousedown(click_func);
79             $('#toc > ul').click(click_func);
80             $('#toc, #toc a').click(function (e) {
81                 e.stopPropagation()
82             });
83         });
84     });
85 })(jQuery);