diff --git a/js/quicktabs.js b/js/quicktabs.js index fa90ec0..b7c1eb2 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.quicktabs-tabs li a span#active-quicktabs-tab").remove(); @@ -31,7 +32,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).append('' + Drupal.t('(active tab)') + ''); } $(element).once(function() {$(this).bind('click', {tab: tab}, Drupal.quicktabs.clickHandler);}); @@ -110,8 +113,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 94fa407..d216a62 100644 --- a/plugins/QuickQuicktabs.inc +++ b/plugins/QuickQuicktabs.inc @@ -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(), ), @@ -138,6 +138,11 @@ 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; @@ -148,7 +153,6 @@ class QuickQuicktabs extends QuickRenderer { */ protected function construct_link_options($tabkey) { $qt_name = $this->quickset->getName(); - $settings = $this->quickset->getSettings(); $contents = $this->quickset->getContents(); $tab_type = $contents[$tabkey]->getType(); $tab_unique_keys = $contents[$tabkey]->getUniqueKeys(); @@ -189,7 +193,6 @@ class QuickQuicktabs extends QuickRenderer { ), 'query' => $query, 'fragment' => 'qt-' . $qt_name, - 'html' => isset($settings['html']) ? $settings['html'] : FALSE, ); return $link_options; } diff --git a/quicktabs.admin.inc b/quicktabs.admin.inc index 6b108f9..4dab763 100644 --- a/quicktabs.admin.inc +++ b/quicktabs.admin.inc @@ -228,7 +228,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( @@ -236,13 +249,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' => '
', ); @@ -642,6 +655,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 f5a2863..271e3a2 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', @@ -209,4 +216,21 @@ function quicktabs_update_7303() { } } return 'Added support for view modes.'; -} \ No newline at end of file +} + +/** + * Add the ajax_always field which dictates whether or not tabs should + * always be fetched via ajax + */ +function quicktabs_update_7304() { + $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 752d25e..a503eb3 100644 --- a/quicktabs.module +++ b/quicktabs.module @@ -241,6 +241,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; @@ -268,8 +269,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);