first import
This commit is contained in:
98
sites/all/modules/quicktabs/plugins/QuickAccordion.inc
Normal file
98
sites/all/modules/quicktabs/plugins/QuickAccordion.inc
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Renders the content using the jQuery UI Accordion widget.
|
||||
*/
|
||||
class QuickAccordion extends QuickRenderer {
|
||||
|
||||
public static function optionsForm($qt) {
|
||||
$form = array();
|
||||
$form['history'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'History',
|
||||
'#description' => t('Store tab state in the URL allowing for browser back / forward and bookmarks.'),
|
||||
'#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['history']) && $qt->options['history']),
|
||||
);
|
||||
$form['jquery_ui'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('JQuery UI options'),
|
||||
);
|
||||
$form['jquery_ui']['autoHeight'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Autoheight',
|
||||
'#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['jquery_ui']['autoHeight']) && $qt->options['jquery_ui']['autoHeight']),
|
||||
);
|
||||
$form['jquery_ui']['collapsible'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Collapsible'),
|
||||
'#default_value' => (isset($qt->renderer) && $qt->renderer == 'accordion' && isset($qt->options['jquery_ui']['collapsible']) && $qt->options['jquery_ui']['collapsible']),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$quickset = $this->quickset;
|
||||
$qsid = 'quickset-' . $quickset->getName();
|
||||
// Build our render array...
|
||||
$render_array = array();
|
||||
$render_array['#attached'] = $this->add_attached();
|
||||
$render_array['content'] = array(
|
||||
'#theme' => 'qt_accordion',
|
||||
'#options' => array('attributes' => array(
|
||||
'id' => $qsid,
|
||||
'class' => array('quick-accordion'),
|
||||
)),
|
||||
'divs' => array(),
|
||||
);
|
||||
|
||||
// Render all tab content.
|
||||
foreach ($quickset->getContents() as $key => $item) {
|
||||
if (!empty($item)) {
|
||||
$render_array['content']['divs'][] = array(
|
||||
'#prefix' => '<h3><a href= "#'. $qsid . '_' . $key .'">'. check_plain($quickset->translateString($item->getTitle(), 'tab', $key)) .'</a></h3><div>',
|
||||
'#suffix' => '</div>',
|
||||
'content' => $item->render(),
|
||||
);
|
||||
}
|
||||
}
|
||||
return $render_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any necessary js, css and libraries for the render array.
|
||||
*/
|
||||
protected function add_attached() {
|
||||
$settings = $this->quickset->getSettings();
|
||||
$options = $settings['options'];
|
||||
|
||||
$attached = array(
|
||||
'library' => array(
|
||||
array('system', 'ui.accordion'),
|
||||
),
|
||||
'js' => array(
|
||||
array('data' => drupal_get_path('module', 'quicktabs') . '/js/qt_accordion.js'),
|
||||
),
|
||||
);
|
||||
|
||||
$javascript = drupal_add_js();
|
||||
foreach ($javascript['settings']['data'] as $key => $settings) {
|
||||
if (key($settings) == 'quicktabs') {
|
||||
$qtkey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($options['history']) {
|
||||
$attached['library'][] = array('system', 'jquery.bbq');
|
||||
$attached['js'][] = array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs_bbq.js');
|
||||
}
|
||||
|
||||
$name = $this->quickset->getName();
|
||||
if (!isset($qtkey) || !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs'])) {
|
||||
$quicktabs_array = array('name' => $name, 'active_tab' => $this->quickset->getActiveTab(), 'options' => $options['jquery_ui'], 'history' => $options['history']);
|
||||
$attached['js'][] = array('data' => array('quicktabs' => array('qt_'. $name => $quicktabs_array)), 'type' => 'setting');
|
||||
}
|
||||
return $attached;
|
||||
}
|
||||
|
||||
}
|
93
sites/all/modules/quicktabs/plugins/QuickBlockContent.inc
Normal file
93
sites/all/modules/quicktabs/plugins/QuickBlockContent.inc
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for tab content of type "block" - this is for rendering a block as tab
|
||||
* content.
|
||||
*/
|
||||
class QuickBlockContent extends QuickContent {
|
||||
|
||||
public static function getType() {
|
||||
return 'block';
|
||||
}
|
||||
|
||||
public function optionsForm($delta, $qt) {
|
||||
$tab = $this->settings;
|
||||
$form = array();
|
||||
$form['block']['bid'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => quicktabs_get_blocks(),
|
||||
'#default_value' => isset($tab['bid']) ? $tab['bid'] : '',
|
||||
'#title' => t('Select a block'),
|
||||
);
|
||||
$form['block']['hide_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Hide the title of this block'),
|
||||
'#default_value' => isset($tab['hide_title']) ? $tab['hide_title'] : 1,
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render($hide_empty = FALSE, $args = array()) {
|
||||
if ($this->rendered_content) {
|
||||
return $this->rendered_content;
|
||||
}
|
||||
$output = array();
|
||||
$item = $this->settings;
|
||||
if (!empty($args)) {
|
||||
// The args have been passed in from an ajax request.
|
||||
$qt_name = array_shift($args);
|
||||
list($item['bid'], $item['hide_title']) = $args;
|
||||
|
||||
// Ensure the block is assigned to the requested quicktabs block. This test prevents
|
||||
// AJAX access to blocks that have not been added to an AJAX-enabled quicktabs block.
|
||||
$break = TRUE;
|
||||
$quicktabs = quicktabs_load($qt_name);
|
||||
// Ensure AJAX is enabled for the quicktabs block.
|
||||
if (!empty($quicktabs) && $quicktabs->ajax == 1) {
|
||||
// Ensure the requested tab has been added to the quicktabs block.
|
||||
foreach ($quicktabs->tabs as $quicktab) {
|
||||
if (isset($quicktab['bid']) && ($quicktab['bid'] == $item['bid'])) {
|
||||
$break = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($break == TRUE) {
|
||||
if (!$hide_empty) {
|
||||
$output['#markup'] = theme('quicktabs_tab_access_denied', $item);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($item['bid'])) {
|
||||
if (module_exists('block')) {
|
||||
$pos = strpos($item['bid'], '_delta_');
|
||||
$module = drupal_substr($item['bid'], 0, $pos);
|
||||
$delta = drupal_substr($item['bid'], $pos + 7);
|
||||
|
||||
$block = block_load($module, $delta);
|
||||
$block->region = 'quicktabs_tabpage';
|
||||
|
||||
if ($block_arr = _block_render_blocks(array($block))) {
|
||||
if ($item['hide_title']) {
|
||||
$block_arr["{$block->module}_{$block->delta}"]->subject = FALSE;
|
||||
}
|
||||
if (!empty($block_arr["{$block->module}_{$block->delta}"]->content)) {
|
||||
$build = _block_get_renderable_array($block_arr);
|
||||
$output = $build;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!$hide_empty) {
|
||||
$output['#markup'] = t('Block module is not enabled, cannot display content.');
|
||||
}
|
||||
}
|
||||
$this->rendered_content = $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getAjaxKeys() {
|
||||
return array('bid', 'hide_title');
|
||||
}
|
||||
}
|
92
sites/all/modules/quicktabs/plugins/QuickCallbackContent.inc
Normal file
92
sites/all/modules/quicktabs/plugins/QuickCallbackContent.inc
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for tab content of type "callback" - this is for rendering the contents
|
||||
* of some menu callback function as tab content.
|
||||
*/
|
||||
class QuickCallbackContent extends QuickContent {
|
||||
|
||||
public static function getType() {
|
||||
return 'callback';
|
||||
}
|
||||
|
||||
public function __construct($item) {
|
||||
parent::__construct($item);
|
||||
|
||||
if (isset($item['path'])) {
|
||||
$url_args = arg();
|
||||
$path = $item['path'];
|
||||
|
||||
foreach ($url_args as $id => $arg) {
|
||||
$path = str_replace("%$id", $arg, $path);
|
||||
}
|
||||
$path = preg_replace(',/?(%\d),', '', $path);
|
||||
if (!empty($path)) {
|
||||
$this->settings['ajax_path'] = rawurlencode($path);
|
||||
}
|
||||
else {
|
||||
$this->settings['ajax_path'] = '';
|
||||
}
|
||||
$this->settings['actual_path'] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
public function optionsForm($delta, $qt) {
|
||||
$tab = $this->settings;
|
||||
$form = array();
|
||||
$form['callback']['path'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => isset($tab['path']) ? $tab['path'] : '',
|
||||
'#title' => t('Path'),
|
||||
'#element_validate' => array('quicktabs_callback_element_validate'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render($hide_empty = FALSE, $args = array()) {
|
||||
if ($this->rendered_content) {
|
||||
return $this->rendered_content;
|
||||
}
|
||||
$item = $this->settings;
|
||||
if (!empty($args)) {
|
||||
// The args have been passed in from an ajax request.
|
||||
// The first element of the args array is the qt_name, which we don't need
|
||||
// for this content type.
|
||||
array_shift($args);
|
||||
$item['actual_path'] = rawurldecode($args[0]);
|
||||
$_GET['q'] = $item['actual_path'];
|
||||
}
|
||||
|
||||
$output = array();
|
||||
if (isset($item['actual_path'])) {
|
||||
// Retain the current page title as we'll need to set it back after
|
||||
// calling menu_execute_active_handler().
|
||||
$page_title = drupal_get_title();
|
||||
$response = menu_execute_active_handler($item['actual_path'], FALSE);
|
||||
// Revert the page title.
|
||||
drupal_set_title($page_title);
|
||||
|
||||
if (!is_array($response)) {
|
||||
if (is_int($response)) {
|
||||
if (MENU_ACCESS_DENIED == $response && !$hide_empty) {
|
||||
$output['#markup'] = theme('quicktabs_tab_access_denied', array('tab' => $item));
|
||||
}
|
||||
// For any other integer response form the menu callback, we'll just
|
||||
// return an empty array.
|
||||
}
|
||||
else {
|
||||
$output = array('#markup' => $response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$output = $response;
|
||||
}
|
||||
}
|
||||
$this->rendered_content = $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getAjaxKeys() {
|
||||
return array('ajax_path');
|
||||
}
|
||||
}
|
72
sites/all/modules/quicktabs/plugins/QuickNodeContent.inc
Normal file
72
sites/all/modules/quicktabs/plugins/QuickNodeContent.inc
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for tab content of type "node" - this is for rendering a node as tab
|
||||
* content.
|
||||
*/
|
||||
class QuickNodeContent extends QuickContent {
|
||||
|
||||
public static function getType() {
|
||||
return 'node';
|
||||
}
|
||||
|
||||
public function optionsForm($delta, $qt) {
|
||||
$tab = $this->settings;
|
||||
$form = array();
|
||||
$form['node']['nid'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Node'),
|
||||
'#description' => t('The node ID of the node.'),
|
||||
'#maxlength' => 10,
|
||||
'#size' => 20,
|
||||
'#default_value' => isset($tab['nid']) ? $tab['nid'] : '',
|
||||
);
|
||||
$form['node']['teaser'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Teaser view'),
|
||||
'#default_value' => isset($tab['teaser']) ? $tab['teaser'] : 0,
|
||||
);
|
||||
$form['node']['hide_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Hide the title of this node'),
|
||||
'#default_value' => isset($tab['hide_title']) ? $tab['hide_title'] : 1,
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render($hide_empty = FALSE, $args = array()) {
|
||||
if ($this->rendered_content) {
|
||||
return $this->rendered_content;
|
||||
}
|
||||
$item = $this->settings;
|
||||
if (!empty($args)) {
|
||||
// The args have been passed in from an ajax request.
|
||||
// The first element of the args array is the qt_name, which we don't need
|
||||
// for this content type.
|
||||
array_shift($args);
|
||||
list($item['nid'], $item['teaser'], $item['hide_title']) = $args;
|
||||
}
|
||||
$output = array();
|
||||
if (isset($item['nid'])) {
|
||||
$node = node_load($item['nid']);
|
||||
if (!empty($node)) {
|
||||
if (node_access('view', $node)) {
|
||||
$buildmode = $item['teaser'] ? 'teaser' : 'full';
|
||||
$nstruct = node_view($node, $buildmode);
|
||||
if ($item['hide_title']) {
|
||||
$nstruct['#node']->title = NULL;
|
||||
}
|
||||
$output = $nstruct;
|
||||
}
|
||||
elseif (!$hide_empty) {
|
||||
$output = array('#markup' => theme('quicktabs_tab_access_denied', array('tab' => $item)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getAjaxKeys() {
|
||||
return array('nid', 'teaser', 'hide_title');
|
||||
}
|
||||
}
|
65
sites/all/modules/quicktabs/plugins/QuickQtabsContent.inc
Normal file
65
sites/all/modules/quicktabs/plugins/QuickQtabsContent.inc
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for tab content of type "qtabs" - this is for rendering a QuickSet instance
|
||||
* as the tab content of another QuickSet instance.
|
||||
*/
|
||||
class QuickQtabsContent extends QuickContent {
|
||||
|
||||
public static function getType() {
|
||||
return 'qtabs';
|
||||
}
|
||||
|
||||
public function optionsForm($delta, $qt) {
|
||||
$tab = $this->settings;
|
||||
$form = array();
|
||||
$tab_options = array();
|
||||
foreach (quicktabs_load_multiple() as $machine_name => $info) {
|
||||
// Do not offer the option to put a tab inside itself.
|
||||
if (!isset($qt->machine_name) || $machine_name != $qt->machine_name) {
|
||||
$tab_options[$machine_name] = $info->title;
|
||||
}
|
||||
}
|
||||
$form['qtabs']['machine_name'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Quicktabs instance'),
|
||||
'#description' => t('The Quicktabs instance to put inside this tab.'),
|
||||
'#options' => $tab_options,
|
||||
'#default_value' => isset($tab['machine_name']) ? $tab['machine_name'] : '',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render($hide_empty = FALSE, $args = array()) {
|
||||
if ($this->rendered_content) {
|
||||
return $this->rendered_content;
|
||||
}
|
||||
$item = $this->settings;
|
||||
if (!empty($args)) {
|
||||
// The args have been passed in from an ajax request.
|
||||
// The first element of the args array is the qt_name, which we don't need
|
||||
// for this content type.
|
||||
array_shift($args);
|
||||
$item['machine_name'] = $args[0];
|
||||
}
|
||||
|
||||
$output = array();
|
||||
if (isset($item['machine_name'])) {
|
||||
if ($quicktabs = quicktabs_load($item['machine_name'])) {
|
||||
$contents = $quicktabs->tabs;
|
||||
$name = $quicktabs->machine_name;
|
||||
unset($quicktabs->tabs, $quicktabs->machine_name);
|
||||
$options = (array) $quicktabs;
|
||||
if ($qt = QuickSet::QuickSetRendererFactory($name, $contents, $quicktabs->renderer, $options)) {
|
||||
$output = $qt->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->rendered_content = $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getAjaxKeys() {
|
||||
return array('machine_name');
|
||||
}
|
||||
}
|
156
sites/all/modules/quicktabs/plugins/QuickQuicktabs.inc
Normal file
156
sites/all/modules/quicktabs/plugins/QuickQuicktabs.inc
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Renders the content using the original Quicktabs mechanism of previous versions.
|
||||
* Includes support for ajax rendered content.
|
||||
*/
|
||||
class QuickQuicktabs extends QuickRenderer {
|
||||
|
||||
public function render() {
|
||||
$quickset = $this->quickset;
|
||||
|
||||
$render_array = array();
|
||||
|
||||
$active_tab = $quickset->getActiveTab();
|
||||
if ($tabs = $this->build_tablinks($active_tab)) {
|
||||
$render_array['#attached'] = $this->add_attached();
|
||||
|
||||
$qt_name = $quickset->getName();
|
||||
$settings = $quickset->getSettings();
|
||||
$contents = $quickset->getContents();
|
||||
|
||||
$render_array['content'] = array(
|
||||
'#theme' => 'qt_quicktabs',
|
||||
'#options' => array('attributes' => array(
|
||||
'id' => 'quicktabs-' . $qt_name,
|
||||
'class' => 'quicktabs-wrapper quicktabs-style-' . drupal_strtolower($settings['style']),
|
||||
)),
|
||||
'tabs' => array('#theme' => 'qt_quicktabs_tabset', '#options' => array('active' => $active_tab, 'style' => drupal_strtolower($settings['style'])), 'tablinks' => $tabs),
|
||||
// The main content area, each quicktab container needs a unique id.
|
||||
'container' => array(
|
||||
'#prefix' => '<div id="quicktabs-container-' . $qt_name .'" class="quicktabs_main quicktabs-style-' . drupal_strtolower($settings['style']) .'">',
|
||||
'#suffix' => '</div>',
|
||||
'divs' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
// If in ajax mode, we'll only be rendering one tab, otherwise all of them.
|
||||
$tabs_to_render = $settings['ajax'] ? array($active_tab => $contents[$active_tab]) : $contents;
|
||||
foreach ($tabs_to_render as $key => $tab) {
|
||||
if (!empty($tab)) {
|
||||
$attribs = array(
|
||||
'id' => 'quicktabs-tabpage-'. $qt_name . '-'. $key,
|
||||
'class' => array('quicktabs-tabpage', ($active_tab == $key ? '' : 'quicktabs-hide')),
|
||||
);
|
||||
$render_array['content']['container']['divs'][] = array(
|
||||
'#prefix' => '<div '. drupal_attributes($attribs) .'>',
|
||||
'#suffix' => '</div>',
|
||||
'content' => $tab->render(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $render_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the actual tab links, with appropriate href, title and attributes.
|
||||
*
|
||||
* @param $active_tab The index of the active tab.
|
||||
*/
|
||||
protected function build_tablinks($active_tab) {
|
||||
$quickset = $this->quickset;
|
||||
$settings = $quickset->getSettings();
|
||||
$tabs = array();
|
||||
foreach ($quickset->getContents() as $i => $tab) {
|
||||
if (!empty($tab)) {
|
||||
$tablink = array(
|
||||
'#type' => 'link',
|
||||
'#title' => $quickset->translateString($tab->getTitle(), 'tab', $i),
|
||||
'#href' => $_GET['q'],
|
||||
'#options' => $this->construct_link_options($i),
|
||||
);
|
||||
if ($settings['ajax']) {
|
||||
$tab_settings = $tab->getSettings();
|
||||
$ajax_keys = $tab->getAjaxKeys();
|
||||
$ajax_args = array();
|
||||
foreach ($ajax_keys as $key) {
|
||||
$ajax_args[] = $tab_settings[$key];
|
||||
}
|
||||
$ajax_path = $quickset->getAjaxPath($i, $tab->getType());
|
||||
$ajax_href = $ajax_path . '/'. implode('/', $ajax_args);
|
||||
$tablink['#ajax'] = array(
|
||||
'progress' => array('message' => '', 'type' => 'throbber'),
|
||||
'path' => $ajax_href,
|
||||
);
|
||||
}
|
||||
$tabs[$i] = $tablink;
|
||||
}
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any necessary js, css and libraries for the render array.
|
||||
*/
|
||||
protected function add_attached() {
|
||||
$attached = array(
|
||||
'css' => array(
|
||||
array('data' => drupal_get_path('module', 'quicktabs') .'/css/quicktabs.css'),
|
||||
),
|
||||
'js' => array(
|
||||
array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs.js'),
|
||||
array('data' => 'misc/progress.js', 'weight' => JS_LIBRARY),
|
||||
),
|
||||
);
|
||||
$settings = $this->quickset->getSettings();
|
||||
// Add the custom style css if a custom style has been set.
|
||||
$style_css = quicktabs_get_css($settings['style']);
|
||||
if (!empty($style_css)) {
|
||||
$attached['css'][] = $style_css;
|
||||
}
|
||||
// Prepare a tab_settings array for passing the tab info to our JavaScript.
|
||||
$tab_settings = array();
|
||||
foreach ($this->quickset->getContents() as $i => $content) {
|
||||
if (!empty($content)) {
|
||||
$tab_settings[$i] = $content->getSettings();
|
||||
}
|
||||
}
|
||||
// Add our JS settings
|
||||
$javascript = drupal_add_js();
|
||||
foreach ($javascript['settings']['data'] as $key => $settings) {
|
||||
if (key($settings) == 'quicktabs') {
|
||||
$qtkey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$name = $this->quickset->getName();
|
||||
if (!isset($qtkey) || (isset($javascript['settings']['data'][$qtkey]['quicktabs'])
|
||||
&& !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs']))) {
|
||||
$quicktabs_array = array_merge(array('name' => $name, 'tabs' => $tab_settings), $settings);
|
||||
$attached['js'][] = array('data' => array('quicktabs' => array('qt_' . $name => $quicktabs_array)), 'type' => 'setting');
|
||||
}
|
||||
return $attached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to construct link options for tab links.
|
||||
*/
|
||||
protected function construct_link_options($tabkey) {
|
||||
$qt_name = $this->quickset->getName();
|
||||
$id = 'quicktabs-tab-' . implode('-', array($qt_name, $tabkey));
|
||||
|
||||
// Need to construct the correct querystring for the tab links.
|
||||
$query = drupal_get_query_parameters(NULL, array("qt-$qt_name", 'q', 'page'));
|
||||
$query["qt-{$qt_name}"] = $tabkey;
|
||||
|
||||
$link_options = array(
|
||||
'attributes' => array(
|
||||
'id' => $id,
|
||||
),
|
||||
'query' => $query,
|
||||
'fragment' => 'qt-' . $qt_name,
|
||||
);
|
||||
return $link_options;
|
||||
}
|
||||
}
|
113
sites/all/modules/quicktabs/plugins/QuickUiTabs.inc
Normal file
113
sites/all/modules/quicktabs/plugins/QuickUiTabs.inc
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Renders the content using the jQuery UI Tabs widget.
|
||||
*/
|
||||
class QuickUiTabs extends QuickRenderer {
|
||||
|
||||
public static function optionsForm($qt) {
|
||||
$form = array();
|
||||
$form['history'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'History',
|
||||
'#description' => t('Store tab state in the URL allowing for browser back / forward and bookmarks.'),
|
||||
'#default_value' => (isset($qt->renderer) && $qt->renderer == 'ui_tabs' && isset($qt->options['history']) && $qt->options['history']),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$quickset = $this->quickset;
|
||||
|
||||
$active_tab = $quickset->getActiveTab();
|
||||
$tabs = $this->build_tablinks($active_tab);
|
||||
$qt_name = $quickset->getName();
|
||||
$render_array = array(
|
||||
'#attached' => $this->add_attached(),
|
||||
'content' => array(
|
||||
'#theme' => 'qt_ui_tabs',
|
||||
'#options' => array('attributes' => array(
|
||||
'id' => 'quicktabs-' . $qt_name,
|
||||
'class' => 'quicktabs-ui-wrapper',
|
||||
)),
|
||||
'tabs' => array('#theme' => 'qt_ui_tabs_tabset', '#options' => array('active' => $active_tab), 'tablinks' => $tabs),
|
||||
'divs' => array(),
|
||||
),
|
||||
);
|
||||
foreach ($quickset->getContents() as $key => $tab) {
|
||||
if (!empty($tab)) {
|
||||
$attribs = array(
|
||||
'id' => 'qt-'. $qt_name .'-ui-tabs' . ($key+1),
|
||||
);
|
||||
$render_array['content']['divs'][] = array(
|
||||
'#prefix' => '<div '. drupal_attributes($attribs) .'>',
|
||||
'#suffix' => '</div>',
|
||||
'content' => $tab->render(),
|
||||
);
|
||||
}
|
||||
}
|
||||
return $render_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the actual tab links, with appropriate href, title and attributes.
|
||||
*
|
||||
* @param $active_tab The index of the active tab.
|
||||
*/
|
||||
protected function build_tablinks($active_tab) {
|
||||
$tabs = array();
|
||||
$qt_name = $this->quickset->getName();
|
||||
foreach ($this->quickset->getContents() as $i => $tab) {
|
||||
if (!empty($tab)) {
|
||||
// If we use l() here or a render array of type 'link', the '#' symbol will
|
||||
// be escaped. Sad panda is sad.
|
||||
$href = '#qt-'. $qt_name .'-ui-tabs' . ($i+1);
|
||||
$tablink = array(
|
||||
'#markup' => '<a href="'. $href .'">'. check_plain($this->quickset->translateString($tab->getTitle(), 'tab', $i)) .'</a>',
|
||||
);
|
||||
$tabs[$i] = $tablink;
|
||||
}
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any necessary js, css and libraries for the render array.
|
||||
*/
|
||||
protected function add_attached() {
|
||||
$active_tab = $this->quickset->getActiveTab();
|
||||
$settings = $this->quickset->getSettings();
|
||||
$options = $settings['options'];
|
||||
|
||||
$attached = array(
|
||||
'library' => array(
|
||||
array('system', 'ui.tabs'),
|
||||
array('system', 'jquery.bbq'),
|
||||
),
|
||||
'js' => array(
|
||||
array('data' => drupal_get_path('module', 'quicktabs') . '/js/qt_ui_tabs.js', 'weight' => JS_DEFAULT + 1),
|
||||
),
|
||||
);
|
||||
|
||||
$javascript = drupal_add_js();
|
||||
foreach ($javascript['settings']['data'] as $key => $settings) {
|
||||
if (key($settings) == 'quicktabs') {
|
||||
$qtkey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($options['history']) {
|
||||
$attached['library'][] = array('system', 'jquery.bbq');
|
||||
$attached['js'][] = array('data' => drupal_get_path('module', 'quicktabs') . '/js/quicktabs_bbq.js', 'weight' => JS_DEFAULT);
|
||||
}
|
||||
|
||||
$name = $this->quickset->getName();
|
||||
if (!isset($qtkey) || !array_key_exists('qt_' . $name, $javascript['settings']['data'][$qtkey]['quicktabs'])) {
|
||||
$quicktabs_array = array('name' => $name, 'active_tab' => $this->quickset->getActiveTab(), 'history' => $options['history']);
|
||||
$attached['js'][] = array('data' => array('quicktabs' => array('qt_'. $name => $quicktabs_array)), 'type' => 'setting');
|
||||
}
|
||||
return $attached;
|
||||
}
|
||||
}
|
141
sites/all/modules/quicktabs/plugins/QuickViewContent.inc
Normal file
141
sites/all/modules/quicktabs/plugins/QuickViewContent.inc
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class for tab content of type "view" - this is for rendering a view as tab
|
||||
* content.
|
||||
*/
|
||||
class QuickViewContent extends QuickContent {
|
||||
|
||||
// Each view that we render, whether via ajax or not, will need a unique DOM
|
||||
// id. Unfortunately we can only control the ones that Quicktabs is responsible
|
||||
// for, so if there are other views on the page, there may be duplicate ids.
|
||||
static $view_dom_id = 1;
|
||||
|
||||
public static function getType() {
|
||||
return 'view';
|
||||
}
|
||||
|
||||
public function optionsForm($delta, $qt) {
|
||||
$tab = $this->settings;
|
||||
$form = array();
|
||||
$views = quicktabs_get_views();
|
||||
$views_keys = array_keys($views);
|
||||
|
||||
$selected_view = (isset($tab['vid']) ? $tab['vid'] : (isset($views_keys[0]) ? $views_keys[0] : ''));
|
||||
$form['view']['vid'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $views,
|
||||
'#default_value' => $selected_view,
|
||||
'#title' => t('Select a view'),
|
||||
'#ajax' => array(
|
||||
'callback' => '_quicktabs_replace_view_displays_callback',
|
||||
),
|
||||
);
|
||||
$form['view']['display'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'display',
|
||||
'#options' => _quicktabs_get_views_displays($selected_view),
|
||||
'#default_value' => isset($tab['display']) ? $tab['display'] : '',
|
||||
'#prefix' => '<div id="view-display-dropdown-' . $delta . '">',
|
||||
'#suffix' => '</div>'
|
||||
);
|
||||
$form['view']['args'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'arguments',
|
||||
'#size' => '40',
|
||||
'#required' => FALSE,
|
||||
'#default_value' => isset($tab['args']) ? $tab['args'] : '',
|
||||
'#description' => t('Additional arguments to send to the view as if they were part of the URL in the form of arg1/arg2/arg3. You may use %0, %1, ..., %N to grab arguments from the URL.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function __construct($item) {
|
||||
parent::__construct($item);
|
||||
if (module_exists('views')) views_add_js('ajax_view');
|
||||
$this->settings['view_path'] = rawurlencode($_GET['q']);
|
||||
$this->settings['view_dom_id'] = self::$view_dom_id++;
|
||||
if (isset($item['args'])) {
|
||||
$url_args = arg();
|
||||
$args = $item['args'];
|
||||
|
||||
foreach ($url_args as $id => $arg) {
|
||||
$args = str_replace("%$id", $arg, $args);
|
||||
}
|
||||
$args = preg_replace(',/?(%\d),', '', $args);
|
||||
if (!empty($args)) {
|
||||
$this->settings['ajax_args'] = rawurlencode($args);
|
||||
$args_array = explode('/', $args);
|
||||
}
|
||||
else {
|
||||
$this->settings['ajax_args'] = '';
|
||||
$args_array = array();
|
||||
}
|
||||
$this->settings['actual_args'] = $args_array;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($hide_empty = FALSE, $args = array()) {
|
||||
if (!empty($args)) {
|
||||
// The args have been passed in from an ajax request. We use Views' own
|
||||
// ajax functionality to get the view.
|
||||
// The first element of the args array is the qt_name, which we don't need
|
||||
// for this content type.
|
||||
array_shift($args);
|
||||
// The order of these arguments corresponds to the array returned in
|
||||
// $this->getAjaxKeys().
|
||||
$_REQUEST['view_name'] = array_shift($args);
|
||||
$_REQUEST['view_display_id'] = array_shift($args);
|
||||
$_REQUEST['view_dom_id'] = array_shift($args);
|
||||
$view_path = array_shift($args);
|
||||
$_REQUEST['view_path'] = rawurldecode($view_path);
|
||||
if (!empty($args)) {
|
||||
$view_args = array_shift($args);
|
||||
$_REQUEST['view_args'] = rawurldecode($view_args);
|
||||
}
|
||||
|
||||
module_load_include('inc', 'views', 'includes/ajax');
|
||||
$view = views_ajax();
|
||||
foreach ($view['#commands'] as $command) {
|
||||
if ($command['command'] == 'insert') {
|
||||
return array('#markup' => trim($command['data']));
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
// Non-ajax rendering of a view.
|
||||
if ($this->rendered_content) {
|
||||
return $this->rendered_content;
|
||||
}
|
||||
$item = $this->settings;
|
||||
$output = array();
|
||||
if (isset($item['vid'])) {
|
||||
if (module_exists('views')) {
|
||||
if ($view = views_get_view($item['vid'])) {
|
||||
if ($view->access($item['display'])) {
|
||||
$view->set_display($item['display']);
|
||||
$view->set_arguments($item['actual_args']);
|
||||
$view_output = $view->preview();
|
||||
if (!empty($view->result) || $view->display_handler->get_option('empty') || !empty($view->style_plugin->definition['even empty'])) {
|
||||
$output['#markup'] = $view_output;
|
||||
}
|
||||
}
|
||||
elseif (!$hide_empty) {
|
||||
$output['#markup'] = theme('quicktabs_tab_access_denied', array('tab' => $item));
|
||||
}
|
||||
$view->destroy();
|
||||
}
|
||||
}
|
||||
elseif (!$hide_empty) {
|
||||
$output['#markup'] = t('Views module is not enabled, cannot display content.');
|
||||
}
|
||||
}
|
||||
$this->rendered_content = $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getAjaxKeys() {
|
||||
return array('vid', 'display', 'view_dom_id', 'view_path', 'ajax_args');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user