Make tab prepend/append just edge cases of insert

This commit is contained in:
Joe Cheng
2017-07-28 00:40:17 -07:00
committed by Barbara Borges Ribeiro
parent 48b8923b67
commit f1873a014c
3 changed files with 20 additions and 21 deletions

View File

@@ -135,8 +135,6 @@ insertTab <- function(inputId, tab, target,
divTag = processDeps(item$divTag, session),
menuName = NULL,
target = target,
prepend = FALSE,
append = FALSE,
position = position)
}
session$onFlushed(callback, once = TRUE)
@@ -173,9 +171,7 @@ prependTab <- function(inputId, tab, menuName = NULL,
divTag = processDeps(item$divTag, session),
menuName = menuName,
target = NULL,
prepend = TRUE,
append = FALSE,
position = NULL)
position = "after")
}
session$onFlushed(callback, once = TRUE)
}
@@ -199,9 +195,7 @@ appendTab <- function(inputId, tab, menuName = NULL,
divTag = processDeps(item$divTag, session),
menuName = menuName,
target = NULL,
prepend = FALSE,
append = TRUE,
position = NULL)
position = "before")
}
session$onFlushed(callback, once = TRUE)
}

View File

@@ -1493,11 +1493,7 @@ ShinySession <- R6Class(
)
},
sendInsertTab = function(inputId, liTag, divTag, menuName,
target, prepend, append, position) {
if (is.null(target) && prepend == append) {
stop("If target is NULL, either `prepend` or `append` ",
"must be TRUE. Both cannot be TRUE, however.")
}
target, position) {
private$sendMessage(
`shiny-insert-tab` = list(
inputId = inputId,
@@ -1505,8 +1501,6 @@ ShinySession <- R6Class(
divTag = divTag,
menuName = menuName,
target = target,
prepend = prepend,
append = append,
position = position
)
)

View File

@@ -767,9 +767,11 @@ var ShinyApp = function() {
// Unless the item is being prepended/appended, the target tab
// must be provided
var target = null;
var $targetLiTag = null;
if (message.target !== null) {
var target = getTargetTabs($tabset, $tabContent, message.target);
var $targetLiTag = target.$liTag;
target = getTargetTabs($tabset, $tabContent, message.target);
$targetLiTag = target.$liTag;
}
// If the item is to be placed inside a navbarMenu (dropdown),
@@ -797,10 +799,19 @@ var ShinyApp = function() {
}
// actually insert the item into the right place
if (message.prepend) $tabset.prepend($liTag);
else if (message.append) $tabset.append($liTag);
else if (message.position === "before") $targetLiTag.before($liTag);
else if (message.position === "after") $targetLiTag.after($liTag);
if (message.position === "before") {
if ($targetLiTag) {
$targetLiTag.before($liTag);
} else {
$tabset.append($liTag);
}
} else if (message.position === "after") {
if ($targetLiTag) {
$targetLiTag.after($liTag);
} else {
$tabset.prepend($liTag);
}
}
$tabContent.append($divTag);
exports.renderContent($liTag[0], $liTag.html());