mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-07 13:15:00 -05:00
document similar things together; add prependTab and appendTab
This commit is contained in:
@@ -715,9 +715,9 @@ var ShinyApp = function() {
|
||||
});
|
||||
|
||||
addMessageHandler('shiny-insert-tab', function(message) {
|
||||
var $tabsetPanel = $("#" + message.tabsetPanelId);
|
||||
var $tabsetPanel = $("#" + message.inputId);
|
||||
if ($tabsetPanel.length === 0) {
|
||||
throw 'There is no tabsetPanel with id ' + message.tabsetPanelId;
|
||||
throw 'There is no tabsetPanel with id ' + message.inputId;
|
||||
};
|
||||
|
||||
// This is the JS equivalent of the builtItem() R function that is used
|
||||
@@ -733,7 +733,9 @@ var ShinyApp = function() {
|
||||
});
|
||||
prevTabIds = prevTabIds.map(Number);
|
||||
var tabId = Math.max.apply(null, prevTabIds) + 1;
|
||||
var thisId = "tab-" + $tabsetPanel.attr("data-tabsetid") + "-" + tabId;
|
||||
|
||||
var tabsetNumericId = $tabsetPanel.attr("data-tabsetid");
|
||||
var thisId = "tab-" + tabsetNumericId + "-" + tabId;
|
||||
var icon = message.icon.html;
|
||||
|
||||
// if there is an icon, render the possible deps
|
||||
@@ -749,35 +751,33 @@ var ShinyApp = function() {
|
||||
var $divTag = $tab.attr("id", thisId);
|
||||
$divTag.removeAttr("title");
|
||||
|
||||
var $tabContent = $("div.tab-content[data-tabsetid='" + $tabsetPanel.attr("data-tabsetid") + "']");
|
||||
var $tabContent = $("div.tab-content[data-tabsetid='" + tabsetNumericId + "']");
|
||||
|
||||
if (message.target === null) {
|
||||
if (message.position === "left") {
|
||||
$tabsetPanel.prepend($liTag);
|
||||
$tabContent.prepend($divTag);
|
||||
if (message.prepend) {
|
||||
$tabsetPanel.prepend($liTag);
|
||||
$tabContent.prepend($divTag);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (message.position === "right") {
|
||||
$tabsetPanel.append($liTag);
|
||||
$tabContent.append($divTag);
|
||||
}
|
||||
if (message.append) {
|
||||
$tabsetPanel.append($liTag);
|
||||
$tabContent.append($divTag);
|
||||
return;
|
||||
}
|
||||
|
||||
var dataValue = "[data-value='" + message.target + "']";
|
||||
var $targetTabsetPanel = $tabsetPanel.find("a" + dataValue).parent();
|
||||
var $targetTabContent = $tabContent.find("div" + dataValue);
|
||||
|
||||
if ($targetTabsetPanel.length === 0) {
|
||||
throw 'There is no tabPanel with value ' + message.target + '. ' + 'Appending tab to the end...';
|
||||
} else {
|
||||
var dataValue = "[data-value='" + message.target + "']";
|
||||
var $targetTabsetPanel = $tabsetPanel.find("a" + dataValue).parent();
|
||||
var $targetTabContent = $tabContent.find("div" + dataValue);
|
||||
|
||||
if ($targetTabsetPanel.length === 0) {
|
||||
console.warn('There is no tabPanel with value ' + message.target + '. ' +
|
||||
'Appending tab to the end...');
|
||||
$tabsetPanel.append($liTag);
|
||||
$tabContent.append($divTag);
|
||||
} else {
|
||||
if (message.position === "left") {
|
||||
$targetTabsetPanel.before($liTag);
|
||||
$targetTabContent.before($divTag);
|
||||
} else if (message.position === "right") {
|
||||
$targetTabsetPanel.after($liTag);
|
||||
$targetTabContent.after($divTag);
|
||||
}
|
||||
if (message.position === "before") {
|
||||
$targetTabsetPanel.before($liTag);
|
||||
$targetTabContent.before($divTag);
|
||||
} else if (message.position === "after") {
|
||||
$targetTabsetPanel.after($liTag);
|
||||
$targetTabContent.after($divTag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,9 +786,9 @@ var ShinyApp = function() {
|
||||
});
|
||||
|
||||
addMessageHandler('shiny-remove-tab', function(message) {
|
||||
var $tabsetPanel = $("#" + message.tabsetPanelId);
|
||||
var $tabsetPanel = $("#" + message.inputId);
|
||||
if ($tabsetPanel.length === 0) {
|
||||
throw 'There is no tabsetPanel with id ' + message.tabsetPanelId;
|
||||
throw 'There is no tabsetPanel with id ' + message.inputId;
|
||||
};
|
||||
var $tabContent = $tabsetPanel.find("+ .tab-content");
|
||||
var dataValue = "[data-value='" + message.target + "']";
|
||||
@@ -807,10 +807,10 @@ var ShinyApp = function() {
|
||||
});
|
||||
});
|
||||
|
||||
addMessageHandler('shiny-show-tab', function(message) {
|
||||
var $tabsetPanel = $("#" + message.tabsetPanelId);
|
||||
addMessageHandler('shiny-change-tab-visibility', function(message) {
|
||||
var $tabsetPanel = $("#" + message.inputId);
|
||||
if ($tabsetPanel.length === 0) {
|
||||
throw 'There is no tabsetPanel with id ' + message.tabsetPanelId;
|
||||
throw 'There is no tabsetPanel with id ' + message.inputId;
|
||||
};
|
||||
|
||||
var dataValue = "[data-value='" + message.target + "']";
|
||||
@@ -820,23 +820,8 @@ var ShinyApp = function() {
|
||||
throw 'There is no tabPanel with value ' + message.target;
|
||||
}
|
||||
|
||||
$targetTabsetPanel.show();
|
||||
});
|
||||
|
||||
addMessageHandler('shiny-hide-tab', function(message) {
|
||||
var $tabsetPanel = $("#" + message.tabsetPanelId);
|
||||
if ($tabsetPanel.length === 0) {
|
||||
throw 'There is no tabsetPanel with id ' + message.tabsetPanelId;
|
||||
};
|
||||
|
||||
var dataValue = "[data-value='" + message.target + "']";
|
||||
var $targetTabsetPanel = $tabsetPanel.find("a" + dataValue).parent();
|
||||
|
||||
if ($targetTabsetPanel.length === 0) {
|
||||
throw 'There is no tabPanel with value ' + message.target;
|
||||
}
|
||||
|
||||
$targetTabsetPanel.hide();
|
||||
if (message.type === "show") $targetTabsetPanel.show();
|
||||
else if (message.type === "hide") $targetTabsetPanel.hide();
|
||||
});
|
||||
|
||||
addMessageHandler('updateQueryString', function(message) {
|
||||
|
||||
Reference in New Issue
Block a user