Skip to content

Instantly share code, notes, and snippets.

@jwahyoung
Created October 10, 2014 19:08
Show Gist options
  • Save jwahyoung/5f76affd2075d797a3de to your computer and use it in GitHub Desktop.
Save jwahyoung/5f76affd2075d797a3de to your computer and use it in GitHub Desktop.
Golden-Layout: Stack not saving to localstorage
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="https://golden-layout.com/files/latest/js/goldenlayout.min.js"></script>
<script type="text/javascript" src="index.js"></script>
<link type="text/css" rel="stylesheet" href="https://golden-layout.com/files/latest/css/goldenlayout-base.css" />
<link type="text/css" rel="stylesheet" href="https://golden-layout.com/files/latest/css/goldenlayout-dark-theme.css" />
</head>
<body>
</body>
</html>
'use strict';
(function ($) {
var config = {
content: [{
type: 'row',
content: [{
type: 'component',
componentName: 'testComponent',
componentState: {
label: 'A'
}
}, {
type: 'column',
content: [{
type: 'component',
componentName: 'testComponent',
componentState: {
label: 'B'
}
}, {
type: 'component',
componentName: 'testComponent',
componentState: {
label: 'C'
}
}]
}]
}]
};
var myLayout = new GoldenLayout(JSON.parse(localStorage.getItem('layoutState')) || config);
myLayout.registerComponent('testComponent', function (container, componentState) {
container.getElement().html('<h2>' + componentState.label + '</h2>')
});
myLayout.init();
myLayout.on('stateChanged', function () {
var state = JSON.stringify(myLayout.toConfig());
localStorage.setItem('layoutState', state);
});
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment