diff --git a/js/media.browser.js b/js/media.browser.js index 236df27..41931d4 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,22 +22,37 @@ 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(); - $('.ui-tabs-nav li').mouseup(function() { - Drupal.media.browser.activeTab = $(this).index(); + $('#media-browser-tabset').tabs({ + 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 () { }; @@ -101,49 +115,12 @@ Drupal.media.browser.finalizeSelection = function () { } }; -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 - Drupal.media.browser.selectTab(index); - } -} - -Drupal.media.browser.selectActiveTab = function() { - // Find the index of the last active tab. - setTimeout(function() { - Drupal.media.browser.selectTab(Drupal.media.browser.activeTab); - }, 10); -}; - /** - * Helper function to change the media browser jQuery UI tabs - * since it requires two different methods dependingon the version. + * Resize the Media Browser to the content height. */ -Drupal.media.browser.selectTab = function(index) { - var ver = jQuery.ui.version.split('.'); - if (ver[0] == '1' && parseInt(ver[1]) <= 8) { - // jQuery UI <= 1.8 - $('#media-browser-tabset').tabs('select', index); - } - else { - // jQuery UI 1.9+ - $('#media-browser-tabset').tabs('option', 'active', index); - } - - $('.media-modal-frame').width('100%'); - - // Update the active tab variable. - Drupal.media.browser.activeTab = index; +Drupal.media.browser.resizeIframe = function (event) { + var h = $('body').height(); + $(parent.window.document).find('#mediaBrowser').height(h); }; }(jQuery));