mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-12-02 17:57:05 +00:00
1982eb268b
Change-Id: I4ecc5d842cccc3905ee4794106bc63de707c9fbb
53 lines
1.5 KiB
JavaScript
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 ) );
|