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