Skip to content

Commit

Permalink
keep track of notifications timer so we can cancel them when they are…
Browse files Browse the repository at this point in the history
… no longer needed (important for long timeouts)

git-svn-id: https://xpra.org/svn/Xpra/trunk@18987 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 4, 2018
1 parent fab541b commit 83e75bb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/html5/js/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

$(function() {

window.notification_timers = {};

window.doNotification = function(type, nid, title, message, timeout, icon, actions, hints, onAction, onClose){
console.debug("doNotification", type, nid, title, message, timeout, icon, actions, hints, onAction, onClose);
var nID = 'notification' + nid;
Expand Down Expand Up @@ -42,6 +44,7 @@ $(function() {
}

a.on('click', '.dismiss', function() {
window.cancelNotificationTimer(nid);
a.removeClass('visible').addClass('hidden');
a.on('transitionend webkitTransitionEnd', $.debounce(250, function() {
a.trigger('dismissed');
Expand Down Expand Up @@ -70,6 +73,7 @@ $(function() {
a.data('timeLeft', tleft);
}
}, 1000);
window.notification_timers[nid] = it;
}
return a;
};
Expand All @@ -87,18 +91,33 @@ $(function() {
});
return notification_button;
}


window.cancelNotificationTimer = function(nid) {
var timer = window.notification_timers[nid];
if (timer) {
window.clearInterval(timer);
delete window.notification_timers[nid];
}
}
window.cancelNotificationTimers = function() {
for (var nid in window.notification_timers) {
window.cancelNotificationTimer(nid);
}
}

window.closeNotification = function(nid) {
window.cancelNotificationTimer(nid);
var nID = 'notification' + nid;
$('.notifications').find('#'+nID).find('.dismiss').trigger('click');
}

window.clearNotifications = function(){
window.cancelNotificationTimers();
$('.notifications').find('.dismiss').trigger('click');
};

window.removeNotifications = function(){
window.cancelNotificationTimers();
$('.notifications').empty();
};
});

0 comments on commit 83e75bb

Please sign in to comment.