$(function () { var sound = new Audio('sound.mp3'); sound.volume = 0.2; window.addEventListener('message', function (event) { if (event.data.action == 'open') { var number = Math.floor((Math.random() * 1000) + 1); $('.toast').append(`
${event.data.message}
`) $(`.wrapper-${number}`).css({ "margin-bottom": "10px", "width": "275px", "margin": "0 0 8px -180px", "border-radius": "10px" }) $('.notification_main-'+number).addClass('main') $('.text-'+number).css({ "font-size": "14px" }) if (event.data.type == 'success') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('success-icon') $(`.wrapper-${number}`).addClass('success success-border') } else if (event.data.type == 'info') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('info-icon') $(`.wrapper-${number}`).addClass('info info-border') } else if (event.data.type == 'error') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('error-icon') $(`.wrapper-${number}`).addClass('error error-border') sound.play(); } else if (event.data.type == 'warning') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('warning-icon') $(`.wrapper-${number}`).addClass('warning warning-border') sound.play(); } else if (event.data.type == 'phonemessage') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('phonemessage-icon') $(`.wrapper-${number}`).addClass('phonemessage phonemessage-border') } else if (event.data.type == 'neutral') { $(`.title-${number}`).html(event.data.title).css({ "font-size": "16px", "font-weight": "600" }) $(`.notification_main-${number}`).addClass('neutral-icon') $(`.wrapper-${number}`).addClass('neutral neutral-border') } anime({ targets: `.wrapper-${number}`, translateX: -50, duration: 750, easing: 'spring(1, 70, 100, 10)', }) setTimeout(function () { anime({ targets: `.wrapper-${number}`, translateX: 500, duration: 750, easing: 'spring(1, 80, 100, 0)' }) setTimeout(function () { $(`.wrapper-${number}`).remove() }, 750) }, event.data.time) } }) })