-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils_shinyjs.R
121 lines (115 loc) · 2.24 KB
/
utils_shinyjs.R
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#' @include internal.R
NULL
#' Enable a HTML element
#'
#' Enable a HTML element.
#'
#' @param inputId HTML element id.
#'
#' @return Invisible `TRUE`.
#'
#' @export
enable_html_element <- function(inputId) {
shinyjs::runjs(
paste0(
"document.getElementById(\"",
inputId,
"\").removeAttribute(\"disabled\");"
)
)
invisible(TRUE)
}
#' Disable a HTML element
#'
#' Disable a HTML element.
#'
#' @param inputId HTML element id.
#'
#' @return Invisible `TRUE`.
#'
#' @export
disable_html_element <- function(inputId) {
shinyjs::runjs(
paste0(
"document.getElementById(\"",
inputId,
"\").setAttribute(\"disabled\", \"\")"
)
)
invisible(TRUE)
}
#' Enable a HTML element using a CSS selector
#'
#' Enable a HTML element using a CSS selector.
#'
#' @param x `character` CSS selector.
#'
#' @return Invisible `TRUE`.
#'
#' @export
enable_html_css_selector <- function(x) {
shinyjs::runjs(
paste0(
"document.querySelector('", x, "').classList.remove('disabled');"
)
)
invisible(TRUE)
}
#' Disable HTML element(s) using a CSS selector
#'
#' Disable HTML element(s) using a CSS selector.
#'
#' @param x `character` CSS selector.
#'
#' @return Invisible `TRUE`.
#'
#' @return Invisible `TRUE`.
#'
#' @export
disable_html_css_selector <- function(x) {
shinyjs::runjs(
paste0(
"document.querySelector('", x, "').classList.add('disabled');"
)
)
invisible(TRUE)
}
#' Change file icon and update tool tip
#'
#' @param x `character` CSS selector.
#'
#' @param hex `character` hex color.
#'
#' @param tool_tip `character` description text.
#'
#' @return Invisible `TRUE`.
#'
#' @return Invisible `TRUE`.
#'
#' @export
change_file_icon_js <- function(x, hex, tool_tip) {
shinyjs::runjs(
paste0(
"document.querySelector('", x, "').style.color = '", hex, "';",
"$(document.querySelector('", x, "'))
.attr('title', '", tool_tip, "')
.tooltip('fixTitle');"
)
)
invisible(TRUE)
}
#' Remove map pane using CSS selector
#'
#' @param id `character` CSS selector.
#'
#' @return Invisible `TRUE`.
#'
#' @export
removeMapPane <- function(id) {
shinyjs::runjs(
paste0(
"document.querySelector('.leaflet-pane-", id, "-pane').remove();"
)
)
invisible(TRUE)
}