mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-24 06:13:58 +00:00
97c134e397
Also: Add license (MIT). Change-Id: Ia184b396b648ecb4ef30b40d13618e2ecf72294a
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
( function ( mw, $ ) {
|
|
/**
|
|
* 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.
|
|
*/
|
|
function setCookie() {
|
|
mw.cookie.set( 'cookiewarning_dismissed', true );
|
|
}
|
|
|
|
// 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().postWithToken( 'options', {
|
|
action: 'options',
|
|
change: '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();
|
|
|
|
ev.preventDefault();
|
|
} );
|
|
} )( mediaWiki, jQuery );
|