3.6.5Widget state (for new windows etc)

The user can choose to take any widget in the MyTrader page container and pop it out into a new browser window. You can copy the settings from the existing widget into the new window using a mechanism very similar to, and often related to, privateSettings.

You need to handle Framework.OnGetState() which the framework calls in order to ask you, "Do you have any stored settings which you want to pass into the new window?". For example:

Framework.OnGetState = function()

{

return {

instrumentId: "EUR/USD",

timeframe: 3600,

visualOptions: {

color: "blue"

}

};

}

The new pop-up browser window will receive this stored state in its Framework.privateSettings.

As a result, it's very common for a widget's storage of private settings and its handling of OnGetState() to be linked. For example:

The widget uses OnGetState() as a general function for building a representation of its current settings.

When saving private settings as a result of a user change, the widget calls its own OnGetState() function.

For example:

// Build some representation of the widget's state. This is returned both internally

// and to the framework when opening a new window.

Framework.OnGetState = function() {

var settings = { … };

return settings;

};

// Private internal function which our widget calls whenever the user makes a change

// and new settings need to be saved. We simply re-use OnGetState() as a way

// of getting the current state.

Framework.$SaveMySettings = function() {

Framework.SavePrivateSettings(Framework.OnGetState());

}

Note: OnGetState() is also the mechanism which allows a widget to keep running even if the user navigates to a different page of the app.