@@ -40,7 +40,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
40
40
/**
41
41
* Initialize MathJax.
42
42
*/
43
- async initialize ( ) : Promise < void > {
43
+ initialize ( ) : void {
44
44
if ( document . head . querySelector ( '#core-filter-mathjax-script' ) ) {
45
45
// Script already added, don't add it again.
46
46
return ;
@@ -111,8 +111,6 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
111
111
* @inheritdoc
112
112
*/
113
113
async handleHtml ( container : HTMLElement ) : Promise < void > {
114
- await this . waitForReady ( ) ;
115
-
116
114
// Make sure the element is in DOM, otherwise some equations don't work.
117
115
// Automatically timeout the promise after a certain time, we don't want to wait forever.
118
116
await CorePromiseUtils . ignoreErrors ( CorePromiseUtils . timeoutPromise ( CoreDom . waitToBeInDOM ( container ) , 15000 ) ) ;
@@ -150,6 +148,12 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
150
148
*/
151
149
protected async typeset ( container : HTMLElement ) : Promise < void > {
152
150
const equations = Array . from ( container . getElementsByClassName ( 'filter_mathjaxloader_equation' ) ) ;
151
+ if ( ! equations . length ) {
152
+ return ;
153
+ }
154
+
155
+ this . initialize ( ) ;
156
+ await this . waitForReady ( ) ;
153
157
154
158
await Promise . all ( equations . map ( ( node ) => this . typesetNode ( node ) ) ) ;
155
159
}
@@ -186,12 +190,12 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
186
190
* @returns Promise resolved when ready or if it took too long to load.
187
191
*/
188
192
protected async waitForReady ( retries : number = 0 ) : Promise < void > {
189
- if ( this . window . MathJax ?. typesetPromise || retries >= 20 ) {
193
+ if ( this . window . MathJax ?. typesetPromise || retries >= 25 ) {
190
194
// Loaded or too many retries, stop.
191
195
return ;
192
196
}
193
197
194
- await CoreWait . wait ( 250 ) ;
198
+ await CoreWait . wait ( 20 + 10 * retries ) ;
195
199
await CorePromiseUtils . ignoreErrors ( this . waitForReady ( retries + 1 ) ) ;
196
200
}
197
201
0 commit comments