summaryrefslogtreecommitdiffstats
path: root/plugins/styles/tabs.inc
blob: 2920a7c1a31693de13fe58e63621aa46c57d0851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php


/**
 * @file
 * Definition of the 'Tabs' panel style.
 */

// Plugin definition
$plugin = array(
  'title' => t('Tabs'),
  'description' => t('Show panel panes in a region as tabs.'),
  'render region' => 'panels_style_pack_tabs_style_render_region',
  'settings form' => 'panels_style_pack_tabs_style_settings_form',
);

/**
 * Render callback.
 *
 * @ingroup themeable
 */
function theme_panels_style_pack_tabs_style_render_region($vars) {
  $display = $vars['display'];
  $region_id = $vars['region_id'];
  $owner_id = $vars['owner_id'];
  $panes = $vars['panes'];
  $settings_tabs = $vars['settings'];
  $tab_id = 'tabs-' . $owner_id . '-' . $region_id;
  
  if($settings_tabs['tab_type'] === 'horizontal' || $settings_tabs['tab_type'] === 'bottom') {
  $element = array(
    '#prefix' => '<div id="' . $tab_id . '">',
    '#suffix' => '</div>',
    '#attached' => array(
      'library' => array(array('system', 'ui.tabs')),
      'js' => array(
        drupal_get_path('module', 'panels_style_pack') . '/js/panels_style_pack.js' => array('type' => 'file'),
      ),
    ),
  );
  $settings = array();
  $settings['panelsTabs']['tab_style'] = $settings_tabs['tab_style'];
  $settings['panelsTabs']['tabsID'][] = $tab_id;
  $settings['type'] = 'tabs';
  $settings['panelsTabs']['orientation'] = $settings_tabs['tab_type'];

  $element['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => $settings,
  );

  // Get the pane titles.
  $items = array();
  $delta = 1;
  foreach ($display->panels[$region_id] as $pane_id) {
    // Make sure the pane exists.
    if (!empty($panes[$pane_id])) {
      $title = panels_style_pack_pane_titles($display->did, $pane_id);
      $title = $title ? $title : t('Tab @delta', array('@delta' => $delta));
      $items[] = '<a href="#'. $tab_id . '-' . $delta .'">' . $title . '</a>';
      ++$delta;
    }
  }

  $element['tabs_title'] = array('#theme' => 'item_list', '#items' => $items);

  $items = array();
  $delta = 1;
  foreach ($panes as $pane_id => $item) {
    $element['tabs_content'][$pane_id] = array(
      '#prefix' => '<div id="' . $tab_id . '-' . $delta . '">',
      '#suffix' => '</div>',
      '#markup' => $item,
    );
    ++$delta;
  }
  if($settings_tabs['tab_type'] === 'bottom') {
  	$element['#prefix'] = '<div id="' . $tab_id . '" class="tabs-bottom">';
  	}
  return drupal_render($element);
  }
  else if($settings_tabs['tab_type'] === 'vertical_left') {
 
    $form['vertical_tabs'] = array(
    '#type' => 'vertical_tabs',
    '#tree' => TRUE,
  );
  
  $items = array();
  $delta = 1;
  foreach ($display->panels[$region_id] as $pane_id) {
    // Make sure the pane exists.
    if (!empty($panes[$pane_id])) {
      $title = panels_style_pack_pane_titles($display->did, $pane_id);
      $title = $title ? $title : t('Tab @delta', array('@delta' => $delta));
      $items[] = $title;
      ++$delta;
    }
  }
  foreach($panes as $pane_id => $item) {
  	 $pane = $display->content[$pane_id];
    $form['vertical_tabs'][$pane_id] = array(
      '#type' => 'fieldset',
      '#title' => $items[$pane_id-1],
      '#group' => 'vertical_tabs',
      '#tree' => TRUE,
    );
 
    $form['vertical_tabs'][$pane_id]['content'] = array(
     '#prefix' => '<div id="' . $tab_id . '-' . $delta . '">',
      '#suffix' => '</div>',
      '#markup' => $item,
    );
    ++$delta;
  }
  return drupal_render($form);
  }
}

function panels_style_pack_tabs_style_settings_form($style_settings) {
	$form = array();
	
	$form['tab_type'] = array(
    '#type' => 'select',
    '#title' => t('Tab Type'),
    '#default_value' => $style_settings['tab_type'],
    '#options' => array(
      'horizontal' => t('Horizontal'),
      'vertical_left' => t('Vertical Left'),
      'bottom' => t('Bottom'),
      ),
    '#description' => t('The type of tab'),
    );
    
    $form['tab_style'] = array(
    '#type' => 'select',
    '#title' => t('Tab Style'),
    '#default_value' => $style_settings['tab_style'],
    '#options' => array(
      'collapsible' => t('Collapsible'),
      'open_mouseover' => t('Open on mouseover'),
      ),
    '#description' => t('The Style of the tabs'),
    );
     return $form;
	}