Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / resources / src / mediawiki / mediawiki.storage.js
blobcb62fbf26c63e6c2a9b0a37cd435f024d2b05459
1 ( function ( mw ) {
2         'use strict';
4         /**
5          * Library for storing device specific information. It should be used for storing simple
6          * strings and is not suitable for storing large chunks of data.
7          *
8          * @class mw.storage
9          * @singleton
10          */
11         mw.storage = {
13                 localStorage: window.localStorage,
15                 /**
16                  * Retrieve value from device storage.
17                  *
18                  * @param {string} key Key of item to retrieve
19                  * @return {string|boolean} False when localStorage not available, otherwise string
20                  */
21                 get: function ( key ) {
22                         try {
23                                 return mw.storage.localStorage.getItem( key );
24                         } catch ( e ) {}
25                         return false;
26                 },
28                 /**
29                   * Set a value in device storage.
30                   *
31                   * @param {string} key Key name to store under
32                   * @param {string} value Value to be stored
33                   * @return {boolean} Whether the save succeeded or not
34                   */
35                 set: function ( key, value ) {
36                         try {
37                                 mw.storage.localStorage.setItem( key, value );
38                                 return true;
39                         } catch ( e ) {}
40                         return false;
41                 },
43                 /**
44                   * Remove a value from device storage.
45                   *
46                   * @param {string} key Key of item to remove
47                   * @return {boolean} Whether the save succeeded or not
48                   */
49                 remove: function ( key ) {
50                         try {
51                                 mw.storage.localStorage.removeItem( key );
52                                 return true;
53                         } catch ( e ) {}
54                         return false;
55                 }
56         };
58 }( mediaWiki ) );