yard 0.9.39 → 0.9.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +18 -21
  4. data/docs/GettingStarted.md +41 -15
  5. data/docs/Tags.md +5 -5
  6. data/docs/WhatsNew.md +59 -7
  7. data/docs/templates/default/yard_tags/html/setup.rb +1 -1
  8. data/lib/yard/autoload.rb +17 -0
  9. data/lib/yard/cli/diff.rb +7 -2
  10. data/lib/yard/code_objects/proxy.rb +1 -1
  11. data/lib/yard/handlers/processor.rb +1 -0
  12. data/lib/yard/handlers/rbs/attribute_handler.rb +43 -0
  13. data/lib/yard/handlers/rbs/base.rb +38 -0
  14. data/lib/yard/handlers/rbs/constant_handler.rb +18 -0
  15. data/lib/yard/handlers/rbs/method_handler.rb +327 -0
  16. data/lib/yard/handlers/rbs/mixin_handler.rb +20 -0
  17. data/lib/yard/handlers/rbs/namespace_handler.rb +26 -0
  18. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -4
  19. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  20. data/lib/yard/i18n/locale.rb +1 -1
  21. data/lib/yard/i18n/pot_generator.rb +1 -1
  22. data/lib/yard/parser/rbs/rbs_parser.rb +325 -0
  23. data/lib/yard/parser/rbs/statement.rb +75 -0
  24. data/lib/yard/parser/ruby/ruby_parser.rb +51 -1
  25. data/lib/yard/parser/source_parser.rb +3 -2
  26. data/lib/yard/registry_resolver.rb +7 -0
  27. data/lib/yard/server/library_version.rb +1 -1
  28. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +208 -12
  29. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +1 -17
  30. data/lib/yard/server/templates/default/method_details/html/permalink.erb +4 -2
  31. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +3 -3
  32. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +2 -3
  33. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +22 -16
  34. data/lib/yard/tags/directives.rb +7 -0
  35. data/lib/yard/tags/library.rb +3 -3
  36. data/lib/yard/tags/types_explainer.rb +2 -1
  37. data/lib/yard/templates/helpers/base_helper.rb +1 -1
  38. data/lib/yard/templates/helpers/html_helper.rb +15 -4
  39. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +6 -1
  40. data/lib/yard/templates/helpers/markup/hybrid_markdown.rb +2125 -0
  41. data/lib/yard/templates/helpers/markup_helper.rb +4 -2
  42. data/lib/yard/version.rb +1 -1
  43. data/po/ja.po +82 -82
  44. data/templates/default/fulldoc/html/full_list.erb +4 -4
  45. data/templates/default/fulldoc/html/js/app.js +503 -319
  46. data/templates/default/fulldoc/html/js/full_list.js +310 -213
  47. data/templates/default/layout/html/headers.erb +1 -1
  48. data/templates/default/method/html/header.erb +3 -3
  49. data/templates/default/module/html/defines.erb +3 -3
  50. data/templates/default/module/html/inherited_methods.erb +1 -0
  51. data/templates/default/module/html/method_summary.erb +8 -0
  52. data/templates/default/module/setup.rb +20 -0
  53. data/templates/default/onefile/html/layout.erb +3 -4
  54. data/templates/guide/fulldoc/html/js/app.js +57 -26
  55. data/templates/guide/layout/html/layout.erb +9 -11
  56. metadata +13 -4
