JS [WIP]: Added a notification popup

This commit is contained in:
veselcraft 2021-10-14 22:21:10 +03:00
parent 4d532239e8
commit ffb8c6d5df
3 changed files with 164 additions and 0 deletions

View file

@ -21,6 +21,7 @@
{if $theme->inheritDefault()}
{css "css/style.css"}
{css "css/dialog.css"}
{css "css/notifications.css"}
{if $isXmas}
{css "css/xmas.css"}
{/if}
@ -33,6 +34,7 @@
{else}
{css "css/style.css"}
{css "css/dialog.css"}
{css "css/notifications.css"}
{if $isXmas}
{css "css/xmas.css"}
{/if}
@ -53,6 +55,7 @@
{css "css/style.css"}
{css "css/dialog.css"}
{css "css/nsfw-posts.css"}
{css "css/notifications.css"}
{if $isXmas}
{css "css/xmas.css"}
@ -71,6 +74,7 @@
</div>
<div n:if="OPENVK_ROOT_CONF['openvk']['preferences']['bellsAndWhistles']['testLabel']" id="test-label">FOR TESTING PURPOSES ONLY</div>
<div class="notifications_global_wrap"></div>
<div class="dimmer"></div>
<div class="toTop">
⬆ Вверх
@ -256,6 +260,7 @@
<script src="https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js"></script>
{script "js/node_modules/ky/umd.js"}
{script "js/messagebox.js"}
{script "js/notifications.js"}
{script "js/scroll.js"}
{script "js/al_wall.js"}
{script "js/al_api.js"}

View file

@ -0,0 +1,100 @@
.notifications_global_wrap {
bottom: 0;
position: fixed;
display: flex;
flex-direction: column-reverse;
overflow: hidden;
width: 330px;
z-index: 1000;
}
.notification_ballon_wrap {
margin: 0 0 14px 14px;
}
.notification_ballon {
border-radius: 6px;
background-color: rgba(0, 0, 0, 0.7);
width: 300px;
height: 90px;
color: white !important;
display: inline-block;
animation-name: notification_ballon_appears;
animation-duration: 0.5s;
cursor: pointer;
}
.notification_ballon.disappears {
animation-name: notification_ballon_disappears;
animation-duration: 0.5s;
}
.notification_ballon notification_title {
margin: 6px 10px;
font-size: 10pt;
font-weight: bold;
display: block;
}
.notification_ballon notification_title .close {
width: 10px;
height: 16px;
float: right;
overflow: auto;
opacity: 0.1;
color: #fff;
transition-duration: 0.3s;
}
.notification_ballon notification_title .close:hover {
opacity: 0.5;
}
.notification_ballon wrap {
/* uuuuh */
display: flex;
flex-direction: row;
padding: 0 10px 0 10px;
}
.notification_ballon wrap avatar {
width: 50px;
padding-right: 10px;
}
.notification_ballon wrap avatar img {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 6px;
}
.notification_ballon wrap content {
font-size: 11px;
}
.notification_ballon wrap content a {
color: rgb(94, 165, 231);
font-weight: bold;
}
@keyframes notification_ballon_appears {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes notification_ballon_disappears {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}

View file

@ -0,0 +1,59 @@
Function.noop = () => {};
var _n_counter = 0;
function NewNotification(title, body, avatar = null, callback = () => {}, time = 5000) {
if(avatar != null) {
avatar = '<avatar>' +
'<img src="' + avatar + '">' +
'</avatar>';
} else {
avatar = '';
}
_n_counter += 1;
let id = _n_counter;
let notification = u(
`<div class="notification_ballon notification_ballon_wrap" id="n${id}">
<notification_title>
${title}
<a class="close">X</a>
</notification_title>
<wrap>
${avatar}
<content>
${body}
</content>
</wrap>
</div>
`);
u(".notifications_global_wrap").append(notification);
function getPrototype() {
return u("#n"+id);
}
function __closeNotification() {
getPrototype().addClass('disappears');
setTimeout(() => {getPrototype().remove()}, 500);
}
setTimeout(() => {__closeNotification()}, time);
notification.children('notification_title').children('a.close').on('click', function(e) {
__closeNotification();
});
notification.on('click', function(e) {
if (!notification.hasClass('disappears')) {
Reflect.apply(callback, {
closeNotification: () => __closeNotification(),
$notification: () => getPrototype()
}, [e]);
__closeNotification();
}
});
}