Slightly simplified the collapsing menu code
[kohana-userguide.git] / media / guide / js / kodoc.js
blobc9072fe49b0ee7dad142c341946e79f6d1d6a59d
1 $(document).ready(function()
4 // Syntax highlighter
6         $('pre:not(.debug) code').each(function()
7         {
8                 $(this).addClass('brush: php, class-name: highlighted');
9         });
11         SyntaxHighlighter.config.tagName = 'code';
12         // Don't show the toolbar or line-numbers.
13         SyntaxHighlighter.defaults.gutter = false;
14         SyntaxHighlighter.all();
15         
16         // Any link that has the current page as its href should be class="current"
17         $('a[href="'+ window.location.pathname +'"]').addClass('current');
18         
19 // Breadcrumbs magic
21         last = $('#kodoc-nav .breadcrumb-last');
22         li = $('<li></li>');
23         
24         $('#kodoc-menu li').has('a.current').each(function()
25         {
26                 // Only add if we aren't already on that page
27                 if ($(this).find(':first-child').first().attr('href') != window.location.pathname)
28                 {
29                         // Clone the empty li, set it's html as the link or span, then prepend it to the last breadcrumb item
30                         last.before(li.clone().html($(this).find(':first-child').first().clone()));
31                 }
32         });
33         
34         // Now kill the duplicate link for the current page
35         //last.prev().remove();
37 // Collapsing menus
39         $('#topics li:has(li)').each(function()
40         {
41                 var $this = $(this);
42                 var toggle = $('<span class="toggle"></span>');
43                 var menu = $this.find('>ul,>ol');
45                 toggle.click(function()
46                 {
47                         if (menu.is(':visible'))
48                         {
49                                 menu.stop(true, true).slideUp('fast');
50                                 toggle.html('+');
51                         }
52                         else
53                         {
54                                 menu.stop(true, true).slideDown('fast');
55                                 toggle.html('&ndash;');
56                         }
57                 });
59                 $this.find('>span').click(function()
60                 {
61                         // Menu without a link
62                         toggle.click();
63                 });
65                 if ( ! $this.is(':has(a.current)'))
66                 {
67                         menu.hide();
68                 }
70                 toggle.html(menu.is(':visible') ? '&ndash;' : '+').prependTo($this);
71         });
73 // Show source links
75         $('#kodoc-main .method-source').each(function()
76         {
77                 var self = $(this);
78                 var togg = $(' <a class="sourcecode-toggle">[show]</a>').appendTo($('h4', self));
79                 var code = self.find('pre').hide();
81                 togg.toggle(function()
82                 {
83                         togg.html('[hide]');
84                         code.stop(true, true).slideDown();
85                 },
86                 function()
87                 {
88                         togg.html('[show]');
89                         code.stop(true, true).slideUp();
90                 });
91         });
93 // "Link to this" link that appears when you hover over a header
95         $('#kodoc-main')
96                 .find('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]')
97                 .append(function(index, html){
98                         return '<a href="#' + $(this).attr('id') + '" class="permalink">link to this</a>';
99                 });
101 // Table of contents for userguide pages
102         
103         // When the show/hide link for the page toc is clicked, toggle visibility
104         $('#kodoc-toc-toggle').click(function()
105         {
106                 if ($('#kodoc-page-toc-content').is(':visible'))
107                 {
108                         // Hide the contents
109                         $(this).html('show');
110                         $('#kodoc-page-toc').addClass('closed').removeClass('open')
111                         $('#kodoc-page-toc-content').hide();
112                         $.cookie('kodoc-toc-show',"false");
113                 }
114                 else
115                 {
116                         // Show the contents
117                         $(this).html('hide');
118                         $('#kodoc-page-toc').addClass('open').removeClass('closed')
119                         $('#kodoc-page-toc-content').show();
120                         $.cookie('kodoc-toc-show',"true");
121                 }
122         });
123         
124         // If the cookie says to hide the toc, hide it by clicking the toggle
125         if ($.cookie('kodoc-toc-show') == "false")
126         {
127                 $('#kodoc-toc-toggle').click();
128         }