Mercurial > hg > rr-repo
comparison sites/all/modules/quicktabs/plugins/QuickQuicktabs.inc @ 2:b74b41bb73f0
-- Google analytics module
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 22 Aug 2013 17:22:54 +0100 |
parents | |
children | a75ead649730 |
comparison
equal
deleted
inserted
replaced
1:67ce89da90df | 2:b74b41bb73f0 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Renders the content using the original Quicktabs mechanism of previous versions. | |
5 * Includes support for ajax rendered content. | |
6 */ | |
7 class QuickQuicktabs extends QuickRenderer { | |
8 | |
9 public function render() { | |
10 $quickset = $this->quickset; | |
11 | |
12 $render_array = array(); | |
13 | |
14 $active_tab = $quickset->getActiveTab(); | |
15 if ($tabs = $this->build_tablinks($active_tab)) { | |
16 $render_array['#attached'] = $this->add_attached(); | |
17 | |
18 $qt_name = $quickset->getName(); | |
19 $settings = $quickset->getSettings(); | |
20 $contents = $quickset->getContents(); | |
21 | |
22 $render_array['content'] = array( | |
23 '#theme' => 'qt_quicktabs', | |
24 '#options' => array('attributes' => array( | |
25 'id' => 'quicktabs-' . $qt_name, | |
26 'class' => 'quicktabs-wrapper quicktabs-style-' . drupal_strtolower($settings['style']), | |
27 )), | |
28 'tabs' => array('#theme' => 'qt_quicktabs_tabset', '#options' => array('active' => $active_tab, 'style' => drupal_strtolower($settings['style'])), 'tablinks' => $tabs), | |
29 // The main content area, each quicktab container needs a unique id. | |
30 'container' => array( | |
31 '#prefix' => '<div id="quicktabs-container-' . $qt_name .'" class="quicktabs_main quicktabs-style-' . drupal_strtolower($settings['style']) .'">', | |
32 '#suffix' => '</div>', | |
33 'divs' => array(), | |
34 ), | |
35 ); | |
36 | |
37 // If in ajax mode, we'll only be rendering one tab, otherwise all of them. | |
38 $tabs_to_render = $settings['ajax'] ? array($active_tab => $contents[$active_tab]) : $contents; | |
39 foreach ($tabs_to_render as $key => $tab) { | |
40 if (!empty($tab)) { | |
41 $attribs = array( | |
42 'id' => 'quicktabs-tabpage-'. $qt_name . '-'. $key, | |
43 'class' => array('quicktabs-tabpage', ($active_tab == $key ? '' : 'quicktabs-hide')), | |
44 ); | |
45 $render_array['content']['container']['divs'][] = array( | |
46 '#prefix' => '<div '. drupal_attributes($attribs) .'>', | |
47 '#suffix' => '</div>', | |
48 'content' => $tab->render(), | |
49 ); | |
50 } | |
51 } | |
52 } | |
53 return $render_array; | |
54 } | |
55 | |
56 /** | |
57 * Build the actual tab links, with appropriate href, title and attributes. | |
58 * | |
59 * @param $active_tab The index of the active tab. | |
60 */ | |
61 protected function build_tablinks($active_tab) { | |
62 $quickset = $this->quickset; | |
63 $settings = $quickset->getSettings(); | |
64 $tabs = array(); | |
65 foreach ($quickset->getContents() as $i => $tab) { | |
66 if (!empty($tab)) { | |
67 $tablink = array( | |
68 '#type' => 'link', | |
69 '#title' => $quickset->translateString($tab->getTitle(), 'tab', $i), | |
70 '#href' => $_GET['q'], | |
71 '#options' => $this->construct_link_options($i), | |
72 ); | |
73 if ($settings['ajax']) { | |
74 $tab_settings = $tab->getSettings(); | |
75 $ajax_keys = $tab->getAjaxKeys(); | |
76 $ajax_args = array(); | |
77 foreach ($ajax_keys as $key) { | |
78 $ajax_args[] = $tab_settings[$key]; | |
79 } | |
80 $ajax_path = $quickset->getAjaxPath($i, $tab->getType()); | |
81 $ajax_href = $ajax_path . '/'. implode('/', $ajax_args); | |
82 $tablink['#ajax'] = array( | |
83 'progress' => array('message' => '', 'type' => 'throbber'), | |
84 'path' => $ajax_href, | |
85 ); | |
86 } | |
87 $tabs[$i] = $tablink; | |
88 } | |
89 } | |
90 return $tabs; | |
91 } | |
92 | |
93 /** | |
94 * Add any necessary js, css and libraries for the render array. | |
95 */ | |
96 protected function add_attached() { | |
97 $attached = array( | |
98 'css' => array( | |
99 array('data' => drupal_get_path('module', 'quicktabs') .'/css/quicktabs.css'), | |
100 ), | |
101 'js' => array( | |
102 array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs.js'), | |
103 array('data' => 'misc/progress.js', 'weight' => JS_LIBRARY), | |
104 ), | |
105 ); | |
106 $settings = $this->quickset->getSettings(); | |
107 // Add the custom style css if a custom style has been set. | |
108 $style_css = quicktabs_get_css($settings['style']); | |
109 if (!empty($style_css)) { | |
110 $attached['css'][] = $style_css; | |
111 } | |
112 // Prepare a tab_settings array for passing the tab info to our JavaScript. | |
113 $tab_settings = array(); | |
114 foreach ($this->quickset->getContents() as $i => $content) { | |
115 if (!empty($content)) { | |
116 $tab_settings[$i] = $content->getSettings(); | |
117 } | |
118 } | |
119 // Add our JS settings | |
120 $javascript = drupal_add_js(); | |
121 foreach ($javascript['settings']['data'] as $key => $settings) { | |
122 if (key($settings) == 'quicktabs') { | |
123 $qtkey = $key; | |
124 break; | |
125 } | |
126 } | |
127 $name = $this->quickset->getName(); | |
128 if (!isset($qtkey) || (isset($javascript['settings']['data'][$qtkey]['quicktabs']) | |
129 && !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs']))) { | |
130 $quicktabs_array = array_merge(array('name' => $name, 'tabs' => $tab_settings), $settings); | |
131 $attached['js'][] = array('data' => array('quicktabs' => array('qt_' . $name => $quicktabs_array)), 'type' => 'setting'); | |
132 } | |
133 return $attached; | |
134 } | |
135 | |
136 /** | |
137 * Helper function to construct link options for tab links. | |
138 */ | |
139 protected function construct_link_options($tabkey) { | |
140 $qt_name = $this->quickset->getName(); | |
141 $id = 'quicktabs-tab-' . implode('-', array($qt_name, $tabkey)); | |
142 | |
143 // Need to construct the correct querystring for the tab links. | |
144 $query = drupal_get_query_parameters(NULL, array("qt-$qt_name", 'q', 'page')); | |
145 $query["qt-{$qt_name}"] = $tabkey; | |
146 | |
147 $link_options = array( | |
148 'attributes' => array( | |
149 'id' => $id, | |
150 ), | |
151 'query' => $query, | |
152 'fragment' => 'qt-' . $qt_name, | |
153 ); | |
154 return $link_options; | |
155 } | |
156 } |