Clean up ULS localstorage preference saving system
These changes affect anonymous users: * Old code to restore preferences from jStorage removed * No cookie used anymore Bug: T100639 Change-Id: I3cfec447703d9c67cd2310ec4acc5692ad76be8e
This commit is contained in:
committed by
Niklas Laxström
parent
6733a951c1
commit
3e58259ca7
@@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
* ULS preferences system for MediaWiki.
|
* ULS preferences system for MediaWiki.
|
||||||
* Local storage for anonymous users, preferences for logged in users.
|
* Localstorage for anonymous users, preferences for logged in users.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
|
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
|
||||||
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
|
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
|
||||||
@@ -41,12 +41,10 @@
|
|||||||
if ( typeof value === 'object' ) {
|
if ( typeof value === 'object' ) {
|
||||||
value = JSON.stringify( value );
|
value = JSON.stringify( value );
|
||||||
}
|
}
|
||||||
// Set the store
|
|
||||||
try {
|
try {
|
||||||
localStorage.setItem( key, value );
|
localStorage.setItem( key, value );
|
||||||
} catch ( e ) { // Use cookie
|
} catch ( e ) {}
|
||||||
$.cookie( key, value, { path: '/' } );
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
* Returns the value of the given key
|
* Returns the value of the given key
|
||||||
@@ -56,29 +54,9 @@
|
|||||||
get: function ( key ) {
|
get: function ( key ) {
|
||||||
var data;
|
var data;
|
||||||
|
|
||||||
// No value supplied, return value
|
|
||||||
try {
|
try {
|
||||||
data = localStorage.getItem( key );
|
data = JSON.parse( localStorage.getItem( key ) );
|
||||||
if ( !data ) {
|
} catch ( e ) {}
|
||||||
// Try to restore the old preferences, if any, if possible.
|
|
||||||
try {
|
|
||||||
data = JSON.parse( localStorage.getItem( 'jStorage' ) )[ 'uls-preferences' ];
|
|
||||||
// And try to remove it.
|
|
||||||
localStorage.removeItem( 'jStorage' );
|
|
||||||
} catch ( e ) {
|
|
||||||
// Don't bother about it.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch ( e ) { // Use cookie
|
|
||||||
data = $.cookie( key );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to parse JSON
|
|
||||||
try {
|
|
||||||
data = JSON.parse( data );
|
|
||||||
} catch ( e ) {
|
|
||||||
data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user