Index: dhtml_menu.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dhtml_menu/dhtml_menu.js,v
retrieving revision 1.47
diff -u -r1.47 dhtml_menu.js
--- dhtml_menu.js 25 Oct 2009 14:36:44 -0000 1.47
+++ dhtml_menu.js 7 Nov 2009 10:15:31 -0000
@@ -221,7 +221,7 @@
// If the siblings effect is on, close all sibling menus.
if (effects.siblings != 'none') {
- var id = link.attr('id');
+ var id = li.attr('id');
/* Siblings are all open menus that are neither parents nor children of this menu.
* First, mark this item's children for exclusion.
*/
@@ -234,7 +234,7 @@
else {
var root = $('ul.menu');
}
- var siblings = root.find('li.expanded').not('.own-children-temp').not(':has(#' + id + ')');
+ var siblings = root.find('li.expanded').not('.own-children-temp').not('#' + id);
// If children should not get closed automatically...
if (effects.children == 'none') {
@@ -296,7 +296,7 @@
Drupal.dhtmlMenu.cookieSet = function() {
var expanded = new Array();
$('li.expanded').each(function() {
- expanded.push($(this).children('a:first').attr('id'));
+ expanded.push(this.id);
});
document.cookie = 'dhtml_menu=' + expanded.join(',') + ';path=/';
}
Index: dhtml_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dhtml_menu/dhtml_menu.module,v
retrieving revision 1.47
diff -u -r1.47 dhtml_menu.module
--- dhtml_menu.module 25 Oct 2009 14:58:28 -0000 1.47
+++ dhtml_menu.module 7 Nov 2009 10:15:31 -0000
@@ -45,25 +45,4 @@
'file' => 'dhtml_menu.admin.inc',
);
return $menu;
-}
-
-/**
- * Implementation of hook_theme_registry_alter().
- * Replaces the theme functions for the menu_item functions, and stores the
- * original functions in order to call them when this module is done with preprocessing.
- */
-function dhtml_menu_theme_registry_alter(&$theme_registry) {
- global $theme;
-
- // Back up the existing theme functions.
- $themes = variable_get('dhtml_menu_theme', array());
- $themes[$theme] = array(
- 'menu_item' => $theme_registry['menu_item']['function'],
- 'menu_item_link' => $theme_registry['menu_item_link']['function'],
- );
- variable_set('dhtml_menu_theme', $themes);
-
- // Replace them with our own. These will "preprocess" and call the real functions.
- $theme_registry['menu_item']['function'] = 'dhtml_menu_theme_menu_item';
- $theme_registry['menu_item_link']['function'] = 'dhtml_menu_theme_menu_item_link';
-}
+}
\ No newline at end of file
Index: dhtml_menu.theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dhtml_menu/dhtml_menu.theme.inc,v
retrieving revision 1.12
diff -u -r1.12 dhtml_menu.theme.inc
--- dhtml_menu.theme.inc 25 Oct 2009 14:32:36 -0000 1.12
+++ dhtml_menu.theme.inc 7 Nov 2009 10:15:31 -0000
@@ -8,122 +8,46 @@
*/
/**
- * Preprocessor for menu_item_link.
- * Adds an ID attribute to menu links and helps the module
- * follow the recursion of menu_tree_output().
+ * Preprocessor for menu_link.
+ * Adds the required HTML attributes and loads subtrees if necessary.
*/
-function dhtml_menu_theme_menu_item_link($link) {
- global $theme;
- $function = &drupal_static(__FUNCTION__);
+function dhtml_menu_preprocess_menu_link(&$variables) {
+ $cookie = &drupal_static(__FUNCTION__);
$settings = variable_get('dhtml_menu_settings');
- if (!isset($function)) {
- $registry = variable_get('dhtml_menu_theme', array());
- if (isset($registry[$theme]) && function_exists($registry[$theme]['menu_item_link'])) {
- $function = $registry[$theme]['menu_item_link'];
- }
- else {
- $function = 'theme_menu_item_link';
- }
- }
-
- // Do not stack items that have no menu or mlid.
- if (empty($link['menu_name']) || empty($link['mlid'])) {
- return $function($link);
- }
-
- $extended_link = $link;
-
- // If the menu is blacklisted or not whitelisted, mark the link as disabled for DHTML.
- $extended_link['dhtml_disabled'] = ($settings['filter']['type'] == 'blacklist') == !empty($settings['filter']['list'][$link['menu_name']]);
-
- // Add the ID attribute.
- $extended_link = array_merge_recursive($extended_link, array('localized_options' => array('attributes' => array())));
- $extended_link['localized_options']['attributes']['id'] = 'dhtml_menu-' . _dhtml_menu_unique_id($link['mlid']);
-
- // Each link in series is another level of recursion. Add it to the stack, even if it is disabled.
- _dhtml_menu_stack($extended_link);
-
- // Pass the altered variables to the normal menu themer, but only if DHTML should be used.
- return $function(!$extended_link['dhtml_disabled'] ? $extended_link : $link);
-}
-
-/**
- * Preprocessor for menu_item.
- * Checks whether the current item has children that
- * were not rendered, and loads and renders them.
- */
-function dhtml_menu_theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
- global $theme;
- $cookie = &drupal_static(__FUNCTION__ . ':cookie', array());
- $function = &drupal_static(__FUNCTION__ . ':function');
-
- if (empty($function)) {
- $settings = variable_get('dhtml_menu_settings');
+
+ // Parse the cookie, if it is enabled.
+ if (!isset($cookie)) {
if ($settings['effects']['remember'] && $settings['nav'] != 'open' && $settings['effects']['siblings'] != 'close-all') {
$cookie = explode(',', @$_COOKIE['dhtml_menu']);
}
- $registry = variable_get('dhtml_menu_theme', array());
- if (isset($registry[$theme]) && function_exists($registry[$theme]['menu_item'])) {
- $function = $registry[$theme]['menu_item'];
- }
else {
- $function = 'theme_menu_item';
+ $cookie = array();
}
}
- /* When theme('menu_item') is called, the menu tree below it has been
- * rendered already. Since we are done on this recursion level,
- * one element must be popped off the stack.
- */
- $item = _dhtml_menu_stack();
-
- // If this item should not have DHTML, then return to the "parent" function.
- if (!$item || !empty($item['dhtml_disabled'])) {
- return $function($link, $has_children, $menu, $in_active_trail, $extra_class);
- }
-
- $extra_class .= ' dhtml-menu ';
-
- // If there are children, but they were not loaded...
- if ($has_children && !$menu) {
- // Load the tree below the current position.
- $tree = _dhtml_menu_subtree($item);
-
- // Render it...
- $menu = menu_tree_output($tree);
-
- // Sanitize the tree - uncheck has_children if no children were loaded.
- if (!$menu) {
- $has_children = FALSE;
- }
- }
+ // Saves a lot of code.
+ $l = &$variables['element']['#original_link'];
- // If the current item can expand, and is neither saved as open nor in the active trail, close it.
- if ($menu && !($in_active_trail || in_array($item['localized_options']['attributes']['id'], $cookie))) {
- $extra_class .= ' collapsed start-collapsed ';
+ // Determine if the menu is blacklisted or not whitelisted.
+ $disabled = ($settings['filter']['type'] == 'blacklist') == !empty($settings['filter']['list'][$l['menu_name']]);
+ if (empty($l['menu_name']) || empty($l['mlid']) || $disabled) {
+ return;
}
- // Cascade up to the original theming function.
- return $function($link, $has_children, $menu, $in_active_trail, $extra_class);
-}
-
-/**
- * Helper function for storing recursion levels.
- *
- * @param $link
- * If a menu item link is passed, it will be pushed onto the stack.
- * Otherwise, one element will be popped off the stack.
- *
- * @return
- * The last element of the stack, if no argument is passed.
- */
-function _dhtml_menu_stack($link = FALSE) {
- static $stack = array();
- if ($link) {
- $stack[] = $link;
+ // Add the ID and class attributes.
+
+ $variables['element']['#attributes']['id'] = 'dhtml_menu-' . _dhtml_menu_unique_id($l['mlid']);
+ $variables['element']['#attributes']['class'][] = 'dhtml-menu';
+
+ // If there are children, but they were not loaded, load them.
+ if ($l['has_children'] && !$variables['element']['#below']) {
+ $variables['element']['#below'] = _dhtml_menu_subtree($l['menu_name'], $l['mlid']);
}
- else {
- return array_pop($stack);
+
+ // If the current item can expand, and is neither saved as open nor in the active trail, close it.
+ if ($l['has_children'] && !$l['in_active_trail'] && !in_array($variables['element']['attributes']['id'], $cookie)) {
+ $variables['element']['#attributes']['class'][] = 'collapsed';
+ $variables['element']['#attributes']['class'][] = 'start-collapsed';
}
}
@@ -131,33 +55,35 @@
* Traverses the menu tree and returns the sub-tree of the item
* indicated by the parameter.
*
- * @param $item
- * A menu item link that must contain the keys "mlid" and "menu_name".
+ * @param $menu_name
+ * The internal name of the menu.
+ * @param $mlid
+ * The menu link ID.
*
* @return
- * The tree below the menu item, or an empty array.
+ * The tree below the menu item, as a renderable array, or an empty array.
*/
-function _dhtml_menu_subtree($item) {
+function _dhtml_menu_subtree($menu_name, $mlid) {
static $index = array();
static $indexed = array();
// This looks expensive, but menu_tree_all_data uses static caching.
- $tree = menu_tree_all_data($item['menu_name']);
+ $tree = menu_tree_all_data($menu_name);
// Index the menu tree to find ancestor paths for each item.
- if (!isset($indexed[$item['menu_name']])) {
+ if (!isset($indexed[$menu_name])) {
$index += _dhtml_menu_index($tree);
- $indexed[$item['menu_name']] = TRUE;
+ $indexed[$menu_name] = TRUE;
}
// If the menu tree does not contain this item, stop.
- if (!isset($index[$item['mlid']])) {
+ if (!isset($index[$mlid])) {
return array();
}
// Traverse the tree using the ancestor path.
- foreach ($index[$item['mlid']]['parents'] as $mlid) {
- $key = $index[$mlid]['key'];
+ foreach ($index[$mlid]['parents'] as $id) {
+ $key = $index[$id]['key'];
if (isset($tree[$key])) {
$tree = $tree[$key]['below'];
}
@@ -167,8 +93,8 @@
}
// Go one level further to go below the current item.
- $key = $index[$item['mlid']]['key'];
- return isset($tree[$key]) ? $tree[$key]['below'] : array();
+ $key = $index[$mlid]['key'];
+ return isset($tree[$key]) ? menu_tree_output($tree[$key]['below']) : array();
}
/**
Index: dhtml_menu.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dhtml_menu/dhtml_menu.install,v
retrieving revision 1.15
diff -u -r1.15 dhtml_menu.install
--- dhtml_menu.install 25 Oct 2009 14:58:28 -0000 1.15
+++ dhtml_menu.install 7 Nov 2009 10:15:30 -0000
@@ -36,21 +36,10 @@
* Implementation of hook_enable().
*/
function dhtml_menu_enable() {
- // Register our theme interceptors.
- // This does not happen on its own because we have no hook_theme().
- drupal_theme_rebuild();
drupal_set_message(t('DHTML Menu offers a wide range of customization options. If you wish to change them, please visit the configuration page.', array('@url' => url('admin/settings/dhtml_menu'))), 'warning');
}
/**
- * Implementation of hook_disable().
- */
-function dhtml_menu_disable() {
- // Unregister our theme interceptors.
- drupal_theme_rebuild();
-}
-
-/**
* Implementation of hook_install().
* This will create our system variable defaults.
* The benefit is that we do not need to pass defaults
@@ -65,8 +54,6 @@
* Only clears our variables, so a fresh installation can repopulate them.
*/
function dhtml_menu_uninstall() {
- // Theme registry backup.
- variable_del('dhtml_menu_theme');
// Settings.
variable_del('dhtml_menu_settings');
}
@@ -189,3 +176,10 @@
return array();
}
+/**
+ * #7104: Theme registry interceptor is dead.
+ */
+function dhtml_menu_update_7104() {
+ variable_del('dhtml_menu_theme');
+}
+