From 6780fcb95b2bd4f73ae2cf5e78b84b2b53131876 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 21 Sep 2017 12:32:47 +0200 Subject: [PATCH] Replace "Add to addressbook" icon with a menu (#47) --- skins/elastic/styles/widgets/buttons.less | 11 +---- skins/elastic/styles/widgets/toolbar.less | 6 +++ skins/elastic/templates/message.html | 15 ++++-- skins/elastic/ui.js | 59 +++++++++++++++++++++-- 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/skins/elastic/styles/widgets/buttons.less b/skins/elastic/styles/widgets/buttons.less index d4eeed722..755143089 100644 --- a/skins/elastic/styles/widgets/buttons.less +++ b/skins/elastic/styles/widgets/buttons.less @@ -13,7 +13,7 @@ a.rcmaddcontact { - text-decoration: none; + display: none; } .button.disabled { @@ -110,15 +110,6 @@ a.button.icon { } } -a.rcmaddcontact:before { - &:extend(.font-icon-class); - content: @fa-var-user-plus; - display: inline; - float: none; - margin-left: 5px; - font-size: inherit; -} - @media screen and (max-width: @screen-width-small) { .btn:focus { box-shadow: none; diff --git a/skins/elastic/styles/widgets/toolbar.less b/skins/elastic/styles/widgets/toolbar.less index 9de170dda..02b92cea8 100644 --- a/skins/elastic/styles/widgets/toolbar.less +++ b/skins/elastic/styles/widgets/toolbar.less @@ -439,6 +439,12 @@ a.insertresponse:before { content: @fa-var-comment; } + a.compose:before { + content: @fa-var-edit; + } + a.addressbook:before { + content: @fa-var-user; + } } #layout > .sidebar, diff --git a/skins/elastic/templates/message.html b/skins/elastic/templates/message.html index 0338ded51..fe2829a3a 100644 --- a/skins/elastic/templates/message.html +++ b/skins/elastic/templates/message.html @@ -49,9 +49,18 @@

+
+ +
+

+
diff --git a/skins/elastic/ui.js b/skins/elastic/ui.js index 33512204e..dfb31cef8 100644 --- a/skins/elastic/ui.js +++ b/skins/elastic/ui.js @@ -56,6 +56,7 @@ function rcube_elastic_ui() this.searchmenu = searchmenu; this.headersmenu = headersmenu; this.attachmentmenu = attachmentmenu; + this.mailtomenu = mailtomenu; this.show_list = show_list; this.show_sidebar = show_sidebar; @@ -421,6 +422,13 @@ function rcube_elastic_ui() if (rcmail.env.action == 'compose' && !rcmail.env.extwin) { $('a.button.mail', layout.menu).attr('onclick', "return rcmail.command('list','',this,event)"); } + + // Append contact menu to all mailto: links + if (rcmail.env.action == 'preview' || rcmail.env.action == 'show') { + $('a').filter('[href^="mailto:"]').each(function() { + mailtomenu_append(this); + }); + } } rcmail.env.thread_padding = '1.5rem'; @@ -1814,16 +1822,59 @@ function rcube_elastic_ui() title: label, 'class': 'button icon dropdown skip-content' }) - .on('click keypress', function(e) { - if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) { - attachmentmenu($('#attachmentmenu'), button, e); - } + .on('click', function(e) { + attachmentmenu($('#attachmentmenu'), button, e); }) .append($('').attr('class', 'inner').text(label)) .appendTo(item); } }; + /** + * Mailto menu + */ + function mailtomenu(obj, button, event) + { + var mailto = $(button).attr('href').replace(/^mailto:/, ''); + + if (mailto.indexOf('@') < 0) { + return true; // let the browser to handle this + } + + if (rcmail.env.has_writeable_addressbook) { + $('.addressbook', obj).addClass('active') + .off('click').on('click', function(e) { + var i, contact = mailto, + txt = $(button).filter('.rcmContactAddress').text(); + + contact = contact.split('?')[0].replace(/(^<|>$)/g, ''); + + if (txt) { + txt = txt.replace('<' + contact + '>', ''); + contact = $.trim(txt) + ' <' + contact + '>'; + } + + return rcmail.command('add-contact', contact, this); + }); + } + + $('.compose', obj).off('click').on('click', function(e) { + return rcmail.command('compose', mailto, this); + }); + + return rcmail.command('menu-open', {menu: 'mailto-menu', link: button}, button, event); + }; + + /** + * Appends popup menu to mailto links + */ + function mailtomenu_append(item) + { + $(item).attr('onclick', '').on('click', function(e) { + return mailtomenu($('#mailto-menu'), item, e); + }); + }; + /** * Headers menu in mail compose */