Skip to content

Instantly share code, notes, and snippets.

@micc83
Last active December 24, 2015 14:49
Show Gist options
  • Save micc83/6815838 to your computer and use it in GitHub Desktop.
Save micc83/6815838 to your computer and use it in GitHub Desktop.
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">&times;</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