var asciidoc = {
+ // toc generator
+ toc: function () {
+ var tocholder = jQuery("#toc");
+ if (!tocholder) {
+ return;
+ }
+
+ tocholder.html('');
+ tocholder.hide();
+
+ var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
+
+ var n = 0;
+ jQuery("#asciidoccontent div.sect1").each(function(){
+ var h = jQuery(this).find("h2").first();
+ var id = h.attr("id");
+ if (id != null) {
+ n++;
+ html += "<li class=\"toclevel-1\">" +
+ "<a href=\"#" + id + "\">" +
+ "<span class=\"toctext\">" + h.html() +
+ "</span></a></li>";
+ }
+ });
+
+ html += "</ul>";
+
+ if (n > 3) {
+ tocholder.html(html);
+ tocholder.show();
+ }
+ },
+
// footnote generator
footnotes: function () {
- var noteholder = $("#footnotes");
+ var noteholder = jQuery("#footnotes");
if (!noteholder) {
return;
}
var n = 0;
var inner_html = '';
- $("#asciidoccontent span.footnote").each(function(){
+ jQuery("#asciidoccontent span.footnote").each(function(){
n++;
- var span = $(this);
+ var span = jQuery(this);
var note = span.attr("data-note");
var id = span.attr("id");
if (!note) {
if (n != 0) {
// process footnoterefs.
- $("#asciidoccontent span.footnoteref").each(function(){
- var span = $(this);
+ jQuery("#asciidoccontent span.footnoteref").each(function(){
+ var span = jQuery(this);
var href = span.find("a").first().attr("href");
href = href.match(/#.*/)[0]; // in case it return full URL.
n = refs[href];
}
};
-$(document).ready(function(){
+// add init to mediawiki resource loader queue
+(window.RLQ=window.RLQ||[]).push(function(){
asciidoc.footnotes();
+ asciidoc.toc();
});
-