Hi.

I have a couple of environments setup, so when I initally press the environment name it drops down and shows a list of the other environments to switch to.

If I click away to another page, and click on the envoronment name again to see the list, it doesn't work. The ul list is there in the html, but the javascript doesnt work.

If I flush the cache, it works again for one page load but then it stops again.

Let me know what information you need on my setup to debug it

Huw

Comments

beardedgeek’s picture

Issue summary: View changes
pkiff’s picture

I'm intermittently running into this issue as well, but am having difficulty troubleshooting.

@beardedgeek: Two Questions

1. Are you using admin_menu?
I found that if I switched to the default Drupal 7 toolbar, or to the Mobile Friendly Toolbar (aka navbar), then the problem went away. But I want to fix it for a site using admin_menu too.

2. Does it still occur with JS Aggregation turned off?
I'm having problems figuring out if this is a JavaScript issue, a theme issue, a jquery issue, or....? But if I disable JS aggregation, it almost always fixes the problem. I thought at one point that changing my jQuery Update version settings resolved the problem, but that does not seem to consistently be the case.

When it is NOT working for me, it looks like the JavaScript does not even get activated - the reason the toolbar tray doesn't appear is that the element display value is never switched from "none" to "block". But in such cases, as with beardedgeek's report, if I flush caches, then it works correctly...once.

komlenic’s picture

Version: 7.x-2.5 » 7.x-2.6

I have this same issue. Regarding the above:

1. Yes, I am using the admin_menu module.

2. Yes, the problem still occurs with JS aggregation on or off.

Other data:

I'm also using JQuery Update, set to use 1.10, although this problem occurs for me with JQuery Update disabled as well.

Edit:

I've also created a quick test site, using a minimal module set, with admin_menu and environment_indicator. Default D7 themes. No JQuery Update module. The issue is repeatable both with and without JS aggregation enabled.

dpacassi’s picture

Hey guys!

I was able to track down the problem:
In environment_indicator.js we attach the slideToggle() using the '#environment-indicator .environment-indicator-name, #toolbar .environment-indicator-name-wrapper, #navbar-bar .environment-indicator-name-wrapper' selector.

This works fine the first time after we flush drupal's cache.
Now, the admin_menu module has an option to cache it's menu in client-side browser which is by default ON.

If it's ON, the admin_menu module will load the menu content via AJAX as the page is being loaded.
So, while the AJAX request is still going on (or has not even started yet), our environment_indicator.js is already being included and the selector written above doesn't find any elements and doesn't attach the slideToggle() to any element.

The fix would probably be to check whether admin_menu is enabled and if so, wait until their cache-request has run. Maybe the module provides an API where you can attach JS easily but I haven't looked into that.

A quick workaround without any hacking would be to simply disable admin_menu's client-side cache.
You can do that on /admin/config/administration/admin_menu under the tab "Performance".

Cheers,
David