a45eb966dabd091da1de7a6cc9d6d0fe4b7ba36e
[ccsdk/features.git] /
1 (function( app ) {
2         
3         var ux = app.ns("ux");
4         var services = app.ns("services");
5
6         services.Preferences = ux.Singleton.extend({
7                 init: function() {
8                         this._storage = window.localStorage;
9                         this._setItem("__version", 1 );
10                 },
11                 get: function( key ) {
12                         return this._getItem( key );
13                 },
14                 set: function( key, val ) {
15                         return this._setItem( key, val );
16                 },
17                 _getItem: function( key ) {
18                         try {
19                                 return JSON.parse( this._storage.getItem( key ) );
20                         } catch(e) {
21                                 console.warn( e );
22                                 return undefined;
23                         }
24                 },
25                 _setItem: function( key, val ) {
26                         try {
27                                 return this._storage.setItem( key, JSON.stringify( val ) );
28                         } catch(e) {
29                                 console.warn( e );
30                                 return undefined;
31                         }
32                 }
33         });
34
35 })( this.app );