mkhairi / materialize-sass

Materializecss rubygem for Rails Asset Pipeline / Sprockets
http://materialize.labs.my/
MIT License
805 stars 243 forks source link

sideNav() or dropdown() aren't working after navigating to another page on the site #116

Closed treble-maker123 closed 7 years ago

treble-maker123 commented 7 years ago

I have

$("document").ready(function(){
  init_materialize();
});

function init_materialize(){
  if(debug){
    console.log("Materialize initialized.");  
  }

  $(".button-collapse").sideNav();
  $(".dropdown-button").dropdown();
}

The dropdowns and sidenavs work fine when I first land on the site. But when I'm moving to another page on the site, they don't seem to work anymore.

I've tried things like

$('a').click(function(){
  init_materialize();
});

or

<body onload="init_materialize();">

as work-around, but neither seem to be working.

Any ideas?

treble-maker123 commented 7 years ago

I don't quite understand what the $("button-collapse").sideNav() or $(".dropdown-button").dropdown() does, but if I add onclick="init_materialize();" to an element, the sidenav and dropdown start working again after I click said element.

treble-maker123 commented 7 years ago

Finally got it working! For anyone else running into this issue with Rails, adding jquery-turbolinks gem did the trick.

https://github.com/kossnocorp/jquery.turbolinks