]> git.proxmox.com Git - pve-docs.git/blob - asciidoc/asciidoc.js
asciidoc.js: use jQuery instead of $
[pve-docs.git] / asciidoc / asciidoc.js
1 //////////////////////////////////////////////////////////////////////////
2 // asciidoc JS helper for Proxmox VE mediawiki pages
3 //
4 // code based on original asciidoc.js, but re-written using jQuery
5 //
6 //////////////////////////////////////////////////////////////////////////
7
8 var asciidoc = {
9
10 // toc generator
11 toc: function () {
12 var tocholder = jQuery("#toc");
13 if (!tocholder) {
14 return;
15 }
16
17 tocholder.html('');
18 tocholder.hide();
19
20 var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
21
22 var n = 0;
23 jQuery("#asciidoccontent div.sect1").each(function(){
24 var h = jQuery(this).find("h2").first();
25 var id = h.attr("id");
26 if (id != null) {
27 n++;
28 html += "<li class=\"toclevel-1\">" +
29 "<a href=\"#" + id + "\">" +
30 "<span class=\"toctext\">" + h.html() +
31 "</span></a></li>";
32 }
33 });
34
35 html += "</ul>";
36
37 if (n > 3) {
38 tocholder.html(html);
39 tocholder.show();
40 }
41 },
42
43 // footnote generator
44 footnotes: function () {
45 var noteholder = jQuery("#footnotes");
46 if (!noteholder) {
47 return;
48 }
49
50 noteholder.html('');
51
52 // Rebuild footnote entries.
53 var refs = {};
54 var n = 0;
55 var inner_html = '';
56
57 jQuery("#asciidoccontent span.footnote").each(function(){
58 n++;
59 var span = jQuery(this);
60 var note = span.attr("data-note");
61 var id = span.attr("id");
62 if (!note) {
63 // Use [\s\S] in place of . so multi-line matches work.
64 // Because JavaScript has no s (dotall) regex flag.
65 note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1];
66 span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" +
67 n + "' title='View footnote' class='footnote'>" + n +
68 "</a>]");
69 span.attr("data-note", note);
70 }
71 inner_html +=
72 "<div class='footnote' id='_footnote_" + n + "'>" +
73 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
74 n + "</a>. " + note + "</div>";
75
76 if (id != null) { refs["#"+id] = n; }
77 });
78
79 if (inner_html) { noteholder.html("<hr>" + inner_html); }
80
81 if (n != 0) {
82 // process footnoterefs.
83 jQuery("#asciidoccontent span.footnoteref").each(function(){
84 var span = jQuery(this);
85 var href = span.find("a").first().attr("href");
86 href = href.match(/#.*/)[0]; // in case it return full URL.
87 n = refs[href];
88 span.html("[<a href='#_footnote_" + n +
89 "' title='View footnote' class='footnote'>" + n + "</a>]");
90 });
91 }
92 }
93 };
94
95 jQuery(document).ready(function(){
96 asciidoc.footnotes();
97 asciidoc.toc();
98 });
99