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,
|
|
|
|
* failed for any reason.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2016-01-10 17:58:21 +00:00
|
|
|
// Click handler for the "Ok" element in the cookiewarning information bar
|
2015-08-16 09:49:05 +00:00
|
|
|
$( '.mw-cookiewarning-dismiss' ).on( 'click', function ( ev ) {
|
2016-01-10 17:58:21 +00:00
|
|
|
// an anonymous user doesn't have preferences, so don't try to save this in
|
|
|
|
// the user preferences.
|
2015-08-16 09:49:05 +00:00
|
|
|
if ( !mw.user.isAnon() ) {
|
2016-01-10 17:58:21 +00:00
|
|
|
// try to save, that the cookiewarning was disabled, in the user preferences
|
2015-08-16 09:49:05 +00:00
|
|
|
new mw.Api().postWithToken( 'options', {
|
|
|
|
action: 'options',
|
|
|
|
change: 'cookiewarning_dismissed=1'
|
|
|
|
} ).fail( function ( code, result ) {
|
2016-01-10 17:58:21 +00:00
|
|
|
// if it fails, fall back to the cookie
|
2015-08-16 09:49:05 +00:00
|
|
|
mw.log.warn( 'Failed to save dismissed CookieWarning: ' + code + '\n' + result.error + '. Using cookie now.' );
|
|
|
|
setCookie();
|
|
|
|
} );
|
|
|
|
} else {
|
2016-01-10 17:58:21 +00:00
|
|
|
// use cookies for anonymous users
|
2015-08-16 09:49:05 +00:00
|
|
|
setCookie();
|
|
|
|
}
|
2016-01-10 17:58:21 +00:00
|
|
|
// always remove the cookiewarning element
|
2015-07-27 17:18:44 +00:00
|
|
|
$( '.mw-cookiewarning-container' ).detach();
|
2016-01-10 17:58:21 +00:00
|
|
|
|
2015-07-27 17:18:44 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
} );
|
|
|
|
} )( mediaWiki, jQuery );
|