Вопрос

I'm using gmaps4rails and I need to execute javascript inside a marker's info window. Every marker's underlying object has a sound file associated with it, and I want to be able to play that file inside the info window. The player I'm using is jwplayer and it is instantiated with javascript call with few params.

I've tried to use the gmaps4rails own method to insert the code into info window like below

def gmaps4rails_infowindow
  "<div id='jwplayer_#{self.id}'>Here comes the player...</div>
    <script type=\"text/javascript\">
      //<![CDATA[
        jwplayer(\"jwplayer_#{self.id}\").setup(#{options});
      //]]>
   </script>"
end

but that doesn't work. Actually anything with a < script> tag inside that method seems to break the gmap4rails map loading anyway I try it.

Is there a way to get javascript executed inside the info window by using gmaps4rails, or do I need to roll some other solution for that?

Это было полезно?

Решение

You won't be able to add any <script> in gmaps4rails (as well as raw google maps API I guess).

You should deal with this problem using click event on the marker + close event of infowindow.

Use the callbacks to add these functions.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top