mediawiki-extensions-Cookie.../resources/ext.CookieWarning.geolocation/cookiePolicy.js
Fomafix 1982eb268b Use mw.config instead of window.mw.config in JavaScript
Change-Id: I4ecc5d842cccc3905ee4794106bc63de707c9fbb
2018-08-27 21:10:03 +02:00

53 lines
1.5 KiB
JavaScript

( function ( mw, $ ) {
'use strict';
var geoLocation;
geoLocation = {
/**
* @return {string} Two-letter country code
*/
getCountryCode: function () {
/**
* safe fallback -- if geolocation fails, display the notice anyway
*/
var countryCode = 'EU';
if ( !$.cookie( 'euCookieWarningCountryCode' ) ) {
// @see http://www.dwuser.com/education/content/web-services-made-practical-where-are-your-visitors-from/
$.get( mw.config.get( 'wgCookieWarningGeoIPServiceURL' ), function ( data ) {
// Get the country code
countryCode = data.country_code;
// Store the result in a cookie (ah, the sweet, sweet irony) to
// avoid hitting the geolocation service unnecessarily
$.cookie( 'euCookieWarningCountryCode', countryCode, {
domain: mw.config.get( 'wgCookieDomain' ),
path: '/',
expires: 30
} );
}, 'jsonp' );
} else if ( $.cookie( 'euCookieWarningCountryCode' ) !== null ) {
countryCode = $.cookie( 'euCookieWarningCountryCode' );
}
return countryCode;
},
/**
* Check if the supplied country code is that of a configured region.
*
* @return {boolean}
*/
isInRegion: function () {
return mw.config.get( 'wgCookieWarningForCountryCodes' ).hasOwnProperty( this.getCountryCode() );
}
};
$( function () {
if ( geoLocation.isInRegion() ) {
$( '.mw-cookiewarning-container' ).show();
} else {
$( '.mw-cookiewarning-container' ).detach();
}
} );
}( mediaWiki, jQuery ) );