From c36d66558c7ddcff03397c07c89f0b819aa2f446 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 26 Mar 2022 22:33:49 +0200 Subject: Added changing page width setting --- src/scripts/page-width.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/scripts/page-width.js (limited to 'src/scripts') diff --git a/src/scripts/page-width.js b/src/scripts/page-width.js new file mode 100644 index 0000000..577c590 --- /dev/null +++ b/src/scripts/page-width.js @@ -0,0 +1,20 @@ +const widthBtn = document.getElementById('changeWidthBtn'); +const articleElem = document.getElementsByTagName('article')[0]; + +if (localStorage.getItem('width') === 'wide') { + widthBtn.src = '/img/viewport-narrow-tabler.svg'; + articleElem.classList.add('noMaxWidth'); +} + +widthBtn.onclick = function() { + articleElem.classList.toggle('noMaxWidth'); + + if (localStorage.getItem('width') !== 'norm') { + widthBtn.src = '/img/viewport-wide-tabler.svg'; + localStorage.setItem('width', 'norm'); + } + else { + widthBtn.src = '/img/viewport-narrow-tabler.svg'; + localStorage.setItem('width', 'wide'); + } +} -- cgit v1.3.1-23-gd82d