I'm using the following JS in a custom module that implements a toggle menu for mobile browsers:

(function ($) {
  Drupal.behaviors.mobilemenu = {
    attach: function (context, settings) {
     $("#toggle").click(function() {
        $("#block-menu-block-5").slideToggle('fast');
        return false;
     });

    }
  };

})(jQuery);

On any page with an openlayers map, a click to the #toggle link opens and closes the intended element (rather than staying open). Seeking any advice as to why this may be the case.

Thanks in advance.

Comments

Pol’s picture

I don't think that this is related to the OL Drupal module, but the OL library itself.

Can you debug with firebug ?

IshaDakota’s picture

I think you are right about the problem being in the library. I am going to try debugging... I'm not terribly proficient in javascript.

I can see already, though that the root of the problem is the the script is loaded twice and then fires twice on the click event.

cdykstra’s picture

Issue summary: View changes

I'm experiencing the same issue with slideToggle and openlayers. Was a resolution ever found for this?

Thanks!

jienckebd’s picture

I'm having the same problem as well.

IshaDakota’s picture

Should have documented this when I got it to work. I used unbind() as such,

(function ($) {
  Drupal.behaviors.mobilemenu = {
    attach: function (context, settings) {
     $("#toggle").unbind('click').click(function() {
        $("#block-menu-block-5").slideToggle('fast');
        return false;
     });
    }
  };  
})(jQuery);

Not sure this is the right way to do it, but it did work for me.

cdykstra’s picture

IshaDakota, you rock! This fixed the issue for me, thanks for coming back around and sharing your fix.

letrotteur’s picture

That did the trick for me too. Thank you!

mansspams’s picture

Maybe it did the trick, but it did not fix OpenLayers behaviours. Your jQuery will fire as many times as there are maps on page plus one. Because...

            // Finally, attach behaviors
            Drupal.attachBehaviors(this);

I'm looking into issue. Let's hope there is a way ;)

slcp’s picture

This appears to be being addressed in 7.x-3.x in this issue #1332836: Behavior re-architecting, use map level event system.

Pol’s picture

Status: Active » Closed (won't fix)

This message is part of the issue cleanup initiative.

Openlayers 2.x has been deprecated since the release of Openlayers 3.x the 31 December 2015.
If you want to stay on 2.x, you should try with the latest version of the 2.x release.

However, I strongly encourage you to move on version 3.
Version 3 is much more stable than version 2. It does not yet contain all the features but the main ones are there.

I'll close this thread, feel free to reopen it if needed.

Thanks for your understanding.