learnpress icon indicating copy to clipboard operation
learnpress copied to clipboard

Lessons sidebar default state

Open vitalie-work opened this issue 9 months ago • 2 comments

Hi guys,

how can i set sidebar menu on lesson page to be closed by default its look nasty on small mobile screen

I didn't find any option for this in settings, so maybe I can add some 'code' in functions to get this to work? I tried to add a cookie you used for this, but its not working well can you provide any other working solution, please

Image

vitalie-work avatar Apr 02 '25 14:04 vitalie-work

Hi vitalie-work,

Default, the sidebar always display none on mobile. The devices screen smaller than 768px. Can you provide link your site, we'll check it.

Thanks.

tungnxt89 avatar May 26 '25 01:05 tungnxt89

Hi

i can't give you a link its not public with direct access in few words its like you need to enter through an iframe and in incognito 😄

and seems iframe is the case

even using JS on first load I need click twice to close menu

window.addEventListener('DOMContentLoaded', function () {
  const menu = document.querySelector('#sidebar-toggle');

  const cookieName = "LP";
  const cookieValue = getCookieValue(cookieName);
  const closeMenu = () => {
    menu.click();
    if(!menu.checked) setTimeout(() => menu.click(), 500);
  }
  if (cookieValue !== null) {
    if (isJSONParsable(cookieValue)) {
      const parsedValue = JSON.parse(cookieValue);
      if( !parsedValue['sidebar-toggle'] ) {
        closeMenu();
      }
    } else {
      closeMenu();
    }
  } else {
    closeMenu();
  }
});

vitalie-work avatar May 26 '25 19:05 vitalie-work