dropdown.theme.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @file
  4. * Provide a javascript based dropdown menu.
  5. *
  6. * The dropdown menu will show up as a clickable link; when clicked,
  7. * a small menu will slide down beneath it, showing the list of links.
  8. *
  9. * The dropdown will stay open until either the user has moved the mouse
  10. * away from the box for > .5 seconds, or can be immediately closed by
  11. * clicking the link again. The code is smart enough that if the mouse
  12. * moves away and then back within the .5 second window, it will not
  13. * re-close.
  14. *
  15. * Multiple dropdowns can be placed per page.
  16. *
  17. * If the user does not have javascript enabled, the link will not appear,
  18. * and instead by default the list of links will appear as a normal inline
  19. * list.
  20. *
  21. * The menu is heavily styled by default, and to make it look different
  22. * will require a little bit of CSS. You can apply your own class to the
  23. * dropdown to help ensure that your CSS can override the dropdown's CSS.
  24. *
  25. * In particular, the text, link, background and border colors may need to
  26. * be changed. Please see dropdown.css for information about the existing
  27. * styling.
  28. */
  29. /**
  30. * Delegated implementation of hook_theme()
  31. */
  32. function ctools_dropdown_theme(&$items) {
  33. $items['ctools_dropdown'] = array(
  34. 'variables' => array('title' => NULL, 'links' => NULL, 'image' => FALSE, 'class' => ''),
  35. 'file' => 'includes/dropdown.theme.inc',
  36. );
  37. }
  38. /**
  39. * Create a dropdown menu.
  40. *
  41. * @param $title
  42. * The text to place in the clickable area to activate the dropdown.
  43. * @param $links
  44. * A list of links to provide within the dropdown, suitable for use
  45. * in via Drupal's theme('links').
  46. * @param $image
  47. * If true, the dropdown link is an image and will not get extra decorations
  48. * that a text dropdown link will.
  49. * @param $class
  50. * An optional class to add to the dropdown's container div to allow you
  51. * to style a single dropdown however you like without interfering with
  52. * other dropdowns.
  53. */
  54. function theme_ctools_dropdown($vars) {
  55. // Provide a unique identifier for every dropdown on the page.
  56. static $id = 0;
  57. $id++;
  58. $class = 'ctools-dropdown-no-js ctools-dropdown' . ($vars['class'] ? (' ' . $vars['class']) : '');
  59. ctools_add_js('dropdown');
  60. ctools_add_css('dropdown');
  61. $output = '';
  62. $output .= '<div class="' . $class . '" id="ctools-dropdown-' . $id . '">';
  63. $output .= '<div class="ctools-dropdown-link-wrapper">';
  64. if ($vars['image']) {
  65. $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-image-link">' . $vars['title'] . '</a>';
  66. }
  67. else {
  68. $output .= '<a href="#" class="ctools-dropdown-link ctools-dropdown-text-link">' . check_plain($vars['title']) . '</a>';
  69. }
  70. $output .= '</div>'; // wrapper
  71. $output .= '<div class="ctools-dropdown-container-wrapper">';
  72. $output .= '<div class="ctools-dropdown-container">';
  73. $output .= theme_links(array('links' => $vars['links'], 'attributes' => array(), 'heading' => ''));
  74. $output .= '</div>'; // container
  75. $output .= '</div>'; // container wrapper
  76. $output .= '</div>'; // dropdown
  77. return $output;
  78. }