X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=skins%2Fdefault%2Ffunctions.js;h=8482e375a8af082b7dd39f02738c53e4613fa927;hb=76507f7c63a660742e76889ad6e3919f3dde3bb0;hp=9e71f6f9a0e9b677c0d80564d758505d091c747a;hpb=3adad46e27086084a8b28a32fc4fbc953dbfef6c;p=roundcube.git diff --git a/skins/default/functions.js b/skins/default/functions.js index 9e71f6f..8482e37 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,96 +8,535 @@ 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').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 = $('#'+id), + fs = content.children('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), 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 fs = $('#'+id).children('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() +{ + this.popups = { + markmenu: {id:'markmessagemenu'}, + replyallmenu: {id:'replyallmenu'}, + forwardmenu: {id:'forwardmenu', editable:1}, + 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, overlap:1}, + // toggle: #1486823, #1486930 + uploadmenu: {id:'attachment-form', editable:1, above:1, toggle:!bw.ie&&!bw.linux }, + uploadform: {id:'upload-form', editable:1, toggle:!bw.ie&&!bw.linux } + }; + + 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]; + } + } +} + +rcube_mail_ui.prototype = { + +show_popup: function(popup, show, config) +{ + var obj; + // auto-register menu object + if (!this.popups[popup] && (obj = $('#'+popup)) && obj.length) + this.popups[popup] = $.extend(config, {id: popup, obj: obj}); + + 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(), + win = $(window), + pos = parent.hasClass('dropbutton') ? parent.offset() : $(ref).offset(); + + 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() - 30; + + obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) }); + } + + obj[show?'show':'hide'](); + + if (bw.ie6 && this.popups[popup].overlap) { + $('select').css('visibility', show?'hidden':'inherit'); + $('select', obj).css('visibility', 'inherit'); + } +}, + +dragmessagemenu: function(show) +{ + this.popups.dragmessagemenu.obj[show?'show':'hide'](); +}, + +forwardmenu: function(show) +{ + $("input[name='forwardtype'][value="+(rcmail.env.forward_attachment ? 1 : 0)+"]", this.popups.forwardmenu.obj) + .prop('checked', true); + this.show_popupmenu('forwardmenu', show); +}, + +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)}); + + if (rcmail.env.search_mods) { + var n, all, + list = $('input:checkbox[name="s_mods[]"]', obj), + mbox = rcmail.env.mailbox, + mods = rcmail.env.search_mods; + + if (rcmail.env.task == 'mail') { + mods = mods[mbox] ? mods[mbox] : mods['*']; + all = 'text'; + } + else { + all = '*'; + } + + if (mods[all]) + list.map(function() { + this.checked = true; + this.disabled = this.value != all; + }); + else { + list.prop('disabled', false).prop('checked', false); + for (n in mods) + $('#s_mod_' + n).prop('checked', true); + } + } + } + obj[show?'show':'hide'](); +}, + +set_searchmod: function(elem) +{ + var all, m, task = rcmail.env.task, + mods = rcmail.env.search_mods, + mbox = rcmail.env.mailbox; + + if (!mods) + mods = {}; + + if (task == 'mail') { + if (!mods[mbox]) + mods[mbox] = rcube_clone_object(mods['*']); + m = mods[mbox]; + all = 'text'; + } + else { //addressbook + m = mods; + all = '*'; + } + + if (!elem.checked) + delete(m[elem.value]); + else + m[elem.value] = 1; + + // mark all fields + if (elem.value != all) + return; + + $('input:checkbox[name="s_mods[]"]').map(function() { + if (this == elem) + return; + + this.checked = true; + if (elem.checked) { + this.disabled = true; + delete m[this.value]; + } + else { + this.disabled = false; + m[this.value] = 1; + } + }); +}, + +listmenu: function(show) +{ + var obj = this.popups.listmenu.obj, + ref = rcube_find_object('listmenulink'); + + if (typeof show == 'undefined') + show = obj.is(':visible') ? false : true; + + if (show && ref) { + var pos = $(ref).offset(), + menuwidth = obj.width(), + pagewidth = $(document).width(); + + if (pagewidth - pos.left < menuwidth && pos.left > menuwidth) + pos.left = pos.left - menuwidth; + + obj.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)}); + // set form values + $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop('checked', true); + $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC'); + $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC'); + $('input[name="view"][value="thread"]').prop('checked', rcmail.env.threading ? true : false); + $('input[name="view"][value="list"]').prop('checked', rcmail.env.threading ? false : true); + // list columns + var found, 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('rcmail_ui.show_popup("'+i+'",false);', 50); + } + } +}, + +target_overlaps: function (target, elementid) { - var link, row, parent, ns, ps; - - link = document.getElementById(id + '-link'); - parent = link.parentNode; + var element = rcube_find_object(elementid); + while (target.parentNode) { + if (target.parentNode == element) + return true; + target = target.parentNode; + } + return false; +}, + +body_keydown: function(evt, p) +{ + 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); + } + } +}, + +switch_preview_pane: function(elem) +{ + 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.command('save-pref', {name: 'preview_pane', value: (elem.checked?1:0)}); +}, + +/* Message composing */ +init_compose_form: function() +{ + var f, field, fields = ['cc', 'bcc', 'replyto', 'followupto'], + div = document.getElementById('compose-div'), + headers_div = document.getElementById('compose-headers-div'); + + // Show input elements with non-empty value + for (f=0; f li a, #mailboxlist ul:visible > li a'); -body_mouseup: function(evt, p) -{ - if (this.markmenu && this.markmenu.visible && rcube_event.get_target(evt) != rcube_find_object('markreadbutton')) - this.show_markmenu(false); -}, + // it's too slow with really big number of folders, especially on IE + if (list.length > 500 * (bw.ie ? 0.2 : 1)) + return; -body_keypress: function(evt, p) -{ - if (rcube_event.get_keycode(evt) == 27 && this.markmenu && this.markmenu.visible) - this.show_markmenu(false); -} + list.each(function(){ + var elem = $(this), + text = elem.data('text'); -}; + if (!text) { + text = elem.text().replace(/\s+\(.+$/, ''); + elem.data('text', text); + } + if (text.length < 6) + return; -var rcmail_ui; + var abbrev = fit_string_to_size(text, elem, elem.width() - elem.children('span.unreadcount').width()); + if (abbrev != text) + elem.attr('title', text); + elem.contents().filter(function(){ return (this.nodeType == 3); }).get(0).data = abbrev; + }); +} -function rcube_init_mail_ui() +// inspired by https://gist.github.com/24261/7fdb113f1e26111bd78c0c6fe515f6c0bf418af5 +function fit_string_to_size(str, elem, len) { - rcmail_ui = new rcube_mail_ui(); - rcube_event.add_listener({ object:rcmail_ui, method:'body_mouseup', event:'mouseup' }); - rcube_event.add_listener({ object:rcmail_ui, method:'body_keypress', event:'keypress' }); + var w, span, result = str, ellip = '...'; + + if (!rcmail.env.tmp_span) { + // it should be appended to elem to use the same css style + // but for performance reasons we'll append it to body (once) + span = $('').css({visibility: 'hidden', padding: '0px'}) + .appendTo($('body', document)).get(0); + rcmail.env.tmp_span = span; + } + else { + span = rcmail.env.tmp_span; + } + span.innerHTML = result; + + // on first run, check if string fits into the length already. + w = span.offsetWidth; + if (w > len) { + var cut = Math.max(1, Math.floor(str.length * ((w - len) / w) / 2)), + mid = Math.floor(str.length / 2), + offLeft = mid, + offRight = mid; + + while (true) { + offLeft = mid - cut; + offRight = mid + cut; + span.innerHTML = str.substring(0,offLeft) + ellip + str.substring(offRight); + + // break loop if string fits size + if (offLeft < 3 || span.offsetWidth) + break; + + cut++; + } + + // build resulting string + result = str.substring(0,offLeft) + ellip + str.substring(offRight); + } + + return result; } + +// Optional parameters used by TinyMCE +var rcmail_editor_settings = { + skin : "default", // "default", "o2k7" + skin_variant : "" // "", "silver", "black" +};