mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-31 00:08:08 +01:00
Stack convert section, don't remove. Move remove into own js
This commit is contained in:
parent
95a9e10dc8
commit
fca6dc1fd8
@ -1,5 +1,5 @@
|
|||||||
function getStoredOrDefaultLocale() {
|
function getStoredOrDefaultLocale() {
|
||||||
const storedLocale = localStorage.getItem("languageCode");
|
const storedLocale = localStorage.getItem('languageCode');
|
||||||
return storedLocale || getDetailedLanguageCode();
|
return storedLocale || getDetailedLanguageCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7,10 +7,10 @@ function setLanguageForDropdown(dropdownClass) {
|
|||||||
const storedLocale = getStoredOrDefaultLocale();
|
const storedLocale = getStoredOrDefaultLocale();
|
||||||
const dropdownItems = document.querySelectorAll(dropdownClass);
|
const dropdownItems = document.querySelectorAll(dropdownClass);
|
||||||
|
|
||||||
dropdownItems.forEach(item => {
|
dropdownItems.forEach((item) => {
|
||||||
item.classList.toggle("active", item.dataset.bsLanguageCode === storedLocale);
|
item.classList.toggle('active', item.dataset.bsLanguageCode === storedLocale);
|
||||||
item.removeEventListener("click", handleDropdownItemClick);
|
item.removeEventListener('click', handleDropdownItemClick);
|
||||||
item.addEventListener("click", handleDropdownItemClick);
|
item.addEventListener('click', handleDropdownItemClick);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,62 +24,46 @@ function handleDropdownItemClick(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const languageCode = event.currentTarget.dataset.bsLanguageCode;
|
const languageCode = event.currentTarget.dataset.bsLanguageCode;
|
||||||
if (languageCode) {
|
if (languageCode) {
|
||||||
localStorage.setItem("languageCode", languageCode);
|
localStorage.setItem('languageCode', languageCode);
|
||||||
updateUrlWithLanguage(languageCode);
|
updateUrlWithLanguage(languageCode);
|
||||||
} else {
|
} else {
|
||||||
console.error("Language code is not set for this item.");
|
console.error('Language code is not set for this item.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUserLanguage(defaultLocale) {
|
function checkUserLanguage(defaultLocale) {
|
||||||
if (!localStorage.getItem("languageCode") || document.documentElement.getAttribute("data-language") != defaultLocale) {
|
if (
|
||||||
localStorage.setItem("languageCode", defaultLocale);
|
!localStorage.getItem('languageCode') ||
|
||||||
updateUrlWithLanguage(defaultLocale);
|
document.documentElement.getAttribute('data-language') != defaultLocale
|
||||||
|
) {
|
||||||
|
localStorage.setItem('languageCode', defaultLocale);
|
||||||
|
updateUrlWithLanguage(defaultLocale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initLanguageSettings() {
|
function initLanguageSettings() {
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
setLanguageForDropdown(".lang_dropdown-item");
|
setLanguageForDropdown('.lang_dropdown-item');
|
||||||
|
|
||||||
const defaultLocale = getStoredOrDefaultLocale();
|
const defaultLocale = getStoredOrDefaultLocale();
|
||||||
checkUserLanguage(defaultLocale);
|
checkUserLanguage(defaultLocale);
|
||||||
|
|
||||||
const dropdownItems = document.querySelectorAll(".lang_dropdown-item");
|
const dropdownItems = document.querySelectorAll('.lang_dropdown-item');
|
||||||
dropdownItems.forEach(item => {
|
dropdownItems.forEach((item) => {
|
||||||
item.classList.toggle("active", item.dataset.bsLanguageCode === defaultLocale);
|
item.classList.toggle('active', item.dataset.bsLanguageCode === defaultLocale);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeElements() {
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
|
||||||
document.querySelectorAll(".navbar-item").forEach((element) => {
|
|
||||||
const dropdownItems = element.querySelectorAll(".dropdown-item");
|
|
||||||
const items = Array.from(dropdownItems).filter(item => !item.querySelector("hr.dropdown-divider"));
|
|
||||||
|
|
||||||
if (items.length <= 2) {
|
|
||||||
if (
|
|
||||||
element.previousElementSibling &&
|
|
||||||
element.previousElementSibling.classList.contains("navbar-item") &&
|
|
||||||
element.previousElementSibling.classList.contains("nav-item-separator")
|
|
||||||
) {
|
|
||||||
element.previousElementSibling.remove();
|
|
||||||
}
|
|
||||||
element.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortLanguageDropdown() {
|
function sortLanguageDropdown() {
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
const dropdownMenu = document.querySelector('.dropdown-menu .dropdown-item.lang_dropdown-item').parentElement;
|
const dropdownMenu = document.querySelector('.dropdown-menu .dropdown-item.lang_dropdown-item').parentElement;
|
||||||
if (dropdownMenu) {
|
if (dropdownMenu) {
|
||||||
const items = Array.from(dropdownMenu.children).filter(child => child.matches('a'));
|
const items = Array.from(dropdownMenu.children).filter((child) => child.matches('a'));
|
||||||
items.sort((a, b) => a.dataset.bsLanguageCode.localeCompare(b.dataset.bsLanguageCode))
|
items
|
||||||
.forEach(node => dropdownMenu.appendChild(node));
|
.sort((a, b) => a.dataset.bsLanguageCode.localeCompare(b.dataset.bsLanguageCode))
|
||||||
}
|
.forEach((node) => dropdownMenu.appendChild(node));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/main/resources/static/js/navbar.js
Normal file
19
src/main/resources/static/js/navbar.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
function removeElements() {
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
document.querySelectorAll('.navbar-item').forEach((element) => {
|
||||||
|
const dropdownItems = element.querySelectorAll('.dropdown-item');
|
||||||
|
const items = Array.from(dropdownItems).filter((item) => !item.querySelector('hr.dropdown-divider'));
|
||||||
|
|
||||||
|
if (items.length == 0) {
|
||||||
|
if (
|
||||||
|
element.previousElementSibling &&
|
||||||
|
element.previousElementSibling.classList.contains('navbar-item') &&
|
||||||
|
element.previousElementSibling.classList.contains('nav-item-separator')
|
||||||
|
) {
|
||||||
|
element.previousElementSibling.remove();
|
||||||
|
}
|
||||||
|
element.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
<div th:fragment="navbar" class="mx-auto">
|
<div th:fragment="navbar" class="mx-auto">
|
||||||
<script th:src="@{'/js/languageSelection.js'}"></script>
|
<script th:src="@{'/js/languageSelection.js'}"></script>
|
||||||
|
<script th:src="@{'/js/navbar.js'}"></script>
|
||||||
<script th:src="@{'/js/additionalLanguageCode.js'}"></script>
|
<script th:src="@{'/js/additionalLanguageCode.js'}"></script>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
// Initializing the scripts
|
// Initializing the scripts
|
||||||
@ -81,8 +82,9 @@
|
|||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-single-page', 'looks_one', 'home.PdfToSinglePage.title', 'home.PdfToSinglePage.desc', 'PdfToSinglePage.tags', 'organize')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-single-page', 'looks_one', 'home.PdfToSinglePage.title', 'home.PdfToSinglePage.desc', 'PdfToSinglePage.tags', 'organize')}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="navbar-item col-lg-2 col-sm-6 py px-xl-1 px-2"style="display:flex; flex-direction: column;">
|
||||||
<!-- Convert to PDF menu items -->
|
<!-- Convert to PDF menu items -->
|
||||||
<div class="navbar-item col-lg-2 col-sm-6 py px-xl-1 px-2">
|
<div class="navbar-item py px-xl-1 px-2">
|
||||||
<h6 class="menu-title" th:text="#{navbar.sections.convertTo}"></h6>
|
<h6 class="menu-title" th:text="#{navbar.sections.convertTo}"></h6>
|
||||||
<div
|
<div
|
||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('img-to-pdf', 'image', 'home.imageToPdf.title', 'home.imageToPdf.desc', 'imageToPdf.tags', 'image')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('img-to-pdf', 'image', 'home.imageToPdf.title', 'home.imageToPdf.desc', 'imageToPdf.tags', 'image')}">
|
||||||
@ -99,12 +101,12 @@
|
|||||||
<div
|
<div
|
||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('markdown-to-pdf', 'markdown', 'home.MarkdownToPDF.title', 'home.MarkdownToPDF.desc', 'MarkdownToPDF.tags', 'convert')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('markdown-to-pdf', 'markdown', 'home.MarkdownToPDF.title', 'home.MarkdownToPDF.desc', 'MarkdownToPDF.tags', 'convert')}">
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('book-to-pdf', 'book', 'home.BookToPDF.title', 'home.BookToPDF.desc', 'BookToPDF.tags', 'convert')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('book-to-pdf', 'book', 'home.BookToPDF.title', 'home.BookToPDF.desc', 'BookToPDF.tags', 'convert')}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Convert from PDF menu items -->
|
<!-- Convert from PDF menu items -->
|
||||||
<div class="navbar-item col-lg-2 col-sm-6 py px-xl-1 px-2">
|
<div class="navbar-item py px-xl-1 px-2" style="margin-top: 1rem;">
|
||||||
<h6 class="menu-title" th:text="#{navbar.sections.convertFrom}"></h6>
|
<h6 class="menu-title" th:text="#{navbar.sections.convertFrom}"></h6>
|
||||||
<div
|
<div
|
||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-img', 'image', 'home.pdfToImage.title', 'home.pdfToImage.desc', 'pdfToImage.tags', 'image')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-img', 'image', 'home.pdfToImage.title', 'home.pdfToImage.desc', 'pdfToImage.tags', 'image')}">
|
||||||
@ -134,6 +136,7 @@
|
|||||||
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-book', 'book', 'home.PDFToBook.title', 'home.PDFToBook.desc', 'PDFToBook.tags', 'convert')}">
|
th:replace="~{fragments/navbarEntry :: navbarEntry ('pdf-to-book', 'book', 'home.PDFToBook.title', 'home.PDFToBook.desc', 'PDFToBook.tags', 'convert')}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Security menu items -->
|
<!-- Security menu items -->
|
||||||
<div class="navbar-item col-lg-2 col-sm-6 py px-xl-1 px-2">
|
<div class="navbar-item col-lg-2 col-sm-6 py px-xl-1 px-2">
|
||||||
<h6 class="menu-title" th:text="#{navbar.sections.security}"></h6>
|
<h6 class="menu-title" th:text="#{navbar.sections.security}"></h6>
|
||||||
|
Loading…
Reference in New Issue
Block a user