Mercurial > hg > rr-repo
comparison sites/all/modules/quicktabs/plugins/QuickUiTabs.inc @ 2:b74b41bb73f0
-- Google analytics module
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 22 Aug 2013 17:22:54 +0100 |
parents | |
children | 134d4b2e75f6 |
comparison
equal
deleted
inserted
replaced
1:67ce89da90df | 2:b74b41bb73f0 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Renders the content using the jQuery UI Tabs widget. | |
5 */ | |
6 class QuickUiTabs extends QuickRenderer { | |
7 | |
8 public static function optionsForm($qt) { | |
9 $form = array(); | |
10 $form['history'] = array( | |
11 '#type' => 'checkbox', | |
12 '#title' => 'History', | |
13 '#description' => t('Store tab state in the URL allowing for browser back / forward and bookmarks.'), | |
14 '#default_value' => (isset($qt->renderer) && $qt->renderer == 'ui_tabs' && isset($qt->options['history']) && $qt->options['history']), | |
15 ); | |
16 return $form; | |
17 } | |
18 | |
19 public function render() { | |
20 $quickset = $this->quickset; | |
21 | |
22 $active_tab = $quickset->getActiveTab(); | |
23 $tabs = $this->build_tablinks($active_tab); | |
24 $qt_name = $quickset->getName(); | |
25 $render_array = array( | |
26 '#attached' => $this->add_attached(), | |
27 'content' => array( | |
28 '#theme' => 'qt_ui_tabs', | |
29 '#options' => array('attributes' => array( | |
30 'id' => 'quicktabs-' . $qt_name, | |
31 'class' => 'quicktabs-ui-wrapper', | |
32 )), | |
33 'tabs' => array('#theme' => 'qt_ui_tabs_tabset', '#options' => array('active' => $active_tab), 'tablinks' => $tabs), | |
34 'divs' => array(), | |
35 ), | |
36 ); | |
37 foreach ($quickset->getContents() as $key => $tab) { | |
38 if (!empty($tab)) { | |
39 $attribs = array( | |
40 'id' => 'qt-'. $qt_name .'-ui-tabs' . ($key+1), | |
41 ); | |
42 $render_array['content']['divs'][] = array( | |
43 '#prefix' => '<div '. drupal_attributes($attribs) .'>', | |
44 '#suffix' => '</div>', | |
45 'content' => $tab->render(), | |
46 ); | |
47 } | |
48 } | |
49 return $render_array; | |
50 } | |
51 | |
52 | |
53 /** | |
54 * Build the actual tab links, with appropriate href, title and attributes. | |
55 * | |
56 * @param $active_tab The index of the active tab. | |
57 */ | |
58 protected function build_tablinks($active_tab) { | |
59 $tabs = array(); | |
60 $qt_name = $this->quickset->getName(); | |
61 foreach ($this->quickset->getContents() as $i => $tab) { | |
62 if (!empty($tab)) { | |
63 // If we use l() here or a render array of type 'link', the '#' symbol will | |
64 // be escaped. Sad panda is sad. | |
65 $href = '#qt-'. $qt_name .'-ui-tabs' . ($i+1); | |
66 $tablink = array( | |
67 '#markup' => '<a href="'. $href .'">'. check_plain($this->quickset->translateString($tab->getTitle(), 'tab', $i)) .'</a>', | |
68 ); | |
69 $tabs[$i] = $tablink; | |
70 } | |
71 } | |
72 return $tabs; | |
73 } | |
74 | |
75 /** | |
76 * Add any necessary js, css and libraries for the render array. | |
77 */ | |
78 protected function add_attached() { | |
79 $active_tab = $this->quickset->getActiveTab(); | |
80 $settings = $this->quickset->getSettings(); | |
81 $options = $settings['options']; | |
82 | |
83 $attached = array( | |
84 'library' => array( | |
85 array('system', 'ui.tabs'), | |
86 array('system', 'jquery.bbq'), | |
87 ), | |
88 'js' => array( | |
89 array('data' => drupal_get_path('module', 'quicktabs') . '/js/qt_ui_tabs.js', 'weight' => JS_DEFAULT + 1), | |
90 ), | |
91 ); | |
92 | |
93 $javascript = drupal_add_js(); | |
94 foreach ($javascript['settings']['data'] as $key => $settings) { | |
95 if (key($settings) == 'quicktabs') { | |
96 $qtkey = $key; | |
97 break; | |
98 } | |
99 } | |
100 | |
101 if ($options['history']) { | |
102 $attached['library'][] = array('system', 'jquery.bbq'); | |
103 $attached['js'][] = array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs_bbq.js', 'weight' => JS_DEFAULT); | |
104 } | |
105 | |
106 $name = $this->quickset->getName(); | |
107 if (!isset($qtkey) || !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs'])) { | |
108 $quicktabs_array = array('name' => $name, 'active_tab' => $this->quickset->getActiveTab(), 'history' => $options['history']); | |
109 $attached['js'][] = array('data' => array('quicktabs' => array('qt_'. $name => $quicktabs_array)), 'type' => 'setting'); | |
110 } | |
111 return $attached; | |
112 } | |
113 } |