diff options
| author | Adrien Dieudonne <adr@odoo.com> | 2016-06-16 08:50:03 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2016-06-16 13:48:18 +0200 |
| commit | 8580636bad43df2b4879b1985965a766cb796543 (patch) | |
| tree | 166d3fa58f5f4c29ce100fbcde99f2cade764763 /addons/web/static/src/js/framework | |
| parent | 6c9567ae3c863c16529475b386659c24e14be61d (diff) | |
[ADD] web: js module to communicate with localStorage
Private browsing in Safari doesn't allow to store anything in the localStorage,
and it throws an error when you try to do so. This new JS module is a connector
to the browser's localStorage if it is enabled, and if not, it simply keeps its
own storage in RAM.
Diffstat (limited to 'addons/web/static/src/js/framework')
| -rw-r--r-- | addons/web/static/src/js/framework/local_storage.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/web/static/src/js/framework/local_storage.js b/addons/web/static/src/js/framework/local_storage.js new file mode 100644 index 00000000000..6cf82e87752 --- /dev/null +++ b/addons/web/static/src/js/framework/local_storage.js @@ -0,0 +1,34 @@ +odoo.define('web.local_storage', function (require) { +'use strict'; + +var Class = require('web.Class'); + +// Compatibility with private browsing in Safari +// Use dict in case of local storage is disabled +var localStorage = window.localStorage; +try { + var uid = new Date(); + localStorage.setItem(uid, uid); + localStorage.removeItem(uid); +} catch (exception) { + var storage = {}; + var RamStorage = Class.extend({ + setItem: function(key, value) { + storage[key] = value; + }, + getItem: function(key) { + return storage[key]; + }, + removeItem: function(key) { + delete storage[key]; + }, + clear: function() { + storage = {}; + }, + }); + localStorage = new RamStorage(); +} + +return localStorage; + +}); |
