dropdown.theme.inc 3.1 KB

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