Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit85629d0d33656d60235585068771db601e5f285f (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-09-14 11:03:22 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-01 21:26:27 +0300
Filesb7ed74036790d57fe2211ed00a26e95b744c8482
syndamia.com-85629d0d33656d60235585068771db601e5f285f.tar
syndamia.com-85629d0d33656d60235585068771db601e5f285f.tar.gz
syndamia.com-85629d0d33656d60235585068771db601e5f285f.zip
Parent4918ab617c7a0e0154bc336ed0c1fbb530b1ca08 (diff)
[scripts/presentation] Improved logic to be more flexible and shortened ?a=y to ?a
1 files changed, 21 insertions, 9 deletions
-rw-r--r--src/scripts/presentation.js30
diff --git a/src/scripts/presentation.js b/src/scripts/presentation.js
index 77fa226..625b0ec 100644
--- a/src/scripts/presentation.js
+++ b/src/scripts/presentation.js
@@ -112,27 +112,39 @@ window.addEventListener('load', fixAbsoluteSlideScale);
/* Show as article button */
function toggleArticleMode() {
+ var href = window.location.href;
+ var indqa = href.indexOf('?a');
+
printBtn.classList.toggle('nodisplay');
presentBtn.classList.toggle('nodisplay');
// Toggle presentation.css
document.styleSheets.item(3).disabled = !document.styleSheets.item(3).disabled;
- // Add a=y to url when in article mode
- var url = window.location.href.substring(0, window.location.href.indexOf('?'));
- if (document.styleSheets.item(3).disabled) url += '?a=y';
- url += window.location.href.substr(window.location.href.indexOf('#'));
+ // Add "a" to url when in article mode
+ if (document.styleSheets.item(3).disabled && indqa == -1) {
+ var indquery = href.indexOf('?');
+ if (indquery < 0) {
+ var indend = Math.max(href.lastIndexOf('/'), href.indexOf('.html') + 4);
+ href = href.slice(0, indend + 1) + '?a' + href.slice(indend + 1);
+ }
+ else {
+ href = href.slice(0, indquery + 1) + 'a' + href.slice(indquery + 1);
+ }
+ }
+ else if (!document.styleSheets.item(3).disabled && indqa > -1) {
+ href = href.slice(0, indqa) + href.slice(indqa + 2);
+ }
- window.history.replaceState(history.state, document.title, url);
+ window.history.replaceState(history.state, document.title, href);
// Fix message
- if (articleBtn.innerText[0] === 'A') {
+ if (articleBtn.innerText[0] === 'A')
articleBtn.innerText = 'Slide' + articleBtn.innerText.substr(7);
- } else {
+ else
articleBtn.innerText = 'Article' + articleBtn.innerText.substr(5);
- }
}
articleBtn.addEventListener('click', toggleArticleMode);
window.addEventListener('load', function() {
- if (window.location.href.substr(window.location.href.indexOf('?'), 4) === '?a=y')
+ if (window.location.href.substr(window.location.href.indexOf('?'), 2) === '?a')
toggleArticleMode();
});