-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 214d6ef
Showing
11 changed files
with
765 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
^capture\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
*.Rproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Package: capture | ||
Title: Capture Screenshot in Web Page | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
c(person(given = "Victor", | ||
family = "Perrier", | ||
role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
person(given = "Fanny", | ||
family = "Meyer", | ||
role = "aut")) | ||
Description: What the package does (one paragraph). | ||
License: GPL-3 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.1 | ||
Imports: | ||
htmltools |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(html_dependency_domtoimage) | ||
importFrom(htmltools,htmlDependency) | ||
importFrom(utils,packageVersion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
#' @title Capture Screenshot | ||
#' | ||
#' @description Add a button to take a screenshot of a specified element. | ||
#' | ||
#' @param selector A CSS selector, for example \code{body} to target the whole page or \code{#<ID>} to target a specific ouput. | ||
#' @param filename Name of the file that will be created. | ||
#' @param ... Arguments passed to HTML button. | ||
#' | ||
#' @return an HTML tag. | ||
#' @export | ||
#' | ||
#' @examples | ||
capture <- function(selector, filename, ...) { | ||
tagList( | ||
tags$button( | ||
class = "btn btn-default btn-capture-screenshot", | ||
`data-selector` = selector, | ||
`data-filename` = filename, | ||
... | ||
), | ||
html_dependency_domtoimage() | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#' HTML dependencies used by capture | ||
#' | ||
#' @return an \code{\link[htmltools]{htmlDependency}}. | ||
#' @export | ||
#' | ||
#' @importFrom utils packageVersion | ||
#' @importFrom htmltools htmlDependency | ||
#' | ||
#' @name html-dependencies | ||
#' | ||
html_dependency_domtoimage <- function() { | ||
htmlDependency( | ||
name = "dom-to-image", | ||
version = "2.6.0", | ||
src = list(file = "assets"), | ||
package = "capture", | ||
script = c( | ||
"dom-to-image/dom-to-image.min.js", | ||
"js/capture.js" | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright 2015 Anatolii Saienko | ||
https://github.com/tsayen | ||
|
||
Copyright 2012 Paul Bakaus | ||
http://paulbakaus.com/ | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*! | ||
* Copyright (c) 2020 dreamRs | ||
* | ||
* capture, JavaScript bindings to take screenshot of an element of the page | ||
* | ||
* @version 0.0.1 | ||
*/ | ||
|
||
/*jshint | ||
browser:true, | ||
devel: true | ||
*/ | ||
/*global domtoimage */ | ||
|
||
(function() { | ||
function download(filename, dataImage) { | ||
var element = document.createElement("a"); | ||
element.setAttribute("href", dataImage); | ||
element.setAttribute("download", filename); | ||
|
||
element.style.display = "none"; | ||
document.body.appendChild(element); | ||
|
||
element.click(); | ||
|
||
document.body.removeChild(element); | ||
} | ||
|
||
document.addEventListener("click", function(e) { | ||
var el = e.target; | ||
if (el.classList.contains("btn-capture-screenshot") === false) { | ||
return; | ||
} | ||
var toCapture = el.getAttribute("data-selector"); | ||
var node = document.querySelector(toCapture); | ||
var fileName = el.getAttribute("data-filename"); | ||
domtoimage | ||
.toPng(node) | ||
.then(function(dataUrl) { | ||
download(fileName, dataUrl); | ||
}) | ||
.catch(function(error) { | ||
console.error("Capture: oops, something went wrong!", error); | ||
}); | ||
}); | ||
})(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.