File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ function inject_ads_client() {
19
19
script . src = "https://media.ethicalads.io/media/client/beta/ethicalads.min.js" ;
20
20
script . type = "text/javascript" ;
21
21
script . async = true ;
22
+ script . id = "ethicaladsjs" ;
22
23
document . getElementsByTagName ( "head" ) [ 0 ] . appendChild ( script ) ;
23
24
}
24
25
@@ -185,6 +186,14 @@ function init() {
185
186
// Ad client prevented from loading - check ad blockers
186
187
adblock_admonition ( ) ;
187
188
adblock_nag ( placement ) ;
189
+ } else {
190
+ // The ad client hasn't loaded yet which could happen due to a variety of issues
191
+ // Add an event listener for it to load
192
+ $ ( "#ethicaladsjs" ) . on ( "load" , function ( ) {
193
+ if ( typeof ethicalads !== "undefined" ) {
194
+ ethicalads . load ( ) ;
195
+ }
196
+ } ) ;
188
197
}
189
198
} ,
190
199
error : function ( ) {
Original file line number Diff line number Diff line change @@ -7,11 +7,22 @@ var sphinx = require('./doc-embed/sphinx');
7
7
var search = require ( './doc-embed/search' ) ;
8
8
9
9
10
- $ ( document ) . ready ( function ( ) {
11
- footer . init ( ) ;
12
- sphinx . init ( ) ;
13
- // grokthedocs.init();
14
- // mkdocs.init();
15
- search . init ( ) ;
16
- sponsorship . init ( ) ;
17
- } ) ;
10
+ // While much of this script relies on jQuery (which Sphinx relies on),
11
+ // we purposefully do not use it before DOMContentLoaded in case scripts are loaded out of order
12
+ ( function ( ) {
13
+ function domReady ( fn ) {
14
+ // If the DOM is already done parsing
15
+ if ( document . readyState === "complete" || document . readyState === "interactive" ) {
16
+ setTimeout ( fn , 1 ) ;
17
+ } else {
18
+ document . addEventListener ( "DOMContentLoaded" , fn ) ;
19
+ }
20
+ }
21
+
22
+ domReady ( function ( ) {
23
+ footer . init ( ) ;
24
+ sphinx . init ( ) ;
25
+ search . init ( ) ;
26
+ sponsorship . init ( ) ;
27
+ } ) ;
28
+ } ( ) ) ;
You can’t perform that action at this time.
0 commit comments