Support for non-javascript viewers
vidr - October 27, 2009 - 16:44
| Project: | DHTML Menu |
| Version: | 6.x-3.5 |
| Component: | Graceful degradation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | won't fix |
| Issue tags: | append css, jQuery |
Jump to:
Description
I'd like the menus to be expanded by default if the user doesn't have javascript available (or enabled).
I think this could be accomplished by loading the css via jQuery.
No javascript = no jQuery = no CSS = no inaccessible menu items.
Everyone can navigate our site. Hooray!
Thanks

#1
Here's my suggested fix:
Line: 20 in dhtml_menu.module;
function dhtml_menu_init() {+ //append the css with javascript instead of php to accommodate non-javascript users by displaying menu items by default.
- drupal_add_css(drupal_get_path('module', 'dhtml_menu') .'/dhtml_menu.css');
+ drupal_add_js("$('head').append('<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"".drupal_get_path('module', 'dhtml_menu') ."/dhtml_menu.css\" />');", "inline");
I've tested it with success on my Mac: OS 10.5.8: with FireFox 3.5.3, Safari 4.0.3 and Opera 9.64
PC: Window's 7: IE8 and FF 3.0.14
#2
Updated suggestion;
I encountered a situation where it's better to refer to the root in the head.append so I added a slash before drupal_get_path.
Here's the updated code relative to the current release:
function dhtml_menu_init() {+ //append the css with javascript instead of php to accommodate non-javascript users by displaying menu items by default.
- drupal_add_css(drupal_get_path('module', 'dhtml_menu') .'/dhtml_menu.css');
+ drupal_add_js("$('head').append('<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"/".drupal_get_path('module', 'dhtml_menu') ."/dhtml_menu.css\" />');", "inline");
#3
This is an interesting trick, but you can have that more easily - just set the menu to be expanded by default in the menu settings. DHTML Menu will (should) respect that setting and leave the menu as open.
I'm afraid the idea of statically expanding *all* menus is not in the scope of this module: It is supposed to enhance the page when JS is there, and do nothing otherwise - keep in mind that the navigation without JS is the same now whether or not DHTML Menu is disabled. It'd be an undocumented, unexpected and non-optional feature, which we usually class as "bugs". :)