window.addEventListener('message', function (event) { switch(event.data.action) { case 'shortnotif': DoShortHudText(event.data); break; case 'notif': DoHudText(event.data); break; case 'longnotif': DoLongHudText(event.data); break; default: DoCustomHudText(event.data); break; } }); function DoShortHudText(data) { var $notification = $('.notification.template').clone(); $notification.removeClass('template'); $notification.addClass(data.type); $notification.html(data.text); $notification.fadeIn(); $('.notif-container').append($notification); setTimeout(function() { $.when($notification.fadeOut()).done(function() { $notification.remove() }); }, 1000); } function DoHudText(data) { var $notification = $('.notification.template').clone(); $notification.removeClass('template'); $notification.addClass(data.type); $notification.html(data.text); $notification.fadeIn(); $('.notif-container').append($notification); setTimeout(function() { $.when($notification.fadeOut()).done(function() { $notification.remove() }); }, 7500); } function DoLongHudText(data) { var $notification = $('.notification.template').clone(); $notification.removeClass('template'); $notification.addClass(data.type); $notification.html(data.text); $notification.fadeIn(); $('.notif-container').append($notification); setTimeout(function() { $.when($notification.fadeOut()).done(function() { $notification.remove() }); }, 5000); } function DoCustomHudText(data) { var $notification = $('.notification.template').clone(); $notification.removeClass('template'); $notification.addClass(data.type); $notification.html(data.text); $notification.fadeIn(); $('.notif-container').append($notification); setTimeout(function() { $.when($notification.fadeOut()).done(function() { $notification.remove() }); }, data.length === undefined ? data.length : 2500); }