Skip to content

Commit 2832a32

Browse files
committed
Allow full-width (full screen)
1 parent 2938a0a commit 2832a32

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

R/examplesWebR.R

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,34 @@ webr_inline_css <- function() {
638638
'.rocleteer-webr-iframe-container {',
639639
' display: none;',
640640
'}',
641+
'.rocleteer-webr-container.rocleteer-webr-fullwidth {',
642+
' position: fixed;',
643+
' top: 0;',
644+
' left: 0;',
645+
' width: 100vw;',
646+
' height: 100vh;',
647+
' z-index: var(--rocleteer-webr-fullwidth-z-index, 1050);',
648+
' margin: 0;',
649+
' border-radius: 0;',
650+
' border: none;',
651+
' overflow: auto;',
652+
' background-color: var(--_container-bg);',
653+
' transition: all 0.3s ease-in-out;',
654+
'}',
655+
'.rocleteer-webr-container.rocleteer-webr-fullwidth .rocleteer-webr-iframe {',
656+
' height: calc(100vh - 180px) !important;',
657+
' border: none;',
658+
'}',
659+
'.rocleteer-webr-fullwidth-backdrop {',
660+
' position: fixed;',
661+
' top: 0;',
662+
' left: 0;',
663+
' width: 100vw;',
664+
' height: 100vh;',
665+
' background-color: rgba(0, 0, 0, 0.5);',
666+
' z-index: var(--rocleteer-webr-backdrop-z-index, 1040);',
667+
' display: none;',
668+
'}',
641669
'.rocleteer-webr-iframe-controls {',
642670
' margin-bottom: 12px;',
643671
'}',
@@ -664,10 +692,17 @@ webr_inline_css <- function() {
664692
' .rocleteer-webr-iframe-controls .rocleteer-webr-btn {',
665693
' display: inline-block;',
666694
' margin: 0 4px 0 0;',
695+
' font-size: 12px;',
696+
' padding: 6px 12px;',
697+
' }',
698+
' .rocleteer-webr-container.rocleteer-webr-fullwidth {',
699+
' padding: 8px;',
700+
' }',
701+
' .rocleteer-webr-container.rocleteer-webr-fullwidth .rocleteer-webr-iframe {',
702+
' height: calc(100vh - 120px) !important;',
667703
' }',
668704
'}',
669-
'</style>',
670-
collapse = "\n"
705+
'</style>'
671706
)
672707
}
673708

