Enh: use LocalStorage in panel menu

Use LocalStorage to save panel menu's state instead of cookies
This commit is contained in:
Hany El Nokaly 2019-01-17 01:37:18 +02:00
parent d434197aee
commit f99f993cb0
3 changed files with 6 additions and 18 deletions

View File

@ -13,6 +13,4 @@ HumHub Change Log (DEVELOP)
- Chng: Removed `atwho` asset and dependency
- Cnng: Removed old IE support
- Fix #2946: Use Yii2 default timezone handling
- Enh: use LocalStorage in panel menu

View File

@ -25,7 +25,7 @@ $this->registerJsFile("@web-static/js/panelMenu.js", ['position' => yii\web\View
<script>
$(function() {
// check and set panel state from cookie
// check and set panel state from LocalStorage
checkPanelMenuCookie('<?= $this->context->id; ?>');
});
</script>

View File

@ -8,7 +8,7 @@ function togglePanelUp($id) {
$('#' + $id + ' .panel-expand').show();
$('#' + $id).addClass('panel-collapsed');
$.cookie('pm_' + $id, 'collapsed', 5*365);
localStorage.setItem('pm_' + $id, 'collapsed');
});
}
@ -22,7 +22,7 @@ function togglePanelDown($id) {
$('#' + $id + ' .panel-collapse').show();
$('#' + $id).removeClass('panel-collapsed');
$.cookie('pm_' + $id, 'expanded', 5*365);
localStorage.removeItem('pm_' + $id);
});
}
@ -30,17 +30,9 @@ function togglePanelDown($id) {
* Check and change current panel state, if necessary
*/
function checkPanelMenuCookie($id) {
// check if cookie exists
if ($.cookie('pm_' + $id) == undefined) {
// if not, create new cookie with current panel state
$.cookie('pm_' + $id, 'expanded', 5*365);
} else if ($.cookie('pm_' + $id) == 'collapsed') {
// collapse panel, if cookie is 'collapsed'
// checks if panel's saved state in LocalStorage is collapsed
if (localStorage.getItem('pm_' + $id) === 'collapsed') {
$('#' + $id + ' .panel-body').css({
overflow: 'hidden',
display: 'none'
});
@ -48,7 +40,5 @@ function checkPanelMenuCookie($id) {
$('#' + $id + ' .panel-collapse').hide();
$('#' + $id + ' .panel-expand').show();
$('#' + $id).addClass('panel-collapsed');
}
}