Save a popout’s state
The popout library provides the ability for your application to monitor the state of popped out content. This can be used to persist the popout’s state, or even to reflect the state of the popped out content in the main window.
Example
Here is a simple example of how to persist that state of a popout using local storage.
First we create a popout in our main window, and set a tradeType
property on it. We will default this value to 'SPOT'
, but use the value in local storage if it exists:
var ticketPopout = new caplin.popout.Popout('ticket');
var properties = { tradeType : 'SPOT' };
if(localStorage.popoutProperties !== undefined) {
properties = JSON.parse(localStorage.popoutProperties);
}
ticketPopout.setProperties(properties);
ticketPopout.open(200, 400);
We then add a listener to the popout that updates local storage whenever its properties change:
ticketPopout.on(caplin.popout.Popout.EVENTS.PROPERTIES_CHANGED, function(properties) {
localStorage.popoutProperties = JSON.stringify(properties);
});
Then, in our popout window, we set the tradeType
property to 'FORWARD'
:
var popoutService = caplin.core.ServiceRegistry.getService('caplin.popout-service');
popoutService.setProperties({ tradeType : 'FORWARD' });
The next time the popout is opened, it will be opened with a tradeType
of 'FORWARD'
.
See also: