diff --git a/simplemenu.js b/simplemenu.js
index 1283075a..637e082a 100644
--- a/simplemenu.js
+++ b/simplemenu.js
@@ -21,12 +21,11 @@ $(document).ready(function() {
$('body').css('margin-top', '23px');
- // Drupal menu callback
- $('#simplemenu').load(basePath + 'simplemenu/menu', function() {
- $('li', this).hover(function() {
- $('ul', this).slideDown(200);
- }, function() {});
- $('a', this).title('');
- $(this).children('li.expanded').addClass('root');
- });
+ // Build menu
+ $('#simplemenu').append(simplemenu);
+ $('#simplemenu li').hover(function() {
+ $('ul', this).slideDown(200);
+ }, function() {});
+ $('#simplemenu a').title('');
+ $('#simplemenu').children('li.expanded').addClass('root');
});
\ No newline at end of file
diff --git a/simplemenu.module b/simplemenu.module
index f2dfe5b9..250ea05d 100644
--- a/simplemenu.module
+++ b/simplemenu.module
@@ -12,14 +12,7 @@
function simplemenu_menu($may_cache) {
$items = array();
- if ($may_cache) {
- $items[] = array(
- 'path' => 'simplemenu/menu',
- 'access' => user_access('view simplemenu'),
- 'callback' => 'simplemenu_get_menu',
- 'type' => MENU_CALLBACK
- );
-
+ if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/simplemenu',
'title' => t('SimpleMenu'),
@@ -57,6 +50,7 @@ function simplemenu_footer() {
);
drupal_add_js(array('simplemenu' => $settings), 'setting');
+ drupal_add_js('var simplemenu = '. drupal_to_js(simplemenu_get_menu() .';'), 'inline');
drupal_add_js($path .'/simplemenu.js');
}
}
@@ -129,6 +123,53 @@ function simplemenu_admin_settings() {
return system_settings_form($form);
}
+/**
+ * Render an HTML list of links for a given menu.
+ */
+function simplemenu_get_menu() {
+ $output = '';
+
+ $menu = simplemenu_menu_tree(variable_get('simplemenu_menu', 1));
+
+ if (!$menu) {
+ $menu = '
'. t('No menu items found. Try a different menu as the default.') .'';
+ }
+
+ $output .= simplemenu_get_devel();
+ $output .= $menu;
+
+ return $output;
+}
+
+/**
+ * Custom implementation of menu_tree().
+ * We want to retrieve the entire menu structure for a given menu,
+ * regardless of whether or not the menu item is expanded or not.
+ */
+function simplemenu_menu_tree($pid = 1) {
+ $menu = menu_get_menu();
+ $output = '';
+
+ if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
+ foreach ($menu['visible'][$pid]['children'] as $mid) {
+ $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
+ $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
+ $output .= theme('menu_item', $mid, simplemenu_theme_menu_tree($mid), count($children) == 0);
+ }
+ }
+
+ return $output;
+}
+
+/**
+ * Custom implementation of theme_menu_tree() to call our custom menu above.
+ */
+function simplemenu_theme_menu_tree($pid = 1) {
+ if ($tree = simplemenu_menu_tree($pid)) {
+ return '';
+ }
+}
+
/**
* Return a list of devel module links if the module is enabled
* and the user has access to this module.
@@ -159,48 +200,4 @@ function simplemenu_get_devel() {
}
return $output;
-}
-
-/**
- * Custom implementation of menu_tree().
- * We want to retrieve the entire menu structure for a given menu,
- * regardless of whether or not the menu item is expanded or not.
- */
-function simplemenu_menu_tree($pid = 1) {
- $menu = menu_get_menu();
- $output = '';
-
- if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
- foreach ($menu['visible'][$pid]['children'] as $mid) {
- $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
- $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
- $output .= theme('menu_item', $mid, simplemenu_theme_menu_tree($mid), count($children) == 0);
- }
- }
-
- return $output;
-}
-
-/**
- * Custom implementation of theme_menu_tree() to call our custom menu above.
- */
-function simplemenu_theme_menu_tree($pid = 1) {
- if ($tree = simplemenu_menu_tree($pid)) {
- return '';
- }
-}
-
-/**
- * AJAX menu callback to return an HTML list of links for a given menu.
- */
-function simplemenu_get_menu() {
- $menu = simplemenu_menu_tree(variable_get('simplemenu_menu', 1));
-
- if (!$menu) {
- $menu = ''. t('No menu items found. Try a different menu as the default.') .'';
- }
-
- print simplemenu_get_devel();
- print $menu;
- exit;
}
\ No newline at end of file