mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-01-14 17:07:53 +00:00
rewrite showDesktopNotification()
This commit is contained in:
parent
5acb60a7c8
commit
44641a5271
@ -27,7 +27,7 @@ var MAL = function()
|
||||
|
||||
installPostboardClick();
|
||||
} else {
|
||||
$(".postboard-loading").hide();
|
||||
$(".postboard-loading").hide(); // FIXME need to decide which one we need to hide actually
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +104,15 @@ var MAL = function()
|
||||
newTweetsBarMenu.addClass("show");
|
||||
|
||||
if ($.Options.showDesktopNotifPosts.val === 'enable') {
|
||||
this.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_posts', newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', $.Options.showDesktopNotifPostsTimer.val, (function() {
|
||||
requestTimelineUpdate('pending',this,followingUsers,promotedPostsOnly);
|
||||
}).bind(newPosts), false)
|
||||
this.showDesktopNotification({
|
||||
body: polyglot.t('You got') + ' ' + polyglot.t('new_posts', newPosts) + ' '
|
||||
+ polyglot.t('in postboard') + '.',
|
||||
tag: 'twister_notification_new_posts',
|
||||
timeout: $.Options.showDesktopNotifPostsTimer.val,
|
||||
funcClick: (function() {
|
||||
requestTimelineUpdate('pending', this.postsCount, followingUsers, promotedPostsOnly);
|
||||
}).bind({postsCount: newPosts})
|
||||
});
|
||||
}
|
||||
} else {
|
||||
newTweetsBar.hide();
|
||||
@ -430,44 +436,36 @@ var MAL = function()
|
||||
}
|
||||
};
|
||||
|
||||
this.showDesktopNotif = function(notifyTitle, notifyBody, notifyIcon, notifyTag, notifyTimer, actionOnClick, actionOnPermDenied) {
|
||||
function doNotification() {
|
||||
if (!notifyTitle) {
|
||||
notifyTitle = polyglot.t('notify_desktop_title');
|
||||
}
|
||||
if (!notifyIcon) {
|
||||
notifyIcon = '../img/twister_mini.png';
|
||||
}
|
||||
if (!notifyTag) {
|
||||
notifyTag = 'twister_notification';
|
||||
}
|
||||
if (!notifyTimer) {
|
||||
notifyTimer = 3600 * 24 * 30; // one month
|
||||
}
|
||||
var doActionOnClick = false;
|
||||
if (typeof actionOnClick === 'function') {
|
||||
doActionOnClick = function() {
|
||||
actionOnClick();
|
||||
window.focus();
|
||||
}
|
||||
}
|
||||
|
||||
var desktopNotification = new Notify(notifyTitle, {
|
||||
body: notifyBody,
|
||||
icon: notifyIcon,
|
||||
tag: notifyTag,
|
||||
timeout: notifyTimer,
|
||||
notifyClick: doActionOnClick,
|
||||
notifyError: function() { alert(polyglot.t('notify_desktop_error')) }
|
||||
});
|
||||
desktopNotification.show();
|
||||
}
|
||||
|
||||
this.showDesktopNotification = function(req) {
|
||||
if (Notify.needsPermission) {
|
||||
Notify.requestPermission(false, actionOnPermDenied);
|
||||
} else {
|
||||
doNotification();
|
||||
Notify.requestPermission(false, req.funcPermDenied);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!req.title)
|
||||
req.title = polyglot.t('notify_desktop_title');
|
||||
if (!req.icon)
|
||||
req.icon = '../img/twister_mini.png';
|
||||
if (!req.tag)
|
||||
req.tag = 'twister_notification';
|
||||
if (!req.timeout)
|
||||
req.timeout = 2592000; // 60 * 60 * 24 * 30, one month
|
||||
|
||||
if (typeof req.funcClick === 'function')
|
||||
req.funcClick = (function() {window.focus(); this.funcClick();})
|
||||
.bind({funcClick: req.funcClick});
|
||||
else
|
||||
req.funcClick = function() {window.focus();}
|
||||
|
||||
var desktopNotification = new Notify(req.title, {
|
||||
body: req.body,
|
||||
icon: req.icon,
|
||||
tag: req.tag,
|
||||
timeout: req.timeout,
|
||||
notifyClick: req.funcClick,
|
||||
notifyError: function() {alert(polyglot.t('notify_desktop_error'));}
|
||||
});
|
||||
desktopNotification.show();
|
||||
};
|
||||
|
||||
this.reqRepAfterCB = function(postLi, postsFromJson) {
|
||||
|
@ -310,8 +310,14 @@ twisterOptions.prototype.initControls = function () {
|
||||
}
|
||||
}
|
||||
|
||||
$('#testDesktopNotif').on('click', function() {
|
||||
$.MAL.showDesktopNotif(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, false, function() { alert(polyglot.t('notify_desktop_perm_denied', {'this_domain': document.domain})) })
|
||||
$('#testDesktopNotif').on('click', function () {
|
||||
$.MAL.showDesktopNotification({
|
||||
title: polyglot.t('notify_desktop_test'),
|
||||
body: 'twister_notification_test',
|
||||
funcClick: function () {
|
||||
alert(polyglot.t('notify_desktop_perm_denied', {'this_domain': document.domain}));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tickOptionsPostPreview();
|
||||
|
Loading…
Reference in New Issue
Block a user