2025-01-30 18:55:33 +00:00
|
|
|
/*<![CDATA[*/
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
if (window.analyticsPromptBoolean) {
|
|
|
|
const analyticsModal = new bootstrap.Modal(document.getElementById('analyticsModal'));
|
|
|
|
analyticsModal.show();
|
2025-05-10 13:25:21 +01:00
|
|
|
|
|
|
|
let retryCount = 0;
|
|
|
|
function hideCookieBanner() {
|
|
|
|
const cookieBanner = document.querySelector('#cc-main');
|
|
|
|
if (cookieBanner && cookieBanner.offsetHeight > 0) {
|
|
|
|
cookieBanner.style.display = "none";
|
|
|
|
} else if (retryCount < 20) {
|
|
|
|
retryCount++;
|
|
|
|
setTimeout(hideCookieBanner, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hideCookieBanner();
|
2025-01-30 18:55:33 +00:00
|
|
|
}
|
|
|
|
});
|
2025-05-10 13:25:21 +01:00
|
|
|
/*]]>*/function setAnalytics(enabled) {
|
2025-01-30 18:55:33 +00:00
|
|
|
fetchWithCsrf('api/v1/settings/update-enable-analytics', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify(enabled),
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
if (response.status === 200) {
|
|
|
|
console.log('Analytics setting updated successfully');
|
|
|
|
bootstrap.Modal.getInstance(document.getElementById('analyticsModal')).hide();
|
2025-05-10 13:25:21 +01:00
|
|
|
|
|
|
|
if (typeof CookieConsent !== "undefined") {
|
|
|
|
if (enabled) {
|
|
|
|
CookieConsent.acceptCategory(['analytics']);
|
|
|
|
} else {
|
|
|
|
CookieConsent.acceptCategory([]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-30 18:55:33 +00:00
|
|
|
} else if (response.status === 208) {
|
|
|
|
console.log('Analytics setting has already been set. Please edit /config/settings.yml to change it.', response);
|
|
|
|
alert('Analytics setting has already been set. Please edit /config/settings.yml to change it.');
|
|
|
|
} else {
|
|
|
|
throw new Error('Unexpected response status: ' + response.status);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Error updating analytics setting:', error);
|
|
|
|
alert('An error occurred while updating the analytics setting. Please try again.');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFavoriteIcons();
|
2025-03-20 08:53:29 +01:00
|
|
|
const contentPath = /*[[${@contextPath}]]*/ '';
|
2025-01-30 18:55:33 +00:00
|
|
|
|
2025-05-28 22:43:06 +01:00
|
|
|
const defaultView = localStorage.getItem('defaultView') || 'home'; // Default to "home"
|
|
|
|
if (defaultView === 'home-legacy') {
|
|
|
|
window.location.href = contentPath + 'home-legacy'; // Redirect to legacy view
|
|
|
|
}
|
2025-01-30 18:55:33 +00:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
2025-03-01 20:36:11 +00:00
|
|
|
const surveyVersion = '3.0';
|
2025-01-30 18:55:33 +00:00
|
|
|
const modal = new bootstrap.Modal(document.getElementById('surveyModal'));
|
|
|
|
const dontShowAgain = document.getElementById('dontShowAgain');
|
|
|
|
const takeSurveyButton = document.getElementById('takeSurvey');
|
|
|
|
|
|
|
|
const viewThresholds = [5, 10, 15, 22, 30, 50, 75, 100, 150, 200];
|
|
|
|
|
|
|
|
// Check if survey version changed and reset page views if it did
|
|
|
|
const storedVersion = localStorage.getItem('surveyVersion');
|
|
|
|
if (storedVersion && storedVersion !== surveyVersion) {
|
|
|
|
localStorage.setItem('pageViews', '0');
|
2025-02-28 23:53:49 +13:00
|
|
|
localStorage.setItem('surveyVersion', surveyVersion);
|
2025-01-30 18:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let pageViews = parseInt(localStorage.getItem('pageViews') || '0');
|
|
|
|
|
|
|
|
pageViews++;
|
|
|
|
localStorage.setItem('pageViews', pageViews.toString());
|
|
|
|
|
|
|
|
function shouldShowSurvey() {
|
Add SHOW_SURVEY Environment variable to Docker (#3378)
In the previous implementation, the survey was displayed on the main
screen when the homepage was opened for the 5th, 10th, 15th, 22nd, 30th,
50th, 75th, 100th, 150th, or 200th time, as long as the "Do not show
again" option hadn't been selected.
With this new feature, if the SHOW_SURVEY environment variable is set to
true or not set at all in the Docker configuration, the survey will
continue to be shown as before.
<img width="1679" alt="Screenshot 2025-04-18 at 08 17 37"
src="https://github.com/user-attachments/assets/696b9dc2-9502-4d66-9991-d2b81b52cd02"
/>
However, if the SHOW_SURVEY parameter is explicitly set to false, the
survey will no longer be displayed.
<img width="1707" alt="Screenshot 2025-04-18 at 08 18 39"
src="https://github.com/user-attachments/assets/b57c568a-b5e7-4927-bccf-f9a398bea702"
/>
Closes #1573
---
## Checklist
### General
- [X] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [X] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [X] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [X] I have performed a self-review of my own code
- [X] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [X] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [X] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-04-20 13:49:34 +03:00
|
|
|
if(!window.showSurvey) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-01-30 18:55:33 +00:00
|
|
|
if (localStorage.getItem('dontShowSurvey') === 'true' || localStorage.getItem('surveyTaken') === 'true') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If survey version changed and we hit a threshold, show the survey
|
|
|
|
if (localStorage.getItem('surveyVersion') !== surveyVersion && viewThresholds.includes(pageViews)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewThresholds.includes(pageViews);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldShowSurvey()) {
|
|
|
|
modal.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
dontShowAgain.addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
localStorage.setItem('dontShowSurvey', 'true');
|
|
|
|
localStorage.setItem('surveyVersion', surveyVersion);
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem('dontShowSurvey');
|
|
|
|
localStorage.removeItem('surveyVersion');
|
|
|
|
}
|
|
|
|
});
|
2025-03-01 20:36:11 +00:00
|
|
|
if (takeSurveyButton) {
|
2025-01-30 18:55:33 +00:00
|
|
|
takeSurveyButton.addEventListener('click', function () {
|
|
|
|
localStorage.setItem('surveyTaken', 'true');
|
|
|
|
localStorage.setItem('surveyVersion', surveyVersion);
|
|
|
|
modal.hide();
|
|
|
|
});
|
2025-03-01 20:36:11 +00:00
|
|
|
}
|
2025-01-30 18:55:33 +00:00
|
|
|
if (localStorage.getItem('dontShowSurvey')) {
|
|
|
|
modal.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.location.pathname === '/') {
|
|
|
|
const navItem = document.getElementById('navItemToHide');
|
|
|
|
if (navItem) {
|
|
|
|
navItem.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateFavoritesDropdown();
|
|
|
|
});
|
|
|
|
function setAsDefault(value) {
|
|
|
|
localStorage.setItem('defaultView', value);
|
|
|
|
console.log(`Default view set to: ${value}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustVisibleElements() {
|
|
|
|
const container = document.querySelector('.recent-features');
|
Add SHOW_SURVEY Environment variable to Docker (#3378)
In the previous implementation, the survey was displayed on the main
screen when the homepage was opened for the 5th, 10th, 15th, 22nd, 30th,
50th, 75th, 100th, 150th, or 200th time, as long as the "Do not show
again" option hadn't been selected.
With this new feature, if the SHOW_SURVEY environment variable is set to
true or not set at all in the Docker configuration, the survey will
continue to be shown as before.
<img width="1679" alt="Screenshot 2025-04-18 at 08 17 37"
src="https://github.com/user-attachments/assets/696b9dc2-9502-4d66-9991-d2b81b52cd02"
/>
However, if the SHOW_SURVEY parameter is explicitly set to false, the
survey will no longer be displayed.
<img width="1707" alt="Screenshot 2025-04-18 at 08 18 39"
src="https://github.com/user-attachments/assets/b57c568a-b5e7-4927-bccf-f9a398bea702"
/>
Closes #1573
---
## Checklist
### General
- [X] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [X] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [X] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [X] I have performed a self-review of my own code
- [X] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [X] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [X] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-04-20 13:49:34 +03:00
|
|
|
if(!container) return;
|
2025-01-30 18:55:33 +00:00
|
|
|
const subElements = Array.from(container.children);
|
|
|
|
|
|
|
|
let totalWidth = 0;
|
|
|
|
|
|
|
|
subElements.forEach((element) => {
|
|
|
|
totalWidth += 12 * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
|
|
|
|
|
|
if (totalWidth > window.innerWidth) {
|
|
|
|
element.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
element.style.display = 'block';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustContainerAlignment() {
|
|
|
|
document.querySelectorAll('.features-container').forEach((parent) => {
|
|
|
|
parent.querySelectorAll('.feature-rows').forEach((container) => {
|
|
|
|
const containerWidth = parent.offsetWidth;
|
|
|
|
if (containerWidth < 32 * parseFloat(getComputedStyle(document.documentElement).fontSize)) {
|
|
|
|
container.classList.add('single-column');
|
|
|
|
} else {
|
|
|
|
container.classList.remove('single-column');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function toolsManager() {
|
|
|
|
const convertToPDF = document.querySelector('#groupConvertTo');
|
|
|
|
const convertFromPDF = document.querySelector('#groupConvertFrom');
|
|
|
|
|
|
|
|
if (convertToPDF && convertFromPDF) {
|
|
|
|
const itemsTo = Array.from(convertToPDF.querySelectorAll('.dropdown-item')).filter(
|
|
|
|
(item) => !item.querySelector('hr.dropdown-divider')
|
|
|
|
);
|
|
|
|
const itemsFrom = Array.from(convertFromPDF.querySelectorAll('.dropdown-item')).filter(
|
|
|
|
(item) => !item.querySelector('hr.dropdown-divider')
|
|
|
|
);
|
|
|
|
|
|
|
|
const totalItems = itemsTo.length + itemsFrom.length;
|
|
|
|
|
|
|
|
if (totalItems > 12) {
|
|
|
|
document.querySelectorAll('#convertGroup').forEach((element) => element.remove());
|
|
|
|
document.querySelectorAll('#groupConvertTo').forEach((element) => (element.style.display = 'flex'));
|
|
|
|
document.querySelectorAll('#groupConvertFrom').forEach((element) => (element.style.display = 'flex'));
|
|
|
|
} else {
|
|
|
|
document.querySelectorAll('#convertGroup').forEach((element) => (element.style.display = 'flex'));
|
|
|
|
document.querySelectorAll('#groupConvertTo').forEach((element) => element.remove());
|
|
|
|
document.querySelectorAll('#groupConvertFrom').forEach((element) => element.remove());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
toolsManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
adjustContainerAlignment();
|
|
|
|
adjustVisibleElements();
|
|
|
|
});
|
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
adjustContainerAlignment();
|
|
|
|
adjustVisibleElements();
|
|
|
|
});
|