Merge "Remove last remnants of pre-1.16 live preview"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.storage.js
1 ( function ( mw ) {
2 'use strict';
3
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 = {
12
13 localStorage: ( function () {
14 // Catch exceptions to avoid fatal in Chrome's "Block data storage" mode
15 // which throws when accessing the localStorage property itself, as opposed
16 // to the standard behaviour of throwing on getItem/setItem. (T148998)
17 try {
18 return window.localStorage;
19 } catch ( e ) {}
20 }() ),
21
22 /**
23 * Retrieve value from device storage.
24 *
25 * @param {string} key Key of item to retrieve
26 * @return {string|boolean} False when localStorage not available, otherwise string
27 */
28 get: function ( key ) {
29 try {
30 return mw.storage.localStorage.getItem( key );
31 } catch ( e ) {}
32 return false;
33 },
34
35 /**
36 * Set a value in device storage.
37 *
38 * @param {string} key Key name to store under
39 * @param {string} value Value to be stored
40 * @return {boolean} Whether the save succeeded or not
41 */
42 set: function ( key, value ) {
43 try {
44 mw.storage.localStorage.setItem( key, value );
45 return true;
46 } catch ( e ) {}
47 return false;
48 },
49
50 /**
51 * Remove a value from device storage.
52 *
53 * @param {string} key Key of item to remove
54 * @return {boolean} Whether the save succeeded or not
55 */
56 remove: function ( key ) {
57 try {
58 mw.storage.localStorage.removeItem( key );
59 return true;
60 } catch ( e ) {}
61 return false;
62 }
63 };
64
65 }( mediaWiki ) );