diff --git a/bower.json b/bower.json index b1092b8..b7eb859 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "localstorage", "main": "dist/local-storage.js", - "version": "1.4.1", + "version": "1.4.3", "homepage": "https://github.com/bevacqua/local-storage", "authors": [ "Nicolas Bevacqua " diff --git a/changelog.markdown b/changelog.markdown index c36023f..e4479c6 100644 --- a/changelog.markdown +++ b/changelog.markdown @@ -1,4 +1,12 @@ -# 1.4.1 +# 1.4.3 + +Make it work inside iframe (where localStorage doesn't work cross domains, so we use stub) + +# 1.4.2 Keyboard Smasher + +Fixed a bug where `local-storage` wouldn't retrieve any values unless they had a `'key'` key + +# 1.4.1 Bear Hunt Fix a bug where `local-storage` would throw in IE when using the `file://` protocol diff --git a/dist/local-storage.js b/dist/local-storage.js index a8e16f2..f3d151a 100644 --- a/dist/local-storage.js +++ b/dist/local-storage.js @@ -4,7 +4,18 @@ var stub = require('./stub'); var tracking = require('./tracking'); -var ls = 'localStorage' in global && global.localStorage ? global.localStorage : stub; + +var localStorageAvailable = function () { + try { + global.localStorage.setItem('_test-local-storage-availability_', '1'); + global.localStorage.removeItem('_test-local-storage-availability_'); + return true; + } catch (e) { + return false; + } +}; + +var ls = localStorageAvailable() ? global.localStorage : stub; function accessor (key, value) { if (arguments.length === 1) { @@ -50,7 +61,7 @@ module.exports = accessor; var ms = {}; function getItem (key) { - return 'key' in ms ? ms[key] : null; + return key in ms ? ms[key] : null; } function setItem (key, value) { diff --git a/local-storage.js b/local-storage.js index 2bd56aa..05f5e97 100644 --- a/local-storage.js +++ b/local-storage.js @@ -2,7 +2,18 @@ var stub = require('./stub'); var tracking = require('./tracking'); -var ls = 'localStorage' in global && global.localStorage ? global.localStorage : stub; + +var localStorageAvailable = function () { + try { + global.localStorage.setItem('_test-local-storage-availability_', '1'); + global.localStorage.removeItem('_test-local-storage-availability_'); + return true; + } catch (e) { + return false; + } +}; + +var ls = localStorageAvailable() ? global.localStorage : stub; function accessor (key, value) { if (arguments.length === 1) { diff --git a/package.json b/package.json index 77d119a..0caf47c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "local-storage", - "version": "1.4.1", + "version": "1.4.3", "description": "A simplified localStorage API that just works", "main": "local-storage.js", "repository": {