From ae0899cfc5143190f092b4575d166707862261cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hozda?= Date: Wed, 7 Oct 2020 23:50:23 +0200 Subject: [PATCH] fix line breaks on single-letter words --- src/routes/oborovky.svelte | 29 +++++++++++++++++++++++++++++ src/routes/prebiram.svelte | 29 +++++++++++++++++++++++++++++ src/routes/predseda.svelte | 27 ++++++++++++++++++++++++++- src/routes/zalozit-spolek.svelte | 29 +++++++++++++++++++++++++++++ src/routes/zapojit-se.svelte | 25 +++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 1 deletion(-) diff --git a/src/routes/oborovky.svelte b/src/routes/oborovky.svelte index 246461c..4a531bf 100644 --- a/src/routes/oborovky.svelte +++ b/src/routes/oborovky.svelte @@ -17,6 +17,35 @@ import LLink from '../components/llink.svelte'; import Carousel from '@beyonk/svelte-carousel'; import ZjistiBtn from '../components/zjisti-vice.svelte'; + import { onMount } from 'svelte'; + + onMount(() => { + const setup = () => { + const pList = document.querySelectorAll('p, li, a, span'); + pList.forEach(p => noMoreLonelyWords(p)); + }; + + const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' '); + const noMoreLonelyWords = (target) => { + let textArray = target.textContent.split(' '); + let newTextArray = []; + textArray.forEach((word, i, list) => { + let textEntry = ''; + if(word.length === 1) + textEntry = word + '\xa0'; + else + textEntry = word + ' '; + newTextArray.push(textEntry); + }); + target.textContent = newTextArray.join(''); + }; + const updateWordBreaks = (target) => { + clearWordBreaks(target); + noMoreLonelyWords(target); + }; + + setup(); + }); diff --git a/src/routes/prebiram.svelte b/src/routes/prebiram.svelte index 7b429cf..c2a8272 100644 --- a/src/routes/prebiram.svelte +++ b/src/routes/prebiram.svelte @@ -10,6 +10,35 @@ import MenuBtn from '../components/menu-btn.svelte'; import LLink from '../components/llink.svelte'; import ZjistiBtn from '../components/zjisti-vice.svelte'; + import { onMount } from 'svelte'; + + onMount(() => { + const setup = () => { + const pList = document.querySelectorAll('p, li, a, span'); + pList.forEach(p => noMoreLonelyWords(p)); + }; + + const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' '); + const noMoreLonelyWords = (target) => { + let textArray = target.textContent.split(' '); + let newTextArray = []; + textArray.forEach((word, i, list) => { + let textEntry = ''; + if(word.length === 1) + textEntry = word + '\xa0'; + else + textEntry = word + ' '; + newTextArray.push(textEntry); + }); + target.textContent = newTextArray.join(''); + }; + const updateWordBreaks = (target) => { + clearWordBreaks(target); + noMoreLonelyWords(target); + }; + + setup(); + }); diff --git a/src/routes/predseda.svelte b/src/routes/predseda.svelte index dbf8986..6bb27f5 100644 --- a/src/routes/predseda.svelte +++ b/src/routes/predseda.svelte @@ -14,7 +14,32 @@ onMount(async () => { window.currentSlide(1); - }) + const setup = () => { + const pList = document.querySelectorAll('p, li, a, span'); + pList.forEach(p => noMoreLonelyWords(p)); + }; + + const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' '); + const noMoreLonelyWords = (target) => { + let textArray = target.textContent.split(' '); + let newTextArray = []; + textArray.forEach((word, i, list) => { + let textEntry = ''; + if(word.length === 1) + textEntry = word + '\xa0'; + else + textEntry = word + ' '; + newTextArray.push(textEntry); + }); + target.textContent = newTextArray.join(''); + }; + const updateWordBreaks = (target) => { + clearWordBreaks(target); + noMoreLonelyWords(target); + }; + + setup(); + }); diff --git a/src/routes/zalozit-spolek.svelte b/src/routes/zalozit-spolek.svelte index 904c128..6259bcc 100644 --- a/src/routes/zalozit-spolek.svelte +++ b/src/routes/zalozit-spolek.svelte @@ -10,6 +10,35 @@ import MenuBtn from '../components/menu-btn.svelte'; import LLink from '../components/llink.svelte'; import ZjistiBtn from '../components/zjisti-vice.svelte'; + import { onMount } from 'svelte'; + + onMount(() => { + const setup = () => { + const pList = document.querySelectorAll('p, li, a, span'); + pList.forEach(p => noMoreLonelyWords(p)); + }; + + const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' '); + const noMoreLonelyWords = (target) => { + let textArray = target.textContent.split(' '); + let newTextArray = []; + textArray.forEach((word, i, list) => { + let textEntry = ''; + if(word.length === 1) + textEntry = word + '\xa0'; + else + textEntry = word + ' '; + newTextArray.push(textEntry); + }); + target.textContent = newTextArray.join(''); + }; + const updateWordBreaks = (target) => { + clearWordBreaks(target); + noMoreLonelyWords(target); + }; + + setup(); + }); diff --git a/src/routes/zapojit-se.svelte b/src/routes/zapojit-se.svelte index ed697fb..5196d68 100644 --- a/src/routes/zapojit-se.svelte +++ b/src/routes/zapojit-se.svelte @@ -19,6 +19,31 @@ onMount(async () => { window.showSlides(1, "mySlides2", "slideIndex2", 'dot2'); window.showSlides(1, "mySlides3", "slideIndex3", 'dot3'); + const setup = () => { + const pList = document.querySelectorAll('p, li, a, span'); + pList.forEach(p => noMoreLonelyWords(p)); + }; + + const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' '); + const noMoreLonelyWords = (target) => { + let textArray = target.textContent.split(' '); + let newTextArray = []; + textArray.forEach((word, i, list) => { + let textEntry = ''; + if(word.length === 1) + textEntry = word + '\xa0'; + else + textEntry = word + ' '; + newTextArray.push(textEntry); + }); + target.textContent = newTextArray.join(''); + }; + const updateWordBreaks = (target) => { + clearWordBreaks(target); + noMoreLonelyWords(target); + }; + + setup(); });