Created
October 10, 2014 19:08
-
-
Save jwahyoung/5f76affd2075d797a3de to your computer and use it in GitHub Desktop.
Golden-Layout: Stack not saving to localstorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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