From f5626531a29c8a25693d09c12e2a98dfacf0700a Mon Sep 17 00:00:00 2001 From: sualko Date: Sun, 22 Jan 2017 00:21:01 +0100 Subject: [PATCH] add icons to notice --- img/megaphone_icon_black.svg | 73 ++++++++++++++++++++++++++++++++++++ scss/_jsxc.scss | 4 ++ src/jsxc.lib.notice.js | 20 +++++++--- src/jsxc.lib.notification.js | 23 +++++++----- src/jsxc.lib.xmpp.js | 17 +++++++-- 5 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 img/megaphone_icon_black.svg diff --git a/img/megaphone_icon_black.svg b/img/megaphone_icon_black.svg new file mode 100644 index 0000000..23a924f --- /dev/null +++ b/img/megaphone_icon_black.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/scss/_jsxc.scss b/scss/_jsxc.scss index 89180e7..c96d12e 100644 --- a/scss/_jsxc.scss +++ b/scss/_jsxc.scss @@ -506,6 +506,10 @@ img.jsxc_vCard { background-image: image-url("bookmark_black.svg"); } +.jsxc_announcementicon { + background-image: image-url("megaphone_icon_black.svg"); +} + .jsxc_more { float: right; width: 44px; diff --git a/src/jsxc.lib.notice.js b/src/jsxc.lib.notice.js index 7a60c15..d004eac 100644 --- a/src/jsxc.lib.notice.js +++ b/src/jsxc.lib.notice.js @@ -26,7 +26,7 @@ jsxc.notice = { if (saved.hasOwnProperty(key)) { var val = saved[key]; - jsxc.notice.add(val.msg, val.description, val.fnName, val.fnParams, key); + jsxc.notice.add(val, val.fnName, val.fnParams, key); } } }, @@ -35,16 +35,19 @@ jsxc.notice = { * Add a new notice to the stack; * * @memberOf jsxc.notice - * @param msg Header message - * @param description Notice description - * @param fnName Function name to be called if you open the notice + * @param {Object} data + * @param {String} data.msg Header message + * @param {String} data.description Notice description + * @param {String} fnName Function name to be called if you open the notice * @param fnParams Array of params for function - * @param id Notice id + * @param {String} id Notice id */ - add: function(msg, description, fnName, fnParams, id) { + add: function(data, fnName, fnParams, id) { var nid = id || Date.now(); var list = $('#jsxc_notice ul'); var notice = $('
  • '); + var msg = data.msg; + var description = data.description; notice.click(function() { jsxc.notice.remove(nid); @@ -54,6 +57,10 @@ jsxc.notice = { return false; }); + if (data.type) { + notice.addClass('jsxc_' + data.type + 'icon'); + } + notice.text(msg); notice.attr('title', description || ''); notice.attr('data-nid', nid); @@ -67,6 +74,7 @@ jsxc.notice = { saved[nid] = { msg: msg, description: description, + type: data.type, fnName: fnName, fnParams: fnParams }; diff --git a/src/jsxc.lib.notification.js b/src/jsxc.lib.notification.js index 99e049e..aea8dbd 100644 --- a/src/jsxc.lib.notification.js +++ b/src/jsxc.lib.notification.js @@ -1,6 +1,6 @@ /** * This namespace handles the Notification API. - * + * * @namespace jsxc.notification */ jsxc.notification = { @@ -10,7 +10,7 @@ jsxc.notification = { /** * Register notification on incoming messages. - * + * * @memberOf jsxc.notification */ init: function() { @@ -39,7 +39,7 @@ jsxc.notification = { /** * Shows a pop up notification and optional play sound. - * + * * @param title Title * @param msg Message * @param d Duration @@ -108,7 +108,7 @@ jsxc.notification = { /** * Checks if browser has support for notifications and add on chrome to the * default api. - * + * * @returns {Boolean} True if the browser has support. */ hasSupport: function() { @@ -163,7 +163,10 @@ jsxc.notification = { $(document).one('postmessagein.jsxc', function() { setTimeout(function() { - jsxc.notice.add($.t('Notifications') + '?', $.t('Should_we_notify_you_'), 'gui.showRequestNotification'); + jsxc.notice.add({ + msg: $.t('Notifications') + '?', + description: $.t('Should_we_notify_you_') + }, 'gui.showRequestNotification'); }, 1000); }); }, @@ -187,7 +190,7 @@ jsxc.notification = { /** * Check permission. - * + * * @returns {Boolean} True if we have the permission */ hasPermission: function() { @@ -196,7 +199,7 @@ jsxc.notification = { /** * Plays the given file. - * + * * @memberOf jsxc.notification * @param {string} soundFile File relative to the sound directory * @param {boolean} loop True for loop @@ -230,7 +233,7 @@ jsxc.notification = { /** * Stop/remove current sound. - * + * * @memberOf jsxc.notification */ stopSound: function() { @@ -244,7 +247,7 @@ jsxc.notification = { /** * Mute sound. - * + * * @memberOf jsxc.notification * @param {boolean} external True if triggered from external tab. Default: * false. @@ -259,7 +262,7 @@ jsxc.notification = { /** * Unmute sound. - * + * * @memberOf jsxc.notification * @param {boolean} external True if triggered from external tab. Default: * false. diff --git a/src/jsxc.lib.xmpp.js b/src/jsxc.lib.xmpp.js index 244e6fb..84a7ef7 100644 --- a/src/jsxc.lib.xmpp.js +++ b/src/jsxc.lib.xmpp.js @@ -692,7 +692,11 @@ jsxc.xmpp = { jid: jid, approve: -1 }); - jsxc.notice.add($.t('Friendship_request'), $.t('from') + ' ' + jid, 'gui.showApproveDialog', [jid]); + jsxc.notice.add({ + msg: $.t('Friendship_request'), + description: $.t('from') + ' ' + jid, + type: 'contact' + }, 'gui.showApproveDialog', [jid]); return true; } else if (ptype === 'unavailable' || ptype === 'unsubscribed') { @@ -854,7 +858,10 @@ jsxc.xmpp = { var chat = jsxc.storage.getUserItem('chat', bid) || []; if (chat.length === 0) { - jsxc.notice.add($.t('Unknown_sender'), $.t('You_received_a_message_from_an_unknown_sender') + ' (' + bid + ').', 'gui.showUnknownSender', [bid]); + jsxc.notice.add({ + msg: $.t('Unknown_sender'), + description: $.t('You_received_a_message_from_an_unknown_sender') + ' (' + bid + ').' + }, 'gui.showUnknownSender', [bid]); } var msg = jsxc.removeHTML(body); @@ -966,7 +973,11 @@ jsxc.xmpp = { var subject = stanza.find('subject:first').text() || $.t('Notification'); var body = stanza.find('body:first').text(); - jsxc.notice.add(subject, body, 'gui.showNotification', [subject, body, from]); + jsxc.notice.add({ + msg: subject, + description: body, + type: (domain === from) ? 'announcement' : null + }, 'gui.showNotification', [subject, body, from]); return true; },