Between version 2.1 and 2.5 the directives to add the JS and CSS to the page were moved OUT of a hook_init function into a custom function. This breaks basic/core drupal themeing abilities and doesn't allow a theme a chance to override the CSS of the module by replicating the CSS files in the module (http://www.drupalcoder.com/blog/overriding-css-stylesheets-in-drupal-the...).

Comments

perignon’s picture

This function should be restored to follow drupal coding standards for themeing:

/**
 * Implements hook_init().
 *
 * We are adding the JavaScript and CSS here rather than theme_nice_menu
 * because when block caching is enabled none of it would get fired
 * and the menus are unstyled.
 */
function nice_menus_init() {
  // Add Superfish JavaScript, if enabled.
  if (variable_get('nice_menus_js', 1) == 1) {
    // The script, from http://users.tpg.com.au/j_birch/plugins/superfish.
    drupal_add_js(drupal_get_path('module', 'nice_menus') . '/superfish/js/superfish.js');
    // Add the Superfish options variables.
    drupal_add_js(array(
      'nice_menus_options' => array(
        'delay' => variable_get('nice_menus_sf_delay', 800),
        'speed' => variable_get('nice_menus_sf_speed', 1),
      ),
    ), array('type' => 'setting', 'scope' => JS_DEFAULT));
    // Add the bgIframe plugin.
    drupal_add_js(drupal_get_path('module', 'nice_menus') . '/superfish/js/jquery.bgiframe.min.js');
    // Add the HoverIntent plugin.
    drupal_add_js(drupal_get_path('module', 'nice_menus') . '/superfish/js/jquery.hoverIntent.minified.js');
    // The Nice menus implementation.
    drupal_add_js(drupal_get_path('module', 'nice_menus') . '/nice_menus.js');
  }

  // Add main CSS functionality.
  drupal_add_css(drupal_get_path('module', 'nice_menus') . '/nice_menus.css', array('group' => CSS_DEFAULT, 'basename' => 'nice_menus.css'));
  // Add custom CSS layout if specified.
  if ($custom = variable_get('nice_menus_custom_css', '')) {
    drupal_add_css($custom, array('group' => CSS_DEFAULT, 'basename' => 'nice_menus_custom.css'));
  }
  // Fall back to default layout.
  else {
    drupal_add_css(drupal_get_path('module', 'nice_menus') . '/nice_menus_default.css', array('group' => CSS_DEFAULT, 'basename' => 'nice_menus_default.css'));
  }
}
xiukun.zhou’s picture

Status: Active » Needs review

thanks Perignon.
if move all js and css to hook_init. then will load nice_menu css and js in the all page.
@see #2020617: CSS Conflict: Path to custom Nice menus CSS file loads css file in admin theme

perignon’s picture

I bet if a use case analysis were done it would show that most every website using nice_menu's loads menu's on every page of the site. So that probably isn't that big of an issue.

This upgrade broke the CSS on my site when I performed the upgrade. Took me a few minutes to realize what happened when I finally dug into the module code to see that the hook_init was removed.

xiukun.zhou’s picture

Status: Needs review » Active
avpaderno’s picture

Version: 7.x-2.5 » 7.x-2.x-dev
Issue summary: View changes
astonvictor’s picture

Status: Active » Closed (outdated)

D7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.