]> git.r.bdr.sh - rbdr/lyricli.rb/blame - doc/js/app.js
Skeletons for the exceptions
[rbdr/lyricli.rb] / doc / js / app.js
CommitLineData
823e558b
BB
1function createSourceLinks() {
2 $('.method_details_list .source_code').
3 before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4 $('.toggleSource').toggle(function() {
5 $(this).parent().nextAll('.source_code').slideDown(100);
6 $(this).text("Hide source");
7 },
8 function() {
9 $(this).parent().nextAll('.source_code').slideUp(100);
10 $(this).text("View source");
11 });
12}
13
14function createDefineLinks() {
15 var tHeight = 0;
16 $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17 $('.toggleDefines').toggle(function() {
18 tHeight = $(this).parent().prev().height();
19 $(this).prev().show();
20 $(this).parent().prev().height($(this).parent().height());
21 $(this).text("(less)");
22 },
23 function() {
24 $(this).prev().hide();
25 $(this).parent().prev().height(tHeight);
26 $(this).text("more...");
27 });
28}
29
30function createFullTreeLinks() {
31 var tHeight = 0;
32 $('.inheritanceTree').toggle(function() {
33 tHeight = $(this).parent().prev().height();
34 $(this).parent().toggleClass('showAll');
35 $(this).text("(hide)");
36 $(this).parent().prev().height($(this).parent().height());
37 },
38 function() {
39 $(this).parent().toggleClass('showAll');
40 $(this).parent().prev().height(tHeight);
41 $(this).text("show all");
42 });
43}
44
45function fixBoxInfoHeights() {
46 $('dl.box dd.r1, dl.box dd.r2').each(function() {
47 $(this).prev().height($(this).height());
48 });
49}
50
51function searchFrameLinks() {
52 $('.full_list_link').click(function() {
53 toggleSearchFrame(this, $(this).attr('href'));
54 return false;
55 });
56}
57
58function toggleSearchFrame(id, link) {
59 var frame = $('#search_frame');
60 $('#search a').removeClass('active').addClass('inactive');
61 if (frame.attr('src') == link && frame.css('display') != "none") {
62 frame.slideUp(100);
63 $('#search a').removeClass('active inactive');
64 }
65 else {
66 $(id).addClass('active').removeClass('inactive');
67 frame.attr('src', link).slideDown(100);
68 }
69}
70
71function linkSummaries() {
72 $('.summary_signature').click(function() {
73 document.location = $(this).find('a').attr('href');
74 });
75}
76
77function framesInit() {
78 if (hasFrames) {
79 document.body.className = 'frames';
80 $('#menu .noframes a').attr('href', document.location);
81 window.top.document.title = $('html head title').text();
82 }
83 else {
84 $('#menu .noframes a').text('frames').attr('href', framesUrl);
85 }
86}
87
88function keyboardShortcuts() {
89 if (window.top.frames.main) return;
90 $(document).keypress(function(evt) {
91 if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
92 if (typeof evt.target !== "undefined" &&
93 (evt.target.nodeName == "INPUT" ||
94 evt.target.nodeName == "TEXTAREA")) return;
95 switch (evt.charCode) {
96 case 67: case 99: $('#class_list_link').click(); break; // 'c'
97 case 77: case 109: $('#method_list_link').click(); break; // 'm'
98 case 70: case 102: $('#file_list_link').click(); break; // 'f'
99 default: break;
100 }
101 });
102}
103
104function summaryToggle() {
105 $('.summary_toggle').click(function() {
34d0bf15
BB
106 if (localStorage) {
107 localStorage.summaryCollapsed = $(this).text();
823e558b 108 }
34d0bf15
BB
109 $('.summary_toggle').each(function() {
110 $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
111 var next = $(this).parent().parent().nextAll('ul.summary').first();
112 if (next.hasClass('compact')) {
113 next.toggle();
114 next.nextAll('ul.summary').first().toggle();
115 }
116 else if (next.hasClass('summary')) {
117 var list = $('<ul class="summary compact" />');
118 list.html(next.html());
119 list.find('.summary_desc, .note').remove();
120 list.find('a').each(function() {
121 $(this).html($(this).find('strong').html());
122 $(this).parent().html($(this)[0].outerHTML);
123 });
124 next.before(list);
125 next.toggle();
126 }
127 });
823e558b
BB
128 return false;
129 });
130 if (localStorage) {
34d0bf15
BB
131 if (localStorage.summaryCollapsed == "collapse") {
132 $('.summary_toggle').first().click();
133 }
823e558b
BB
134 else localStorage.summaryCollapsed = "expand";
135 }
136}
137
138function fixOutsideWorldLinks() {
139 $('a').each(function() {
140 if (window.location.host != this.host) this.target = '_parent';
141 });
142}
143
144function generateTOC() {
145 if ($('#filecontents').length === 0) return;
146 var _toc = $('<ol class="top"></ol>');
147 var show = false;
148 var toc = _toc;
149 var counter = 0;
150 var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
151 var i;
152 if ($('#filecontents h1').length > 1) tags.unshift('h1');
153 for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
154 var lastTag = parseInt(tags[0][1], 10);
155 $(tags.join(', ')).each(function() {
156 if ($(this).parents('.method_details .docstring').length != 0) return;
157 if (this.id == "filecontents") return;
158 show = true;
159 var thisTag = parseInt(this.tagName[1], 10);
160 if (this.id.length === 0) {
161 var proposedId = $(this).attr('toc-id');
162 if (typeof(proposedId) != "undefined") this.id = proposedId;
163 else {
164 var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
165 if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
166 this.id = proposedId;
167 }
168 }
169 if (thisTag > lastTag) {
170 for (i = 0; i < thisTag - lastTag; i++) {
171 var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
172 }
173 }
174 if (thisTag < lastTag) {
175 for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
176 }
177 var title = $(this).attr('toc-title');
178 if (typeof(title) == "undefined") title = $(this).text();
179 toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
180 lastTag = thisTag;
181 });
182 if (!show) return;
183 html = '<div id="toc"><p class="title"><a class="hide_toc" href="#"><strong>Table of Contents</strong></a> <small>(<a href="#" class="float_toc">left</a>)</small></p></div>';
184 $('#content').prepend(html);
185 $('#toc').append(_toc);
186 $('#toc .hide_toc').toggle(function() {
187 $('#toc .top').slideUp('fast');
188 $('#toc').toggleClass('hidden');
189 $('#toc .title small').toggle();
190 }, function() {
191 $('#toc .top').slideDown('fast');
192 $('#toc').toggleClass('hidden');
193 $('#toc .title small').toggle();
194 });
195 $('#toc .float_toc').toggle(function() {
196 $(this).text('float');
197 $('#toc').toggleClass('nofloat');
198 }, function() {
199 $(this).text('left');
200 $('#toc').toggleClass('nofloat');
201 });
202}
203
204$(framesInit);
205$(createSourceLinks);
206$(createDefineLinks);
207$(createFullTreeLinks);
208$(fixBoxInfoHeights);
209$(searchFrameLinks);
210$(linkSummaries);
211$(keyboardShortcuts);
212$(summaryToggle);
213$(fixOutsideWorldLinks);
214$(generateTOC);