]> git.proxmox.com Git - pve-docs.git/blame - asciidoc/mediawiki-asciidoc.js
fix clean-static find call
[pve-docs.git] / asciidoc / mediawiki-asciidoc.js
CommitLineData
110ebe8f
DM
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
8var asciidoc = {
9
7cbfd919 10 // toc generator
119de298
DM
11 toc: function ($content) {
12 var tocholder = $content.find('#toc');
13
7cbfd919
DM
14 if (!tocholder) {
15 return;
16 }
17
18 tocholder.html('');
19 tocholder.hide();
20
21 var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
22
23 var n = 0;
119de298 24 $content.find("div.sect1").each(function(){
a7d40e1f 25 var h = jQuery(this).find("h2").first();
7cbfd919
DM
26 var id = h.attr("id");
27 if (id != null) {
28 n++;
29 html += "<li class=\"toclevel-1\">" +
30 "<a href=\"#" + id + "\">" +
31 "<span class=\"toctext\">" + h.html() +
32 "</span></a></li>";
33 }
34 });
35
36 html += "</ul>";
37
38 if (n > 3) {
39 tocholder.html(html);
40 tocholder.show();
41 }
42 },
43
110ebe8f 44 // footnote generator
119de298
DM
45 footnotes: function ($content) {
46 var noteholder = $content.find('#footnotes');
110ebe8f
DM
47 if (!noteholder) {
48 return;
49 }
50
51 noteholder.html('');
52
53 // Rebuild footnote entries.
54 var refs = {};
55 var n = 0;
56 var inner_html = '';
57
119de298 58 $content.find("span.footnote").each(function(){
110ebe8f 59 n++;
a7d40e1f 60 var span = jQuery(this);
110ebe8f
DM
61 var note = span.attr("data-note");
62 var id = span.attr("id");
63 if (!note) {
64 // Use [\s\S] in place of . so multi-line matches work.
65 // Because JavaScript has no s (dotall) regex flag.
66 note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1];
67 span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" +
68 n + "' title='View footnote' class='footnote'>" + n +
69 "</a>]");
70 span.attr("data-note", note);
71 }
72 inner_html +=
73 "<div class='footnote' id='_footnote_" + n + "'>" +
74 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
75 n + "</a>. " + note + "</div>";
119de298 76
110ebe8f
DM
77 if (id != null) { refs["#"+id] = n; }
78 });
79
80 if (inner_html) { noteholder.html("<hr>" + inner_html); }
119de298 81
110ebe8f
DM
82 if (n != 0) {
83 // process footnoterefs.
119de298 84 $content.find("span.footnoteref").each(function(){
a7d40e1f 85 var span = jQuery(this);
110ebe8f
DM
86 var href = span.find("a").first().attr("href");
87 href = href.match(/#.*/)[0]; // in case it return full URL.
88 n = refs[href];
89 span.html("[<a href='#_footnote_" + n +
90 "' title='View footnote' class='footnote'>" + n + "</a>]");
91 });
92 }
93 }
94};
95
24bec505
DM
96// add init to mediawiki resource loader queue
97(window.RLQ=window.RLQ||[]).push(function(){
119de298
DM
98 mw.hook('wikipage.content').add(function($content) {
99 asciidoc.toc($content);
100 asciidoc.footnotes($content);
101 });
110ebe8f 102});