]> git.r.bdr.sh - rbdr/lyricli.rb/blame_incremental - doc/js/app.js
Integrates iTunes source
[rbdr/lyricli.rb] / doc / js / app.js
... / ...
CommitLineData
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() {
106 localStorage.summaryCollapsed = $(this).text();
107 $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
108 var next = $(this).parent().parent().nextAll('ul.summary').first();
109 if (next.hasClass('compact')) {
110 next.toggle();
111 next.nextAll('ul.summary').first().toggle();
112 }
113 else if (next.hasClass('summary')) {
114 var list = $('<ul class="summary compact" />');
115 list.html(next.html());
116 list.find('.summary_desc, .note').remove();
117 list.find('a').each(function() {
118 $(this).html($(this).find('strong').html());
119 $(this).parent().html($(this)[0].outerHTML);
120 });
121 next.before(list);
122 next.toggle();
123 }
124 return false;
125 });
126 if (localStorage) {
127 if (localStorage.summaryCollapsed == "collapse") $('.summary_toggle').click();
128 else localStorage.summaryCollapsed = "expand";
129 }
130}
131
132function fixOutsideWorldLinks() {
133 $('a').each(function() {
134 if (window.location.host != this.host) this.target = '_parent';
135 });
136}
137
138function generateTOC() {
139 if ($('#filecontents').length === 0) return;
140 var _toc = $('<ol class="top"></ol>');
141 var show = false;
142 var toc = _toc;
143 var counter = 0;
144 var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
145 var i;
146 if ($('#filecontents h1').length > 1) tags.unshift('h1');
147 for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
148 var lastTag = parseInt(tags[0][1], 10);
149 $(tags.join(', ')).each(function() {
150 if ($(this).parents('.method_details .docstring').length != 0) return;
151 if (this.id == "filecontents") return;
152 show = true;
153 var thisTag = parseInt(this.tagName[1], 10);
154 if (this.id.length === 0) {
155 var proposedId = $(this).attr('toc-id');
156 if (typeof(proposedId) != "undefined") this.id = proposedId;
157 else {
158 var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
159 if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
160 this.id = proposedId;
161 }
162 }
163 if (thisTag > lastTag) {
164 for (i = 0; i < thisTag - lastTag; i++) {
165 var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
166 }
167 }
168 if (thisTag < lastTag) {
169 for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
170 }
171 var title = $(this).attr('toc-title');
172 if (typeof(title) == "undefined") title = $(this).text();
173 toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
174 lastTag = thisTag;
175 });
176 if (!show) return;
177 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>';
178 $('#content').prepend(html);
179 $('#toc').append(_toc);
180 $('#toc .hide_toc').toggle(function() {
181 $('#toc .top').slideUp('fast');
182 $('#toc').toggleClass('hidden');
183 $('#toc .title small').toggle();
184 }, function() {
185 $('#toc .top').slideDown('fast');
186 $('#toc').toggleClass('hidden');
187 $('#toc .title small').toggle();
188 });
189 $('#toc .float_toc').toggle(function() {
190 $(this).text('float');
191 $('#toc').toggleClass('nofloat');
192 }, function() {
193 $(this).text('left');
194 $('#toc').toggleClass('nofloat');
195 });
196}
197
198$(framesInit);
199$(createSourceLinks);
200$(createDefineLinks);
201$(createFullTreeLinks);
202$(fixBoxInfoHeights);
203$(searchFrameLinks);
204$(linkSummaries);
205$(keyboardShortcuts);
206$(summaryToggle);
207$(fixOutsideWorldLinks);
208$(generateTOC);