| Current File : /home/jvzmxxx/wiki1/resources/src/mediawiki/mediawiki.storage.js |
( function ( mw ) {
'use strict';
/**
* Library for storing device specific information. It should be used for storing simple
* strings and is not suitable for storing large chunks of data.
*
* @class mw.storage
* @singleton
*/
mw.storage = {
localStorage: ( function () {
// Catch exceptions to avoid fatal in Chrome's "Block data storage" mode
// which throws when accessing the localStorage property itself, as opposed
// to the standard behaviour of throwing on getItem/setItem. (T148998)
try {
return window.localStorage;
} catch ( e ) {}
}() ),
/**
* Retrieve value from device storage.
*
* @param {string} key Key of item to retrieve
* @return {string|boolean} False when localStorage not available, otherwise string
*/
get: function ( key ) {
try {
return mw.storage.localStorage.getItem( key );
} catch ( e ) {}
return false;
},
/**
* Set a value in device storage.
*
* @param {string} key Key name to store under
* @param {string} value Value to be stored
* @return {boolean} Whether the save succeeded or not
*/
set: function ( key, value ) {
try {
mw.storage.localStorage.setItem( key, value );
return true;
} catch ( e ) {}
return false;
},
/**
* Remove a value from device storage.
*
* @param {string} key Key of item to remove
* @return {boolean} Whether the save succeeded or not
*/
remove: function ( key ) {
try {
mw.storage.localStorage.removeItem( key );
return true;
} catch ( e ) {}
return false;
}
};
}( mediaWiki ) );