I haven't been able to get to the bottom of this but there was suspicion that turbolinks was the culprit. Changing menus just to make sure it wasn't some odd mmenu issue.
I open the page, click the menu button - it works, it opens the side menu, I click a link within the menu, and it goes back to my app. The menu button then doesn't fire anymore. Originally when I had with mmenu, it seemed to be missing the click event associated with mmenu. With sidr, it seems to be there, but nothing happens.
I've set up my jquery like this
Rails 4: how to use $(document).ready() with turbo-links
Example sidr
<a id="simple-menu" href="#sidr">Menu link</a>
<div id="sidr">
<ul>
<li><a href="#">List 1</a></li>
<li class="active"><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
</ul>
</div>
JS file included in tree
var ready;
ready = function() {
$('#simple-menu').sidr();
};
$(ready);
$(document).on('page:load', ready);
I've already set up my application.js with jquery turbolinks gem e.g.
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap-sprockets
//= require jquery-ui/core
//= require jquery-ui/autocomplete
//= require jquery.mmenu.min
//= require_tree .
//= require turbolinks
Suggestions?
Here are some thoughts:
1) Make sure that you have your javascript includes in the head and not the bottom of the body. Since Turbolinks reloads the body every time, you would be reloading the same javascript and probably reinitializing duplicate listeners.
2) With the jquery.turbolinks gem, you should only need
$(ready)
and not$(document).on('page:load', ready)
. That is theoretically what jquery.turbolinks does for you.3) Is
ready
firing at all? Did you put aconsole.log
oralert
in there to see?4) Are you loading things through ajax or something after the DOM is ready? If so, you'll need to call
.sidr()
manually whenever it actually appears on the page, even if it is after DOM ready.