Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Oct 15, 2023
2 parents 84648f5 + 60b7988 commit 84af0c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
35 changes: 32 additions & 3 deletions ea-scripts/Slideshow.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ If there are frames, the script will use the frames for the presentation. Frames

```javascript
*/
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.8.17")) {
if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.23")) {
new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
return;
}

const hostLeaf = ea.targetView.leaf;
const hostView = hostLeaf.view;
const statusBarElement = document.querySelector("div.status-bar");
const ctrlKey = ea.targetView.modifierKeyDown.ctrlKey || ea.targetView.modifierKeyDown.metaKey;
const altKey = ea.targetView.modifierKeyDown.altKey || ctrlKey;
Expand All @@ -36,10 +38,13 @@ const SVG_LEFT_ARROW = ea.obsidian.getIcon("lucide-arrow-left").outerHTML;
const SVG_EDIT = ea.obsidian.getIcon("lucide-pencil").outerHTML;
const SVG_MAXIMIZE = ea.obsidian.getIcon("lucide-maximize").outerHTML;
const SVG_MINIMIZE = ea.obsidian.getIcon("lucide-minimize").outerHTML;
const SVG_LASER_ON = ea.obsidian.getIcon("lucide-hand").outerHTML;
const SVG_LASER_OFF = ea.obsidian.getIcon("lucide-wand").outerHTML;

//-------------------------------
//utility & convenience functions
//-------------------------------
let isLaserOn = false;
let slide = 0;
let isFullscreen = false;
const ownerDocument = ea.targetView.ownerDocument;
Expand Down Expand Up @@ -310,6 +315,9 @@ const scrollToNextRect = async ({left,top,right,bottom,nextZoom},steps = TRANSIT
}
}
excalidrawAPI.updateScene({appState:{shouldCacheIgnoreZoom:false}});
if(isLaserOn) {
excalidrawAPI.setActiveTool({type: "laser"});
}
busy = false;
}

Expand Down Expand Up @@ -450,6 +458,22 @@ const createPresentationNavigationPanel = () => {
margin: 0px auto;`
}
});

el.createEl("button",{
attr: {
title: "Toggle Laser Pointer and Panning Mode"
}
}, button => {
button.innerHTML = isLaserOn ? SVG_LASER_ON : SVG_LASER_OFF;
button.onclick = () => {
isLaserOn = !isLaserOn;
excalidrawAPI.setActiveTool({
type: isLaserOn ? "laser" : "selection"
})
button.innerHTML = isLaserOn ? SVG_LASER_ON : SVG_LASER_OFF;
}
});

el.createEl("button",{
attr: {
title: "Toggle fullscreen. If you hold ALT/OPT when starting the presentation it will not go fullscreen."
Expand Down Expand Up @@ -504,7 +528,8 @@ const createPresentationNavigationPanel = () => {
// keyboard navigation
//--------------------
const keydownListener = (e) => {
if(ea.targetView.leaf !== app.workspace.activeLeaf) return;
if(hostLeaf !== app.workspace.activeLeaf) return;
if(hostLeaf.width === 0 && hostLeaf.height === 0) return;
e.preventDefault();
switch(e.key) {
case "Escape":
Expand Down Expand Up @@ -630,6 +655,9 @@ const initializeEventListners = () => {
// Exit presentation
//----------------------------
const exitPresentation = async (openForEdit = false) => {
//this is a hack, not sure why ea loses target view when other scripts are executed while the presentation is running
ea.targetView = hostView;
isLaserOn = false;
statusBarElement.style.display = "inherit";
if(openForEdit) ea.targetView.preventAutozoom();
await exitFullscreen();
Expand Down Expand Up @@ -680,7 +708,8 @@ const exitPresentation = async (openForEdit = false) => {
//Resets pointer offsets. Ugly solution.
//During testing offsets were wrong after presentation, but don't know why.
//This should solve it even if they are wrong.
ea.targetView.refresh();
hostView.refresh();
excalidrawAPI.setActiveTool({type: "selection"});
})
}

Expand Down
Loading

0 comments on commit 84af0c2

Please sign in to comment.