yard 0.9.39 → 0.9.41

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