|
| 1 | +/* eslint-disable */ |
| 2 | +if (!window.localStorage) { |
| 3 | + Object.defineProperty( |
| 4 | + window, |
| 5 | + 'localStorage', |
| 6 | + new function() { |
| 7 | + var aKeys = [], |
| 8 | + oStorage = {}; |
| 9 | + Object.defineProperty(oStorage, 'getItem', { |
| 10 | + value: function(sKey) { |
| 11 | + return sKey ? this[sKey] : null; |
| 12 | + }, |
| 13 | + writable: false, |
| 14 | + configurable: false, |
| 15 | + enumerable: false, |
| 16 | + }); |
| 17 | + Object.defineProperty(oStorage, 'key', { |
| 18 | + value: function(nKeyId) { |
| 19 | + return aKeys[nKeyId]; |
| 20 | + }, |
| 21 | + writable: false, |
| 22 | + configurable: false, |
| 23 | + enumerable: false, |
| 24 | + }); |
| 25 | + Object.defineProperty(oStorage, 'setItem', { |
| 26 | + value: function(sKey, sValue) { |
| 27 | + if (!sKey) { |
| 28 | + return; |
| 29 | + } |
| 30 | + document.cookie = |
| 31 | + escape(sKey) + '=' + escape(sValue) + '; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/'; |
| 32 | + }, |
| 33 | + writable: false, |
| 34 | + configurable: false, |
| 35 | + enumerable: false, |
| 36 | + }); |
| 37 | + Object.defineProperty(oStorage, 'length', { |
| 38 | + get: function() { |
| 39 | + return aKeys.length; |
| 40 | + }, |
| 41 | + configurable: false, |
| 42 | + enumerable: false, |
| 43 | + }); |
| 44 | + Object.defineProperty(oStorage, 'removeItem', { |
| 45 | + value: function(sKey) { |
| 46 | + if (!sKey) { |
| 47 | + return; |
| 48 | + } |
| 49 | + document.cookie = escape(sKey) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; |
| 50 | + }, |
| 51 | + writable: false, |
| 52 | + configurable: false, |
| 53 | + enumerable: false, |
| 54 | + }); |
| 55 | + Object.defineProperty(oStorage, 'clear', { |
| 56 | + value: function() { |
| 57 | + if (!aKeys.length) { |
| 58 | + return; |
| 59 | + } |
| 60 | + for (var sKey in aKeys) { |
| 61 | + document.cookie = escape(sKey) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; |
| 62 | + } |
| 63 | + }, |
| 64 | + writable: false, |
| 65 | + configurable: false, |
| 66 | + enumerable: false, |
| 67 | + }); |
| 68 | + this.get = function() { |
| 69 | + var iThisIndx; |
| 70 | + for (var sKey in oStorage) { |
| 71 | + iThisIndx = aKeys.indexOf(sKey); |
| 72 | + if (iThisIndx === -1) { |
| 73 | + oStorage.setItem(sKey, oStorage[sKey]); |
| 74 | + } else { |
| 75 | + aKeys.splice(iThisIndx, 1); |
| 76 | + } |
| 77 | + delete oStorage[sKey]; |
| 78 | + } |
| 79 | + for (aKeys; aKeys.length > 0; aKeys.splice(0, 1)) { |
| 80 | + oStorage.removeItem(aKeys[0]); |
| 81 | + } |
| 82 | + for ( |
| 83 | + var aCouple, iKey, nIdx = 0, aCouples = document.cookie.split(/\s*;\s*/); |
| 84 | + nIdx < aCouples.length; |
| 85 | + nIdx++ |
| 86 | + ) { |
| 87 | + aCouple = aCouples[nIdx].split(/\s*=\s*/); |
| 88 | + if (aCouple.length > 1) { |
| 89 | + oStorage[(iKey = unescape(aCouple[0]))] = unescape(aCouple[1]); |
| 90 | + aKeys.push(iKey); |
| 91 | + } |
| 92 | + } |
| 93 | + return oStorage; |
| 94 | + }; |
| 95 | + this.configurable = false; |
| 96 | + this.enumerable = true; |
| 97 | + }() |
| 98 | + ); |
| 99 | +} |
0 commit comments