From 435a0cd9ee6db7bcc5918101b4b4fcee42fc8d7c Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Thu, 6 Sep 2018 23:38:41 +0200 Subject: [PATCH] - OS notifications (e.g. rally poke messages) can now be clicked at. -> opens browser at linked map and system, #682 --- js/app.js | 2 +- js/app/map/util.js | 10 +- js/app/notification.js | 12 +- js/app/util.js | 6 +- public/js/v1.4.1/app.js | 2 +- public/js/v1.4.1/app/map/util.js | 10 +- public/js/v1.4.1/app/notification.js | 12 +- public/js/v1.4.1/app/util.js | 6 +- .../js/v1.4.1/lib/pnotify/pnotify.confirm.js | 146 ++++++++++++++++++ 9 files changed, 190 insertions(+), 16 deletions(-) create mode 100644 public/js/v1.4.1/lib/pnotify/pnotify.confirm.js diff --git a/js/app.js b/js/app.js index e6e2aa02..2b8dd65f 100644 --- a/js/app.js +++ b/js/app.js @@ -71,7 +71,7 @@ requirejs.config({ 'datatables.plugins.render.ellipsis': 'lib/datatables/plugins/render/ellipsis', // notification plugin - pnotify: 'lib/pnotify/pnotify', // v3.2.0 PNotify - notification core file - https://sciactive.com/pnotify/ + pnotify: 'lib/pnotify/pnotify', // v3.2.1 PNotify - notification core file - https://sciactive.com/pnotify/ 'pnotify.buttons': 'lib/pnotify/pnotify.buttons', // PNotify - buttons notification extension 'pnotify.confirm': 'lib/pnotify/pnotify.confirm', // PNotify - confirmation notification extension 'pnotify.nonblock': 'lib/pnotify/pnotify.nonblock', // PNotify - notification non-block extension (hover effect) diff --git a/js/app/map/util.js b/js/app/map/util.js index dc5bae08..37f8604b 100644 --- a/js/app/map/util.js +++ b/js/app/map/util.js @@ -1208,8 +1208,8 @@ define([ let defaultOptions = { poke: false, - hideNotification: false, - hideCounter: false, + hideNotification: false, // do not show notification + hideCounter: false // do not start map update counter }; options = $.extend({}, defaultOptions, options); @@ -1269,7 +1269,11 @@ define([ storeLocalData('map', this.mapId, 'rallyPoke', rallyPokeData); notificationOptions.type = 'info'; - Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); + Util.showNotify(notificationOptions, { + desktop: true, + stack: 'barBottom', + click: e => {window.location.href = getMapDeeplinkUrl(mapId, systemId);} + }); } }.bind({ mapId: mapId, diff --git a/js/app/notification.js b/js/app/notification.js index a93384a4..9b43e7a4 100644 --- a/js/app/notification.js +++ b/js/app/notification.js @@ -88,6 +88,7 @@ define([ PNotify.desktop.permission(); customConfig.delay = 10000; + customConfig.nonblock.nonblock = false; // true results in error on "click" desktop notification customConfig.desktop.desktop = true; // make browser tab blink @@ -132,7 +133,16 @@ define([ customConfig.icon = false; } - new PNotify(customConfig); + let notify = new PNotify(customConfig); + + if( + settings && + settings.click + ){ + // set onclick for notification + notify.get().on('click', settings.click); + } + }; /** diff --git a/js/app/util.js b/js/app/util.js index 1a5065c2..d346bd37 100644 --- a/js/app/util.js +++ b/js/app/util.js @@ -1301,11 +1301,11 @@ define([ /** * trigger a notification (on screen or desktop) * @param customConfig - * @param desktop + * @param settings */ - let showNotify = (customConfig, desktop) => { + let showNotify = (customConfig, settings) => { requirejs(['notification'], Notification => { - Notification.showNotify(customConfig, desktop); + Notification.showNotify(customConfig, settings); }); }; diff --git a/public/js/v1.4.1/app.js b/public/js/v1.4.1/app.js index e6e2aa02..2b8dd65f 100644 --- a/public/js/v1.4.1/app.js +++ b/public/js/v1.4.1/app.js @@ -71,7 +71,7 @@ requirejs.config({ 'datatables.plugins.render.ellipsis': 'lib/datatables/plugins/render/ellipsis', // notification plugin - pnotify: 'lib/pnotify/pnotify', // v3.2.0 PNotify - notification core file - https://sciactive.com/pnotify/ + pnotify: 'lib/pnotify/pnotify', // v3.2.1 PNotify - notification core file - https://sciactive.com/pnotify/ 'pnotify.buttons': 'lib/pnotify/pnotify.buttons', // PNotify - buttons notification extension 'pnotify.confirm': 'lib/pnotify/pnotify.confirm', // PNotify - confirmation notification extension 'pnotify.nonblock': 'lib/pnotify/pnotify.nonblock', // PNotify - notification non-block extension (hover effect) diff --git a/public/js/v1.4.1/app/map/util.js b/public/js/v1.4.1/app/map/util.js index dc5bae08..37f8604b 100644 --- a/public/js/v1.4.1/app/map/util.js +++ b/public/js/v1.4.1/app/map/util.js @@ -1208,8 +1208,8 @@ define([ let defaultOptions = { poke: false, - hideNotification: false, - hideCounter: false, + hideNotification: false, // do not show notification + hideCounter: false // do not start map update counter }; options = $.extend({}, defaultOptions, options); @@ -1269,7 +1269,11 @@ define([ storeLocalData('map', this.mapId, 'rallyPoke', rallyPokeData); notificationOptions.type = 'info'; - Util.showNotify(notificationOptions, {desktop: true, stack: 'barBottom'}); + Util.showNotify(notificationOptions, { + desktop: true, + stack: 'barBottom', + click: e => {window.location.href = getMapDeeplinkUrl(mapId, systemId);} + }); } }.bind({ mapId: mapId, diff --git a/public/js/v1.4.1/app/notification.js b/public/js/v1.4.1/app/notification.js index a93384a4..9b43e7a4 100644 --- a/public/js/v1.4.1/app/notification.js +++ b/public/js/v1.4.1/app/notification.js @@ -88,6 +88,7 @@ define([ PNotify.desktop.permission(); customConfig.delay = 10000; + customConfig.nonblock.nonblock = false; // true results in error on "click" desktop notification customConfig.desktop.desktop = true; // make browser tab blink @@ -132,7 +133,16 @@ define([ customConfig.icon = false; } - new PNotify(customConfig); + let notify = new PNotify(customConfig); + + if( + settings && + settings.click + ){ + // set onclick for notification + notify.get().on('click', settings.click); + } + }; /** diff --git a/public/js/v1.4.1/app/util.js b/public/js/v1.4.1/app/util.js index 1a5065c2..d346bd37 100644 --- a/public/js/v1.4.1/app/util.js +++ b/public/js/v1.4.1/app/util.js @@ -1301,11 +1301,11 @@ define([ /** * trigger a notification (on screen or desktop) * @param customConfig - * @param desktop + * @param settings */ - let showNotify = (customConfig, desktop) => { + let showNotify = (customConfig, settings) => { requirejs(['notification'], Notification => { - Notification.showNotify(customConfig, desktop); + Notification.showNotify(customConfig, settings); }); }; diff --git a/public/js/v1.4.1/lib/pnotify/pnotify.confirm.js b/public/js/v1.4.1/lib/pnotify/pnotify.confirm.js new file mode 100644 index 00000000..ee11d62d --- /dev/null +++ b/public/js/v1.4.1/lib/pnotify/pnotify.confirm.js @@ -0,0 +1,146 @@ +// Confirm +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as a module. + define('pnotify.confirm', ['jquery', 'pnotify'], factory); + } else if (typeof exports === 'object' && typeof module !== 'undefined') { + // CommonJS + module.exports = factory(require('jquery'), require('./pnotify')); + } else { + // Browser globals + factory(root.jQuery, root.PNotify); + } +}(typeof window !== "undefined" ? window : this, function($, PNotify){ + PNotify.prototype.options.confirm = { + // Make a confirmation box. + confirm: false, + // Make a prompt. + prompt: false, + // Classes to add to the input element of the prompt. + prompt_class: "", + // The default value of the prompt. + prompt_default: "", + // Whether the prompt should accept multiple lines of text. + prompt_multi_line: false, + // Where to align the buttons. (right, center, left, justify) + align: "right", + // The buttons to display, and their callbacks. + buttons: [ + { + text: "Ok", + addClass: "", + // Whether to trigger this button when the user hits enter in a single line prompt. + promptTrigger: true, + click: function(notice, value){ + notice.remove(); + notice.get().trigger("pnotify.confirm", [notice, value]); + } + }, + { + text: "Cancel", + addClass: "", + click: function(notice){ + notice.remove(); + notice.get().trigger("pnotify.cancel", notice); + } + } + ] + }; + PNotify.prototype.modules.confirm = { + init: function(notice, options){ + // The div that contains the buttons. + this.container = $('
').css('text-align', options.align).appendTo(notice.container); + + if (options.confirm || options.prompt) + this.makeDialog(notice, options); + else + this.container.hide(); + }, + + update: function(notice, options){ + if (options.confirm) { + this.makeDialog(notice, options); + this.container.show(); + } else { + this.container.hide().empty(); + } + }, + + afterOpen: function(notice, options){ + if (options.prompt) { + this.prompt.focus(); + } + }, + + makeDialog: function(notice, options) { + var already = false, that = this, btn, elem; + this.container.empty(); + if (options.prompt) { + // The input element of a prompt. + this.prompt = $('<'+(options.prompt_multi_line ? 'textarea rows="5"' : 'input type="text"')+' style="margin-bottom:5px;clear:both;" />') + .addClass((typeof notice.styles.input === "undefined" ? "" : notice.styles.input)+" "+(typeof options.prompt_class === "undefined" ? "" : options.prompt_class)) + .val(options.prompt_default) + .appendTo(this.container); + } + var customButtons = (options.buttons[0] && options.buttons[0] !== PNotify.prototype.options.confirm.buttons[0]); + for (var i = 0; i < options.buttons.length; i++) { + if (options.buttons[i] === null || (customButtons && PNotify.prototype.options.confirm.buttons[i] && PNotify.prototype.options.confirm.buttons[i] === options.buttons[i])) { + continue; + } + btn = options.buttons[i]; + if (already) { + this.container.append(' '); + } else { + already = true; + } + elem = $('