Skip to content

Commit

Permalink
Make tab prepend/append just edge cases of insert
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 authored and bborgesr committed Aug 4, 2017
1 parent 48b8923 commit f1873a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
10 changes: 2 additions & 8 deletions R/insert-tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
8 changes: 1 addition & 7 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -1493,20 +1493,14 @@ 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,
liTag = liTag,
divTag = divTag,
menuName = menuName,
target = target,
prepend = prepend,
append = append,
position = position
)
)
Expand Down
23 changes: 17 additions & 6 deletions srcjs/shinyapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit f1873a0

Please sign in to comment.