creativetimofficial / ct-material-dashboard-pro

Material Dashboard Pro - Premium Bootstrap 5 Admin
https://demos.creative-tim.com/material-dashboard-pro/pages/dashboards/analytics
116 stars 28 forks source link

PerfectScrollbar .destroy() error #277

Open groovemen opened 4 years ago

groovemen commented 4 years ago

Hello there!

Thank you for your interest in working with our products. Sorry for this inconvenience, we have been reported with this bug and until the next update, we will ask you to change the code into your project from the bottom of the HTML pages like in the example from below:

$('.switch-sidebar-mini input').change(function() { 
.....
});

have to look like this:

$('.switch-sidebar-mini input').change(function() {
  $body = $('body');

  $input = $(this);

  if (md.misc.sidebar_mini_active == true) {
    $('body').removeClass('sidebar-mini');
    md.misc.sidebar_mini_active = false;
    // if we are on windows OS we activate the perfectScrollbar function
    if ($(".sidebar").length != 0) {
      var ps = new PerfectScrollbar('.sidebar');
    }
    if ($(".sidebar-wrapper").length != 0) {
      var ps1 = new PerfectScrollbar('.sidebar-wrapper');
    }
    if ($(".main-panel").length != 0) {
      var ps2 = new PerfectScrollbar('.main-panel');
    }
    if ($(".main").length != 0) {
      var ps3 = new PerfectScrollbar('main');
    }
    $('html').addClass('perfect-scrollbar-on');
  } else {
    if ($(".sidebar").length != 0) {
      var ps = new PerfectScrollbar('.sidebar');
      ps.destroy();
      ps = null;
    }
    if ($(".sidebar-wrapper").length != 0) {
      var ps1 = new PerfectScrollbar('.sidebar-wrapper');
      ps1.destroy();
      ps1 = null;
    }
    if ($(".main-panel").length != 0) {
      var ps2 = new PerfectScrollbar('.main-panel');
      ps2.destroy();
      ps2 = null;
    }
    if ($(".main").length != 0) {
      var ps3 = new PerfectScrollbar('main');
      ps3.destroy();
      ps3 = null;
    }
    $('html').addClass('perfect-scrollbar-off');

    setTimeout(function() {
      $('body').addClass('sidebar-mini');

      md.misc.sidebar_mini_active = true;
    }, 300);
  }

  // we simulate the window Resize so the charts will get updated in realtime.
  var simulateWindowResize = setInterval(function() {
    window.dispatchEvent(new Event('resize'));
  }, 180);

  // we stop the simulation of Window Resize after the animations are completed
  setTimeout(function() {
    clearInterval(simulateWindowResize);
  }, 1000);

});

Hope this information helps you. Please let us know if we can help you with anything else.

All the best, Stefan

babojamo commented 4 years ago

has the same issue on this line image image

Tried Browser : Edge, Google Chrome Version: 2.1.2

groovemen commented 4 years ago

Hello @babojamo,

Thank you for using our products, until the next product update you have to make the following changes to solve this issue:

if ($(".sidebar").length != 0) {
  var ps = new PerfectScrollbar('.sidebar');
}
if ($(".sidebar-wrapper").length != 0) {
  var ps1 = new PerfectScrollbar('.sidebar-wrapper');
}
if ($(".main-panel").length != 0) {
  var ps2 = new PerfectScrollbar('.main-panel');
}
if ($(".main").length != 0) {
  var ps3 = new PerfectScrollbar('main');
}
$('html').addClass('perfect-scrollbar-on');
} else {
$('html').addClass('perfect-scrollbar-off');

Hope that information helps you. Please let us know if we can help you with anything else.

All the best, Stefan