collapsible.theme.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Theme function for the collapsible div tool.
  5. *
  6. * Call theme('ctools_collapsible', $handle, $content, $collapsed) to draw the
  7. * div. The theme function is not necessary; you can add the classes, js and css
  8. * yourself if you really want to.
  9. */
  10. /**
  11. * Delegated implementation of hook_theme()
  12. */
  13. function ctools_collapsible_theme(&$items) {
  14. $items['ctools_collapsible'] = array(
  15. 'variables' => array('handle' => NULL, 'content' => NULL, 'collapsed' => FALSE),
  16. 'file' => 'includes/collapsible.theme.inc',
  17. );
  18. $items['ctools_collapsible_remembered'] = array(
  19. 'variables' => array('id' => NULL, 'handle' => NULL, 'content' => NULL, 'collapsed' => FALSE),
  20. 'file' => 'includes/collapsible.theme.inc',
  21. );
  22. }
  23. /**
  24. * Render a collapsible div.
  25. *
  26. * @param $handle
  27. * Text to put in the handle/title area of the div.
  28. * @param $content
  29. * Text to put in the content area of the div, this is what will get
  30. * collapsed.
  31. * @param $collapsed
  32. * If true, this div will start out collapsed.
  33. */
  34. function theme_ctools_collapsible($vars) {
  35. ctools_add_js('collapsible-div');
  36. ctools_add_css('collapsible-div');
  37. $class = $vars['collapsed'] ? ' ctools-collapsed' : '';
  38. $output = '<div class="ctools-collapsible-container' . $class . '">';
  39. $output .= '<div class="ctools-collapsible-handle">' . $vars['handle'] . '</div>';
  40. $output .= '<div class="ctools-collapsible-content">' . $vars['content'] . '</div>';
  41. $output .= '</div>';
  42. return $output;
  43. }
  44. /**
  45. * Render a collapsible div whose state will be remembered.
  46. *
  47. * @param $id
  48. * The CSS id of the container. This is required.
  49. * @param $handle
  50. * Text to put in the handle/title area of the div.
  51. * @param $content
  52. * Text to put in the content area of the div, this is what will get
  53. * collapsed.
  54. * @param $collapsed
  55. * If true, this div will start out collapsed.
  56. */
  57. function theme_ctools_collapsible_remembered($vars) {
  58. $id = $vars['id'];
  59. $handle = $vars['handle'];
  60. $content = $vars['content'];
  61. $collapsed = $vars['collapsed'];
  62. ctools_add_js('collapsible-div');
  63. ctools_add_css('collapsible-div');
  64. $class = $collapsed ? ' ctools-collapsed' : '';
  65. $output = '<div id="' . $id . '" class="ctools-collapsible-remember ctools-collapsible-container' . $class . '">';
  66. $output .= '<div class="ctools-collapsible-handle">' . $handle . '</div>';
  67. $output .= '<div class="ctools-collapsible-content">' . $content . '</div>';
  68. $output .= '</div>';
  69. return $output;
  70. }