diff --git a/src/extensibility/ExtensionManagerDialog.js b/src/extensibility/ExtensionManagerDialog.js index e21b658685e..b0a6367bf6b 100644 --- a/src/extensibility/ExtensionManagerDialog.js +++ b/src/extensibility/ExtensionManagerDialog.js @@ -291,6 +291,17 @@ define(function (require, exports, module) { return searchDisabled; } + function clearSearch() { + $search.val(""); + views.forEach(function (view, index) { + view.filter(""); + }); + + if (!updateSearchDisabled()) { + $search.focus(); + } + } + // Open the dialog dialog = Dialogs.showModalDialogUsingTemplate(Mustache.render(dialogTemplate, context)); @@ -311,10 +322,14 @@ define(function (require, exports, module) { $searchClear = $(".search-clear", $dlg); function setActiveTab($tab) { - models[_activeTabIndex].scrollPos = $(".modal-body", $dlg).scrollTop(); + if (models[_activeTabIndex]) { + models[_activeTabIndex].scrollPos = $(".modal-body", $dlg).scrollTop(); + } $tab.tab("show"); - $(".modal-body", $dlg).scrollTop(models[_activeTabIndex].scrollPos || 0); - $searchClear.click(); + if (models[_activeTabIndex]) { + $(".modal-body", $dlg).scrollTop(models[_activeTabIndex].scrollPos || 0); + clearSearch(); + } } // Dialog tabs @@ -400,16 +415,7 @@ define(function (require, exports, module) { views.forEach(function (view) { view.filter(query); }); - }).on("click", ".search-clear", function (e) { - $search.val(""); - views.forEach(function (view, index) { - view.filter(""); - }); - - if (!updateSearchDisabled()) { - $search.focus(); - } - }); + }).on("click", ".search-clear", clearSearch); // Disable the search field when there are no items in the model models.forEach(function (model, index) { @@ -420,8 +426,12 @@ define(function (require, exports, module) { }); }); - // Open dialog to Installed tab if extension updates are available - if ($("#toolbar-extension-manager").hasClass('updatesAvailable')) { + var $activeTab = $dlg.find(".nav-tabs li.active a"); + if ($activeTab.length) { // If there's already a tab selected, show it + $activeTab.parent().removeClass("active"); // workaround for bootstrap-tab + $activeTab.tab("show"); + } else if ($("#toolbar-extension-manager").hasClass('updatesAvailable')) { + // Open dialog to Installed tab if extension updates are available $dlg.find(".nav-tabs a.installed").tab("show"); } else { // Otherwise show the first tab $dlg.find(".nav-tabs a:first").tab("show");