@@ -1,395 +1,579 @@
1
- window.__app = function () {
2
- var localStorage = {},
3
- sessionStorage = {};
1
+ (function() {
2
+ var appState = window.__yardAppState || (window.__yardAppState = {
3
+ navigationListenerBound: false,
4
+ navigationChangeBound: false,
5
+ navResizerBound: false,
6
+ searchFrameGlobalsBound: false
7
+ });
8
+ var safeLocalStorage = {};
9
+ var safeSessionStorage = {};
10
+
4
11
  try {
5
- localStorage = window.localStorage;
6
- } catch (e) {}
12
+ safeLocalStorage = window.localStorage;
13
+ } catch (error) {}
14
+
7
15
  try {
8
- sessionStorage = window.sessionStorage;
9
- } catch (e) {}
16
+ safeSessionStorage = window.sessionStorage;
17
+ } catch (error) {}
10
18
 
11
- function createSourceLinks() {
12
- $(".method_details_list .source_code").before(
13
- "<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>"
14
- );
15
- $(".toggleSource").toggle(
16
- function () {
17
- $(this).parent().nextAll(".source_code").slideDown(100);
18
- $(this).text("Hide source");
19
- },
20
- function () {
21
- $(this).parent().nextAll(".source_code").slideUp(100);
22
- $(this).text("View source");
23
- }
24
- );
19
+ function query(selector, root) {
20
+ return (root || document).querySelector(selector);
25
21
  }
26
22
 
27
- function createDefineLinks() {
28
- var tHeight = 0;
29
- $(".defines").after(" <a href='#' class='toggleDefines'>more...</a>");
30
- $(".toggleDefines").toggle(
31
- function () {
32
- tHeight = $(this).parent().prev().height();
33
- $(this).prev().css("display", "inline");
34
- $(this).parent().prev().height($(this).parent().height());
35
- $(this).text("(less)");
36
- },
37
- function () {
38
- $(this).prev().hide();
39
- $(this).parent().prev().height(tHeight);
40
- $(this).text("more...");
41
- }
23
+ function queryAll(selector, root) {
24
+ return Array.prototype.slice.call(
25
+ (root || document).querySelectorAll(selector)
42
26
  );
43
27
  }
44
28
 
45
- function createFullTreeLinks() {
46
- var tHeight = 0;
47
- $(".inheritanceTree").toggle(
48
- function () {
49
- tHeight = $(this).parent().prev().height();
50
- $(this).parent().toggleClass("showAll");
51
- $(this).text("(hide)");
52
- $(this).parent().prev().height($(this).parent().height());
53
- },
54
- function () {
55
- $(this).parent().toggleClass("showAll");
56
- $(this).parent().prev().height(tHeight);
57
- $(this).text("show all");
58
- }
59
- );
29
+ function isVisible(element) {
30
+ if (!element) return false;
31
+ return window.getComputedStyle(element).display !== "none";
60
32
  }
61
33
 
62
- function searchFrameButtons() {
63
- $(".full_list_link").click(function () {
64
- toggleSearchFrame(this, $(this).attr("href"));
65
- return false;
34
+ function toggleDisplay(element, visible, displayValue) {
35
+ if (!element) return;
36
+ element.style.display = visible ? (displayValue || "") : "none";
37
+ }
38
+
39
+ function firstNextMatchingSibling(element, selector) {
40
+ var current = element;
41
+ while (current) {
42
+ current = current.nextElementSibling;
43
+ if (current && current.matches(selector)) return current;
44
+ }
45
+ return null;
46
+ }
47
+
48
+ function ready(callback) {
49
+ if (document.readyState === "loading") {
50
+ document.addEventListener("DOMContentLoaded", callback, { once: true });
51
+ } else {
52
+ callback();
53
+ }
54
+ }
55
+
56
+ function createSourceLinks() {
57
+ queryAll(".method_details_list .source_code").forEach(function(sourceCode) {
58
+ var toggleWrapper = document.createElement("span");
59
+ var link = document.createElement("a");
60
+
61
+ toggleWrapper.className = "showSource";
62
+ toggleWrapper.appendChild(document.createTextNode("["));
63
+ toggleWrapper.appendChild(link);
64
+ toggleWrapper.appendChild(document.createTextNode("]"));
65
+
66
+ link.href = "#";
67
+ link.className = "toggleSource";
68
+ link.textContent = "View source";
69
+
70
+ link.addEventListener("click", function(event) {
71
+ event.preventDefault();
72
+ var expanded = isVisible(sourceCode);
73
+ toggleDisplay(sourceCode, !expanded, "table");
74
+ link.textContent = expanded ? "View source" : "Hide source";
75
+ });
76
+
77
+ sourceCode.parentNode.insertBefore(toggleWrapper, sourceCode);
66
78
  });
67
- window.addEventListener("message", function (e) {
68
- if (e.data === "navEscape") {
69
- $("#nav").slideUp(100);
70
- $("#search a").removeClass("active inactive");
71
- $(window).focus();
72
- }
79
+ }
80
+
81
+ function createDefineLinks() {
82
+ queryAll(".defines").forEach(function(defines) {
83
+ var toggleLink = document.createElement("a");
84
+ var summary = defines.parentElement.previousElementSibling;
85
+
86
+ toggleLink.href = "#";
87
+ toggleLink.className = "toggleDefines";
88
+ toggleLink.textContent = "more...";
89
+ defines.insertAdjacentText("afterend", " ");
90
+ defines.insertAdjacentElement("afterend", toggleLink);
91
+
92
+ toggleLink.addEventListener("click", function(event) {
93
+ event.preventDefault();
94
+ var expanded = toggleLink.dataset.expanded === "true";
95
+
96
+ if (!expanded) {
97
+ toggleLink.dataset.height = String(summary.offsetHeight);
98
+ defines.style.display = "inline";
99
+ summary.style.height = toggleLink.parentElement.offsetHeight + "px";
100
+ toggleLink.textContent = "(less)";
101
+ toggleLink.dataset.expanded = "true";
102
+ } else {
103
+ defines.style.display = "none";
104
+ if (toggleLink.dataset.height) {
105
+ summary.style.height = toggleLink.dataset.height + "px";
106
+ }
107
+ toggleLink.textContent = "more...";
108
+ toggleLink.dataset.expanded = "false";
109
+ }
110
+ });
73
111
  });
112
+ }
74
113
 
75
- $(window).resize(function () {
76
- if ($("#search:visible").length === 0) {
77
- $("#nav").removeAttr("style");
78
- $("#search a").removeClass("active inactive");
79
- $(window).focus();
80
- }
114
+ function createFullTreeLinks() {
115
+ queryAll(".inheritanceTree").forEach(function(toggleLink) {
116
+ var container = toggleLink.parentElement;
117
+ var tree = container.previousElementSibling;
118
+
119
+ toggleLink.addEventListener("click", function(event) {
120
+ event.preventDefault();
121
+ var expanded = toggleLink.dataset.expanded === "true";
122
+
123
+ if (!expanded) {
124
+ toggleLink.dataset.height = String(tree.offsetHeight);
125
+ container.classList.add("showAll");
126
+ toggleLink.textContent = "(hide)";
127
+ tree.style.height = container.offsetHeight + "px";
128
+ toggleLink.dataset.expanded = "true";
129
+ } else {
130
+ container.classList.remove("showAll");
131
+ if (toggleLink.dataset.height) {
132
+ tree.style.height = toggleLink.dataset.height + "px";
133
+ }
134
+ toggleLink.textContent = "show all";
135
+ toggleLink.dataset.expanded = "false";
136
+ }
137
+ });
138
+ });
139
+ }
140
+
141
+ function resetSearchFrame() {
142
+ var frame = query("#nav");
143
+
144
+ if (frame) frame.removeAttribute("style");
145
+ queryAll("#search a").forEach(function(link) {
146
+ link.classList.remove("active");
147
+ link.classList.remove("inactive");
81
148
  });
149
+ window.focus();
82
150
  }
83
151
 
84
- function toggleSearchFrame(id, link) {
85
- var frame = $("#nav");
86
- $("#search a").removeClass("active").addClass("inactive");
87
- if (frame.attr("src") === link && frame.css("display") !== "none") {
88
- frame.slideUp(100);
89
- $("#search a").removeClass("active inactive");
152
+ function toggleSearchFrame(linkElement, link) {
153
+ var frame = query("#nav");
154
+
155
+ if (!frame) return;
156
+
157
+ queryAll("#search a").forEach(function(searchLink) {
158
+ searchLink.classList.remove("active");
159
+ searchLink.classList.add("inactive");
160
+ });
161
+
162
+ if (frame.getAttribute("src") === link && isVisible(frame)) {
163
+ frame.style.display = "none";
164
+ queryAll("#search a").forEach(function(searchLink) {
165
+ searchLink.classList.remove("active");
166
+ searchLink.classList.remove("inactive");
167
+ });
90
168
  } else {
91
- $(id).addClass("active").removeClass("inactive");
92
- if (frame.attr("src") !== link) frame.attr("src", link);
93
- frame.slideDown(100);
169
+ linkElement.classList.add("active");
170
+ linkElement.classList.remove("inactive");
171
+ if (frame.getAttribute("src") !== link) frame.setAttribute("src", link);
172
+ frame.style.display = "block";
94
173
  }
95
174
  }
96
175
 
176
+ function searchFrameButtons() {
177
+ queryAll(".full_list_link").forEach(function(link) {
178
+ if (link.dataset.yardSearchFrameBound === "true") return;
179
+
180
+ link.addEventListener("click", function(event) {
181
+ event.preventDefault();
182
+ toggleSearchFrame(link, link.getAttribute("href"));
183
+ });
184
+
185
+ link.dataset.yardSearchFrameBound = "true";
186
+ });
187
+
188
+ if (appState.searchFrameGlobalsBound) return;
189
+
190
+ window.addEventListener("message", function(event) {
191
+ if (event.data === "navEscape") resetSearchFrame();
192
+ });
193
+
194
+ window.addEventListener("resize", function() {
195
+ if (!isVisible(query("#search"))) resetSearchFrame();
196
+ });
197
+
198
+ appState.searchFrameGlobalsBound = true;
199
+ }
200
+
97
201
  function linkSummaries() {
98
- $(".summary_signature").click(function () {
99
- document.location = $(this).find("a").attr("href");
202
+ queryAll(".summary_signature").forEach(function(signature) {
203
+ signature.addEventListener("click", function(event) {
204
+ if (event.target.closest("a")) return;
205
+ var link = signature.querySelector("a");
206
+ if (link) document.location = link.getAttribute("href");
207
+ });
100
208
  });
101
209
  }
102
210
 
103
- function summaryToggle() {
104
- $(".summary_toggle").click(function (e) {
105
- e.preventDefault();
106
- localStorage.summaryCollapsed = $(this).text();
107
- $(".summary_toggle").each(function () {
108
- $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
109
- var next = $(this).parent().parent().nextAll("ul.summary").first();
110
- if (next.hasClass("compact")) {
111
- next.toggle();
112
- next.nextAll("ul.summary").first().toggle();
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
- }
211
+ function toggleSummaryCollection(toggleSelector, listSelector, cloneBuilder) {
212
+ queryAll(toggleSelector).forEach(function(toggleLink) {
213
+ toggleLink.addEventListener("click", function(event) {
214
+ event.preventDefault();
215
+ safeLocalStorage.summaryCollapsed = toggleLink.textContent;
216
+
217
+ queryAll(toggleSelector).forEach(function(link) {
218
+ link.textContent =
219
+ link.textContent === "collapse" ? "expand" : "collapse";
220
+
221
+ var container = link.parentElement.parentElement;
222
+ var next = firstNextMatchingSibling(container, listSelector);
223
+
224
+ if (!next) return;
225
+
226
+ if (next.classList.contains("compact")) {
227
+ var fullList = firstNextMatchingSibling(next, listSelector);
228
+ toggleDisplay(next, !isVisible(next));
229
+ toggleDisplay(fullList, !isVisible(fullList));
230
+ } else {
231
+ var compactList = cloneBuilder(next.cloneNode(true));
232
+ next.parentNode.insertBefore(compactList, next);
233
+ toggleDisplay(next, false);
234
+ }
235
+ });
124
236
  });
125
- return false;
126
237
  });
127
- if (localStorage.summaryCollapsed == "collapse") {
128
- $(".summary_toggle").first().click();
238
+ }
239
+
240
+ function buildCompactSummary(list) {
241
+ list.className = "summary compact";
242
+
243
+ queryAll(".summary_desc, .note", list).forEach(function(node) {
244
+ node.remove();
245
+ });
246
+
247
+ queryAll("a", list).forEach(function(link) {
248
+ var strong = link.querySelector("strong");
249
+ if (strong) link.innerHTML = strong.innerHTML;
250
+ if (link.parentElement) link.parentElement.outerHTML = link.outerHTML;
251
+ });
252
+
253
+ return list;
254
+ }
255
+
256
+ function buildCompactConstants(list) {
257
+ list.className = "constants compact";
258
+
259
+ queryAll("dt", list).forEach(function(node) {
260
+ var deprecated = !!node.querySelector(".deprecated");
261
+ node.classList.add("summary_signature");
262
+ node.textContent = node.textContent.split("=")[0];
263
+ if (deprecated) node.classList.add("deprecated");
264
+ });
265
+
266
+ queryAll("pre.code", list).forEach(function(pre) {
267
+ var dtElement = pre.parentElement.previousElementSibling;
268
+ var tooltip = pre.textContent;
269
+ if (dtElement.classList.contains("deprecated")) {
270
+ tooltip = "Deprecated. " + tooltip;
271
+ }
272
+ dtElement.setAttribute("title", tooltip);
273
+ });
274
+
275
+ queryAll(".docstring, .tags, dd", list).forEach(function(node) {
276
+ node.remove();
277
+ });
278
+
279
+ return list;
280
+ }
281
+
282
+ function summaryToggle() {
283
+ toggleSummaryCollection(".summary_toggle", "ul.summary", buildCompactSummary);
284
+
285
+ if (safeLocalStorage.summaryCollapsed === "collapse") {
286
+ var toggle = query(".summary_toggle");
287
+ if (toggle) toggle.click();
129
288
  } else {
130
- localStorage.summaryCollapsed = "expand";
289
+ safeLocalStorage.summaryCollapsed = "expand";
131
290
  }
132
291
  }
133
292
 
134
293
  function constantSummaryToggle() {
135
- $(".constants_summary_toggle").click(function (e) {
136
- e.preventDefault();
137
- localStorage.summaryCollapsed = $(this).text();
138
- $(".constants_summary_toggle").each(function () {
139
- $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
140
- var next = $(this).parent().parent().nextAll("dl.constants").first();
141
- if (next.hasClass("compact")) {
142
- next.toggle();
143
- next.nextAll("dl.constants").first().toggle();
144
- } else if (next.hasClass("constants")) {
145
- var list = $('<dl class="constants compact" />');
146
- list.html(next.html());
147
- list.find("dt").each(function () {
148
- $(this).addClass("summary_signature");
149
- $(this).text($(this).text().split("=")[0]);
150
- if ($(this).has(".deprecated").length) {
151
- $(this).addClass("deprecated");
152
- }
153
- });
154
- // Add the value of the constant as "Tooltip" to the summary object
155
- list.find("pre.code").each(function () {
156
- var dt_element = $(this).parent().prev();
157
- var tooltip = $(this).text();
158
- if (dt_element.hasClass("deprecated")) {
159
- tooltip = "Deprecated. " + tooltip;
160
- }
161
- dt_element.attr("title", tooltip);
162
- });
163
- list.find(".docstring, .tags, dd").remove();
164
- next.before(list);
165
- next.toggle();
166
- }
167
- });
168
- return false;
169
- });
170
- if (localStorage.summaryCollapsed == "collapse") {
171
- $(".constants_summary_toggle").first().click();
294
+ toggleSummaryCollection(
295
+ ".constants_summary_toggle",
296
+ "dl.constants",
297
+ buildCompactConstants
298
+ );
299
+
300
+ if (safeLocalStorage.summaryCollapsed === "collapse") {
301
+ var toggle = query(".constants_summary_toggle");
302
+ if (toggle) toggle.click();
172
303
  } else {
173
- localStorage.summaryCollapsed = "expand";
304
+ safeLocalStorage.summaryCollapsed = "expand";
174
305
  }
175
306
  }
176
307
 
177
308
  function generateTOC() {
178
- if ($("#filecontents").length === 0) return;
179
- var _toc = $('<ol class="top"></ol>');
180
- var show = false;
181
- var toc = _toc;
309
+ var fileContents = query("#filecontents");
310
+ var content = query("#content");
311
+
312
+ if (!fileContents || !content) return;
313
+
314
+ var topLevel = document.createElement("ol");
315
+ var currentList = topLevel;
316
+ var currentItem;
182
317
  var counter = 0;
183
- var tags = ["h2", "h3", "h4", "h5", "h6"];
184
- var i;
185
- var curli;
186
- if ($("#filecontents h1").length > 1) tags.unshift("h1");
187
- for (i = 0; i < tags.length; i++) {
188
- tags[i] = "#filecontents " + tags[i];
189
- }
190
- var lastTag = parseInt(tags[0][1], 10);
191
- $(tags.join(", ")).each(function () {
192
- if ($(this).parents(".method_details .docstring").length != 0) return;
193
- if (this.id == "filecontents") return;
194
- show = true;
195
- var thisTag = parseInt(this.tagName[1], 10);
196
- if (this.id.length === 0) {
197
- var proposedId = $(this).attr("toc-id");
198
- if (typeof proposedId != "undefined") this.id = proposedId;
199
- else {
200
- var proposedId = $(this)
201
- .text()
202
- .replace(/[^a-z0-9-]/gi, "_");
203
- if ($("#" + proposedId).length > 0) {
318
+ var headings = ["h2", "h3", "h4", "h5", "h6"];
319
+ var hasEntries = false;
320
+
321
+ topLevel.className = "top";
322
+
323
+ if (queryAll("#filecontents h1").length > 1) headings.unshift("h1");
324
+
325
+ var selectors = headings.map(function(tagName) {
326
+ return "#filecontents " + tagName;
327
+ });
328
+
329
+ var lastLevel = parseInt(headings[0].substring(1), 10);
330
+
331
+ queryAll(selectors.join(", ")).forEach(function(heading) {
332
+ var level;
333
+ var title;
334
+ var item;
335
+
336
+ if (heading.closest(".method_details .docstring")) return;
337
+ if (heading.id === "filecontents") return;
338
+
339
+ hasEntries = true;
340
+ level = parseInt(heading.tagName.substring(1), 10);
341
+
342
+ if (!heading.id) {
343
+ var proposedId = heading.getAttribute("toc-id");
344
+ if (!proposedId) {
345
+ proposedId = heading.textContent.replace(/[^a-z0-9-]/gi, "_");
346
+ if (query("#" + proposedId)) {
204
347
  proposedId += counter;
205
- counter++;
348
+ counter += 1;
206
349
  }
207
- this.id = proposedId;
208
350
  }
351
+ heading.id = proposedId;
209
352
  }
210
- if (thisTag > lastTag) {
211
- for (i = 0; i < thisTag - lastTag; i++) {
212
- if (typeof curli == "undefined") {
213
- curli = $("<li/>");
214
- toc.append(curli);
353
+
354
+ if (level > lastLevel) {
355
+ while (level > lastLevel) {
356
+ if (!currentItem) {
357
+ currentItem = document.createElement("li");
358
+ currentList.appendChild(currentItem);
215
359
  }
216
- toc = $("<ol/>");
217
- curli.append(toc);
218
- curli = undefined;
360
+ var nestedList = document.createElement("ol");
361
+ currentItem.appendChild(nestedList);
362
+ currentList = nestedList;
363
+ currentItem = null;
364
+ lastLevel += 1;
219
365
  }
220
- }
221
- if (thisTag < lastTag) {
222
- for (i = 0; i < lastTag - thisTag; i++) {
223
- toc = toc.parent();
224
- toc = toc.parent();
366
+ } else if (level < lastLevel) {
367
+ while (level < lastLevel && currentList.parentElement) {
368
+ currentList = currentList.parentElement.parentElement;
369
+ lastLevel -= 1;
225
370
  }
226
371
  }
227
- var title = $(this).attr("toc-title");
228
- if (typeof title == "undefined") title = $(this).text();
229
- curli = $('<li><a href="#' + this.id + '">' + title + "</a></li>");
230
- toc.append(curli);
231
- lastTag = thisTag;
372
+
373
+ title = heading.getAttribute("toc-title") || heading.textContent;
374
+ item = document.createElement("li");
375
+ item.innerHTML = '<a href="#' + heading.id + '">' + title + "</a>";
376
+ currentList.appendChild(item);
377
+ currentItem = item;
232
378
  });
233
- if (!show) return;
234
- html =
235
- '<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>';
236
- $("#content").prepend(html);
237
- $("#toc").append(_toc);
238
- $("#toc .hide_toc").toggle(
239
- function () {
240
- $("#toc .top").slideUp("fast");
241
- $("#toc").toggleClass("hidden");
242
- $("#toc .title small").toggle();
243
- },
244
- function () {
245
- $("#toc .top").slideDown("fast");
246
- $("#toc").toggleClass("hidden");
247
- $("#toc .title small").toggle();
248
- }
249
- );
379
+
380
+ if (!hasEntries) return;
381
+
382
+ var toc = document.createElement("div");
383
+ toc.id = "toc";
384
+ toc.innerHTML =
385
+ '<p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p>';
386
+ content.insertBefore(toc, content.firstChild);
387
+ toc.appendChild(topLevel);
388
+
389
+ var hideLink = query("#toc .hide_toc");
390
+ if (hideLink) {
391
+ hideLink.addEventListener("click", function(event) {
392
+ event.preventDefault();
393
+ var list = query("#toc .top");
394
+ var hidden = query("#toc").classList.toggle("hidden");
395
+ toggleDisplay(list, !hidden);
396
+ queryAll("#toc .title small").forEach(function(node) {
397
+ toggleDisplay(node, hidden);
398
+ });
399
+ });
400
+ }
250
401
  }
251
402
 
252
403
  function navResizer() {
253
- const resizer = document.getElementById("resizer");
254
- resizer.addEventListener(
255
- "pointerdown",
256
- function (e) {
257
- resizer.setPointerCapture(e.pointerId);
258
- e.preventDefault();
259
- e.stopPropagation();
260
- },
261
- false
262
- );
263
- resizer.addEventListener(
264
- "pointerup",
265
- function (e) {
266
- resizer.releasePointerCapture(e.pointerId);
267
- e.preventDefault();
268
- e.stopPropagation();
269
- },
270
- false
271
- );
272
- resizer.addEventListener(
273
- "pointermove",
274
- function (e) {
275
- if ((e.buttons & 1) === 0) {
276
- return;
277
- }
404
+ var resizer = document.getElementById("resizer");
278
405
 
279
- sessionStorage.navWidth = e.pageX.toString();
280
- $(".nav_wrap").css("width", Math.max(200, e.pageX));
281
- e.preventDefault();
282
- e.stopPropagation();
283
- },
284
- false
285
- );
406
+ if (!resizer) return;
407
+
408
+ if (!appState.navResizerBound) {
409
+ resizer.addEventListener(
410
+ "pointerdown",
411
+ function(event) {
412
+ resizer.setPointerCapture(event.pointerId);
413
+ event.preventDefault();
414
+ event.stopPropagation();
415
+ },
416
+ false
417
+ );
418
+ resizer.addEventListener(
419
+ "pointerup",
420
+ function(event) {
421
+ resizer.releasePointerCapture(event.pointerId);
422
+ event.preventDefault();
423
+ event.stopPropagation();
424
+ },
425
+ false
426
+ );
427
+ resizer.addEventListener(
428
+ "pointermove",
429
+ function(event) {
430
+ if ((event.buttons & 1) === 0) return;
286
431
 
287
- if (sessionStorage.navWidth) {
288
- $(".nav_wrap").css(
289
- "width",
290
- Math.max(200, parseInt(sessionStorage.navWidth, 10))
432
+ safeSessionStorage.navWidth = String(event.pageX);
433
+ queryAll(".nav_wrap").forEach(function(node) {
434
+ node.style.width = Math.max(200, event.pageX) + "px";
435
+ });
436
+ event.preventDefault();
437
+ event.stopPropagation();
438
+ },
439
+ false
291
440
  );
441
+
442
+ appState.navResizerBound = true;
443
+ }
444
+
445
+ if (safeSessionStorage.navWidth) {
446
+ queryAll(".nav_wrap").forEach(function(node) {
447
+ node.style.width =
448
+ Math.max(200, parseInt(safeSessionStorage.navWidth, 10)) + "px";
449
+ });
292
450
  }
293
451
  }
294
452
 
295
453
  function navExpander() {
296
454
  if (typeof pathId === "undefined") return;
297
- var done = false,
298
- timer = setTimeout(postMessage, 500);
455
+
456
+ var done = false;
457
+ var timer = setTimeout(postMessage, 500);
458
+
299
459
  function postMessage() {
460
+ var frame;
300
461
  if (done) return;
301
462
  clearTimeout(timer);
302
- var opts = { action: "expand", path: pathId };
303
- document.getElementById("nav").contentWindow.postMessage(opts, "*");
463
+ frame = document.getElementById("nav");
464
+ if (!frame || !frame.contentWindow) return;
465
+ frame.contentWindow.postMessage({ action: "expand", path: pathId }, "*");
304
466
  done = true;
305
467
  }
306
468
  }
307
469
 
308
- function mainFocus() {
470
+ function focusHashTarget() {
309
471
  var hash = window.location.hash;
310
- if (hash !== "" && $(hash)[0]) {
311
- $(hash)[0].scrollIntoView();
312
- }
472
+ if (!hash) return;
473
+
474
+ var targetId = hash.slice(1);
475
+ var decodedTargetId = targetId;
476
+
477
+ try {
478
+ decodedTargetId = decodeURIComponent(targetId);
479
+ } catch (error) {}
480
+
481
+ var target =
482
+ document.getElementById(decodedTargetId) ||
483
+ document.getElementById(targetId);
313
484
 
314
- setTimeout(function () {
315
- $("#main").focus();
485
+ if (target) target.scrollIntoView();
486
+ }
487
+
488
+ function mainFocus() {
489
+ focusHashTarget();
490
+ setTimeout(function() {
491
+ var main = query("#main");
492
+ if (main) main.focus();
316
493
  }, 10);
317
494
  }
318
495
 
319
496
  function navigationChange() {
320
- // This works around the broken anchor navigation with the YARD template.
321
- window.onpopstate = function () {
322
- var hash = window.location.hash;
323
- if (hash !== "" && $(hash)[0]) {
324
- $(hash)[0].scrollIntoView();
325
- }
326
- };
497
+ if (appState.navigationChangeBound) return;
498
+
499
+ window.onpopstate = focusHashTarget;
500
+ appState.navigationChangeBound = true;
327
501
  }
328
502
 
329
- $(document).ready(function () {
330
- navResizer();
331
- navExpander();
332
- createSourceLinks();
333
- createDefineLinks();
334
- createFullTreeLinks();
335
- searchFrameButtons();
336
- linkSummaries();
337
- summaryToggle();
338
- constantSummaryToggle();
339
- generateTOC();
340
- mainFocus();
341
- navigationChange();
342
- });
343
- };
344
- window.__app();
345
-
346
- window.addEventListener(
347
- "message",
348
- async (e) => {
349
- if (e.data.action === "navigate") {
350
- const response = await fetch(e.data.url);
351
- const text = await response.text();
352
- const parser = new DOMParser();
353
- const doc = parser.parseFromString(text, "text/html");
354
-
355
- const classListLink =
356
- document.getElementById("class_list_link").classList;
357
-
358
- const content = doc.querySelector("#main").innerHTML;
359
- document.querySelector("#main").innerHTML = content;
360
- document.title = doc.head.querySelector("title").innerText;
361
- document.head.querySelectorAll("script").forEach((script) => {
362
- if (
363
- !script.type ||
364
- (script.type.includes("text/javascript") && !script.src)
365
- ) {
366
- script.remove();
367
- }
368
- });
503
+ window.__app = function() {
504
+ ready(function() {
505
+ navResizer();
506
+ navExpander();
507
+ createSourceLinks();
508
+ createDefineLinks();
509
+ createFullTreeLinks();
510
+ searchFrameButtons();
511
+ linkSummaries();
512
+ summaryToggle();
513
+ constantSummaryToggle();
514
+ generateTOC();
515
+ mainFocus();
516
+ navigationChange();
517
+ });
518
+ };
369
519
 
370
- doc.head.querySelectorAll("script").forEach((script) => {
371
- if (
372
- !script.type ||
373
- (script.type.includes("text/javascript") && !script.src)
374
- ) {
375
- const newScript = document.createElement("script");
376
- newScript.type = "text/javascript";
377
- newScript.textContent = script.textContent;
378
- document.head.appendChild(newScript);
379
- }
380
- });
520
+ window.__app();
381
521
 
382
- window.__app();
522
+ if (!appState.navigationListenerBound) {
523
+ window.addEventListener(
524
+ "message",
525
+ async function(event) {
526
+ if (!event.data || event.data.action !== "navigate") return;
383
527
 
384
- document.getElementById("class_list_link").classList = classListLink;
528
+ var response = await fetch(event.data.url);
529
+ var text = await response.text();
530
+ var parser = new DOMParser();
531
+ var doc = parser.parseFromString(text, "text/html");
532
+ var classListLink = document.getElementById("class_list_link");
533
+ var content = doc.querySelector("#main").innerHTML;
385
534
 
386
- const url = new URL(e.data.url, "https://localhost");
387
- const hash = decodeURIComponent(url.hash ?? "");
388
- if (hash) {
389
- document.getElementById(hash.substring(1)).scrollIntoView();
390
- }
391
- history.pushState({}, document.title, e.data.url);
392
- }
393
- },
394
- false
395
- );
535
+ document.querySelector("#main").innerHTML = content;
536
+ document.title = doc.head.querySelector("title").innerText;
537
+
538
+ queryAll("script", document.head).forEach(function(script) {
539
+ if (
540
+ !script.type ||
541
+ (script.type.indexOf("text/javascript") !== -1 && !script.src)
542
+ ) {
543
+ script.remove();
544
+ }
545
+ });
546
+
547
+ queryAll("script", doc.head).forEach(function(script) {
548
+ if (
549
+ !script.type ||
550
+ (script.type.indexOf("text/javascript") !== -1 && !script.src)
551
+ ) {
552
+ var newScript = document.createElement("script");
553
+ newScript.type = "text/javascript";
554
+ newScript.textContent = script.textContent;
555
+ document.head.appendChild(newScript);
556
+ }
557
+ });
558
+
559
+ window.__app();
560
+
561
+ if (classListLink && document.getElementById("class_list_link")) {
562
+ document.getElementById("class_list_link").className =
563
+ classListLink.className;
564
+ }
565
+
566
+ var url = new URL(event.data.url, "http://localhost");
567
+ var hash = decodeURIComponent(url.hash || "");
568
+ if (hash) {
569
+ var target = document.getElementById(hash.substring(1));
570
+ if (target) target.scrollIntoView();
571
+ }
572
+ history.pushState({}, document.title, event.data.url);
573
+ },
574
+ false
575
+ );
576
+
577
+ appState.navigationListenerBound = true;
578
+ }
579
+ })();