This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

dark / light mode
#1
Hello, Is it possible to put a switch on the visualisation to switch between dark theme and light theme ?
Reply
#2
Do you want to change it locally (only for the current user session) or globally (for all users)?
Reply
#3
(08.03.2024, 07:43)admin Wrote: Do you want to change it locally (only for the current user session) or globally (for all users)?

I want only for the current user but if it's not possible global is good
Reply
#4
Add this to Custom JavaScript:
Code:
$(function(){
  if (window.Storage) {
    var dark = !!Storage.get('darkmode', '');

    $('body').toggleClass('dark', dark);
    
    $('.toggle-dark-mode').off('vclick').on('vclick', function() {
      dark = !dark;
      Storage.set('darkmode', dark ? 'y' : '');
      
      $('body').toggleClass('dark', dark);
    });
  }
});

Create a dummy object and attach a visualization element to it. Set Additional classes to toggle-dark-mode
Clicking this element will toggle between light/dark mode. This setting is stored in browser's local storage.
Reply
#5
(08.03.2024, 09:18)admin Wrote: Add this to Custom JavaScript:
Code:
$(function(){
  if (window.Storage) {
    var dark = !!Storage.get('darkmode', '');

    $('body').toggleClass('dark', dark);
   
    $('.toggle-dark-mode').off('vclick').on('vclick', function() {
      dark = !dark;
      Storage.set('darkmode', dark ? 'y' : '');
     
      $('body').toggleClass('dark', dark);
    });
  }
});

Create a dummy object and attach a visualization element to it. Set Additional classes to toggle-dark-mode
Clicking this element will toggle between light/dark mode. This setting is stored in browser's local storage.

Thanks
Reply
#6
(08.03.2024, 09:18)admin Wrote: Add this to Custom JavaScript:
Code:
$(function(){
  if (window.Storage) {
    var dark = !!Storage.get('darkmode', '');

    $('body').toggleClass('dark', dark);
   
    $('.toggle-dark-mode').off('vclick').on('vclick', function() {
      dark = !dark;
      Storage.set('darkmode', dark ? 'y' : '');
     
      $('body').toggleClass('dark', dark);
    });
  }
});

Create a dummy object and attach a visualization element to it. Set Additional classes to toggle-dark-mode
Clicking this element will toggle between light/dark mode. This setting is stored in browser's local storage.

when I switch from one mode to another the page trends do not immediately change color. I have to refresh the page manually
Reply
#7
This should work with iframes:
Code:
$(function(){
  if (!window.Storage) {
    return;
  }

  var bc = new BroadcastChannel('darkmode');
  
  function get() {
    return !!Storage.get('darkmode', '');
  }
  
  function set() {
    $('body').toggleClass('dark', get());
  }
    
  $('.toggle-dark-mode').off('vclick').on('vclick', function() {
    Storage.set('darkmode', get() ? '' : 'y');

    bc.postMessage('set');
    set();
  });

  bc.addEventListener('message', set);
  
  set();
});
Reply


Forum Jump: