X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=skins%2Fdefault%2Ffunctions.js;h=3e06a54d4e5f96a58094968c31b7b6110997e983;hb=315a64971ff1249e4d5884f309fab5ddbfe55cc6;hp=9e71f6f9a0e9b677c0d80564d758505d091c747a;hpb=3adad46e27086084a8b28a32fc4fbc953dbfef6c;p=roundcube.git diff --git a/skins/default/functions.js b/skins/default/functions.js index 9e71f6f..3e06a54 100644 --- a/skins/default/functions.js +++ b/skins/default/functions.js @@ -1,5 +1,5 @@ /** - * RoundCube functions for default skin interface + * Roundcube functions for default skin interface */ /** @@ -8,162 +8,505 @@ function rcube_init_settings_tabs() { + var tab = '#settingstabdefault'; if (window.rcmail && rcmail.env.action) - { - var action = rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action); - var tab = document.getElementById('settingstab'+action); - } - else - var tab = document.getElementById('settingstabdefault'); - - if (tab) - tab.className = 'tablink-selected'; + tab = '#settingstab' + (rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action.replace(/\./g, ''))); + + $(tab).addClass('tablink-selected'); + $(tab + '> a').removeAttr('onclick').unbind('click').bind('click', function(){return false;}); } function rcube_show_advanced(visible) { - var rows = document.getElementsByTagName('TR'); - for(var i=0; i inside page element (id) +function rcube_init_tabs(id, current) +{ + var content = document.getElementById(id), + // get fieldsets of the higher-level (skip nested fieldsets) + fs = $('fieldset', content).not('fieldset > fieldset'); + + if (!fs.length) + return; + + current = current ? current : 0; + + // first hide not selected tabs + fs.each(function(idx) { if (idx != current) $(this).hide(); }); + + // create tabs container + var tabs = $('
').addClass('tabsbar').appendTo($(content)); + + // convert fildsets into tabs + fs.each(function(idx) { + var tab, a, elm = $(this), + // get first legend element + legend = $(elm).children('legend'); + + // create a tab + a = $('').text(legend.text()).attr('href', '#'); + tab = $('').attr({'id': 'tab'+idx, 'class': 'tablink'}) + .click(function() { rcube_show_tab(id, idx); return false }) + + // remove legend + legend.remove(); + // style fieldset + elm.addClass('tabbed'); + // style selected tab + if (idx == current) + tab.addClass('tablink-selected'); + + // add the tab to container + tab.append(a).appendTo(tabs); + }); +} + +function rcube_show_tab(id, index) +{ + var content = document.getElementById(id), + fs = $('fieldset', content).not('fieldset > fieldset'); + + fs.each(function(idx) { + // Show/hide fieldset (tab content) + $(this)[index==idx ? 'show' : 'hide'](); + // Select/unselect tab + $('#tab'+idx).toggleClass('tablink-selected', idx==index); + }); } /** - * Mail Composing + * Mail UI */ -function rcmail_show_header_form(id) +function rcube_mail_ui() { - var link, row, parent, ns, ps; - - link = document.getElementById(id + '-link'); - parent = link.parentNode; + this.popups = { + markmenu: {id:'markmessagemenu'}, + replyallmenu: {id:'replyallmenu'}, + searchmenu: {id:'searchmenu', editable:1}, + messagemenu: {id:'messagemenu'}, + listmenu: {id:'listmenu', editable:1}, + dragmessagemenu:{id:'dragmessagemenu', sticky:1}, + groupmenu: {id:'groupoptionsmenu', above:1}, + mailboxmenu: {id:'mailboxoptionsmenu', above:1}, + composemenu: {id:'composeoptionsmenu', editable:1}, + // toggle: #1486823, #1486930 + uploadmenu: {id:'attachment-form', editable:1, above:1, toggle:!bw.ie&&!bw.linux } + }; - if ((ns = rcmail_next_sibling(link))) - ns.style.display = 'none'; - else if ((ps = rcmail_prev_sibling(link))) - ps.style.display = 'none'; - - link.style.display = 'none'; + var obj; + for (var k in this.popups) { + obj = $('#'+this.popups[k].id) + if (obj.length) + this.popups[k].obj = obj; + else { + delete this.popups[k]; + } + } +} - if (row = document.getElementById('compose-' + id)) - { - var div = document.getElementById('compose-div'); - var headers_div = document.getElementById('compose-headers-div'); - row.style.display = (document.all && !window.opera) ? 'block' : 'table-row'; - div.style.top = (parseInt(headers_div.offsetHeight)) + 'px'; +rcube_mail_ui.prototype = { + +show_popup: function(popup, show) +{ + if (typeof this[popup] == 'function') + return this[popup](show); + else + return this.show_popupmenu(popup, show); +}, + +show_popupmenu: function(popup, show) +{ + var obj = this.popups[popup].obj, + above = this.popups[popup].above, + ref = rcube_find_object(popup+'link'); + + if (typeof show == 'undefined') + show = obj.is(':visible') ? false : true; + else if (this.popups[popup].toggle && show && this.popups[popup].obj.is(':visible') ) + show = false; + + if (show && ref) { + var parent = $(ref).parent(), + pos = parent.hasClass('dropbutton') ? parent.offset() : $(ref).offset(); + + if (!above && pos.top + ref.offsetHeight + obj.height() > window.innerHeight) + above = true; + + obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) }); + } + + obj[show?'show':'hide'](); +}, + +dragmessagemenu: function(show) +{ + this.popups.dragmessagemenu.obj[show?'show':'hide'](); +}, + +uploadmenu: function(show) +{ + if (typeof show == 'object') // called as event handler + show = false; + + // clear upload form + if (!show) { + try { $('#attachment-form form')[0].reset(); } + catch(e){} // ignore errors + } + + this.show_popupmenu('uploadmenu', show); + + if (!document.all && this.popups.uploadmenu.obj.is(':visible')) + $('#attachment-form input[type=file]').click(); +}, + +searchmenu: function(show) +{ + var obj = this.popups.searchmenu.obj, + ref = rcube_find_object('searchmenulink'); + + if (typeof show == 'undefined') + show = obj.is(':visible') ? false : true; + + if (show && ref) { + var pos = $(ref).offset(); + obj.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)}) + .find(':checked').attr('checked', false); + + if (rcmail.env.search_mods) { + var search_mods = rcmail.env.search_mods[rcmail.env.mailbox] ? rcmail.env.search_mods[rcmail.env.mailbox] : rcmail.env.search_mods['*']; + for (var n in search_mods) + $('#s_mod_' + n).attr('checked', true); } + } + obj[show?'show':'hide'](); +}, - return false; -} +set_searchmod: function(elem) +{ + if (!rcmail.env.search_mods) + rcmail.env.search_mods = {}; + + if (!rcmail.env.search_mods[rcmail.env.mailbox]) + rcmail.env.search_mods[rcmail.env.mailbox] = rcube_clone_object(rcmail.env.search_mods['*']); + + if (!elem.checked) + delete(rcmail.env.search_mods[rcmail.env.mailbox][elem.value]); + else + rcmail.env.search_mods[rcmail.env.mailbox][elem.value] = elem.value; +}, -function rcmail_hide_header_form(id) +listmenu: function(show) { - var row, parent, ns, ps, link, links; + var obj = this.popups.listmenu.obj, + ref = rcube_find_object('listmenulink'); - link = document.getElementById(id + '-link'); - link.style.display = ''; - - parent = link.parentNode; - links = parent.getElementsByTagName('A'); + if (typeof show == 'undefined') + show = obj.is(':visible') ? false : true; - for (var i=0; i menuwidth) + pos.left = pos.left - menuwidth; - if (row = document.getElementById('compose-' + id)) - { - var div = document.getElementById('compose-div'); - var headers_div = document.getElementById('compose-headers-div'); - row.style.display = 'none'; - div.style.top = (parseInt(headers_div.offsetHeight)) + 'px'; + obj.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)}); + // set form values + $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').attr('checked', 1); + $('input[name="sort_ord"][value="DESC"]').attr('checked', rcmail.env.sort_order=='DESC' ? 1 : 0); + $('input[name="sort_ord"][value="ASC"]').attr('checked', rcmail.env.sort_order=='DESC' ? 0 : 1); + $('input[name="view"][value="thread"]').attr('checked', rcmail.env.threading ? 1 : 0); + $('input[name="view"][value="list"]').attr('checked', rcmail.env.threading ? 0 : 1); + // list columns + var cols = $('input[name="list_col[]"]'); + for (var i=0; i maxheight) { + maxheight = height; + } + }); + $('#listmenu fieldset').css("min-height", maxheight+"px") + // IE6 complains if you set this attribute using either method: + //$('#listmenu fieldset').css({'height':'auto !important'}); + //$('#listmenu fieldset').css("height","auto !important"); + .height(maxheight); + }; +}, + +open_listmenu: function(e) +{ + this.listmenu(); +}, + +save_listmenu: function() +{ + this.listmenu(); + + var sort = $('input[name="sort_col"]:checked').val(), + ord = $('input[name="sort_ord"]:checked').val(), + thread = $('input[name="view"]:checked').val(), + cols = $('input[name="list_col[]"]:checked') + .map(function(){ return this.value; }).get(); + + rcmail.set_list_options(cols, sort, ord, thread == 'thread' ? 1 : 0); +}, + +body_mouseup: function(evt, p) +{ + var i, target = rcube_event.get_target(evt); + + for (i in this.popups) { + if (this.popups[i].obj.is(':visible') && target != rcube_find_object(i+'link') + && !this.popups[i].toggle + && (!this.popups[i].editable || !this.target_overlaps(target, this.popups[i].id)) + && (!this.popups[i].sticky || !rcube_mouse_is_over(evt, rcube_find_object(this.popups[i].id))) + ) { + window.setTimeout('$("#'+this.popups[i].id+'").hide()', 50); } + } +}, +target_overlaps: function (target, elementid) +{ + var element = rcube_find_object(elementid); + while (target.parentNode) { + if (target.parentNode == element) + return true; + target = target.parentNode; + } return false; -} +}, -function rcmail_next_sibling(elm) +body_keydown: function(evt, p) { - var ns = elm.nextSibling; - while (ns && ns.nodeType == 3) - ns = ns.nextSibling; - return ns; -} + if (rcube_event.get_keycode(evt) == 27) { + for (var k in this.popups) { + if (this.popups[k].obj.is(':visible')) + this.show_popup(k, false); + } + } +}, -function rcmail_prev_sibling(elm) +switch_preview_pane: function(elem) { - var ps = elm.previousSibling; - while (ps && ps.nodeType == 3) - ps = ps.previousSibling; - return ps; -} + var uid, prev_frm = $('#mailpreviewframe'); + + if (elem.checked) { + rcmail.env.contentframe = 'messagecontframe'; + if (mailviewsplit.layer) { + mailviewsplit.resize(); + mailviewsplit.layer.elm.style.display = ''; + } + else + mailviewsplit.init(); + + if (bw.opera) { + $('#messagelistcontainer').css({height: ''}); + } + prev_frm.show(); + + if (uid = rcmail.message_list.get_single_selection()) + rcmail.show_message(uid, false, true); + } + else { + prev_frm.hide(); + if (bw.ie6 || bw.ie7) { + var fr = document.getElementById('mailcontframe'); + fr.style.bottom = 0; + fr.style.height = parseInt(fr.parentNode.offsetHeight)+'px'; + } + else { + $('#mailcontframe').css({height: 'auto', bottom: 0}); + if (bw.opera) + $('#messagelistcontainer').css({height: 'auto'}); + } + if (mailviewsplit.layer) + mailviewsplit.layer.elm.style.display = 'none'; + + rcmail.env.contentframe = null; + rcmail.show_contentframe(false); + } + rcmail.http_post('save-pref', '_name=preview_pane&_value='+(elem.checked?1:0)); +}, -function rcmail_init_compose_form() +/* Message composing */ +init_compose_form: function() { - var cc_field = document.getElementById('_cc'); - if (cc_field && cc_field.value!='') - rcmail_show_header_form('cc'); + var f, field, fields = ['cc', 'bcc', 'replyto', 'followupto'], + div = document.getElementById('compose-div'), + headers_div = document.getElementById('compose-headers-div'); - var bcc_field = document.getElementById('_bcc'); - if (bcc_field && bcc_field.value!='') - rcmail_show_header_form('bcc'); + // Show input elements with non-empty value + for (f=0; f