MediaWiki:Geonotice.js

Från Wikipedia

OBS: Efter du har publicerat sidan kan du behöva tömma din webbläsares cache för att se ändringarna.

  • Firefox / Safari: Håll ned Skift och klicka på Uppdatera sidan eller tryck Ctrl-F5 eller Ctrl-R (⌘-R på Mac)
  • Google Chrome: Tryck Ctrl-Skift-R (⌘-Skift-R på Mac)
  • Internet Explorer / Edge: Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5
  • Opera: Tryck Ctrl-F5.
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
	$( function() {
		'use strict';
		$.getJSON( mw.config.get( 'wgScript' ) + '?title=MediaWiki:Geonotice.json&action=raw&ctype=text/json', function( notices ) {
			var index;
			function parse( wikitext ) {
				function addNotice( html ) {
					var now = Date.now();
					var notice = notices[ index ];
					var minlat;
					var maxlat;
					var minlon;
					var maxlon;
					var id = notice.id;
					if ( window.Geo ) {
						if ( mw.cookie.get( 'hidegeonotice' + id ) === null ) {
							if ( notice && notice.corners ) {
								minlat = Math.min( notice.corners[ 0 ][ 0 ], notice.corners[ 1 ][ 0 ] );
								maxlat = Math.max( notice.corners[ 0 ][ 0 ], notice.corners[ 1 ][ 0 ] );
								minlon = Math.min( notice.corners[ 0 ][ 1 ], notice.corners[ 1 ][ 1 ] );
								maxlon = Math.max( notice.corners[ 0 ][ 1 ], notice.corners[ 1 ][ 1 ] );
								if ( now > Date.parse( notice.begin ) && now < Date.parse( notice.end ) && minlat < Geo.lat && Geo.lat < maxlat && minlon < Geo.lon && Geo.lon < maxlon ) {
									$( '#mw-content-text' ).prepend( '<div class="geonotice plainlinks" data-geonotice="' + mw.html.escape( id ) + '"><span class="geonotice-hide">[<a href="#">dölj</a>]</span><div class="geonotice-text">' + html + '</div></div>' );
								}
							}
						}
					}
					index = index + 1;
					if ( index < notices.length ) {
						parse( notices[ index ].wikitext );
					}
				}
				( new mw.Api() ).parse( wikitext ).done( function( html ) {
					addNotice( html );
				} );
			}
			if ( Array.isArray( notices ) ) {
				index = 0;
				parse( notices[ index ].wikitext );
			}
		} );
		$( '#mw-content-text' ).on( 'click', '.geonotice-hide a', function( e ) {
			e.preventDefault();
			var notice = $( e.currentTarget ).closest( '.geonotice' );
			var id = notice.attr( 'data-geonotice' );
			mw.cookie.set( 'hidegeonotice' + id, '1' );
			notice.addClass( 'geonotice-hidden' );
		} );
	} );
}