QuickAccordion.inc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Renders the content using the jQuery UI Accordion widget.
  4. */
  5. class QuickAccordion extends QuickRenderer {
  6. public static function optionsForm($qt) {
  7. $form = array();
  8. $form['history'] = array(
  9. '#type' => 'checkbox',
  10. '#title' => 'History',
  11. '#description' => t('Store tab state in the URL allowing for browser back / forward and bookmarks.'),
  12. '#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['history']) && $qt->options['history']),
  13. );
  14. $form['jquery_ui'] = array(
  15. '#type' => 'fieldset',
  16. '#title' => t('JQuery UI options'),
  17. );
  18. $form['jquery_ui']['autoHeight'] = array(
  19. '#type' => 'checkbox',
  20. '#title' => 'Autoheight',
  21. '#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['jquery_ui']['autoHeight']) && $qt->options['jquery_ui']['autoHeight']),
  22. );
  23. $form['jquery_ui']['collapsible'] = array(
  24. '#type' => 'checkbox',
  25. '#title' => t('Collapsible'),
  26. '#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['jquery_ui']['collapsible']) && $qt->options['jquery_ui']['collapsible']),
  27. );
  28. return $form;
  29. }
  30. public function render() {
  31. $quickset = $this->quickset;
  32. $qsid = 'quickset-' . $quickset->getName();
  33. // Build our render array...
  34. $render_array = array();
  35. $render_array['#attached'] = $this->add_attached();
  36. $render_array['content'] = array(
  37. '#theme' => 'qt_accordion',
  38. '#options' => array('attributes' => array(
  39. 'id' => $qsid,
  40. 'class' => array('quick-accordion'),
  41. )),
  42. 'divs' => array(),
  43. );
  44. // Render all tab content.
  45. foreach ($quickset->getContents() as $key => $item) {
  46. if (!empty($item)) {
  47. $render_array['content']['divs'][] = array(
  48. '#prefix' => '<h3><a href= "#'. $qsid . '_' . $key .'">'. check_plain($quickset->translateString($item->getTitle(), 'tab', $key)) .'</a></h3><div>',
  49. '#suffix' => '</div>',
  50. 'content' => $item->render(),
  51. );
  52. }
  53. }
  54. return $render_array;
  55. }
  56. /**
  57. * Add any necessary js, css and libraries for the render array.
  58. */
  59. protected function add_attached() {
  60. $settings = $this->quickset->getSettings();
  61. $options = $settings['options'];
  62. $attached = array(
  63. 'library' => array(
  64. array('system', 'ui.accordion'),
  65. ),
  66. 'js' => array(
  67. array('data' => drupal_get_path('module', 'quicktabs') . '/js/qt_accordion.js'),
  68. ),
  69. );
  70. $javascript = drupal_add_js();
  71. foreach ($javascript['settings']['data'] as $key => $settings) {
  72. if (key($settings) == 'quicktabs') {
  73. $qtkey = $key;
  74. break;
  75. }
  76. }
  77. if ($options['history']) {
  78. $attached['library'][] = array('system', 'jquery.bbq');
  79. $attached['js'][] = array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs_bbq.js');
  80. }
  81. $name = $this->quickset->getName();
  82. if (!isset($qtkey) || !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs'])) {
  83. $quicktabs_array = array('name' => $name, 'active_tab' => $this->quickset->getActiveTab(), 'options' => $options['jquery_ui'], 'history' => $options['history']);
  84. $attached['js'][] = array('data' => array('quicktabs' => array('qt_'. $name => $quicktabs_array)), 'type' => 'setting');
  85. }
  86. return $attached;
  87. }
  88. }