diff --git a/js/media.browser.js b/js/media.browser.js index 1b70335..d535737 100644 --- a/js/media.browser.js +++ b/js/media.browser.js @@ -7,7 +7,6 @@ namespace('Drupal.media.browser'); Drupal.media.browser.selectedMedia = []; -Drupal.media.browser.activeTab = 0; Drupal.media.browser.mediaAdded = function () {}; Drupal.media.browser.selectionFinalized = function (selectedMedia) { // This is intended to be overridden if a callee wants to be triggered @@ -23,26 +22,36 @@ Drupal.behaviors.MediaBrowser = { Drupal.media.browser.finalizeSelection(); } + var showFunc = function(event, ui) { + // store index of the tab being activated. + window.location.hash = $(ui.tab.parentNode).index(); + // Ensure that the modal resizes to the content on each tab switch. + Drupal.media.browser.resizeIframe(event); + }; + var activeTab = Drupal.media.browser.tabFromHash(); // Instantiate the tabs. $('#media-browser-tabset').tabs({ - // Ensure that the modal resizes to the content on each tab switch. - show: Drupal.media.browser.resizeIframe, // jquery ui < 1.8 - activate: Drupal.media.browser.resizeIframe // jquery ui >= 1.8 - }); - - $('.ui-tabs-nav li').mouseup(function() { - Drupal.media.browser.activeTab = $(this).index(); + selected: activeTab, // jquery < 1.9 + active: activeTab, // jquery >= 1.9 + show: showFunc, // jquery ui < 1.8 + activate: showFunc // jquery ui >= 1.8 }); $('.media-browser-tab').each( Drupal.media.browser.validateButtons ); - - Drupal.media.browser.selectActiveTab(); - Drupal.media.browser.selectErrorTab(); - } // Wait for additional params to be passed in. }; +/** + * Get index of the active tab from window.location.hash + */ +Drupal.media.browser.tabFromHash = function () { + if (window.location.hash && (index = parseInt(window.location.hash.substr(1))) && index != 'NaN') { + return index; + } + return 0; +}; + Drupal.media.browser.launch = function () { }; @@ -113,29 +122,4 @@ Drupal.media.browser.resizeIframe = function (event) { $(parent.window.document).find('#mediaBrowser').height(h); }; -Drupal.media.browser.selectErrorTab = function() { - // Find the ID of a tab with an error in it - var errorTabID = $('#media-browser-tabset') - .find('.error') - .parents('.media-browser-tab') - .attr('id'); - - if (errorTabID !== undefined) { - // Find the Tab Link with errorTabID - var tab = $('a[href="#' + errorTabID + '"]'); - // Find the index of the tab - var index = $('#media-browser-tabset a').index(tab); - // Select the tab - $('#media-browser-tabset').tabs('select', index) - } -} - -Drupal.media.browser.selectActiveTab = function() { - // Find the index of the last active tab. - setTimeout(function() { - $('#media-browser-tabset').tabs('select', Drupal.media.browser.activeTab); - Drupal.media.browser.resizeIframe(); - }, 10); -}; - }(jQuery));