You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
libarry bump + toast upload
This commit is contained in:
62
web/js/toast.js
Normal file
62
web/js/toast.js
Normal file
@@ -0,0 +1,62 @@
|
||||
function sendToast(type, title, message, persistent, important) {
|
||||
var toastId = 'toast-' + new Date().getTime(); // Unique ID for each toast
|
||||
|
||||
// If title isn't provided, use the type as the title
|
||||
var toastTitle = title ? title : capitalizeFirstLetter(type);
|
||||
|
||||
// Icon mapping based on the toast type
|
||||
var toastIcons = {
|
||||
success: 'fa-check-circle',
|
||||
error: 'fa-times-circle',
|
||||
warning: 'fa-exclamation-triangle',
|
||||
info: 'fa-info-circle',
|
||||
default: 'fa-bell' // Default icon if the type is not found
|
||||
};
|
||||
|
||||
// Get the icon class based on the toast type, fallback to 'default' if type doesn't exist
|
||||
var iconClass = toastIcons[type] || toastIcons['default'];
|
||||
|
||||
// Create the toast element
|
||||
var $toast = $(`
|
||||
<div class="toast ${type} flex-container ${important ? 'important' : ''}" id="${toastId}">
|
||||
<div class="toast-icon"><i class="fa-solid ${iconClass}"></i></div>
|
||||
<div>
|
||||
<div class="toast-title">${toastTitle}</div>
|
||||
<div class="toast-message">${message}</div>
|
||||
</div>
|
||||
<button class="close-btn"> </button>
|
||||
</div>
|
||||
`);
|
||||
|
||||
// Append the toast to the container
|
||||
$('#toast-container').append($toast);
|
||||
|
||||
// Add the 'show' class after appending for fade-in effect
|
||||
setTimeout(function () {
|
||||
$toast.addClass('show');
|
||||
}, 10); // Timeout to ensure the element is appended before the animation triggers
|
||||
|
||||
// Close button functionality
|
||||
$toast.find('.close-btn').click(function () {
|
||||
closeToast($toast);
|
||||
});
|
||||
|
||||
// If not persistent, remove it after 5 seconds
|
||||
if (!persistent) {
|
||||
setTimeout(function () {
|
||||
closeToast($toast);
|
||||
}, 5000); // 5000 ms = 5 seconds
|
||||
}
|
||||
}
|
||||
|
||||
// Function to close and remove the toast
|
||||
function closeToast($toast) {
|
||||
$toast.removeClass('show'); // Trigger fade-out
|
||||
setTimeout(function () {
|
||||
$toast.remove(); // Remove the element from DOM after the animation
|
||||
}, 300); // Timeout matches the CSS transition duration
|
||||
}
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
Reference in New Issue
Block a user