Commit bb6c26eb authored by Nick Poulden's avatar Nick Poulden
Browse files

Fall back to MemoryStore if LocalStorage is not available

parent 1d84b09c
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -9,8 +9,11 @@ Ext.define("Docs.Favorites", {
     */
    init: function() {
        // Load Favorites from localStorage
        
        this.localStorage = ('localStorage' in window && window['localStorage'] !== null);
        
        this.store = Ext.getStore("Favorites");
        this.store.load();
        if (this.localStorage) this.store.load();
    },

    /**
@@ -21,7 +24,7 @@ Ext.define("Docs.Favorites", {
    add: function(cls) {
        if (!this.has(cls)) {
            this.store.add({cls: cls});
            this.store.sync();
            if (this.localStorage) this.store.sync();
        }
    },

@@ -33,7 +36,7 @@ Ext.define("Docs.Favorites", {
    remove: function(cls) {
        if (this.has(cls)) {
            this.store.removeAt(this.store.find('cls', cls));
            this.store.sync();
            if (this.localStorage) this.store.sync();
        }
    },

+5 −3
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@ Ext.define("Docs.History", {
        }, this);
        Ext.util.History.on("change", this.navigate, this);
        // Load History from localStorage
        this.localStorage = ('localStorage' in window && window['localStorage'] !== null);
        
        this.store = Ext.getStore("History");
        this.store.load();
        if (this.localStorage) this.store.load();
    },

    // Parses current URL and navigates to the page
@@ -83,7 +85,7 @@ Ext.define("Docs.History", {
            while (this.store.getAt(this.maxHistoryLength)) {
                this.store.removeAt(this.maxHistoryLength);
            }
            this.store.sync();
            if (this.localStorage) this.store.sync();
        }
    },

@@ -95,6 +97,6 @@ Ext.define("Docs.History", {
    removeClass: function(cls) {
        var index = this.store.find('cls', cls);
        this.store.removeAt(index);
        this.store.sync();
        if (this.localStorage) this.store.sync();
    }
});
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ Ext.define('Docs.model.Favorite', {
    fields: ['id', 'cls'],
    extend: 'Ext.data.Model',
    proxy: {
        type: 'localstorage',
        type: ('localStorage' in window && window['localStorage'] !== null) ? 'localstorage' : 'memory',
        id  : 'docs-favorites'
    }
});
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ Ext.define('Docs.model.History', {
    fields: ['id', 'cls'],
    extend: 'Ext.data.Model',
    proxy: {
        type: 'localstorage',
        type: ('localStorage' in window && window['localStorage'] !== null) ? 'localstorage' : 'memory',
        id  : 'docs-history'
    }
});
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ Ext.define('Docs.view.tree.Favorites', {

    renderMenu: function() {
        this.hoverMenu = Ext.create('Docs.view.tree.HistoryItems', {
            emptyText: 'No favorites',
            store: Docs.App.getStore('Favorites')
        });

Loading