diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2014-05-08 18:19:20 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2014-05-08 18:19:20 +0200 |
commit | 6789bf1f4dfd32cd54a0fbe520ff3e1a6f6afb8a (patch) | |
tree | 7fe8a301a1fa514f7225424a26047d4cf7bfa79d /skins | |
parent | ea0866a1adc9239b8b115ab2490e1dd88f3c64ec (diff) |
Moved popup-menu functions to Roundcube core for seamless integration of (stackable) skin and core menus
Diffstat (limited to 'skins')
-rw-r--r-- | skins/larry/includes/mailtoolbar.html | 4 | ||||
-rw-r--r-- | skins/larry/templates/compose.html | 5 | ||||
-rw-r--r-- | skins/larry/templates/mail.html | 6 | ||||
-rw-r--r-- | skins/larry/ui.js | 249 |
4 files changed, 70 insertions, 194 deletions
diff --git a/skins/larry/includes/mailtoolbar.html b/skins/larry/includes/mailtoolbar.html index ac93d47cb..6af114ac2 100644 --- a/skins/larry/includes/mailtoolbar.html +++ b/skins/larry/includes/mailtoolbar.html @@ -20,7 +20,7 @@ <div id="forwardmenu" class="popupmenu" aria-hidden="true"> <h3 id="aria-label-forwardmenu" class="voice">Forwarding options</h3> - <ul class="toolbarmenu" role="menu" aria-labelledby="aria-label-forwardmenu"> + <ul id="forwardmenu-menu" class="toolbarmenu" role="menu" aria-labelledby="aria-label-forwardmenu"> <li role="menuitem"><roundcube:button command="forward-inline" label="forwardinline" prop="sub" classAct="forwardlink active" class="forwardlink" /></li> <li role="menuitem"><roundcube:button command="forward-attachment" label="forwardattachment" prop="sub" classAct="forwardattachmentlink active" class="forwardattachmentlink" /></li> <roundcube:container name="forwardmenu" id="forwardmenu" /> @@ -29,7 +29,7 @@ <div id="replyallmenu" class="popupmenu" aria-hidden="true"> <h3 id="aria-label-replyallmenu" class="voice">Reply-all options</h3> - <ul class="toolbarmenu" role="menu" aria-labelledby="aria-label-replyallmenu"> + <ul id="replyallmenu-menu" class="toolbarmenu" role="menu" aria-labelledby="aria-label-replyallmenu"> <li role="menuitem"><roundcube:button command="reply-all" label="replyall" prop="sub" class="replyalllink" classAct="replyalllink active" /></li> <li role="menuitem"><roundcube:button command="reply-list" label="replylist" prop="sub" class="replylistlink" classAct="replylistlink active" /></li> <roundcube:container name="replyallmenu" id="replyallmenu" /> diff --git a/skins/larry/templates/compose.html b/skins/larry/templates/compose.html index 5eedca204..14f5a6d2d 100644 --- a/skins/larry/templates/compose.html +++ b/skins/larry/templates/compose.html @@ -27,7 +27,7 @@ <roundcube:if condition="config:enable_spellcheck" /> <span class="dropbutton"> <roundcube:button command="spellcheck" type="link" class="button spellcheck disabled" classAct="button spellcheck" classSel="button spellcheck pressed" label="spellcheck" title="checkspelling" tabindex="2" /> - <a href="#languages" class="dropbuttontip" id="spellmenulink" onclick="UI.toggle_popup('spellmenu',event);return false" aria-haspopup="true" tabindex="2"></a> + <a href="#languages" class="dropbuttontip" id="spellmenulink" onclick="UI.toggle_popup('spellmenu',event);return false" aria-haspopup="true" tabindex="2">Select Spell Language</a> </span> <roundcube:endif /> <roundcube:button name="addattachment" type="link" class="button attach" label="attach" title="addattachment" onclick="UI.show_uploadform(event);return false" aria-haspopup="true" tabindex="2" /> @@ -77,7 +77,7 @@ <div id="composeheaders" role="region" aria-labelledby="aria-label-composeheaders"> <h2 id="aria-label-composeheaders" class="voice">Message headers</h2> -<a href="#options" id="composeoptionstoggle" class="moreheaderstoggle"><span class="iconlink" title="<roundcube:label name='options' />"></span></a> +<a href="#options" id="composeoptionstoggle" class="moreheaderstoggle" title="<roundcube:label name='options' />"><span class="iconlink"></span></a> <table class="headers-table compose-headers"> <tbody> @@ -167,6 +167,7 @@ <!-- message compose body --> <div id="composeview-bottom"> <div id="composebodycontainer"> + <label for="composebody" class="voice">Message Body</label> <roundcube:object name="composeBody" id="composebody" form="form" cols="70" rows="20" tabindex="1" /> </div> <div id="compose-attachments" class="rightcol" role="region"> diff --git a/skins/larry/templates/mail.html b/skins/larry/templates/mail.html index b41e4b9ae..1e360b422 100644 --- a/skins/larry/templates/mail.html +++ b/skins/larry/templates/mail.html @@ -39,10 +39,10 @@ <h2 id="aria-label-searchform" class="voice">Email message search form</h2> <label for="quicksearchbox" class="voice">Email search input</label> <roundcube:object name="searchform" id="quicksearchbox" /> -<roundcube:button name="searchmenulink" id="searchmenulink" class="iconbutton searchoptions" onclick="UI.toggle_popup('searchmenu',event);return false" title="searchmod" label="options" aria-haspopup="true" aria-owns="searchmenu-menu" /> +<roundcube:button command="menu-open" prop="searchmenu" id="searchmenulink" class="iconbutton searchoptions" title="searchmod" label="options" aria-haspopup="true" aria-owns="searchmenu-menu" /> <roundcube:button command="reset-search" id="searchreset" class="iconbutton reset" title="resetsearch" content="Reset" /> -<div id="searchmenu" class="popupmenu"> +<div id="searchmenu" class="popupmenu" data-editable="true"> <h3 id="aria-label-searchmenu" class="voice"><roundcube:label name="searchmod" /></h3> <ul class="toolbarmenu" id="searchmenu-menu" role="menu" aria-labelledby="aria-label-searchmenu"> <li role="menuitem"><label><input type="checkbox" name="s_mods[]" value="subject" id="s_mod_subject" onclick="UI.set_searchmod(this)" /> <span><roundcube:label name="subject" /></span></label></li> @@ -237,7 +237,7 @@ <br style="clear:both" /> <div class="formbuttons"> <roundcube:button command="menu-save" id="listmenusave" type="input" class="button mainaction" label="save" /> - <roundcube:button command="menu-close" id="listmenucancel" type="input" class="button" label="cancel" /> + <roundcube:button command="menu-close" prop="messagelistmenu" id="listmenucancel" type="input" class="button" label="cancel" /> </div> </div> diff --git a/skins/larry/ui.js b/skins/larry/ui.js index 1d38ceae1..5df2ea194 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -20,21 +20,16 @@ function rcube_mail_ui() searchmenu: { editable:1, callback:searchmenu }, attachmentmenu: { }, listoptions: { editable:1 }, - dragmenu: { sticky:1 }, groupmenu: { above:1 }, mailboxmenu: { above:1 }, spellmenu: { callback: spellmenu }, - // toggle: #1486823, #1486930 - 'attachment-form': { editable:1, above:1, toggle:!bw.ie&&!bw.linux }, - 'upload-form': { editable:1, toggle:!bw.ie&&!bw.linux } + 'folder-selector': { iconized:1 } }; var me = this; var mailviewsplit; var compose_headers = {}; var prefs; - var focused_popup; - var popup_keyboard_active = false; // export public methods this.set = setenv; @@ -358,56 +353,12 @@ function rcube_mail_ui() screen.css('min-width', $('.toolbar').width() + $('#quicksearchbar').width() + $('#searchfilter').width() + 30); } - $(document.body) - .bind('mouseup', body_mouseup) - .bind('keydown', popup_keypress); - - $('iframe').load(function(e){ - // this = iframe - try { - var doc = this.contentDocument ? this.contentDocument : this.contentWindow ? this.contentWindow.document : null; - $(doc).mouseup(body_mouseup); - } - catch (e) { - // catch possible "Permission denied" error in IE - }; - }) - .contents().mouseup(body_mouseup); - // don't use $(window).resize() due to some unwanted side-effects window.onresize = resize; resize(); } /** - * Handler for mouse-up events on the document body. - * This will close all open popup menus - */ - function body_mouseup(e) - { - var config, obj, target = e.target; - - if (target.className == 'inner') - target = e.target.parentNode; - - for (var id in popups) { - obj = popups[id]; - config = popupconfig[id]; - if (obj.is(':visible') - && target.id != id+'link' - && target != obj.get(0) // check if scroll bar was clicked (#1489832) - && !config.toggle - && (!config.editable || !target_overlaps(target, obj.get(0))) - && (!config.sticky || !rcube_mouse_is_over(e, obj.get(0))) - && !$(target).is('.folder-selector-link') - ) { - var myid = id+''; - window.setTimeout(function() { show_popupmenu(myid, false); }, 10); - } - } - } - - /** * Update UI on window resize */ function resize(e) @@ -600,145 +551,33 @@ function rcube_mail_ui() */ function toggle_popup(popup, e, config) { - show_popup(popup, undefined, config, rcube_event.is_keyboard(e)); - } - - /** - * (Deprecated) trigger for popup menus - */ - function show_popup(popup, show, config, keyboard) - { // auto-register menu object if (config || !popupconfig[popup]) add_popup(popup, config); - var visible = show_popupmenu(popup, show, keyboard), - config = popupconfig[popup]; - if (typeof config.callback == 'function') - config.callback(visible); + return rcmail.command('menu-open', popup, e.target, e); } /** - * Show/hide a specific popup menu + * (Deprecated) trigger for popup menus */ - function show_popupmenu(popup, show, keyboard) + function show_popup(popup, show, config) { - var obj = popups[popup], - config = popupconfig[popup], - ref = $(config.link ? config.link : '#'+popup+'link'), - above = config.above; - - if (!obj) { - obj = popups[popup] = $('#'+popup); - obj.appendTo(document.body); // move them to top for proper absolute positioning - } - - if (!obj || !obj.length) - return false; - - if (typeof show == 'undefined') - show = obj.is(':visible') ? false : true; - else if (config.toggle && show && obj.is(':visible')) - show = false; - - if (show && ref.length) { - var parent = ref.parent(), - win = $(window), - pos; - - if (parent.hasClass('dropbutton')) - ref = parent; + // auto-register menu object + if (config || !popupconfig[popup]) + add_popup(popup, config); + config = popupconfig[popup] || {}; + var ref = $(config.link ? config.link : '#'+popup+'link'), pos = ref.offset(); - ref.offsetHeight = ref.outerHeight(); - if (!above && pos.top + ref.offsetHeight + obj.height() > win.height()) - above = true; - if (pos.left + obj.width() > win.width()) - pos.left = win.width() - obj.width() - 12; - - obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) }); - } - else if (!show && keyboard && ref.length) { - ref.focus(); - } - - obj[show?'show':'hide']().attr('aria-hidden', show?'false':'true'); - - popup_keyboard_active = show && keyboard; - if (popup_keyboard_active) { - focused_popup = popup; - obj.find('a,input:not(:disabled)').not('[aria-disabled=true]').first().focus(); - } - else { - focused_popup = null; - } - - return show; - } - - /** - * Handler for keyboard events on active popups - */ - function popup_keypress(e) - { - var target = e.target || {}, - keyCode = rcube_event.get_keycode(e); - - if (e.keyCode != 27 && (!popup_keyboard_active || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT')) - return true; - - switch (keyCode) { - case 38: - case 40: - case 63232: // "up", in safari keypress - case 63233: // "down", in safari keypress - popup_focus_item(mod = keyCode == 38 || keyCode == 63232 ? -1 : 1); - break; - - case 9: // tab - if (focused_popup) { - var mod = rcube_event.get_modifier(e); - if (!popup_focus_item(mod == SHIFT_KEY ? -1 : 1)) { - show_popup(focused_popup, false, undefined, true); - } - } - return rcube_event.cancel(e); - - case 27: // esc - for (var id in popups) { - if (popups[id].is(':visible')) - show_popup(id, false, undefined, true); - } - break; - } - - return true; - } - - /** - * Helper method to move focus to the next/prev popup menu item - */ - function popup_focus_item(dir) - { - var obj, mod = dir < 0 ? 'prevAll' : 'nextAll', limit = dir < 0 ? 'last' : 'first'; - if (focused_popup && (obj = popups[focused_popup])) { - return obj.find(':focus').closest('li')[mod](':has(:not([aria-disabled=true]))').find('a,input')[limit]().focus().length; - } - - return 0; - } - - /** - * - */ - function target_overlaps(target, elem) - { - while (target.parentNode) { - if (target.parentNode == elem) - return true; - target = target.parentNode; - } - return false; + if (ref.has('.inner')) + ref = ref.children('.inner'); + + // fire command with simulated mouse click event + return rcmail.command('menu-open', + { menu:popup, show:show }, + ref.get(0), + $.Event('click', { target:ref.get(0), pageX:pos.left, pageY:pos.top, clientX:pos.left, clientY:pos.top })); } @@ -824,14 +663,51 @@ function rcube_mail_ui() } - /**** popup callbacks ****/ + /**** popup menu callbacks ****/ + /** + * Handler for menu-open and menu-close events + */ function menu_toggle(p) { - if (p && p.props && p.props.menu == 'attachmentmenu') - show_popupmenu('attachmentmenu', undefined, rcube_event.is_keyboard(p.originalEvent)); - else + if (p && p.name == 'messagelistmenu') { show_listoptions(p); + } + else if (p) { + // adjust menu position according to config + var config = popupconfig[p.name] || {}, + ref = $(config.link || '#'+p.name+'link'), + visible = p.obj && p.obj.is(':visible'), + above = config.above; + + // fix position according to config + if (p.obj && visible && ref.length) { + var parent = ref.parent(), + win = $(window), pos; + + if (parent.hasClass('dropbutton')) + ref = parent; + + if (config.above || ref.hasClass('dropbutton')) { + pos = ref.offset(); + p.obj.css({ left:pos.left+'px', top:(pos.top + (config.above ? -p.obj.height() : ref.outerHeight()))+'px' }); + } + } + + // add the right classes + if (p.obj && config.iconized) { + p.obj.children('ul').addClass('iconized'); + } + + // apply some data-attributes from menu config + if (p.obj && config.editable) + p.obj.attr('data-editable', 'true'); + + // trigger callback function + if (typeof config.callback == 'function') { + config.callback(visible, p); + } + } } function searchmenu(show) @@ -884,12 +760,11 @@ function rcube_mail_ui() rcmail.command('menu-open', {menu: 'attachmentmenu', id: id}, elem, event); } - function spellmenu(show) + function spellmenu(show, p) { var k, link, li, lang = rcmail.spellcheck_lang(), - menu = popups.spellmenu, - ul = $('ul', menu); + ul = $('ul', p.obj); if (!ul.length) { ul = $('<ul class="toolbarmenu selectable" role="menu">'); @@ -901,7 +776,7 @@ function rcube_mail_ui() .bind('click keypress', function(e) { if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) { rcmail.spellcheck_lang_set($(this).data('lang')); - show_popupmenu('spellmenu', false, rcube_event.is_keyboard(e)) + rcmail.hide_menu('spellmenu', e); return false; } }); @@ -910,7 +785,7 @@ function rcube_mail_ui() li.appendTo(ul); } - ul.appendTo(menu); + ul.appendTo(p.obj); } // select current language |