Skip to content

Commit

Permalink
Merge pull request #7358 from jdfreder/persistence-page-specific
Browse files Browse the repository at this point in the history
Associate widget state persistence with current URL.
  • Loading branch information
Carreau committed Jan 1, 2015
2 parents 73dcc0c + e0608a5 commit 1e0e703
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions IPython/html/static/widgets/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,20 @@ define([
};

// Use local storage to persist widgets across page refresh by default.
// LocalStorage is per domain, so we need to explicitly set the URL
// that the widgets are associated with so they don't show on other
// pages hosted by the noteboook server.
var url = [window.location.protocol, '//', window.location.host, window.location.pathname].join('');
WidgetManager.set_state_callbacks(function() {
return JSON.parse(localStorage.widgets || '{}');
if (localStorage.widgets && localStorage.widgets[url]) {
return JSON.parse(localStorage.widgets[url]);
}
return {};
}, function(state) {
localStorage.widgets = JSON.stringify(state);
if (localStorage.widgets === undefined) {
localStorage.widgets = {};
}
localStorage.widgets[url] = JSON.stringify(state);
});

//--------------------------------------------------------------------
Expand Down

0 comments on commit 1e0e703

Please sign in to comment.