Thread: Ext.state.WindowNameStateProvider

  1. #1

    Post Ext.state.WindowNameStateProvider

    An alternate state provider that will hold state in the window.name property. This allows state up to 2 megs (?? needs verification -- depending on browser).

    This will keep the state across reloads, but the caveats are:
    * The settings are not persistent across browser sessions and are only for the current window. New tabs, closing the window, other frames will not have the same settings.
    * Other code could change the window.name which would cause loss of state and possibly other bugs.
    Code:
    Ext.state.WindowNameStateProvider = function(config) {
        Ext.state.WindowNameStateProvider.superclass.constructor.call(this);
        Ext.apply(this, config);
        this.state = this.readState();
    };
    
    Ext.extend(Ext.state.WindowNameStateProvider, Ext.state.Provider, {
        // private
        set: function(name, value) {
            if (typeof value == "undefined" || value === null) {
                this.clear(name);
                return;
            }
            Ext.state.WindowNameStateProvider.superclass.set.call(this, name, value);
            this.setState();
        },
    
        // private
        clear: function(name) {
            Ext.state.WindowNameStateProvider.superclass.clear.call(this, name);
            this.setState();
        },
    
        // private
        setState: function(name, value) {
            window.name = Ext.util.JSON.encode(this.state || {});
        },
    
        // private
        readState: function(name) {
            try {
                return Ext.util.JSON.decode(window.name) || {};
            }
            catch (e) {
                return {};
            }
        }
    });
    Attached Files

© 2006-2010 Ext JS, Inc.