Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Last active June 3, 2017 15:28
right click in RStudio Viewer
library(htmltools)
# using discussion from https://stackoverflow.com/questions/2973321/javascript-capturing-right-click-and-disabling-menu-only-within-certain-element
browsable(
tagList(
tags$div(id="divctx","right click me"),
tags$script(
"
$('#divctx').bind('contextmenu', function(e) {
// do stuff here instead of normal context menu
alert('right click');
return false;
});
"
),
rmarkdown::html_dependency_jquery()
)
)
library(htmltools)
browsable(
tagList(
tags$head(
tags$script(src="//cdn.jsdelivr.net/gh/mar10/jquery-ui-contextmenu@v1/jquery.ui-contextmenu.min.js")
),
tags$div(id="divctx","right click me"),
tags$script(
'
$(document).contextmenu({
delegate: "#divctx", autoFocus: true,
preventContextMenuForPopup: true,
preventSelect: true,
taphold: true,
menu: [
{title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "ui-icon-scissors"},
{title: "Copy <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "ui-icon-copy"}
]
})
'
),
rmarkdown::html_dependency_jquery(),
rmarkdown::html_dependency_jqueryui()
)
)
@yonicd
Copy link

yonicd commented Jun 3, 2017

i think i read in a thread yesterday that you can force the default context menu to have 100% opacity, that way only the user defined one is showing. (right now the rstudio one comes over the one you wrote in)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment