1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#' Obtain jQuery Core as an HTML dependency
#'
#' @param major_version The major version of jQuery Core. Currrently 1, 2, and 3 are supported.
#' @param minified whether or not to provide a minified JavaScript file.
#'
#' @return A [htmltools::htmlDependency()] object.
#'
#' @importFrom htmltools htmlDependency
#' @export
jquery_core <- function(major_version = 3, minified = getOption("shiny.minified", TRUE)) {
version <- expand_version(major_version)
if (version == "")
stop("The major version that you seek does not exist on the system!")
script <- paste0("jquery-", version, if (minified) ".min.js" else ".js")
htmlDependency(
"jquery", version,
src = list(file = file.path("lib", version)),
package = "jquerylib",
script = script
)
}
expand_version <- function(major_version) {
actual_version <- system("dpkg -s libjs-jquery |grep '^Version' | sed -e 's/Version:[[:space:]]//g' | cut -d'.' -f1", intern = TRUE)
full_version <- system("dpkg -s libjs-jquery |grep '^Version' | sed -e 's/Version:[[:space:]]//g' | cut -d'+' -f1 | cut -d'-' -f1", intern = TRUE)
if (major_version != actual_version)
return("")
else
return(full_version)
stop("major_version must be 1, 2, or 3.")
}
|