generated from JuliaPluto/static-export-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically update viewport size and sync to MINDFulPluto
- Loading branch information
Showing
5 changed files
with
200 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function getViewportSize() { | ||
var viewportWidth; | ||
var viewportHeight; | ||
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight | ||
if (typeof window.innerWidth != 'undefined') { | ||
viewportWidth = window.innerWidth, | ||
viewportHeight = window.innerHeight | ||
windowDevicePixelRatio = window.devicePixelRatio | ||
} | ||
|
||
//TODO: Add DPR to older versions | ||
/* // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) | ||
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { | ||
viewportWidth = document.documentElement.clientWidth, | ||
viewportHeight = document.documentElement.clientHeight | ||
} | ||
// older versions of IE | ||
else { | ||
viewportWidth = document.getElementsByTagName('body')[0].clientWidth, | ||
viewportHeight = document.getElementsByTagName('body')[0].clientHeight | ||
} */ | ||
|
||
|
||
const viewportHeightInput = document.getElementById('viewportHeight'); | ||
const viewportWidthInput = document.getElementById('viewportWidth'); | ||
const windowDevicePixelRatioInput = document.getElementById('windowDevicePixelRatio'); | ||
|
||
viewportHeightInput.value = viewportHeight; | ||
viewportHeightInput.dispatchEvent(new CustomEvent("input")); | ||
|
||
viewportWidthInput.value = viewportWidth; | ||
viewportWidthInput.dispatchEvent(new CustomEvent("input")); | ||
|
||
windowDevicePixelRatioInput.value = windowDevicePixelRatio; | ||
windowDevicePixelRatioInput.dispatchEvent(new CustomEvent("input")); | ||
|
||
console.log("Set viewport fields") | ||
} | ||
|
||
window.addEventListener("resize", () => { | ||
getViewportSize(); | ||
}) | ||
|
||
//while element windowDevicePixelRatio is not set, keep trying to set it | ||
const vpIntervalID = setInterval(() => { | ||
if (document.getElementById('windowDevicePixelRatio').value == "") { | ||
getViewportSize(); | ||
} | ||
else { | ||
clearInterval(vpIntervalID); | ||
} | ||
}, 1000); |
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,100 @@ | ||
function change_view_display(target, visible) { | ||
const display = visible ? 'block' : 'none'; | ||
const display_flex = visible ? 'flex' : 'none'; | ||
|
||
if (visible === true) { | ||
change_view_display('visualisation', false); | ||
change_view_display('intenttable', false); | ||
change_view_display('devmode', false); | ||
} | ||
|
||
switch (target) { | ||
case "visualisation": | ||
//hide content > .row (vis) | ||
document.querySelectorAll('.content > .row').forEach((card, i) => { | ||
card.style.display = display_flex; | ||
}); | ||
|
||
//hide plotting cells | ||
Array.prototype.slice.call(document.querySelectorAll('.code_folded'), -3).forEach((card, i) => { | ||
card.style.display = display; | ||
}); | ||
break; | ||
|
||
case "intenttable": | ||
//hide content > .table-container | ||
document.querySelectorAll('.content > .table-container').forEach((card, i) => { | ||
card.style.display = display_flex; | ||
}); | ||
break; | ||
|
||
case "devmode": | ||
//hide last 2 cells (dev mode) | ||
var cells = document.querySelectorAll('.show_input '); | ||
cells = Array.prototype.slice.call(cells, -2); | ||
cells.forEach((cell, i) => { | ||
cell.style.display = display; | ||
}); | ||
change_devmode_cell_style(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
function change_devmode_cell_style() { | ||
//get last 3 cells | ||
let cells = document.querySelectorAll('.show_input '); | ||
|
||
//only last 3 cells | ||
cells = Array.prototype.slice.call(cells, -2); | ||
|
||
//move cells to top of screen in a grid | ||
cells.forEach((cell, i) => { | ||
cell.querySelector('.cm-editor').style.background = 'transparent'; | ||
|
||
cell.style.display = 'inline-block'; | ||
cell.style.verticalAlign = 'top'; | ||
cell.style.width = '30vw'; | ||
cell.style.margin = '2.5%'; | ||
cell.style.textAlign = 'start'; | ||
|
||
cell.style.background = 'rgba(217, 147, 232, 0.1)'; | ||
cell.style.borderRadius = '16px'; | ||
cell.style.boxShadow = '0 4px 30px rgba(0, 0, 0, 0.1)'; | ||
|
||
cell.style.padding = '20px 20px 20px 20px'; | ||
|
||
//find element pluto-trafficlight | ||
cell.querySelector('pluto-trafficlight').style.display = 'none'; | ||
|
||
var log_container = cell.querySelector('pluto-logs-container'); | ||
if (log_container != null) { | ||
log_container.style.display = 'transparent'; | ||
} | ||
|
||
//remove pluto-log-icon | ||
var log_icon = cell.querySelector('pluto-log-icon'); | ||
if (log_icon != null) { | ||
log_icon.style.display = 'none'; | ||
} | ||
|
||
//find class=Stdout and change style | ||
var stdout = cell.querySelector('pluto-log-dot') | ||
if (stdout != null) { | ||
stdout.style.background = 'transparent'; | ||
stdout.style.border = '2px solid #FFFFFF'; | ||
} | ||
|
||
|
||
|
||
}); | ||
|
||
//change pluto-notebook style | ||
var p_nb = document.getElementsByTagName('pluto-notebook')[0]; | ||
p_nb.style.marginTop = '1.5vh'; | ||
p_nb.style.marginLeft = '20vw'; | ||
p_nb.style.marginRight = '-25vw'; | ||
p_nb.style.backgroundColor = 'transparent'; | ||
} |
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