2015-07-27 17:18:44 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-01-10 17:58:21 +00:00
|
|
|
/**
|
|
|
|
* Sets the cookie, that the cookiewarning is dismissed. Called,
|
|
|
|
* when the api query to save this information in the user preferences,
|
2017-12-24 15:43:38 +00:00
|
|
|
* failed for any reason, or the user is not logged-in.
|
2016-01-10 17:58:21 +00:00
|
|
|
*/
|
2015-08-16 09:49:05 +00:00
|
|
|
function setCookie() {
|
2015-07-27 17:18:44 +00:00
|
|
|
mw.cookie.set( 'cookiewarning_dismissed', true );
|
2015-08-16 09:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 15:43:38 +00:00
|
|
|
$( function () {
|
|
|
|
if ( mw.cookie.get( 'cookiewarning_dismissed' ) ) {
|
|
|
|
$( '.mw-cookiewarning-container' ).detach();
|
2015-08-16 09:49:05 +00:00
|
|
|
} else {
|
2017-12-24 15:43:38 +00:00
|
|
|
// Click handler for the "Ok" element in the cookiewarning information bar
|
|
|
|
$( '.mw-cookiewarning-dismiss' ).on( 'click', function ( ev ) {
|
|
|
|
// an anonymous user doesn't have preferences, so don't try to save this in
|
|
|
|
// the user preferences.
|
|
|
|
if ( !mw.user.isAnon() ) {
|
|
|
|
// try to save, that the cookiewarning was disabled, in the user preferences
|
|
|
|
new mw.Api().saveOption( 'cookiewarning_dismissed', '1' )
|
|
|
|
.fail( function ( code, result ) {
|
|
|
|
// if it fails, fall back to the cookie
|
|
|
|
mw.log.warn( 'Failed to save dismissed CookieWarning: ' + code + '\n' + result.error + '. Using cookie now.' );
|
|
|
|
setCookie();
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
// use cookies for anonymous users
|
|
|
|
setCookie();
|
|
|
|
}
|
|
|
|
// always remove the cookiewarning element
|
|
|
|
$( '.mw-cookiewarning-container' ).detach();
|
2016-01-10 17:58:21 +00:00
|
|
|
|
2017-12-24 15:43:38 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
} );
|
|
|
|
}
|
2015-07-27 17:18:44 +00:00
|
|
|
} );
|
2018-03-22 20:20:28 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|