From b74315c7f5eb0f7400f5c2c42a41f4e40d37401a Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 15 Jun 2024 12:31:14 -0700 Subject: [PATCH] add "fade up?!" animation to disappearing notifications --- src/UI/UINotification.js | 24 ++++++++++++++++++------ src/css/style.css | 4 +++- src/icons/bell.svg | 10 ++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/icons/bell.svg diff --git a/src/UI/UINotification.js b/src/UI/UINotification.js index ca5e192a..2afe5f26 100644 --- a/src/UI/UINotification.js +++ b/src/UI/UINotification.js @@ -29,7 +29,7 @@ function UINotification(options){ h += `
`; h += ``; h += `
`; - h += ``; + h += ``; h += `
`; h += `
`; h += `
${html_encode(options.title)}
`; @@ -42,6 +42,9 @@ function UINotification(options){ const el_notification = document.getElementById(`ui-notification__${window.global_element_id}`); + // now wrap it in a div + $(el_notification).wrap('
'); + $(el_notification).show(0, function(e){ // options.onAppend() if(options.onAppend && typeof options.onAppend === 'function'){ @@ -50,6 +53,12 @@ function UINotification(options){ }) $(el_notification).on('click', function(e){ + // close button clicked + if($(e.target).hasClass('notification-close')){ + return; + } + + // click event if(options.click && typeof options.click === 'function'){ options.click(options.value); } @@ -62,10 +71,6 @@ function UINotification(options){ $(document).on('click', '.notification', function(e){ if($(e.target).hasClass('notification')){ - // TODO: options isn't available here - // if(options.click && typeof options.click === 'function'){ - // options.click(e); - // } window.close_notification(e.target); }else{ window.close_notification($(e.target).closest('.notification')); @@ -74,15 +79,22 @@ $(document).on('click', '.notification', function(e){ $(document).on('click', '.notification-close', function(e){ window.close_notification($(e.target).closest('.notification')); + e.stopPropagation(); + e.preventDefault(); + return false; }); window.close_notification = function(el_notification){ + $(el_notification).closest('.notification-wrapper').animate({ + height: 0, + opacity: 0 + }, 200); $(el_notification).addClass('animate__fadeOutRight'); - // remove notification setTimeout(function(){ + $(el_notification).closest('.notification-wrapper').remove(); $(el_notification).remove(); }, 300); } diff --git a/src/css/style.css b/src/css/style.css index c77eaf8b..b1209749 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -2432,8 +2432,10 @@ label { /***************************************************** * Notification *****************************************************/ -.notification { +.notification, .notification-wrapper{ width: 320px; +} +.notification { min-height: 54px; background: #ffffffcd; backdrop-filter: blur(5px); diff --git a/src/icons/bell.svg b/src/icons/bell.svg new file mode 100644 index 00000000..1d000d34 --- /dev/null +++ b/src/icons/bell.svg @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file