Alex Neigher
Alex Neigher

Reputation: 907

Jquery Event Handlers not firing in Rails App

I have a Rails 4 app and am having some trouble with jquery event handlers/turbo_links and touch vs click actions. What I mean by this is, I am binding all of my handlers like:

//special bindings for turbolinks application for homepage dropdown nav
$(document).on('click',".dropdown",openDropdown);

//dropdown binding for manufactuers phillips container
$(document).on('click',".manufacturers-dropdown",revealContainer);

//toggle button for the see manufacturers detail click
$(document).on('click',".expand-toggle",ShowMoreInfo);

Which works really well on desktop, and binds the handlers like they are supposed to on page load, and back to page actions.

PROBLEM

They are not binding on mobile. I am building an app that is responsive, and on a mobile client (non-desktop), the event handlers are not being bound, and none of the clicks (touches) do anything. Am I missing something?

Traditionally, I bind handlers like:

$(document).ready(function(){
  //this is where the handers are attached
});

but something about turbo_links doesnt play nicely with jquery, so this option is out. Any suggestions?

Upvotes: 0

Views: 759

Answers (1)

Alex Neigher
Alex Neigher

Reputation: 907

2pt answer...

1: gem jquery-tubrolinks

2: //= require jquery.turbolinks

Finally, don't bind stuff directly to the document, rather, bind like this:

 $(document).ready(function(){
   //special bindings for turbolinks application for homepage dropdown nav
   $(".dropdown").click(openDropdown);

   //dropdown binding for manufactuers phillips container
   $(".manufacturers-dropdown").click(revealContainer);

   //toggle button for the see manufacturers detail click
   $(".expand-toggle").click(ShowMoreInfo);
 });

good ol' document.ready works again!

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

Upvotes: 1

Related Questions