Browse Source

rewrite showDesktopNotification()

readme-update
Simon Grim 9 years ago
parent
commit
44641a5271
  1. 80
      js/mobile_abstract.js
  2. 10
      js/options.js

80
js/mobile_abstract.js

@ -27,7 +27,7 @@ var MAL = function()
installPostboardClick(); installPostboardClick();
} else { } 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"); newTweetsBarMenu.addClass("show");
if ($.Options.showDesktopNotifPosts.val === 'enable') { 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() { this.showDesktopNotification({
requestTimelineUpdate('pending',this,followingUsers,promotedPostsOnly); body: polyglot.t('You got') + ' ' + polyglot.t('new_posts', newPosts) + ' '
}).bind(newPosts), false) + 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 { } else {
newTweetsBar.hide(); newTweetsBar.hide();
@ -430,44 +436,36 @@ var MAL = function()
} }
}; };
this.showDesktopNotif = function(notifyTitle, notifyBody, notifyIcon, notifyTag, notifyTimer, actionOnClick, actionOnPermDenied) { this.showDesktopNotification = function(req) {
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();
}
if (Notify.needsPermission) { if (Notify.needsPermission) {
Notify.requestPermission(false, actionOnPermDenied); Notify.requestPermission(false, req.funcPermDenied);
} else { return;
doNotification(); }
}
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) { this.reqRepAfterCB = function(postLi, postsFromJson) {

10
js/options.js

@ -310,8 +310,14 @@ twisterOptions.prototype.initControls = function () {
} }
} }
$('#testDesktopNotif').on('click', 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})) }) $.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(); tickOptionsPostPreview();

Loading…
Cancel
Save