Last active
December 24, 2015 14:49
-
-
Save micc83/6815838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready( function($) { | |
function send_popup( title, text, popup_class, delay ) { | |
// Initialize parameters | |
title = title !== '' ? '<span class="title">' + title + '</span>' : ''; | |
text = text !== '' ? text : ''; | |
popup_class = popup_class !== '' ? popup_class : 'update'; | |
delay = typeof delay === 'number' ? delay : 20000; | |
var object = $('<div/>', { | |
class: 'popup_notification ' + popup_class, | |
html: title + text + '<span class="close">×</span>' | |
}); | |
$('#popup_container').prepend(object); | |
$(object).hide().fadeIn(500); | |
setTimeout(function() { | |
$(object).slideUp(500); | |
}, delay); | |
} | |
$('<div/>', { id: 'popup_container' } ).appendTo('body'); | |
$('body').on('click', '.close', function () { $(this).parent().slideUp(200); }); | |
var blabla; | |
// Tick | |
wp.heartbeat.enqueue( 'my_tick', 'tick', false ); | |
// Bum bum | |
$(document).on( 'heartbeat-tick.my_tick', function( e, data ) { | |
// Tack | |
wp.heartbeat.enqueue( 'my_tick', 'tack', false ); | |
if ( !data['message'] ) return; | |
$.each( data['message'], function( index, notification ) { | |
if ( index != blabla ){ | |
send_popup( notification['title'], notification['content'], notification['type'] ); | |
} | |
blabla = index; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment