asciidoc.js: use mediawiki mw.hook

To trigger toc generation more reliable.
This commit is contained in:
Dietmar Maurer 2016-10-26 17:16:49 +02:00
parent 24bec5055d
commit 119de29835

View File

@ -8,8 +8,9 @@
var asciidoc = { var asciidoc = {
// toc generator // toc generator
toc: function () { toc: function ($content) {
var tocholder = jQuery("#toc"); var tocholder = $content.find('#toc');
if (!tocholder) { if (!tocholder) {
return; return;
} }
@ -20,7 +21,7 @@ var asciidoc = {
var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>"; var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
var n = 0; var n = 0;
jQuery("#asciidoccontent div.sect1").each(function(){ $content.find("div.sect1").each(function(){
var h = jQuery(this).find("h2").first(); var h = jQuery(this).find("h2").first();
var id = h.attr("id"); var id = h.attr("id");
if (id != null) { if (id != null) {
@ -41,8 +42,8 @@ var asciidoc = {
}, },
// footnote generator // footnote generator
footnotes: function () { footnotes: function ($content) {
var noteholder = jQuery("#footnotes"); var noteholder = $content.find('#footnotes');
if (!noteholder) { if (!noteholder) {
return; return;
} }
@ -54,7 +55,7 @@ var asciidoc = {
var n = 0; var n = 0;
var inner_html = ''; var inner_html = '';
jQuery("#asciidoccontent span.footnote").each(function(){ $content.find("span.footnote").each(function(){
n++; n++;
var span = jQuery(this); var span = jQuery(this);
var note = span.attr("data-note"); var note = span.attr("data-note");
@ -80,7 +81,7 @@ var asciidoc = {
if (n != 0) { if (n != 0) {
// process footnoterefs. // process footnoterefs.
jQuery("#asciidoccontent span.footnoteref").each(function(){ $content.find("span.footnoteref").each(function(){
var span = jQuery(this); var span = jQuery(this);
var href = span.find("a").first().attr("href"); var href = span.find("a").first().attr("href");
href = href.match(/#.*/)[0]; // in case it return full URL. href = href.match(/#.*/)[0]; // in case it return full URL.
@ -94,6 +95,8 @@ var asciidoc = {
// add init to mediawiki resource loader queue // add init to mediawiki resource loader queue
(window.RLQ=window.RLQ||[]).push(function(){ (window.RLQ=window.RLQ||[]).push(function(){
asciidoc.footnotes(); mw.hook('wikipage.content').add(function($content) {
asciidoc.toc(); asciidoc.toc($content);
asciidoc.footnotes($content);
});
}); });