Remember the open state of the sidebar (fixes #1973)

This commit is contained in:
Djamil Legato
2020-11-16 21:14:48 -08:00
parent ed8f24a8e7
commit 9f4e480b90
4 changed files with 16 additions and 3 deletions

View File

@@ -5,7 +5,8 @@
* Auto-link a plugin/theme license in details if it starts with `http` * Auto-link a plugin/theme license in details if it starts with `http`
* Allow to fallback to `docs:` instead of `readme:` * Allow to fallback to `docs:` instead of `readme:`
* Forward a `sid` to GPM when downloading a premium package * Forward a `sid` to GPM when downloading a premium package
* Better support for array field key/value when either key or value is empty [#1972](https://github.com/getgrav/grav-plugin-admin/issues/1972) * Better support for array field key/value when either key or value is stored empty [#1972](https://github.com/getgrav/grav-plugin-admin/issues/1972)
* Remember the open state of the sidebar [#1973](https://github.com/getgrav/grav-plugin-admin/issues/1973)
1. [](#bugfix) 1. [](#bugfix)
* Fixed Safari issue with new ACL picker field [#1955](https://github.com/getgrav/grav-plugin-admin/issues/1955) * Fixed Safari issue with new ACL picker field [#1955](https://github.com/getgrav/grav-plugin-admin/issues/1955)
* Stop propagation of ACL add button in ACL picker [flex-objects#83](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/83) * Stop propagation of ACL add button in ACL picker [flex-objects#83](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/83)

View File

@@ -1,5 +1,6 @@
import $ from 'jquery'; import $ from 'jquery';
import Map from 'es6-map'; import Map from 'es6-map';
import Cookies from 'cookies-js';
const MOBILE_BREAKPOINT = 48 - 0.062; const MOBILE_BREAKPOINT = 48 - 0.062;
const DESKTOP_BREAKPOINT = 75 + 0.063; const DESKTOP_BREAKPOINT = 75 + 0.063;
@@ -123,6 +124,7 @@ export default class Sidebar {
if (event) { event.preventDefault(); } if (event) { event.preventDefault(); }
clearTimeout(this.timeout); clearTimeout(this.timeout);
let isDesktop = global.matchMedia(DESKTOP_QUERY).matches; let isDesktop = global.matchMedia(DESKTOP_QUERY).matches;
let cookie = null;
if (isDesktop) { if (isDesktop) {
this.body.removeClass('sidebar-open'); this.body.removeClass('sidebar-open');
@@ -135,6 +137,14 @@ export default class Sidebar {
this.body.toggleClass(`sidebar-${isDesktop ? 'closed' : 'open'}`); this.body.toggleClass(`sidebar-${isDesktop ? 'closed' : 'open'}`);
$(global).trigger('sidebar_state._grav', isDesktop); $(global).trigger('sidebar_state._grav', isDesktop);
if (isDesktop) {
cookie = !this.body.hasClass('sidebar-closed');
} else {
cookie = this.body.hasClass('sidebar-open');
}
Cookies.set('grav-admin-sidebar', cookie, { expires: Infinity });
} }
checkMatch(data) { checkMatch(data) {

File diff suppressed because one or more lines are too long

View File

@@ -43,7 +43,9 @@
</head> </head>
{% block body %} {% block body %}
<body class="ga-theme-17x {{ config.plugins.admin.sidebar.size == 'small' ? 'sidebar-closed' : '' }} {{ config.plugins.admin.body_classes }} {{ body_classes }}"> {% set sidebarStatus = get_cookie('grav-admin-sidebar') %}
{% set sidebarStatus = (sidebarStatus is not null and sidebarStatus == 'false') or config.plugins.admin.sidebar.size == 'small' ? 'sidebar-closed' : '' %}
<body class="ga-theme-17x {{ sidebarStatus }} {{ config.plugins.admin.body_classes }} {{ body_classes }}">
{% if not authorize(['admin.login']) %} {% if not authorize(['admin.login']) %}
{% include 'partials/messages.html.twig' %} {% include 'partials/messages.html.twig' %}