@@ -782,7 +817,7 @@ webr_repl_iframe <- function(encoded_code, version = "latest", height = 300, mod
782817
iframe_id <- paste0("webr_iframe_", hashed_id)
783818

784819
html <- paste0(
785-
# Include CSS
820+
# Include CSS once
786821
webr_inline_css(),
787822

788823
'<div class="rocleteer-webr-container">',
@@ -793,7 +828,7 @@ webr_repl_iframe <- function(encoded_code, version = "latest", height = 300, mod
793828
# Initial buttons (before iframe loads)
794829
'<div id="', iframe_id, '_initial" class="rocleteer-webr-initial">',
795830
'<p class="rocleteer-webr-initial-text">Interactive Example Available</p>',
796-
'<button onclick="loadWebRIframe(\'', iframe_id, '\', \'', url, '\', ', height, ')" ',
831+
'<button onclick="loadWebRIframe(\'', iframe_id, '\', \'', url, '\', ', height, ', false)" ',
797832
'class="rocleteer-webr-btn rocleteer-webr-btn-success rocleteer-webr-btn-try">',
798833
'\U0001F680 Try it in your browser</button>',
799834
'<button onclick="window.open(\'', url, '\', \'_blank\')" ',
@@ -807,6 +842,10 @@ webr_repl_iframe <- function(encoded_code, version = "latest", height = 300, mod
807842
'<button onclick="hideWebRIframe(\'', iframe_id, '\')" ',
808843
'class="rocleteer-webr-btn rocleteer-webr-btn-secondary rocleteer-webr-btn-back">',
809844
'\U0001F519 Go back</button>',
845+
'<button onclick="toggleWebRFullWidth(\'', iframe_id, '\')" ',
846+
'class="rocleteer-webr-btn rocleteer-webr-btn-primary rocleteer-webr-btn-toggle" ',
847+
'id="', iframe_id, '_toggle">',
848+
'\U00026F6 Full Screen</button>',
810849
'<button onclick="window.open(\'', url, '\', \'_blank\')" ',
811850
'class="rocleteer-webr-btn rocleteer-webr-btn-primary rocleteer-webr-btn-open">',
812851
'\U0001F310 Open in Tab</button>',
@@ -818,18 +857,59 @@ webr_repl_iframe <- function(encoded_code, version = "latest", height = 300, mod
818857

819858
# JavaScript for iframe management
820859
'<script>',
821-
'function loadWebRIframe(id, url, height) {',
860+
'function loadWebRIframe(id, url, height, fullwidth) {',
861+
' fullwidth = fullwidth || false;',
822862
' document.getElementById(id + "_initial").style.display = "none";',
823863
' document.getElementById(id + "_container").style.display = "block";',
824864
' document.getElementById(id + "_content").innerHTML = ',
825865
' \'<iframe src="\' + url + \'" class="rocleteer-webr-iframe" height="\' + height + \'px" \' +',
826866
' \'title="webR REPL"></iframe>\';',
867+
' if (fullwidth) {',
868+
' enterWebRFullWidth(id);',
869+
' }',
827870
'}',
828871
'function hideWebRIframe(id) {',
872+
' exitWebRFullWidth(id);',
829873
' document.getElementById(id + "_initial").style.display = "block";',
830874
' document.getElementById(id + "_container").style.display = "none";',
831875
' document.getElementById(id + "_content").innerHTML = "";',
832876
'}',
877+
'function toggleWebRFullWidth(id) {',
878+
' var container = document.getElementById(id + "_container").closest(".rocleteer-webr-container");',
879+
' if (container.classList.contains("rocleteer-webr-fullwidth")) {',
880+
' exitWebRFullWidth(id);',
881+
' } else {',
882+
' enterWebRFullWidth(id);',
883+
' }',
884+
'}',
885+
'function enterWebRFullWidth(id) {',
886+
' var container = document.getElementById(id + "_container").closest(".rocleteer-webr-container");',
887+
' var backdrop = document.createElement("div");',
888+
' backdrop.className = "rocleteer-webr-fullwidth-backdrop";',
889+
' backdrop.id = id + "_backdrop";',
890+
' backdrop.onclick = function() { exitWebRFullWidth(id); };',
891+
' document.body.appendChild(backdrop);',
892+
' backdrop.style.display = "block";',
893+
' container.classList.add("rocleteer-webr-fullwidth");',
894+
' document.body.style.overflow = "hidden";',
895+
' var toggleBtn = document.getElementById(id + "_toggle");',
896+
' if (toggleBtn) {',
897+
' toggleBtn.innerHTML = "\\u274C Exit Full Screen";',
898+
' }',
899+
'}',
900+
'function exitWebRFullWidth(id) {',
901+
' var container = document.getElementById(id + "_container").closest(".rocleteer-webr-container");',
902+
' var backdrop = document.getElementById(id + "_backdrop");',
903+
' if (backdrop) {',
904+
' backdrop.remove();',
905+
' }',
906+
' container.classList.remove("rocleteer-webr-fullwidth");',
907+
' document.body.style.overflow = "";',
908+
' var toggleBtn = document.getElementById(id + "_toggle");',
909+
' if (toggleBtn) {',
910+
' toggleBtn.innerHTML = "\\u26F6 Full width";',
911+
' }',
912+
'}',
833913
'</script>'
834914
)
835915

0 commit comments

Comments
 (0)