functions.min.js 19.9 KB
/**
 * Roundcube functions for default skin interface
 *
 * @licstart  The following is the entire license notice for the
 * JavaScript code in this file.
 *
 * Copyright (c) The Roundcube Dev Team
 *
 * The JavaScript code in this page is free software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * @licend  The above is the entire license notice
 * for the JavaScript code in this file.
 */
function rcube_init_settings_tabs(){var e,t=$("#tabsbar"),i=$("span",t).last(),n="#settingstabpreferences",s=window.rcmail&&rcmail.env.action?rcmail.env.action:null;i&&"settingstababout"!=i.attr("id")&&(e=$("#settingstababout"))&&(t=e.clone(!0),e.remove(),i.after(t)),s&&(n="#settingstab"+(0<s.indexOf("identity")?"identities":s.replace(/\./g,""))),$(n).addClass("tablink-selected"),$("a",n).removeAttr("onclick").click(function(){return!1})}function rcube_init_tabs(a,o){var l,e=$("#"+a),t=e.children("fieldset");t.length&&(o=o||0,(l=e.find(".tabsbar")).length||(l=$("<div>").addClass("tabsbar").appendTo(e)),t.each(function(e){var t,i,n=$(this),s=n.children("legend");n.is(":visible")&&!n.hasClass("tabbed")&&(i=$("<a>").text(s.text()).attr("href","#"),t=$("<span>").attr({id:"tab"+e,class:"tablink"}).click(function(){return rcube_show_tab(a,e),!1}),s.remove(),n.addClass("tabbed"),e==o&&t.addClass("tablink-selected"),t.append(i).appendTo(l))}),t.each(function(e){e!=o&&$(this).hide()}))}function rcube_show_tab(e,t){$("#"+e).children("fieldset").each(function(e){$(this)[t==e?"show":"hide"](),$("#tab"+e).toggleClass("tablink-selected",e==t)})}function rcube_mail_ui(){var e,t;for(t in this.popups={markmenu:{id:"markmessagemenu"},replyallmenu:{id:"replyallmenu"},forwardmenu:{id:"forwardmenu",editable:1},searchmenu:{id:"searchmenu",editable:1},messagemenu:{id:"messagemenu"},attachmentmenu:{id:"attachmentmenu"},dragmenu:{id:"dragmenu",sticky:1},groupmenu:{id:"groupoptionsmenu",above:1},mailboxmenu:{id:"mailboxoptionsmenu",above:1},composemenu:{id:"composeoptionsmenu",editable:1,overlap:1},spellmenu:{id:"spellmenu"},responsesmenu:{id:"responsesmenu"},uploadmenu:{id:"attachment-form",editable:1,above:1,toggle:!bw.ie&&!bw.linux},uploadform:{id:"upload-form",editable:1,toggle:!bw.ie&&!bw.linux}},this.popups)(e=$("#"+this.popups[t].id)).length?this.popups[t].obj=e:delete this.popups[t]}function rcube_layer(e,t){if(this.name=e,this.create=function(e){var t=e.x||0,i=e.y||0,n=e.width,s=e.height,a=e.zindex,o=e.vis,l=e.parent,e=document.createElement("DIV");e.id=this.name,e.style.position="absolute",e.style.visibility=o?2==o?"inherit":"visible":"hidden",e.style.left=t+"px",e.style.top=i+"px",n&&(e.style.width=n.toString().match(/\%$/)?n:n+"px"),s&&(e.style.height=s.toString().match(/\%$/)?s:s+"px"),a&&(e.style.zIndex=a),(l||document.body).appendChild(e),this.elm=e},null!=t?(this.create(t),this.name=this.elm.id):this.elm=document.getElementById(e),!this.elm)return!1;this.css=this.elm.style,this.event=this.elm,this.width=this.elm.offsetWidth,this.height=this.elm.offsetHeight,this.x=parseInt(this.elm.offsetLeft),this.y=parseInt(this.elm.offsetTop),this.visible="visible"==this.css.visibility||"show"==this.css.visibility||"inherit"==this.css.visibility,this.move=function(e,t){this.x=e,this.y=t,this.css.left=Math.round(this.x)+"px",this.css.top=Math.round(this.y)+"px"},this.resize=function(e,t){this.css.width=e+"px",this.css.height=t+"px",this.width=e,this.height=t},this.show=function(e){1==e?(this.css.visibility="visible",this.visible=!0):2==e?(this.css.visibility="inherit",this.visible=!0):(this.css.visibility="hidden",this.visible=!1)},this.write=function(e){this.elm.innerHTML=e}}function rcmail_scroller(e,t,i){var n=this;this.list=$(e),this.top=$(t),this.bottom=$(i),this.step_size=6,this.step_time=20,this.delay=500,this.top.mouseenter(function(){n.ts=window.setTimeout(function(){n.scroll("down")},n.delay)}).mouseout(function(){n.ts&&window.clearTimeout(n.ts)}),this.bottom.mouseenter(function(){n.ts=window.setTimeout(function(){n.scroll("up")},n.delay)}).mouseout(function(){n.ts&&window.clearTimeout(n.ts)}),this.scroll=function(e){var t=this,i=this.step_size;rcmail.drag_active&&("down"==e&&(i*=-1),this.list.get(0).scrollTop+=i,this.ts=window.setTimeout(function(){t.scroll(e)},this.step_time))}}function rcube_render_mailboxlist(){var e=$("#mailboxlist > li > a, #mailboxlist ul:visible > li > a");100<e.length||e.each(function(){var e,t=$(this),i=t.data("text");i||(i=t.text().replace(/\s+\([0-9]+\)$/,""),t.data("text",i)),i.length<6||((e=fit_string_to_size(i,t,t.width()-t.children("span.unreadcount").width()-16))!=i&&t.attr("title",i),t.contents().filter(function(){return 3==this.nodeType}).get(0).data=e)})}function fit_string_to_size(e,t,i){var n,s,a=e;if(rcmail.env.tmp_span?n=rcmail.env.tmp_span:(n=$("<b>").css({visibility:"hidden",padding:"0px","font-family":t.css("font-family"),"font-size":t.css("font-size")}).appendTo($("body",document)).get(0),rcmail.env.tmp_span=n),(s=$(n)).text(a),i<(t=n.offsetWidth)){for(var o=Math.max(1,Math.floor(e.length*((t-i)/t)/2)),l=Math.floor(e.length/2),r=l,c=l;;){if(c=l+o,s.text(e.substring(0,r=l-o)+"..."+e.substring(c)),r<3||n.offsetWidth)break;o++}a=e.substring(0,r)+"..."+e.substring(c)}return a}function update_quota(e){var t;percent_indicator(rcmail.gui_objects.quotadisplay,e),e.table&&((t=!(t=$("#quotamenu")).length?$('<div id="quotamenu" class="popupmenu">').appendTo($("body")):t).html(e.table),$("#quotaimg").css("cursor","pointer").off("click").on("click",function(e){return rcmail.command("menu-open","quotamenu",e.target,e)}))}function percent_indicator(e,t){if(!t||!e)return!1;var i=t.width||rcmail.env.indicator_width||100,n=t.height||rcmail.env.indicator_height||14,s=t.percent?Math.abs(parseInt(t.percent)):0,a=parseInt(s/100*i),o=$(e).position();o.top=Math.max(0,o.top),o.left=Math.max(0,o.left),rcmail.env.indicator_width=i,rcmail.env.indicator_height=n,i<a&&(a=i,s=100),t.title&&(t.title=rcmail.get_label("quota")+": "+t.title);var l=$("<div>");l.css({position:"absolute",top:o.top,left:o.left,width:i+"px",height:n+"px",zIndex:100,lineHeight:n+"px"}).attr("title",t.title).addClass("quota_text").html(s+"%");var r=$("<div>");r.css({position:"absolute",top:o.top+1,left:o.left+1,width:a+"px",height:n+"px",zIndex:99});a=$("<div>");a.css({position:"absolute",top:o.top+1,left:o.left+1,width:i+"px",height:n+"px",zIndex:98}).addClass("quota_bg"),80<=s?(l.addClass(" quota_text_high"),r.addClass("quota_high")):55<=s?(l.addClass(" quota_text_mid"),r.addClass("quota_mid")):(l.addClass(" quota_text_low"),r.addClass("quota_low")),$(e).html("").append(r).append(a).append(l),$("#quotaimg").attr("title",t.title)}function attachment_menu_append(e){$(e).is(".no-menu")||$(e).append($('<a class="drop"></a>').on("click keypress",function(e){if("keypress"!=e.type||13==e.which)return rcmail_ui.show_attachmentmenu(this,e),!1}))}rcube_mail_ui.prototype={show_popup:function(e,t,i){var n;return!this.popups[e]&&(n=$("#"+e))&&n.length&&(this.popups[e]=$.extend(i,{id:e,obj:n})),"function"==typeof this[e]?this[e](t):this.show_popupmenu(e,t)},show_popupmenu:function(e,t){var i,n=this.popups[e].obj,s=this.popups[e].above,a=$(this.popups[e].link||rcube_find_object(e+"link"));void 0===t?t=!n.is(":visible"):this.popups[e].toggle&&t&&this.popups[e].obj.is(":visible")&&(t=!1),t&&a.length&&(i=a.parent(),e=$(window),i=(i.hasClass("dropbutton")?i:a).offset(),!s&&i.top+a.height()+n.height()>e.height()&&(s=!0),i.left+n.width()>e.width()&&(i.left=e.width()-n.width()-30),n.css({left:i.left,top:i.top+(s?-n.height():a.height())})),n[t?"show":"hide"]()},dragmenu:function(e){this.popups.dragmenu.obj[e?"show":"hide"]()},forwardmenu:function(e){$("input[name='forwardtype'][value="+(rcmail.env.forward_attachment?1:0)+"]",this.popups.forwardmenu.obj).prop("checked",!0),this.show_popupmenu("forwardmenu",e)},uploadmenu:function(e){if(!(e="object"==typeof e?!1:e))try{$("#attachment-form form")[0].reset()}catch(e){}rcmail.mailvelope_editor||(this.show_popupmenu("uploadmenu",e),!document.all&&this.popups.uploadmenu.obj.is(":visible")&&$("#attachment-form input[type=file]").click())},searchmenu:function(e){var t=this.popups.searchmenu.obj,i=rcube_find_object("searchmenulink");if((e=void 0===e?!t.is(":visible"):e)&&i){var n=$(i).offset();if(t.css({left:n.left,top:n.top+i.offsetHeight+2}),rcmail.env.search_mods){var s,a,o=$('input:checkbox[name="s_mods[]"]',t),l=rcmail.env.mailbox,n=rcmail.env.search_mods,i=rcmail.env.search_scope||"base";if("mail"==rcmail.env.task?(n=n[l]||n["*"],a="text",$('input:radio[name="s_scope"]').prop("checked",!1).filter("#s_scope_"+i).prop("checked",!0)):a="*",n[a])o.map(function(){this.checked=!0,this.disabled=this.value!=a});else for(s in o.prop("disabled",!1).prop("checked",!1),n)$("#s_mod_"+s).prop("checked",!0)}}t[e?"show":"hide"]()},set_searchmod:function(e){var t,i=rcmail.env.task,n=rcmail.env.search_mods||{},s=rcmail.env.mailbox,n=($('input[name="s_scope"]:checked').val(),"mail"==i?(n[s]||(n[s]=rcube_clone_object(n["*"])),t=n[s],"text"):(t=n,"*"));e.checked?t[e.value]=1:delete t[e.value],e.value==n&&$('input:checkbox[name="s_mods[]"]').not(e).map(function(){this.checked=!0,e.checked?(this.disabled=!0,delete t[this.value]):(this.disabled=!1,t[this.value]=1)}),rcmail.set_searchmods(t)},show_listmenu:function(e){var t=this,i={},n=$("#listmenu");n.is(":visible")?n.dialog("close",e.originalEvent):($('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop("checked",!0),$('input[name="sort_ord"][value="DESC"]').prop("checked","DESC"==rcmail.env.sort_order),$('input[name="sort_ord"][value="ASC"]').prop("checked","DESC"!=rcmail.env.sort_order),$('input[name="view"][value="thread"]').prop("checked",!!rcmail.env.threading),$('input[name="view"][value="list"]').prop("checked",!rcmail.env.threading),$('input[name="list_col[]"]').each(function(){$(this).prop("checked",-1!=$.inArray(this.value,rcmail.env.listcols))}),$.each(["widescreen","desktop","list"],function(){$('input[name="layout"][value="'+this+'"]').prop("checked",rcmail.env.layout==this)}),$("#listoptions-columns",n)["widescreen"==rcmail.env.layout?"hide":"show"](),i[rcmail.gettext("save")]=function(e){n.dialog("close",e),t.save_listmenu()},n.dialog({modal:!0,resizable:!1,closeOnEscape:!0,title:null,open:function(e){var t=0;$("#listmenu fieldset").each(function(){var e=$(this).height();t<e&&(t=e)}).css("min-height",t+"px").height(t),setTimeout(function(){n.find("a, input:not(:disabled)").not("[aria-disabled=true]").first().focus()},100)},close:function(e){n.dialog("destroy").hide(),e.originalEvent&&rcube_event.is_keyboard(e.originalEvent)&&$("#listmenulink").focus()},buttons:i,minWidth:500,width:n.width()+20}).show())},save_listmenu:function(){var e=$('input[name="sort_col"]:checked').val(),t=$('input[name="sort_ord"]:checked').val(),i=$('input[name="view"]:checked').val(),n=$('input[name="layout"]:checked').val(),s=$('input[name="list_col[]"]:checked').map(function(){return this.value}).get();rcmail.set_list_options(s,e,t,"thread"==i?1:0,n)},spellmenu:function(e){var t,n=rcmail.spellcheck_lang(),s=this.popups.spellmenu.obj,a=$("ul",s);if(!a.length){for(i in a=$("<ul>"),rcmail.env.spell_langs)t=$("<li>"),$('<a href="#"></a>').text(rcmail.env.spell_langs[i]).addClass("active").data("lang",i).click(function(){rcmail.spellcheck_lang_set($(this).data("lang"))}).appendTo(t),t.appendTo(a);a.appendTo(s)}$("li",a).each(function(){var e=$("a",this);e.data("lang")==n?e.addClass("selected"):e.hasClass("selected")&&e.removeClass("selected")}),this.show_popupmenu("spellmenu",e)},show_attachmentmenu:function(e,t){var i=e.parentNode.id.replace(/^attach/,"");$.each(["open","download","rename"],function(){var t=this;$("#attachmenu"+t).off("click").attr("onclick","").click(function(e){return rcmail.command(t+"-attachment",i,this)})}),this.popups.attachmentmenu.link=e,rcmail.command("menu-open",{menu:"attachmentmenu",id:i},e,t)},menu_open:function(e){e&&"messagelistmenu"==e.name&&this.show_listmenu()},body_mouseup:function(i){var n=i.target;ref=this,$.each(this.popups,function(e,t){!t.obj.is(":visible")||n==rcube_find_object(e+"link")||t.toggle||n==t.obj.get(0)||t.editable&&ref.target_overlaps(n,t.id)||t.sticky&&rcube_mouse_is_over(i,rcube_find_object(t.id))||$(n).is(".folder-selector-link")||$(n).children(".folder-selector-link").length||window.setTimeout('rcmail_ui.show_popup("'+e+'",false);',50)})},target_overlaps:function(e,t){for(var i=rcube_find_object(t);e.parentNode;){if(e.parentNode==i)return!0;e=e.parentNode}return!1},body_keydown:function(e){if(27==e.keyCode)for(var t in this.popups)this.popups[t].obj.is(":visible")&&this.show_popup(t,!1)},set_layout:function(e){var t=e?e.new_layout:rcmail.env.layout,i=$("#mailcontframe"),n=$("#mailpreviewframe");e&&$("#mailrightcontainer").removeClass().addClass(t),this.mailviewsplitv||(this.mailviewsplitv=new rcube_splitter({id:"mailviewsplitterv",p1:"mailleftcontainer",p2:"mailrightcontainer",orientation:"v",relative:!0,start:165,callback:rcube_render_mailboxlist}),this.mailviewsplitv.init()),$("#mailviewsplitter")["desktop"==t?"show":"hide"](),$("#mailviewsplitter2")["widescreen"==t?"show":"hide"](),$("#mailpreviewframe")["list"!=t?"show":"hide"](),rcmail.env.contentframe="list"==t?null:"messagecontframe","widescreen"==t?($("#countcontrols").detach().appendTo($("#messagelistheader")),i.css({height:"auto",width:400}),n.css({top:0,left:410,height:"auto"}).show(),this.mailviewsplit2?this.mailviewsplit2.resize():(this.mailviewsplit2=new rcube_splitter({id:"mailviewsplitter2",p1:"mailcontframe",p2:"mailpreviewframe",orientation:"v",relative:!0,start:405}),this.mailviewsplit2.init())):"desktop"==t?(i.css({height:200,width:"100%"}),n.css({left:0,top:210,height:"auto"}).show(),this.mailviewsplit?this.mailviewsplit.resize():(this.mailviewsplit=new rcube_splitter({id:"mailviewsplitter",p1:"mailcontframe",p2:"mailpreviewframe",orientation:"h",relative:!0,start:205}),this.mailviewsplit.init())):(i.css({height:"auto",width:"100%"}),n.hide()),e&&"widescreen"==e.old_layout&&$("#countcontrols").detach().appendTo($("#messagelistfooter"))},init_compose_form:function(){for(var e,t,i=["cc","bcc","replyto","followupto"],n=document.getElementById("compose-div"),s=document.getElementById("compose-headers-div"),a=0;a<i.length;a++)e=i[a],(t=$("#_"+e)).length&&(t.on("change",{v:e},function(e){this.value&&rcmail_ui.show_header_form(e.data.v)}),""!=t.val()&&rcmail_ui.show_header_form(e));bw.ie&&(rcube_find_object("form").onkeydown=function(e){27==rcube_event.get_keycode(e)&&rcube_event.cancel(e)}),$(window).resize(function(){rcmail_ui.resize_compose_body()}),$("#compose-container").resize(function(){rcmail_ui.resize_compose_body()}),n.style.top=parseInt(s.offsetHeight,10)+3+"px",$(window).resize(),$("#contacts-table").css("top",$("#directorylist").height()+24+"px"),$("#quicksearchbox").keydown(function(e){13==rcube_event.get_keycode(e)&&rcmail.command("search")})},resize_compose_body:function(){var e=$("#compose-div .boxlistcontent"),t=e.width()-6,i=e.height()-2,e=bw.ie||bw.opera?4:0;$("#compose-body_ifr").width(6+t).height(i-1-$("div.tox-toolbar").height()),$("#compose-body").width(t-e).height(i),$("#googie_edit_layer").width(t).height(i)},resize_compose_body_ev:function(){window.setTimeout(function(){rcmail_ui.resize_compose_body()},100)},show_header_form:function(e){var t,i=document.getElementById(e+"-link");return((t=this.next_sibling(i))||(t=this.prev_sibling(i)))&&(t.style.display="none"),i.style.display="none",(t=document.getElementById("compose-"+e))&&(i=document.getElementById("compose-div"),e=document.getElementById("compose-headers-div"),$(t).show(),i.style.top=parseInt(e.offsetHeight,10)+3+"px",this.resize_compose_body()),!1},hide_header_form:function(e){var t,i,n=document.getElementById(e+"-link"),s=n.parentNode.getElementsByTagName("a");n.style.display="";for(var a=0;a<s.length;a++)if("none"!=s[a].style.display)for(var o=a+1;o<s.length;o++)if("none"!=s[o].style.display&&(i=this.next_sibling(s[a]))){i.style.display="";break}return document.getElementById("_"+e).value="",(t=document.getElementById("compose-"+e))&&(n=document.getElementById("compose-div"),e=document.getElementById("compose-headers-div"),t.style.display="none",n.style.top=parseInt(e.offsetHeight,10)+1+"px",this.resize_compose_body()),!1},next_sibling:function(e){for(var t=e.nextSibling;t&&3==t.nodeType;)t=t.nextSibling;return t},prev_sibling:function(e){for(var t=e.previousSibling;t&&3==t.nodeType;)t=t.previousSibling;return t},enable_command:function(e){var t;"reply-list"==e.command&&1==rcmail.env.reply_all_mode?(t=rcmail.gettext(e.status?"replylist":"replyall"),$("a.button.replyAll").attr("title",t)):"compose-encrypted"==e.command?$("#messagetoolbar a.encrypt").parent().show():"compose-encrypted-signed"==e.command&&$("#encryptionmenulink").show()},folder_search_init:function(a){$(".boxtitle a.search",a).click(function(e){var i=$(".boxtitle",a),t=$(".listsearchbox",a),n=t.is(":visible")?-1:1,s=24+($("select",t).length?24:0);return t.slideToggle({duration:160,progress:function(e,t){n<0&&(t=1-t),$(".boxlistcontent",a).css("top",i.outerHeight()+s*t+"px")},complete:function(){t.toggleClass("expanded"),t.is(":visible")?t.find("input[type=text]").focus():$("a.reset",t).click()}}),!1})}};var rcmail_ui,rcmail_editor_settings={};function rcube_init_mail_ui(){rcmail_ui=new rcube_mail_ui,$(document.body).mouseup(function(e){rcmail_ui.body_mouseup(e)}).mousedown(function(e){rcmail_ui.body_keydown(e)}),rcmail.addEventListener("init",function(){rcmail.env.quota_content&&update_quota(rcmail.env.quota_content),rcmail.addEventListener("setquota",update_quota),rcube_webmail.set_iframe_events({mouseup:function(e){return rcmail_ui.body_mouseup(e)}}),"mail"==rcmail.env.task?(rcmail.addEventListener("enable-command","enable_command",rcmail_ui).addEventListener("menu-open","menu_open",rcmail_ui).addEventListener("aftersend-attachment","uploadmenu",rcmail_ui).addEventListener("aftertoggle-editor","resize_compose_body_ev",rcmail_ui).addEventListener("afterbounce",function(){rcmail_ui.show_popup("forwardmenu",!1)}).gui_object("dragmenu","dragmenu"),rcmail.gui_objects.mailboxlist&&(rcmail.treelist.addEventListener("expand",rcube_render_mailboxlist),rcmail.addEventListener("responseaftermark",rcube_render_mailboxlist).addEventListener("responseaftergetunread",rcube_render_mailboxlist).addEventListener("responseaftercheck-recent",rcube_render_mailboxlist).addEventListener("responseafterrefresh",rcube_render_mailboxlist).addEventListener("afterimport-messages",function(){rcmail_ui.show_popup("uploadform",!1)})),rcmail.init_pagejumper("#pagejumper"),bw.ie&&rcmail.message_list&&$(window).resize(function(){setTimeout(function(){rcmail.message_list.resize()},10)}),"list"!=rcmail.env.action&&rcmail.env.action?"compose"==rcmail.env.action?(rcmail_ui.init_compose_form(),rcmail.addEventListener("compose-encrypted",function(e){$("a.button.encrypt")[e.active?"addClass":"removeClass"]("selected"),$("select[name='editorSelector']").prop("disabled",e.active),$("a.button.attach, a.button.responses, a.button.attach, #uploadmenulink")[e.active?"addClass":"removeClass"]("buttonPas disabled"),$("#responseslist a.insertresponse")[e.active?"removeClass":"addClass"]("active")}),rcmail.addEventListener("fileappended",function(e){e.attachment.complete&&attachment_menu_append(e.item)}),$("#attachmentslist > li").each(function(){attachment_menu_append(this)})):"show"!=rcmail.env.action&&"preview"!=rcmail.env.action||($('#attachment-list > li[id^="attach"]').each(function(){attachment_menu_append(this)}),$(window).resize(function(){$('#attachment-list > li[id^="attach"]').length||$("#attachment-list").hide();var e,t=$("#messagebody.mailvelope");t.length&&(e=((e=$("#messageframe")).length?e.height()+e.offset().top-25:$(this).height())-t.offset().top-20,t.height(e))})):(rcmail.addEventListener("layout-change","set_layout",rcmail_ui),rcmail_ui.set_layout())):"addressbook"==rcmail.env.task?rcmail.addEventListener("afterupload-photo",function(){rcmail_ui.show_popup("uploadform",!1)}).gui_object("dragmenu","dragmenu"):"settings"==rcmail.env.task&&("folders"==rcmail.env.action&&rcmail_ui.folder_search_init($("#folder-manager")),$("#mainscreen > #prefs-title").detach().prependTo($("#mainscreen > .box")))})}