-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes to adapt to yihui/servr@2dbf293
the handler script should be a JS function now, and dynamic_site() no longer parses the JSON message automatically (so we parse it inside xaringan by ourselves)
- Loading branch information
Showing
4 changed files
with
26 additions
and
21 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: xaringan | ||
Type: Package | ||
Title: Presentation Ninja | ||
Version: 0.28.1 | ||
Version: 0.28.2 | ||
Authors@R: c( | ||
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")), | ||
person(given = "Posit Software, PBC", role = c("cph", "fnd")), | ||
|
@@ -46,13 +46,14 @@ Depends: R (>= 3.5.0) | |
Imports: | ||
htmltools, | ||
knitr (>= 1.30), | ||
servr (>= 0.13), | ||
servr (>= 0.28.2), | ||
xfun (>= 0.18), | ||
rmarkdown (>= 2.8) | ||
Suggests: rstudioapi, testit | ||
Suggests: rstudioapi, jsonlite, testit | ||
License: MIT + file LICENSE | ||
URL: https://github.com/yihui/xaringan | ||
BugReports: https://github.com/yihui/xaringan/issues | ||
VignetteBuilder: knitr | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.1 | ||
Remotes: yihui/servr |
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
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
36 changes: 19 additions & 17 deletions
36
inst/rmarkdown/templates/xaringan/resources/js/ws-handler.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 |
---|---|---|
@@ -1,45 +1,47 @@ | ||
var flag, focused = false; | ||
ws.onmessage = function(event) { | ||
((interval, path) => { | ||
const ws = new WebSocket(location.href.replace(/^http/, 'ws').replace(/\/?$/, '/websocket/')); | ||
let flag, focused = false; | ||
|
||
window.addEventListener('focus', e => { focused = true; }); | ||
window.addEventListener('blur', e => { focused = false; }); | ||
|
||
ws.onmessage = event => { | ||
flag = true; | ||
var d = JSON.parse(event.data); | ||
const d = JSON.parse(event.data); | ||
if (d === true) { | ||
// fire a servr:reload event | ||
Event && document.dispatchEvent(new Event('servr:reload')); | ||
return location.reload(); | ||
} | ||
if (!window.slideshow || !window.remark || d === false || d === null) return; | ||
var p = d.page; if (p < 1) p = 1; | ||
let p = d.page; if (p < 1) p = 1; | ||
if (!focused) slideshow.gotoSlide(p); | ||
if (d.markdown === false) return; | ||
var el = document.getElementsByClassName('remark-slides-area'); | ||
let el = document.getElementsByClassName('remark-slides-area'); | ||
el = el[0].children[p - 1].querySelector('.remark-slide-content'); | ||
var n = el.querySelector('.remark-slide-number').outerHTML.toString(); | ||
const n = el.querySelector('.remark-slide-number').outerHTML.toString(); | ||
el.innerHTML = remark.convert(d.markdown) + n; | ||
if (window.MathJax) { | ||
slideshow._releaseMath(el); | ||
MathJax.Hub.Queue(['Typeset', MathJax.Hub, el]); | ||
} | ||
var i, code, codes = el.getElementsByTagName('pre'); | ||
for (i = 0; i < codes.length; i++) { | ||
code = codes[i]; | ||
[...el.getElementsByTagName('pre')].forEach(code => { | ||
if (code.querySelector('.\\.hidden')) { | ||
code.style.display = 'none'; continue; | ||
code.style.display = 'none'; return; | ||
} | ||
remark.highlighter.engine.highlightBlock(codes[i]); | ||
} | ||
remark.highlighter.engine.highlightBlock(code); | ||
}); | ||
}; | ||
|
||
// send the page number to R, so RStudio can move to the Rmd source of the | ||
// current slide | ||
setInterval(function() { | ||
setInterval(() => { | ||
if (flag === false || ws.readyState !== ws.OPEN) return; | ||
flag = false; | ||
ws.send((window.slideshow && window.remark) ? JSON.stringify({ | ||
'n': slideshow.getCurrentSlideIndex() + 1, | ||
'N': slideshow.getSlideCount(), | ||
'focused': focused | ||
}) : '{}'); | ||
}, !!SERVR_INTERVAL); | ||
|
||
window.addEventListener('focus', function(e) { focused = true; }); | ||
window.addEventListener('blur', function(e) { focused = false; }); | ||
}, interval); | ||
}) |