diff --git a/js/media.browser.js b/js/media.browser.js index e06ef0d..1eb0829 100644 --- a/js/media.browser.js +++ b/js/media.browser.js @@ -30,6 +30,7 @@ Drupal.behaviors.MediaBrowser = { $('.media-browser-tab').each( Drupal.media.browser.validateButtons ); + Drupal.media.browser.selectActiveTab(); Drupal.media.browser.selectErrorTab(); } @@ -123,4 +124,21 @@ Drupal.media.browser.selectErrorTab = function() { } } +Drupal.media.browser.selectActiveTab = function() { + // Find the ID of a tab with an error in it + var activeTabID = $('#media-browser-tabset') + .find('input[name*="media-selected-tab"]') + .parents('.media-browser-tab') + .attr('id'); + + if (activeTabID !== undefined) { + // Find the Tab Link with errorTabID + var tab = $('a[href="#' + activeTabID + '"]'); + // Find the index of the tab + var index = $('#media-browser-tabset a').index(tab); + // Select the tab + $('#media-browser-tabset').tabs('select', index) + } +} + }(jQuery)); diff --git a/media.module b/media.module index 4375984..829c9db 100644 --- a/media.module +++ b/media.module @@ -505,6 +505,13 @@ function media_form_alter(&$form, &$form_state, $form_id) { // still uses the media_browser_form_submit callback. if (current_path() == 'media/browser' && $form_id != 'views_exposed_form') { $form_state['#media_browser'] = TRUE; + if (isset($form_state['values']['op']) && $form_state['values']['op'] != t('Submit')) { + // We assume this is a tab related action mark it as selected tab + $form['media-selected-tab'] = array( + '#type' => 'hidden', + '#value' => $form_id, + ); + } } // If the #media_browser key isset and is true we are using the browser