diff --git a/js/quicktabs.js b/js/quicktabs.js index ec99c65..cf8aa29 100644 --- a/js/quicktabs.js +++ b/js/quicktabs.js @@ -20,6 +20,7 @@ Drupal.behaviors.quicktabs = { Drupal.quicktabs.prepare = function(el) { // el.id format: "quicktabs-$name" var qt_name = Drupal.quicktabs.getQTName(el); + var qtKey = 'qt_' + qt_name; var $ul = $(el).find('ul.quicktabs-tabs:first'); $ul.find('li a').each(function(i, element){ element.myTabIndex = i; @@ -27,7 +28,9 @@ Drupal.quicktabs.prepare = function(el) { var tab = new Drupal.quicktabs.tab(element); var parent_li = $(element).parents('li').get(0); if ($(parent_li).hasClass('active')) { - $(element).addClass('quicktabs-loaded'); + if (Drupal.settings.quicktabs[qtKey].qt.ajax_always == 0 || Drupal.settings.quicktabs[qtKey].qt.ajax == 0) { + $(element).addClass('quicktabs-loaded'); + } } $(element).once(function() {$(this).bind('click', {tab: tab}, Drupal.quicktabs.clickHandler);}); }); @@ -101,8 +104,11 @@ if (Drupal.ajax) { if (!$(element).hasClass('quicktabs-loaded')) { ajax.beforeSerialize(ajax.element, ajax.options); $.ajax(ajax.options); - if ($(element).parents('ul').hasClass('quicktabs-tabs')) { - $(element).addClass('quicktabs-loaded'); + var qtKey = 'qt_' + element.qt_name; + if (Drupal.settings.quicktabs[qtKey].qt.ajax_always == 0) { + if ($(element).parents('ul').hasClass('quicktabs-tabs')) { + $(element).addClass('quicktabs-loaded'); + } } } } diff --git a/plugins/QuickQuicktabs.inc b/plugins/QuickQuicktabs.inc index 9dcb7de..ffe47ae 100644 --- a/plugins/QuickQuicktabs.inc +++ b/plugins/QuickQuicktabs.inc @@ -5,10 +5,10 @@ * Includes support for ajax rendered content. */ class QuickQuicktabs extends QuickRenderer { - + public function render() { $quickset = $this->quickset; - + $render_array = array(); $active_tab = $quickset->getActiveTab(); @@ -23,12 +23,12 @@ class QuickQuicktabs extends QuickRenderer { '#theme' => 'qt_quicktabs', '#options' => array('attributes' => array( 'id' => 'quicktabs-' . $qt_name, - 'class' => 'quicktabs-wrapper quicktabs-style-' . drupal_html_class($settings['style']), + 'class' => 'quicktabs-wrapper quicktabs-style-' . drupal_strtolower($settings['style']), )), - 'tabs' => array('#theme' => 'qt_quicktabs_tabset', '#options' => array('active' => $active_tab, 'style' => drupal_html_class($settings['style'])), 'tablinks' => $tabs), + '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' => '
', + '#prefix' => '
', '#suffix' => '
', 'divs' => array(), ), @@ -55,7 +55,7 @@ class QuickQuicktabs extends QuickRenderer { /** * 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) { @@ -128,32 +128,34 @@ class QuickQuicktabs extends QuickRenderer { 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); + // Load the qt + if ($qt = quicktabs_load($name)) { + // Add the qt settings as well + $quicktabs_array['qt'] = (array) $qt; + } $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(); - $settings = $this->quickset->getSettings(); - $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, - 'html' => isset($settings['html']) ? $settings['html'] : FALSE, ); return $link_options; } -} +} \ No newline at end of file diff --git a/quicktabs.admin.inc b/quicktabs.admin.inc index ea320a5..482cd9a 100644 --- a/quicktabs.admin.inc +++ b/quicktabs.admin.inc @@ -225,7 +225,20 @@ function _quicktabs_admin_main_form($form_state, &$qt) { '#default_value' => isset($qt->ajax) ? $qt->ajax : 0, '#description' => t('Choose how the content of tabs should be loaded.

By choosing "Yes", only the first tab will be loaded when the page first viewed. Content for other tabs will be loaded only when the user clicks the other tab. This will provide faster initial page loading, but subsequent tab clicks will be slower. This can place less load on a server.

By choosing "No", all tabs will be loaded when the page is first viewed. This will provide slower initial page loading, and more server load, but subsequent tab clicks will be faster for the user. Use with care if you have heavy views.

Warning: if you enable Ajax, any block you add to this quicktabs block will be accessible to anonymous users, even if you place role restrictions on the quicktabs block. Do not enable Ajax if the quicktabs block includes any blocks with potentially sensitive information.

'), '#states' => array('visible' => array(':input[name="renderer"]' => array('value' => 'quicktabs'))), - '#weight' => -5, + '#weight' => -4, + ); + + $form['ajax_always'] = array( + '#type' => 'radios', + '#title' => t('Use Ajax every time a tab is toggled'), + '#options' => array( + TRUE => t('Yes'), + FALSE => t('No'), + ), + '#default_value' => isset($qt->ajax_always) ? $qt->ajax_always : 0, + '#description' => t('Choose whether or not the tab content should be refetched via Ajax every single time a tab is toggled.'), + '#states' => array('visible' => array(':input[name="ajax"]' => array('value' => '1'))), + '#weight' => -3, ); $form['hide_empty_tabs'] = array( @@ -233,13 +246,13 @@ function _quicktabs_admin_main_form($form_state, &$qt) { '#title' => t('Hide empty tabs'), '#default_value' => isset($qt->hide_empty_tabs) ? $qt->hide_empty_tabs : 0, '#description' => t('Empty and restricted tabs will not be displayed. Could be useful when the tab content is not accessible.
This option does not work in ajax mode.'), - '#weight' => -4, + '#weight' => -2, ); // Add a wrapper for the tabs and Add Another Tab button. $form['qt_wrapper'] = array( '#tree' => FALSE, - '#weight' => -3, + '#weight' => -1, '#prefix' => '
', '#suffix' => '
', ); @@ -643,6 +656,7 @@ function _quicktabs_convert_form_to_quicktabs($form_state) { $qt = new stdClass(); $qt->title = $form_state['values']['title']; $qt->ajax = $form_state['values']['ajax']; + $qt->ajax_always = $form_state['values']['ajax_always']; $qt->default_tab = isset($form_state['values']['default_tab']) ? $form_state['values']['default_tab'] : 0; $qt->hide_empty_tabs = $form_state['values']['hide_empty_tabs']; $qt->renderer = $renderer; diff --git a/quicktabs.install b/quicktabs.install index c8b30a3..0f6e8d9 100644 --- a/quicktabs.install +++ b/quicktabs.install @@ -37,6 +37,13 @@ function quicktabs_schema() { 'not null' => TRUE, 'default' => 0, ), + 'ajax_always' => array( + 'description' => 'Whether tabs should be loaded via ajax for each toggle.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), 'hide_empty_tabs' => array( 'description' => 'Whether this tabset hides empty tabs.', 'type' => 'int', @@ -175,3 +182,19 @@ function quicktabs_update_7301() { function quicktabs_update_7302() { registry_rebuild(); } + +/** + * Add the ajax_always field which dictates whether or not tabs should + * always be fetched via ajax + */ +function quicktabs_update_7303() { + $ajax_always_field = array( + 'description' => 'Whether tabs should be loaded via ajax for each toggle.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ); + db_add_field('quicktabs', 'ajax_always', $ajax_always_field); + return "Added the ajax_always field"; +} diff --git a/quicktabs.module b/quicktabs.module index 2278686..1637709 100644 --- a/quicktabs.module +++ b/quicktabs.module @@ -235,6 +235,7 @@ function quicktabs_build_quicktabs($name, $settings = array(), $custom_tabs = ar else { unset($settings['sorted']); } + if ($qt = quickset_renderer_factory($name, $contents, $renderer, $settings)) { $renderable_qt = array('#title' => $qt->getTitle(), 'content' => $qt->render()); return $renderable_qt; @@ -262,8 +263,16 @@ function quicktabs_ajax($name, $index, $type) { $data = QuickSet::ajaxRenderContent($type, $variable_args); - $commands = array(); + $qt = quicktabs_load($name); $tabpage_id = 'quicktabs-tabpage-'. $name .'-' . $index; + $commands = array(); + // If AJAX is being used to fetch the tabs each time they're clicked, + // we want to remove the old content before switching tabs. That ensures + // that when we switch back, we won't see old content while the new + // content is loading + if ($qt->ajax_always) { + $commands[] = ajax_command_remove("#quicktabs-container-{$name} div"); + } $commands[] = ajax_command_append('#quicktabs-container-'. $name, '
'. $data .'
'); $page = array('#type' => 'ajax', '#commands' => $commands); ajax_deliver($page);