From f5436d68189bbc3dfa4ebb7acb86de97197883fe Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Thu, 28 Sep 2023 21:40:18 +0200 Subject: [PATCH] Adding accesibility fixes. --- js-src/index.js | 21 +++++++-- public/css/styles.css | 8 +++- public/css/styles.scss | 7 ++- public/js/bundle.js | 2 +- templates/layouts/default.html.ep | 68 +++++++++++++++-------------- templates/page/_mobile_menu.html.ep | 2 +- 6 files changed, 67 insertions(+), 41 deletions(-) diff --git a/js-src/index.js b/js-src/index.js index aede2b2..33edfc6 100644 --- a/js-src/index.js +++ b/js-src/index.js @@ -5,26 +5,41 @@ require('tablesort/src/sorts/tablesort.number'); let fakeSearchInput let searchMobile -window.onload = () => { +document.addEventListener("DOMContentLoaded", function () { const menu_expand = document.querySelector('a.menu-expand'); const mobile_foldable = document.querySelector('nav.mobile-foldable'); const transparentFullscreenHide = document.querySelector('div.transparent-fullscreen-hide'); + const contentsWithoutMenu = document.querySelector('div.contents-without-menu') const tables = document.querySelectorAll('table') fillFarmaciaGuardia(); loadAd() addEasterEggAnimation() - if (menu_expand !== null && mobile_foldable !== null && transparentFullscreenHide !== null) { + if (menu_expand !== null && mobile_foldable !== null && transparentFullscreenHide !== null && contentsWithoutMenu !== null) { + mobile_foldable.toggleAttribute('aria-hidden') + if (mobile_foldable.getAttribute('aria-hidden') !== null) { + mobile_foldable.setAttribute('aria-hidden', true); + } transparentFullscreenHide.addEventListener('click', () => { mobile_foldable.classList.remove('show'); transparentFullscreenHide.classList.remove('show'); menu_expand.classList.remove('active'); + contentsWithoutMenu.removeAttribute('aria-hidden') + mobile_foldable.setAttribute('aria-hidden', true) }); menu_expand.addEventListener('click', () => { menu_expand.classList.toggle('active'); mobile_foldable.classList.toggle('show'); transparentFullscreenHide.classList.toggle('show'); + contentsWithoutMenu.toggleAttribute('aria-hidden') + if (contentsWithoutMenu.getAttribute('aria-hidden') !== null) { + contentsWithoutMenu.setAttribute('aria-hidden', true); + } + mobile_foldable.toggleAttribute('aria-hidden') + if (mobile_foldable.getAttribute('aria-hidden') !== null) { + mobile_foldable.setAttribute('aria-hidden', true); + } }); } @@ -46,7 +61,7 @@ window.onload = () => { searchMobile = document.querySelector('nav.mobile-shortcuts div.search') fakeSearchInput = searchMobile.querySelector('input') addListenersSearch() -}; +}, false); function fillFarmaciaGuardia() { const farmaciaName = document.querySelector('#farmacia-name'); diff --git a/public/css/styles.css b/public/css/styles.css index ec0ea15..3dbd19f 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -200,13 +200,14 @@ body { body div.transparent-fullscreen-hide.show { display: block; } body nav.mobile-foldable { + visibility: hidden; position: fixed; left: 100%; width: 70%; top: 60px; height: calc(100% - 60px); z-index: 500; - transition: left 0.5s ease-in; + transition: left 0.5s ease-in, visibility 0.5s ease-in; background: white; } body nav.mobile-foldable > a:first-child { margin-top: 30px; } @@ -230,7 +231,8 @@ body { display: list-item; font-size: 1em; } body nav.mobile-foldable.show { - left: 30%; } + left: 30%; + visibility: visible; } body nav.mobile-shortcuts > a { display: flex; align-items: center; @@ -238,6 +240,8 @@ body { body nav.mobile-shortcuts > a.active { background: white; color: #dcdcf5; } + body nav.mobile-shortcuts > a.active:focus { + background: #f2eb8c; } body a.menu-expand { padding-bottom: 9px; } body a.menu-expand .open-menu-icon-hover { diff --git a/public/css/styles.scss b/public/css/styles.scss index 79c9710..07ceeb3 100644 --- a/public/css/styles.scss +++ b/public/css/styles.scss @@ -296,13 +296,14 @@ body { } nav.mobile-foldable { + visibility: hidden; position: fixed; left: 100%; width: 70%; top: 60px; height: calc(100% - 60px); z-index: 500; - transition: left 0.5s ease-in; + transition: left 0.5s ease-in, visibility 0.5s ease-in; background: $background_sidebar; & > a:first-child { @@ -339,6 +340,7 @@ body { nav.mobile-foldable.show { left: 30%; + visibility: visible; } nav.mobile-shortcuts > a { @@ -348,6 +350,9 @@ body { &.active { background: $background_sidebar; color: $color_sidebar; + &:focus { + background: $color_div; + } } } diff --git a/public/js/bundle.js b/public/js/bundle.js index 57ac3e4..e432e74 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -16,7 +16,7 @@ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var tablesort__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tablesort */ \"./node_modules/tablesort/src/tablesort.js\");\n/* harmony import */ var tablesort__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tablesort__WEBPACK_IMPORTED_MODULE_0__);\n\n\nwindow.Tablesort = __webpack_require__(/*! tablesort */ \"./node_modules/tablesort/src/tablesort.js\");\n__webpack_require__(/*! tablesort/src/sorts/tablesort.number */ \"./node_modules/tablesort/src/sorts/tablesort.number.js\");\n\nlet fakeSearchInput\nlet searchMobile\nwindow.onload = () => {\n const menu_expand = document.querySelector('a.menu-expand');\n const mobile_foldable = document.querySelector('nav.mobile-foldable');\n const transparentFullscreenHide = document.querySelector('div.transparent-fullscreen-hide');\n const tables = document.querySelectorAll('table')\n\n fillFarmaciaGuardia();\n loadAd()\n addEasterEggAnimation()\n\n if (menu_expand !== null && mobile_foldable !== null && transparentFullscreenHide !== null) {\n transparentFullscreenHide.addEventListener('click', () => {\n mobile_foldable.classList.remove('show');\n transparentFullscreenHide.classList.remove('show');\n menu_expand.classList.remove('active');\n });\n menu_expand.addEventListener('click', () => {\n menu_expand.classList.toggle('active');\n mobile_foldable.classList.toggle('show');\n transparentFullscreenHide.classList.toggle('show');\n });\n }\n\n for (const table of tables) {\n const header = table.querySelector('tr');\n if (header !== null) {\n header.setAttribute('data-sort-method', 'none')\n for (const th of header.querySelectorAll('th')) {\n if (th.getAttribute('data-sort-method') == null) {\n th.setAttribute('data-sort-method', 'thead')\n }\n }\n }\n new (tablesort__WEBPACK_IMPORTED_MODULE_0___default())(table)\n }\n if (window !== undefined && window.Android !== undefined) {\n executeAndroidExclusiveCode(Android)\n } \n searchMobile = document.querySelector('nav.mobile-shortcuts div.search')\n fakeSearchInput = searchMobile.querySelector('input')\n addListenersSearch()\n};\n\nfunction fillFarmaciaGuardia() {\n const farmaciaName = document.querySelector('#farmacia-name');\n const farmaciaAddress = document.querySelector('#farmacia-address');\n if (farmaciaName !== null || farmaciaAddress !== null) {\n const port = _port()\n const url = new URL(window.location.protocol\n + \"//\"\n + window.location.hostname\n + port\n + '/farmacia-guardia.json');\n fetch(url).then(async (res) => {\n const farmacia = await res.json()\n if (farmaciaName !== null) {\n farmaciaName.innerText = farmacia.name;\n farmaciaAddress.innerText = farmacia.address;\n }\n })\n }\n}\n\nfunction addListenersSearch() {\n const searchInPage = document.querySelector('div.search-in-page')\n if (searchMobile !== null) {\n const searchIcon = searchMobile.querySelector('a.search-icon')\n searchIcon.addEventListener('click', (e) => {\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n searchInput.value = fakeSearchInput.value;\n onSearchChange(e)\n onFakeSearchClick(e)\n return true;\n\n })\n fakeSearchInput.addEventListener('keyup', (e) => {\n if (searchInPage === null) {\n return;\n }\n if (fakeSearchInput.value === \"\") {\n searchInPage.classList.remove('active') \n } else {\n searchInPage.classList.add('active') \n }\n if (e.keyCode !== 13) {\n return false;\n }\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n searchInput.value = fakeSearchInput.value;\n onSearchChange(e)\n onFakeSearchClick(e)\n return true;\n });\n }\n const nextResult = searchInPage.querySelector('a.down');\n const prevResult = searchInPage.querySelector('a.up');\n if (nextResult !== null && prevResult !== null) {\n nextResult.addEventListener('click', () => {\n searchInWebsite(fakeSearchInput.value, true);\n });\n prevResult.addEventListener('click', () => {\n searchInWebsite(fakeSearchInput.value, false);\n });\n }\n const exitSearch = document.querySelector('a.exit-search')\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n fakeSearchInput.value = searchInput.value;\n exitSearch.addEventListener('click', onExitSearch)\n const search = document.querySelector('div.search-overlay div.search input');\n if (search !== null) {\n search.addEventListener('change', onSearchChange);\n }\n const searchIconDesktop = document.querySelector('nav.desktop a.search-icon');\n if (searchIconDesktop !== null) {\n searchIconDesktop.addEventListener('click', (e) => {\n onFakeSearchClick(e)\n })\n }\n}\n\nfunction searchInWebsite(value, isToBottom) {\n window.find(value, false, !isToBottom, true)\n const selection = window.getSelection()\n if (selection.anchorNode === null) {\n const pageContents = document.querySelector('div.page-contents'); \n pageContents.focus()\n searchInWebsite(value, isToBottom)\n }\n const anchorNode = selection.anchorNode.parentNode\n if (anchorNode.tagName !== null \n && anchorNode.tagName === \"INPUT\") {\n const pageContents = document.querySelector('div.page-contents'); \n pageContents.focus()\n searchInWebsite(value, isToBottom)\n }\n if (anchorNode !== null) {\n const pageContents = document.querySelector('div.page-contents'); \n const offsetTop = _getOffsetTopWithNParent(anchorNode, pageContents);\n pageContents.scroll(0, offsetTop - 150)\n }\n}\n\nfunction _getOffsetTopWithNParent(element, nParent, _carry = 0) {\n if (element === null) {\n return null;\n }\n if (element === nParent) {\n return _carry;\n }\n _carry += element.offsetTop\n return _getOffsetTopWithNParent(element.offsetParent, nParent, _carry)\n}\n\nfunction _port() {\n let port = window.location.port;\n if (port !== '') {\n port = ':' + port\n }\n return port;\n}\n\nfunction onSearchChange() {\n const search = document.querySelector('div.search-overlay div.search input');\n const searchResults = document.querySelector('div.search-overlay div.search-results');\n if (search === null || searchResults === null) {\n return;\n }\n const query = search.value;\n fakeSearchInput.value = search.value\n const port = _port()\n const url = new URL(window.location.protocol\n + \"//\"\n + window.location.hostname\n + port\n + '/search.json');\n url.searchParams.set('q', query);\n fetch(url).then(async (res) => {\n const json = await res.json()\n if (!json.ok) {\n noResults(searchResults);\n return\n }\n console.log(json.searchObjects.length)\n if (json.searchObjects.length < 1) {\n noResults(searchResults);\n return;\n }\n showResults(searchResults, json.searchObjects);\n })\n search.focus()\n}\n\nfunction showResults(searchResults, searchObjects) {\n searchResults.innerHTML = \"\";\n for (let searchObject of searchObjects) {\n const searchResultContainer = document.createElement('div')\n searchResultContainer.classList.add('search-result')\n const rowTitleUrlImageDiv = document.createElement('div');\n rowTitleUrlImageDiv.classList.add('row-title-url-image');\n const columnTitleUrl = document.createElement('div');\n columnTitleUrl.classList.add('column-title-url');\n const img = document.createElement('img')\n const title = document.createElement('b')\n const url = document.createElement('a')\n const content = document.createElement('p')\n\n title.innerText = searchObject.title\n let port = window.location.port;\n if (port !== '') {\n port = ':' + port\n }\n if (searchObject.url.match(/^\\//)) {\n searchObject.url = window.location.protocol \n + \"//\" + window.location.hostname \n + port\n + searchObject.url\n }\n let urlImage = searchObject.urlImage;\n if (urlImage !== null && urlImage.match(/^\\//)) {\n urlImage = window.location.protocol \n + \"//\" + window.location.hostname \n + port\n + urlImage\n }\n if (urlImage !== null) {\n img.alt = \"\"\n img.src = urlImage\n }\n\n url.href = searchObject.url\n url.innerText = searchObject.url\n content.innerText = searchObject.content\n\n if (urlImage !== null) {\n rowTitleUrlImageDiv.appendChild(img)\n }\n\n columnTitleUrl.appendChild(title);\n columnTitleUrl.appendChild(document.createElement('br'))\n columnTitleUrl.appendChild(url)\n\n rowTitleUrlImageDiv.appendChild(columnTitleUrl)\n\n searchResultContainer.appendChild(rowTitleUrlImageDiv)\n searchResultContainer.appendChild(content)\n searchResults.appendChild(searchResultContainer)\n }\n}\n\nfunction noResults(searchResults) {\n searchResults.innerHTML = \"\"\n const p = document.createElement('p')\n p.innerText = 'No se han encontrado resultados.'\n searchResults.appendChild(p)\n}\n\nfunction onExitSearch() {\n const searchOverlay = document.querySelector('div.search-overlay');\n if (searchOverlay !== null) {\n searchOverlay.classList.toggle('active');\n }\n}\n\nfunction onFakeSearchClick(e) {\n e.preventDefault();\n const searchOverlay = document.querySelector('div.search-overlay');\n if (searchOverlay === null) {\n return\n }\n searchOverlay.classList.toggle('active');\n const search = searchOverlay.querySelector('div.search input');\n if (search !== null) {\n search.focus()\n }\n return false;\n}\n\nfunction absoluteToHost(imageUrl) {\n if (imageUrl.match(/^\\//)) {\n imageUrl = window.location.protocol + \"//\" + window.location.host + imageUrl \n }\n return imageUrl.replace(/\\?.*$/, '');\n}\n\nfunction addListenerOpenInBrowserButton(android) {\n const openInBrowserLink = document.querySelector('a.open-in-browser')\n if (openInBrowserLink === null) {\n return\n }\n openInBrowserLink.addEventListener('click', () => {\n android.openInBrowser(window.location.href)\n })\n}\nfunction executeAndroidExclusiveCode(android) {\n document.querySelectorAll('*.android').forEach((element) => {\n element.classList.remove('android')\n })\n document.querySelectorAll('*.no-android-app').forEach((element) => {\n element.style.display = 'none';\n })\n addListenerOpenInBrowserButton(android)\n const pinToHomeUrl = document.querySelector('a.pin-to-home')\n if (pinToHomeUrl === null) {\n return;\n }\n pinToHomeUrl.addEventListener('click', () => {\n const url = new URL(window.location.href)\n const pathandQuery = url.pathname + url.search;\n const label = (url.pathname.replace(/^.*\\//g, '')\n .replace(/(?:^|-)\\w/g, function(character) {\n return character.toUpperCase() \n })\n .replace(/-/g, ' ')) + ' - Burguillos.info';\n const firstImg = document.querySelector('div.description img');\n let iconUrl;\n if (firstImg !== null) {\n if (!firstImg.src.match(/\\.svg(?:\\?|$)/)) {\n iconUrl = absoluteToHost(firstImg.src);\n }\n }\n if (iconUrl === undefined) {\n const imagePreview = document.querySelector('meta[name=\"image\"]');\n iconUrl = absoluteToHost(imagePreview.content);\n }\n android.pinPage(pathandQuery, label, iconUrl)\n })\n}\n\nfunction addEasterEggAnimation() {\n const logoContainer = document.querySelector('div.burguillos-logo-container')\n if (logoContainer === null) {\n return;\n }\n logoContainer.addEventListener('click', () => {\n logoContainer.classList.toggle('active')\n })\n}\n\nlet current_ad_number = null\n\nfunction expand_page_contents() {\n const pageContents = document.querySelector('div.page-contents'); \n if (pageContents === null) {\n return;\n }\n pageContents.classList.add('no-carousel');\n}\n\nfunction no_more_ads() {\n const carousel = document.querySelector('.carousel');\n if (carousel !== null) {\n carousel.remove();\n }\n expand_page_contents();\n}\n\nfunction loadAd() {\n const params = new URLSearchParams();\n if (current_ad_number !== null) {\n params.append('n', \"\"+current_ad_number);\n }\n fetch('/next-ad.json?' + params).then((res) => {\n return res.json()\n }).then((res) => {\n current_ad_number = res.current_ad_number\n const ad = res.ad\n const must_continue = res.continue\n const carousel = document.querySelector('.carousel');\n if (must_continue === 0\n || carousel === null\n || carousel.offsetWidth === 0) {\n no_more_ads();\n return;\n }\n const a = _retrieveLinkCarousel(carousel)\n a.innerHTML = \"\"\n const image = document.createElement('img')\n const text_container = document.createElement('div')\n const text = document.createElement('h4')\n const promoted = document.createElement('p')\n\n promoted.classList.add('promoted-tag')\n promoted.innerText = \"Promocionado\"\n image.src = ad.img\n image.alt = \"\"\n text.innerText = ad.text\n a.href = ad.href\n\n a.append(image)\n text_container.append(promoted)\n text_container.append(text)\n a.append(text_container)\n\n window.setTimeout(() => {\n loadAd()\n }, ad.seconds * 1000)\n }).catch(() => {\n window.setTimeout(() => {\n loadAd()\n }, 1000)\n });\n}\n\nfunction _retrieveLinkCarousel(carousel) {\n const maybeA = carousel.querySelector('a')\n if (maybeA !== null) {\n return maybeA\n }\n const a = document.createElement('a')\n carousel.innerHTML = \"\"\n carousel.append(a)\n return a\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/index.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var tablesort__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tablesort */ \"./node_modules/tablesort/src/tablesort.js\");\n/* harmony import */ var tablesort__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tablesort__WEBPACK_IMPORTED_MODULE_0__);\n\n\nwindow.Tablesort = __webpack_require__(/*! tablesort */ \"./node_modules/tablesort/src/tablesort.js\");\n__webpack_require__(/*! tablesort/src/sorts/tablesort.number */ \"./node_modules/tablesort/src/sorts/tablesort.number.js\");\n\nlet fakeSearchInput\nlet searchMobile\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n const menu_expand = document.querySelector('a.menu-expand');\n const mobile_foldable = document.querySelector('nav.mobile-foldable');\n const transparentFullscreenHide = document.querySelector('div.transparent-fullscreen-hide');\n const contentsWithoutMenu = document.querySelector('div.contents-without-menu')\n const tables = document.querySelectorAll('table')\n\n fillFarmaciaGuardia();\n loadAd()\n addEasterEggAnimation()\n\n if (menu_expand !== null && mobile_foldable !== null && transparentFullscreenHide !== null && contentsWithoutMenu !== null) {\n mobile_foldable.toggleAttribute('aria-hidden')\n if (mobile_foldable.getAttribute('aria-hidden') !== null) {\n mobile_foldable.setAttribute('aria-hidden', true);\n }\n transparentFullscreenHide.addEventListener('click', () => {\n mobile_foldable.classList.remove('show');\n transparentFullscreenHide.classList.remove('show');\n menu_expand.classList.remove('active');\n contentsWithoutMenu.removeAttribute('aria-hidden')\n mobile_foldable.setAttribute('aria-hidden', true)\n });\n menu_expand.addEventListener('click', () => {\n menu_expand.classList.toggle('active');\n mobile_foldable.classList.toggle('show');\n transparentFullscreenHide.classList.toggle('show');\n contentsWithoutMenu.toggleAttribute('aria-hidden')\n if (contentsWithoutMenu.getAttribute('aria-hidden') !== null) {\n contentsWithoutMenu.setAttribute('aria-hidden', true);\n }\n mobile_foldable.toggleAttribute('aria-hidden')\n if (mobile_foldable.getAttribute('aria-hidden') !== null) {\n mobile_foldable.setAttribute('aria-hidden', true);\n }\n });\n }\n\n for (const table of tables) {\n const header = table.querySelector('tr');\n if (header !== null) {\n header.setAttribute('data-sort-method', 'none')\n for (const th of header.querySelectorAll('th')) {\n if (th.getAttribute('data-sort-method') == null) {\n th.setAttribute('data-sort-method', 'thead')\n }\n }\n }\n new (tablesort__WEBPACK_IMPORTED_MODULE_0___default())(table)\n }\n if (window !== undefined && window.Android !== undefined) {\n executeAndroidExclusiveCode(Android)\n } \n searchMobile = document.querySelector('nav.mobile-shortcuts div.search')\n fakeSearchInput = searchMobile.querySelector('input')\n addListenersSearch()\n}, false);\n\nfunction fillFarmaciaGuardia() {\n const farmaciaName = document.querySelector('#farmacia-name');\n const farmaciaAddress = document.querySelector('#farmacia-address');\n if (farmaciaName !== null || farmaciaAddress !== null) {\n const port = _port()\n const url = new URL(window.location.protocol\n + \"//\"\n + window.location.hostname\n + port\n + '/farmacia-guardia.json');\n fetch(url).then(async (res) => {\n const farmacia = await res.json()\n if (farmaciaName !== null) {\n farmaciaName.innerText = farmacia.name;\n farmaciaAddress.innerText = farmacia.address;\n }\n })\n }\n}\n\nfunction addListenersSearch() {\n const searchInPage = document.querySelector('div.search-in-page')\n if (searchMobile !== null) {\n const searchIcon = searchMobile.querySelector('a.search-icon')\n searchIcon.addEventListener('click', (e) => {\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n searchInput.value = fakeSearchInput.value;\n onSearchChange(e)\n onFakeSearchClick(e)\n return true;\n\n })\n fakeSearchInput.addEventListener('keyup', (e) => {\n if (searchInPage === null) {\n return;\n }\n if (fakeSearchInput.value === \"\") {\n searchInPage.classList.remove('active') \n } else {\n searchInPage.classList.add('active') \n }\n if (e.keyCode !== 13) {\n return false;\n }\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n searchInput.value = fakeSearchInput.value;\n onSearchChange(e)\n onFakeSearchClick(e)\n return true;\n });\n }\n const nextResult = searchInPage.querySelector('a.down');\n const prevResult = searchInPage.querySelector('a.up');\n if (nextResult !== null && prevResult !== null) {\n nextResult.addEventListener('click', () => {\n searchInWebsite(fakeSearchInput.value, true);\n });\n prevResult.addEventListener('click', () => {\n searchInWebsite(fakeSearchInput.value, false);\n });\n }\n const exitSearch = document.querySelector('a.exit-search')\n const searchOverlay = document.querySelector('div.search-overlay');\n const searchInput = searchOverlay.querySelector('div.search input');\n fakeSearchInput.value = searchInput.value;\n exitSearch.addEventListener('click', onExitSearch)\n const search = document.querySelector('div.search-overlay div.search input');\n if (search !== null) {\n search.addEventListener('change', onSearchChange);\n }\n const searchIconDesktop = document.querySelector('nav.desktop a.search-icon');\n if (searchIconDesktop !== null) {\n searchIconDesktop.addEventListener('click', (e) => {\n onFakeSearchClick(e)\n })\n }\n}\n\nfunction searchInWebsite(value, isToBottom) {\n window.find(value, false, !isToBottom, true)\n const selection = window.getSelection()\n if (selection.anchorNode === null) {\n const pageContents = document.querySelector('div.page-contents'); \n pageContents.focus()\n searchInWebsite(value, isToBottom)\n }\n const anchorNode = selection.anchorNode.parentNode\n if (anchorNode.tagName !== null \n && anchorNode.tagName === \"INPUT\") {\n const pageContents = document.querySelector('div.page-contents'); \n pageContents.focus()\n searchInWebsite(value, isToBottom)\n }\n if (anchorNode !== null) {\n const pageContents = document.querySelector('div.page-contents'); \n const offsetTop = _getOffsetTopWithNParent(anchorNode, pageContents);\n pageContents.scroll(0, offsetTop - 150)\n }\n}\n\nfunction _getOffsetTopWithNParent(element, nParent, _carry = 0) {\n if (element === null) {\n return null;\n }\n if (element === nParent) {\n return _carry;\n }\n _carry += element.offsetTop\n return _getOffsetTopWithNParent(element.offsetParent, nParent, _carry)\n}\n\nfunction _port() {\n let port = window.location.port;\n if (port !== '') {\n port = ':' + port\n }\n return port;\n}\n\nfunction onSearchChange() {\n const search = document.querySelector('div.search-overlay div.search input');\n const searchResults = document.querySelector('div.search-overlay div.search-results');\n if (search === null || searchResults === null) {\n return;\n }\n const query = search.value;\n fakeSearchInput.value = search.value\n const port = _port()\n const url = new URL(window.location.protocol\n + \"//\"\n + window.location.hostname\n + port\n + '/search.json');\n url.searchParams.set('q', query);\n fetch(url).then(async (res) => {\n const json = await res.json()\n if (!json.ok) {\n noResults(searchResults);\n return\n }\n console.log(json.searchObjects.length)\n if (json.searchObjects.length < 1) {\n noResults(searchResults);\n return;\n }\n showResults(searchResults, json.searchObjects);\n })\n search.focus()\n}\n\nfunction showResults(searchResults, searchObjects) {\n searchResults.innerHTML = \"\";\n for (let searchObject of searchObjects) {\n const searchResultContainer = document.createElement('div')\n searchResultContainer.classList.add('search-result')\n const rowTitleUrlImageDiv = document.createElement('div');\n rowTitleUrlImageDiv.classList.add('row-title-url-image');\n const columnTitleUrl = document.createElement('div');\n columnTitleUrl.classList.add('column-title-url');\n const img = document.createElement('img')\n const title = document.createElement('b')\n const url = document.createElement('a')\n const content = document.createElement('p')\n\n title.innerText = searchObject.title\n let port = window.location.port;\n if (port !== '') {\n port = ':' + port\n }\n if (searchObject.url.match(/^\\//)) {\n searchObject.url = window.location.protocol \n + \"//\" + window.location.hostname \n + port\n + searchObject.url\n }\n let urlImage = searchObject.urlImage;\n if (urlImage !== null && urlImage.match(/^\\//)) {\n urlImage = window.location.protocol \n + \"//\" + window.location.hostname \n + port\n + urlImage\n }\n if (urlImage !== null) {\n img.alt = \"\"\n img.src = urlImage\n }\n\n url.href = searchObject.url\n url.innerText = searchObject.url\n content.innerText = searchObject.content\n\n if (urlImage !== null) {\n rowTitleUrlImageDiv.appendChild(img)\n }\n\n columnTitleUrl.appendChild(title);\n columnTitleUrl.appendChild(document.createElement('br'))\n columnTitleUrl.appendChild(url)\n\n rowTitleUrlImageDiv.appendChild(columnTitleUrl)\n\n searchResultContainer.appendChild(rowTitleUrlImageDiv)\n searchResultContainer.appendChild(content)\n searchResults.appendChild(searchResultContainer)\n }\n}\n\nfunction noResults(searchResults) {\n searchResults.innerHTML = \"\"\n const p = document.createElement('p')\n p.innerText = 'No se han encontrado resultados.'\n searchResults.appendChild(p)\n}\n\nfunction onExitSearch() {\n const searchOverlay = document.querySelector('div.search-overlay');\n if (searchOverlay !== null) {\n searchOverlay.classList.toggle('active');\n }\n}\n\nfunction onFakeSearchClick(e) {\n e.preventDefault();\n const searchOverlay = document.querySelector('div.search-overlay');\n if (searchOverlay === null) {\n return\n }\n searchOverlay.classList.toggle('active');\n const search = searchOverlay.querySelector('div.search input');\n if (search !== null) {\n search.focus()\n }\n return false;\n}\n\nfunction absoluteToHost(imageUrl) {\n if (imageUrl.match(/^\\//)) {\n imageUrl = window.location.protocol + \"//\" + window.location.host + imageUrl \n }\n return imageUrl.replace(/\\?.*$/, '');\n}\n\nfunction addListenerOpenInBrowserButton(android) {\n const openInBrowserLink = document.querySelector('a.open-in-browser')\n if (openInBrowserLink === null) {\n return\n }\n openInBrowserLink.addEventListener('click', () => {\n android.openInBrowser(window.location.href)\n })\n}\nfunction executeAndroidExclusiveCode(android) {\n document.querySelectorAll('*.android').forEach((element) => {\n element.classList.remove('android')\n })\n document.querySelectorAll('*.no-android-app').forEach((element) => {\n element.style.display = 'none';\n })\n addListenerOpenInBrowserButton(android)\n const pinToHomeUrl = document.querySelector('a.pin-to-home')\n if (pinToHomeUrl === null) {\n return;\n }\n pinToHomeUrl.addEventListener('click', () => {\n const url = new URL(window.location.href)\n const pathandQuery = url.pathname + url.search;\n const label = (url.pathname.replace(/^.*\\//g, '')\n .replace(/(?:^|-)\\w/g, function(character) {\n return character.toUpperCase() \n })\n .replace(/-/g, ' ')) + ' - Burguillos.info';\n const firstImg = document.querySelector('div.description img');\n let iconUrl;\n if (firstImg !== null) {\n if (!firstImg.src.match(/\\.svg(?:\\?|$)/)) {\n iconUrl = absoluteToHost(firstImg.src);\n }\n }\n if (iconUrl === undefined) {\n const imagePreview = document.querySelector('meta[name=\"image\"]');\n iconUrl = absoluteToHost(imagePreview.content);\n }\n android.pinPage(pathandQuery, label, iconUrl)\n })\n}\n\nfunction addEasterEggAnimation() {\n const logoContainer = document.querySelector('div.burguillos-logo-container')\n if (logoContainer === null) {\n return;\n }\n logoContainer.addEventListener('click', () => {\n logoContainer.classList.toggle('active')\n })\n}\n\nlet current_ad_number = null\n\nfunction expand_page_contents() {\n const pageContents = document.querySelector('div.page-contents'); \n if (pageContents === null) {\n return;\n }\n pageContents.classList.add('no-carousel');\n}\n\nfunction no_more_ads() {\n const carousel = document.querySelector('.carousel');\n if (carousel !== null) {\n carousel.remove();\n }\n expand_page_contents();\n}\n\nfunction loadAd() {\n const params = new URLSearchParams();\n if (current_ad_number !== null) {\n params.append('n', \"\"+current_ad_number);\n }\n fetch('/next-ad.json?' + params).then((res) => {\n return res.json()\n }).then((res) => {\n current_ad_number = res.current_ad_number\n const ad = res.ad\n const must_continue = res.continue\n const carousel = document.querySelector('.carousel');\n if (must_continue === 0\n || carousel === null\n || carousel.offsetWidth === 0) {\n no_more_ads();\n return;\n }\n const a = _retrieveLinkCarousel(carousel)\n a.innerHTML = \"\"\n const image = document.createElement('img')\n const text_container = document.createElement('div')\n const text = document.createElement('h4')\n const promoted = document.createElement('p')\n\n promoted.classList.add('promoted-tag')\n promoted.innerText = \"Promocionado\"\n image.src = ad.img\n image.alt = \"\"\n text.innerText = ad.text\n a.href = ad.href\n\n a.append(image)\n text_container.append(promoted)\n text_container.append(text)\n a.append(text_container)\n\n window.setTimeout(() => {\n loadAd()\n }, ad.seconds * 1000)\n }).catch(() => {\n window.setTimeout(() => {\n loadAd()\n }, 1000)\n });\n}\n\nfunction _retrieveLinkCarousel(carousel) {\n const maybeA = carousel.querySelector('a')\n if (maybeA !== null) {\n return maybeA\n }\n const a = document.createElement('a')\n carousel.innerHTML = \"\"\n carousel.append(a)\n return a\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/index.js?"); /***/ }), diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index cd4d2c1..30a98cd 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -58,43 +58,45 @@
%= include 'page/_mobile_menu', categories => $categories %= include 'page/_mobile_foldable', categories => $categories - -
+
+ +
%= include 'page/_desktop_menu', categories => $categories, current_category_slug => $current_category_slug - + % if ($is_android) { - + % } - <%= content %> -
- Añade esta página a la pantalla de inicio de tu móvil. + <%= content %> + +
+
-
- -
%= include 'ads/_carousel' +
diff --git a/templates/page/_mobile_menu.html.ep b/templates/page/_mobile_menu.html.ep index 237d82f..ecf1045 100644 --- a/templates/page/_mobile_menu.html.ep +++ b/templates/page/_mobile_menu.html.ep @@ -2,7 +2,7 @@