You are here

README.txt in Javascript Tools 5

Drupal activemenu.module README.txt
==============================================================================

Makes standard Drupal menus into AJAX-based tree menus. Can also be used for
custom AJAX menus.


Requirements
------------------------------------------------------------------------------
This module is written for Drupal 5.0+ and requires the jstools.module to be
enabled.


Installation
------------------------------------------------------------------------------
Create a directory modules/activemenu (or, for easy updating, 
modules/jstools/activemenu) and copy all the module's files into it. Enable the
module via the administer > modules page.


Developer Usage
-----------------------------------------------------------------------------
Activemenu.module by default handles the standard navigation menu and all
menus generated as blocks by the Menu module.

To create your own activemenus:

1. Write a handler function in a module to accept a path argument (passed as
   a POST variable, 'href') and return an array of sub-items. For an example,
   see activemenu_js(). The sub-items are in the format based on that returned
   by menu_get_item() and have three array keys: children (boolean), path
   (the url of the item), and title (this will be rendered as the text of the
   menu item link).

Example:

function examplemodule_js() {
  if (isset($_POST['href'])) {
    $items = array();
    $path = $_POST['href'];
    switch ($path) {
      case 'examplemodule/parent1':
        $items[] = array(
          'path' => 'examplemodule/parent1/child1',
          'title' => t('First child option'),
          'children' => TRUE
        );
        $items[] = array(
          'path' => 'examplemodule/parent1/child2',
          'title' => t('Second child option'),
          'children' => FALSE
        );
        break;
      case 'examplemodule/parent1/child1':
        $items[] = array(
          'path' => 'examplemodule/parent1/child1/grandchild1',
          'title' => t('First grandchild option'),
          'children' => FALSE
        );
        break;
    }
    print drupal_to_js($items);
  }
  exit();
}

2. Make your handler accessible to the menu system.

Example:

/**
 * Implementation of hook_menu().
 */
function examplemodule_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'examplemodule/js',
      'title' => t('examplemodule'),
      'access' => user_access('access content'),
      'type' => MENU_CALLBACK,
      'callback' => 'examplemodule_js'
     );
  }
  return $items;
}

3. Implement hook_activemenu().

This hook returns an array of page elements to attach the activemenu behaviour to.

Array keys are valid jQuery selectors, while values are the path to load data from.

For example:

function user_activemenu() {
  $items = array();
  $items['#examplemodule-activemenu'] = 'examplemodule/js';
  return $items;
}

File

activemenu/README.txt
View source
  1. Drupal activemenu.module README.txt
  2. ==============================================================================
  3. Makes standard Drupal menus into AJAX-based tree menus. Can also be used for
  4. custom AJAX menus.
  5. Requirements
  6. ------------------------------------------------------------------------------
  7. This module is written for Drupal 5.0+ and requires the jstools.module to be
  8. enabled.
  9. Installation
  10. ------------------------------------------------------------------------------
  11. Create a directory modules/activemenu (or, for easy updating,
  12. modules/jstools/activemenu) and copy all the module's files into it. Enable the
  13. module via the administer > modules page.
  14. Developer Usage
  15. -----------------------------------------------------------------------------
  16. Activemenu.module by default handles the standard navigation menu and all
  17. menus generated as blocks by the Menu module.
  18. To create your own activemenus:
  19. 1. Write a handler function in a module to accept a path argument (passed as
  20. a POST variable, 'href') and return an array of sub-items. For an example,
  21. see activemenu_js(). The sub-items are in the format based on that returned
  22. by menu_get_item() and have three array keys: children (boolean), path
  23. (the url of the item), and title (this will be rendered as the text of the
  24. menu item link).
  25. Example:
  26. function examplemodule_js() {
  27. if (isset($_POST['href'])) {
  28. $items = array();
  29. $path = $_POST['href'];
  30. switch ($path) {
  31. case 'examplemodule/parent1':
  32. $items[] = array(
  33. 'path' => 'examplemodule/parent1/child1',
  34. 'title' => t('First child option'),
  35. 'children' => TRUE
  36. );
  37. $items[] = array(
  38. 'path' => 'examplemodule/parent1/child2',
  39. 'title' => t('Second child option'),
  40. 'children' => FALSE
  41. );
  42. break;
  43. case 'examplemodule/parent1/child1':
  44. $items[] = array(
  45. 'path' => 'examplemodule/parent1/child1/grandchild1',
  46. 'title' => t('First grandchild option'),
  47. 'children' => FALSE
  48. );
  49. break;
  50. }
  51. print drupal_to_js($items);
  52. }
  53. exit();
  54. }
  55. 2. Make your handler accessible to the menu system.
  56. Example:
  57. /**
  58. * Implementation of hook_menu().
  59. */
  60. function examplemodule_menu($may_cache) {
  61. $items = array();
  62. if ($may_cache) {
  63. $items[] = array(
  64. 'path' => 'examplemodule/js',
  65. 'title' => t('examplemodule'),
  66. 'access' => user_access('access content'),
  67. 'type' => MENU_CALLBACK,
  68. 'callback' => 'examplemodule_js'
  69. );
  70. }
  71. return $items;
  72. }
  73. 3. Implement hook_activemenu().
  74. This hook returns an array of page elements to attach the activemenu behaviour to.
  75. Array keys are valid jQuery selectors, while values are the path to load data from.
  76. For example:
  77. function user_activemenu() {
  78. $items = array();
  79. $items['#examplemodule-activemenu'] = 'examplemodule/js';
  80. return $items;
  81. }