/
LeafletLoader.js
47 lines (35 loc) 路 1.02 KB
/
LeafletLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
window.mapsLeafletList = [];
(function( $, mw ) {
function initializeMaps( $content ) {
$content.find( '.maps-leaflet' ).each( function() {
let $this = $( this );
if ( $this.data( 'initialized' ) ) {
return;
}
$this.data( 'initialized', true );
let jqueryMap = $this.leafletmaps(
JSON.parse( $this.find( 'div.mapdata' ).text() )
);
jqueryMap.setup();
window.mapsLeafletList.push(jqueryMap);
} );
}
mw.hook( 'wikipage.content' ).add( initializeMaps );
mw.hook( 've.activationComplete' ).add( function() {
let surface = ve.init.target.getSurface();
// initializeMaps( $( surface.$element[0] ) );
let thread = setInterval(
function() {
initializeMaps( $( surface.$element[0] ) );
},
1000
);
// mw.hook( 've.deactivationComplete' ).add( function() {
// clearInterval( thread );
// } );
// surface.getModel().on( 'history', function() {
// console.log('history');
// initializeMaps( $( surface.$element[0] ) );
// } );
} );
})( window.jQuery, window.mediaWiki );