Commit 9f930a29 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Reload favorites when LocalStorage changes.

parent 0f90795e
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -15,7 +15,24 @@ Ext.define("Docs.LocalStore", {
    init: function() {
        this.localStorage = ('localStorage' in window && window['localStorage'] !== null);
        this.store = Ext.getStore(this.storeName);
        this.localStorage && this.store.load();

        if (this.localStorage) {
            this.store.load();
            if (window.addEventListener) {
                window.addEventListener("storage", Ext.Function.bind(this.onStorageChange, this), false);
            }
            else {
                window.attachEvent("onstorage", Ext.Function.bind(this.onStorageChange, this));
            }
        }
    },

    // When records in localstorage change, reload the store.
    onStorageChange: function(e) {
        e = e || window.event;
        if (e.key === this.store.getProxy().id) {
            this.store.load();
        }
    },

    /**