Summary Files Commits Branches @commit @diff @stats
path: root / src / scripts / presentation.js
diff options
context:
space:
mode:
Commit7456799a58fcbb63c193a1e793a92e6aca17ebfd (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-12-11 10:59:51 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-12-11 10:59:51 +0200
Filesaf38e5953b5ef33f15e7d10197c1c343ccdbb8c1 /src/scripts/presentation.js
syndamia.com-7456799a58fcbb63c193a1e793a92e6aca17ebfd.tar
syndamia.com-7456799a58fcbb63c193a1e793a92e6aca17ebfd.tar.gz
syndamia.com-7456799a58fcbb63c193a1e793a92e6aca17ebfd.zip
Parentd2c7b4eb144d674ad174bf33b43706e7a967ae9f (diff)
(presentation) Big overhaul, presentation.css is now always included, loading an article-mode page happens without slides flash, fixed certain cases where slides wouldn't resize but needed to
1 files changed, 34 insertions, 30 deletions
-rw-r--r--src/scripts/presentation.js64
diff --git a/src/scripts/presentation.js b/src/scripts/presentation.js
index 625b0ec..6250d93 100644
--- a/src/scripts/presentation.js
+++ b/src/scripts/presentation.js
@@ -1,13 +1,12 @@
-/* Add stylesheet to page */
-
-var presStyle = document.createElement('link');
-presStyle.type = 'text/css';
-presStyle.rel = 'stylesheet';
-presStyle.href = '/presentation.css';
-document.head.appendChild(presStyle);
-
/* Print button */
+presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
+ .insertRule("article, body { border: none !important; margin: 0; max-width: none; padding: 0; }");
+presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
+ .insertRule("nav, article > :not(.slide), #pagenav { display: none !important; }");
+presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
+ .insertRule(".slide { height: 210mm; width: 297mm; margin: 0; }");
+
const printBtn = document.getElementById('printBtn');
printBtn.addEventListener('click', function() {
@@ -58,7 +57,7 @@ var pageY = 0;
var pageX = 0;
function togglePresentMode() {
- if (document.styleSheets.item(3).disabled) return;
+ if (presentationStyle.disabled) return;
// Hide the whole page
document.body.classList.toggle('invisible');
@@ -99,29 +98,38 @@ function fixAbsoluteSlideScale() {
var width = (presenting) ? window.innerWidth : articleElem.offsetWidth - 32;
var scale = Math.min(height / slides[0].offsetHeight, width / slides[0].offsetWidth);
// Update .slide
- document.styleSheets.item(3).cssRules[0].style.transform = 'scale(' + scale + ')';
- document.styleSheets.item(3).cssRules[0].style.marginBottom = 'calc(1em - ' + slides[0].offsetHeight + 'px * ' + (1 - scale) + ')';
+ presentationStyle.cssRules[0].style.transform = 'scale(' + scale + ')';
+ presentationStyle.cssRules[0].style.marginBottom = 'calc(1em - ' + slides[0].offsetHeight + 'px * ' + (1 - scale) + ')';
// Update .absolute-slide
- document.styleSheets.item(3).cssRules[1].style.transform = 'translate(-50%, -50%) scale(' + scale + ')';
+ presentationStyle.cssRules[1].style.transform = 'translate(-50%, -50%) scale(' + scale + ')';
// Update .clicked-image
- document.styleSheets.item(3).cssRules[2].style.transform = 'translate(-50%, -50%) scale(' + (1/scale) + ')';
+ presentationStyle.cssRules[2].style.transform = 'translate(-50%, -50%) scale(' + (1/scale) + ')';
}
window.addEventListener('resize', fixAbsoluteSlideScale);
window.addEventListener('load', fixAbsoluteSlideScale);
/* Show as article button */
-function toggleArticleMode() {
- var href = window.location.href;
- var indqa = href.indexOf('?a');
-
+function togglePresentationController() {
printBtn.classList.toggle('nodisplay');
presentBtn.classList.toggle('nodisplay');
+
+ // Fix message
+ if (articleBtn.innerText[0] === 'A')
+ articleBtn.innerText = 'Slide' + articleBtn.innerText.substr(7);
+ else
+ articleBtn.innerText = 'Article' + articleBtn.innerText.substr(5);
+}
+
+function toggleArticleMode() {
// Toggle presentation.css
- document.styleSheets.item(3).disabled = !document.styleSheets.item(3).disabled;
+ presentationStyle.disabled = !presentationStyle.disabled;
- // Add "a" to url when in article mode
- if (document.styleSheets.item(3).disabled && indqa == -1) {
+ // Add or remove "a" to url when in or not in article mode
+ var href = window.location.href;
+ var indqa = href.indexOf('?a');
+
+ if (presentationStyle.disabled && indqa == -1) {
var indquery = href.indexOf('?');
if (indquery < 0) {
var indend = Math.max(href.lastIndexOf('/'), href.indexOf('.html') + 4);
@@ -131,20 +139,16 @@ function toggleArticleMode() {
href = href.slice(0, indquery + 1) + 'a' + href.slice(indquery + 1);
}
}
- else if (!document.styleSheets.item(3).disabled && indqa > -1) {
+ else if (!presentationStyle.disabled && indqa > -1) {
href = href.slice(0, indqa) + href.slice(indqa + 2);
}
window.history.replaceState(history.state, document.title, href);
- // Fix message
- if (articleBtn.innerText[0] === 'A')
- articleBtn.innerText = 'Slide' + articleBtn.innerText.substr(7);
- else
- articleBtn.innerText = 'Article' + articleBtn.innerText.substr(5);
+ togglePresentationController();
+ fixAbsoluteSlideScale();
}
articleBtn.addEventListener('click', toggleArticleMode);
-window.addEventListener('load', function() {
- if (window.location.href.substr(window.location.href.indexOf('?'), 2) === '?a')
- toggleArticleMode();
-});
+
+if (presentationStyle.disabled)
+ togglePresentationController();