#' @title Hotwire Turbo Modifiers
#'
#' @description Modify existing tags to imbue (or disimbue) them with specific
#' Turbo functionality.
#'
#' @param tag (tag) to be modified
#'
#' @family Turbo
#' @name turbo_modifiers
NULL
#' @describeIn turbo_modifiers enable Turbo for this tag and its contents
#' @export
turbo_enable <- function(tag) {
assert_tags(tag)
tag <- tagQuery(tag)
tag$removeAttrs("data-turbo")$addAttrs("data-turbo" = "true")
return(tag$allTags())
}
#' @describeIn turbo_modifiers disable Turbo for this tag and its contents
#' @export
turbo_disable <- function(tag) {
assert_tags(tag)
tag <- tagQuery(tag)
tag$removeAttrs("data-turbo")$addAttrs("data-turbo" = "false")
return(tag$allTags())
}
#' @describeIn turbo_modifiers targets a different frame for this tag
#' @param target (str) ID of another frame or "_top" for the whole page
#' @export
turbo_target <- function(tag, target) {
assert_tags(tag)
assert_string(target, null.ok = TRUE)
tag <- tagQuery(tag)
tag$removeAttrs("data-turbo-frame")$addAttrs("data-turbo-frame" = target)
return(tag$allTags())
}
#' @describeIn turbo_modifiers prevents evaluation on load of a script
#' @export
turbo_noeval <- function(tag) {
assert_tags(tag)
assert_true(tag$name == "script")
tag <- tagQuery(tag)
tag$removeAttrs("data-turbo-eval")$addAttrs("data-turbo-eval" = "false")
return(tag$allTags())
}
#' @describeIn turbo_modifiers makes one permanent; tag must have ID
#' @export
turbo_permanent <- function(tag) {
assert_tags(tag)
tag <- tagQuery(tag)
assert_true(tag$hasAttrs("id"))
tag$removeAttrs("data-turbo-permanent")$addAttrs("data-turbo-permanent" = NA)
return(tag$allTags())
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.