2025-02-23 20:52:25 +01:00

1 line
14 KiB
JavaScript

"use strict";var x=console.log.bind(console);var xsidebar=undefined;$(document).ready(function(){xframework.initialize();xsidebar=rcmail.env.xelastic?new xsidebarElastic:new xsidebarLarry;xsidebar.initialize()});function xscope(controllerName){return angular.element(document.querySelector("[ng-controller='"+controllerName+"']")).scope()}var xframework=new function(){var _this=this;this.language=rcmail.env.locale.substr(0,2);this.showPasswordTimeout=false;this.initialize=function(){if($("#sections-table").length){setTimeout(function(){$("#rcmrow"+xframework.getUrlParameter("_section")).mousedown()},0)}if(typeof rcmail.env.appsMenu!=="undefined"&&rcmail.env.appsMenu){if(rcmail.env.xelastic){$("#show-mobile-xsidebar").before($(rcmail.env.appsMenu));UI.popup_init(document.getElementById("button-apps"))}else{$(".button-settings").after($(rcmail.env.appsMenu))}rcmail.env.appsMenu=false}var showSidebar=$("#show-xsidebar");if(rcmail.env.xelastic&&showSidebar.length){showSidebar.parent("li").attr("id","show-xsidebar-item")}$("#quick-language-change select").on("mouseup",function(event){event.stopPropagation()});if(rcmail.env.set_token!==undefined){setTimeout(function(){$.ajax({url:rcmail.url("set-token"),headers:{"x-csrf-token":rcmail.env.request_token}})},1500)}$("span.sidebar-settings-url").on("click",function(event){event.stopPropagation();window.location=$(event.target).data("url")});var sidebarOrder=$("#xsidebar-order");if(sidebarOrder.length){$("table.propform").attr("id","xsidebar-order-table");var orderTable=$("#xsidebar-order-table");orderTable.after(sidebarOrder);orderTable.after($("#xsidebar-order-note"));orderTable.find("tr:last-child").remove();$("#xsidebar-order-table tbody").sortable({delay:100,distance:10,placeholder:"placeholder",stop:function stop(){var order=[];$("#xsidebar-order-table input[type=checkbox]").each(function(){order.push($(this).attr("data-name"))});sidebarOrder.val(order.join(","))}})}if(xframework.isCpanel()){$("body").addClass("cpanel")}if($("body.xelastic").length){$("#button-apps").on("mouseup",function(){setTimeout(function(){$(".popover .popover-body select:not(.xreverted)").off("mousedown keydown change").on("mousedown click",function(event){event.stopPropagation()}).addClass("xreverted")},300)})}$(".password-toggle-input").each(function(index,element){element=$(element);element.on("blur",function(){if(element.attr("type")=="text"){element.addClass("blurred").attr("type","password")}});var parent=element.parent().addClass("password-toggle-container");if(!parent.find(".password-toggle-button").length){element.after($('<span class="password-toggle-button" onclick="xframework.togglePassword(this)"></span>'))}})};this.togglePassword=function(element){element=$(element).parent().find(".password-toggle-input");clearTimeout(_this.showPasswordTimeout);if(element.attr("type")=="password"){if(element.hasClass("blurred")){element.removeClass("blurred");return}element.attr("type","text").focus();_this.showPasswordTimeout=setTimeout(function(){element.attr("type","password")},1e4)}else{element.attr("type","password")}};this.httpInterceptor=function(){return{request:function request(config){config.data._token=rcmail.env.request_token;config.headers["x-csrf-token"]=rcmail.env.request_token;return config},requestError:function requestError(config){return config},response:function response(_response){return _response.data},responseError:function responseError(response){rcmail.display_message(response.statusText,"error");return false}}};this.getTimezoneOffset=function(){return rcmail.env.timezoneOffset};this.getDateFormat=function(){var type=arguments.length<=0||arguments[0]===undefined?undefined:arguments[0];return rcmail.env.dateFormats[type===undefined?"moment":type]};this.getTimeFormat=function(){var type=arguments.length<=0||arguments[0]===undefined?undefined:arguments[0];return rcmail.env.timeFormats[type===undefined?"moment":type]};this.getDateTimeFormat=function(){var type=arguments.length<=0||arguments[0]===undefined?undefined:arguments[0];return rcmail.env.dateFormats[type===undefined?"moment":type]+" "+rcmail.env.timeFormats[type===undefined?"moment":type]};this.getDmFormat=function(){var type=arguments.length<=0||arguments[0]===undefined?undefined:arguments[0];return rcmail.env.dmFormats[type===undefined?"moment":type]};this.getLanguage=function(){return _this.language};this.getUrl=function(){var url=window.location.protocol+"//"+window.location.host+window.location.pathname;return url+(url.substring(url.length-1)==="/"?"":"/")};this.getUrlParameter=function(parameterName){var url=arguments.length<=1||arguments[1]===undefined?undefined:arguments[1];var match=RegExp("[?&]"+parameterName+"=([^&]*)").exec(url===undefined?window.location.search:url);return match&&decodeURIComponent(match[1].replace(/\+/g," "))};this.mobile=function(){return rcmail.env.xskin_type!==undefined&&rcmail.env.xskin_type=="mobile"};this.htmlEncode=function(html){return document.createElement("a").appendChild(document.createTextNode(html)).parentNode.innerHTML};this.sleep=function(duration){var now=(new Date).getTime();while((new Date).getTime()<now+duration){}};this.isCpanel=function(){return window.location.pathname.indexOf("/cpsess")!=-1};this.replaceUrlParam=function(name,value){var str=location.search;if(new RegExp("[&?]"+name+"([=&].+)?$").test(str)){str=str.replace(new RegExp("(?:[&?])"+name+"[^&]*","g"),"")}str+="&";str+=name+"="+value;str="?"+str.slice(1);return str+location.hash};this.getRandomCode=function(){var code="";var characters="abcdefghijklmnopqrstuvwxyz0123456789";for(var i=0;i<32;i++){code+=characters.charAt(Math.floor(Math.random()*characters.length))}return code};this.showLarryPopup=function(id,event){if(typeof UI.toggle_popup!=="undefined"){UI.toggle_popup(id,event)}};this.ajax=function(route,data,onSuccess,onError,onDone){if(data===undefined)data={};var showMessageOnError=arguments.length<=5||arguments[5]===undefined?true:arguments[5];$.ajax({url:rcmail.url(route),method:"POST",headers:{"x-csrf-token":rcmail.env.request_token},dataType:"json",data:JSON.stringify(data),error:function error(){rcmail.display_message("Ajax error: "+route+" (392884)","error")}}).done(function(response){if(response.success){if(typeof onSuccess==="function"){onSuccess(response)}}else{if(showMessageOnError){rcmail.display_message(response.message||"Server error 388194 (Ajax: "+route+")","error")}if(typeof onError==="function"){onError(response)}}if(typeof onDone==="function"){onDone(response)}})};this.ajaxSuccess=function(response){var showError=arguments.length<=1||arguments[1]===undefined?true:arguments[1];if(!response){return false}if(response.success){return true}if(showError){rcmail.display_message(response.message||"This operation cannot be completed due to server error. (5549481)","error")}return false};this.createCrcTable=function(){var c=undefined;var crcTable=[];for(var n=0;n<256;n++){c=n;for(var k=0;k<8;k++){c=c&1?3988292384^c>>>1:c>>>1}crcTable[n]=c}return crcTable};this.crc32=function(str){if(!_this.crcTable){_this.crcTable=_this.createCrcTable()}var crc=0^-1;for(var i=0;i<str.length;i++){crc=crc>>>8^_this.crcTable[(crc^str.charCodeAt(i))&255]}return(crc^-1)>>>0};this.isValidEmail=function(email){return/\S+@\S+\.\S+/.test(email)};this.extractEmail=function(email){if(email.indexOf("<")!==-1){var matches=/<([^<>]+)>/.exec(email);if(matches&&matches.length>=2&&matches[1]){return matches[1].trim()}}return email.trim()};this.hidePopovers=function(){var element=$(".popover");if(typeof element.popover==="function"){element.popover("hide")}};this.showPassword=function(button){if(_this.showPasswordTimeout){clearTimeout(_this.showPasswordTimeout)}var passwordInput=$(button).prev();if(passwordInput.attr("type")=="password"){passwordInput.attr("type","text");_this.showPasswordTimeout=setTimeout(function(){passwordInput.attr("type","password")},1e4)}else{passwordInput.attr("type","password")}}};(function($){$.fn.alterClass=function(removals,additions){var _this2=this;if(removals.indexOf("*")===-1){this.removeClass(removals)}else{(function(){var patern=new RegExp("\\s"+removals.replace(/\*/g,"[A-Za-z0-9-_]+").split(" ").join("\\s|\\s")+"\\s","g");_this2.each(function(i,it){var cn=" "+it.className+" ";while(patern.test(cn)){cn=cn.replace(patern," ")}it.className=$.trim(cn)})})()}return additions?this.addClass(additions):this}})(jQuery);(function($){var MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;$.fn.attrChange=function(callback){var _this3=this;if(MutationObserver){var _ret2=function(){var options={subtree:false,attributes:true};var observer=new MutationObserver(function(mutations){mutations.forEach(function(e){callback.call(e.target,e.attributeName)})});return{v:_this3.each(function(){observer.observe(this,options)})}}();if(typeof _ret2==="object")return _ret2.v}}})(jQuery);function xsidebarLarry(){var _this4=this;this.initialized=false;this.splitter=false;this.initialize=function(){_this4.sidebar=$("#xsidebar");if(xframework.mobile()||!_this4.sidebar.length||_this4.initialized){return}$("#xsidebar-inner").sortable({delay:100,distance:10,placeholder:"placeholder",stop:function stop(){var order=[];$("#xsidebar .box-wrap").each(function(){order.push($(this).attr("data-name"))});rcmail.save_pref({name:"xsidebar_order",value:order.join(",")})}});_this4.mainscreen=$("#mainscreen");_this4.mainscreencontent=$("#mainscreencontent");$("#messagesearchtools").addClass("xsidebar-wrap");_this4.splitter=$("<div>").attr("id","xsidebar-splitter").attr("unselectable","on").attr("role","presentation").addClass("splitter splitter-v").appendTo("#mainscreen").mousedown(function(e){xsidebar.onSplitterDragStart(e)});_this4.setSize(_this4.validateSize(window.UI?window.UI.get_pref("xsidebar-size"):250));var sidebarVisible=window.UI.get_pref("xsidebar-visible");if(sidebarVisible===undefined&&rcmail.env.xsidebarVisible!==undefined){sidebarVisible=!!rcmail.env.xsidebarVisible}if(sidebarVisible===undefined||sidebarVisible){_this4.show()}else{_this4.hide()}$(document).on("mousemove.#mainscreen",function(e){xsidebar.onSplitterDrag(e)}).on("mouseup.#mainscreen",function(e){xsidebar.onSplitterDragStop(e)});_this4.initialized=true};this.isVisible=function(){return $("body").hasClass("xsidebar-visible")};this.show=function(){$("body").addClass("xsidebar-visible")};this.hide=function(){$("body").removeClass("xsidebar-visible");_this4.mainscreencontent.css("width","").css("right","0px")};this.validateSize=function(size){if(size==undefined){return 250}if(size>_this4.mainscreen.width()/2){return _this4.mainscreen.width()/2}if(size<150){return 150}return size};this.setSize=function(size){size=size==undefined?xsidebar.sidebar.width():size;_this4.sidebar.width(size);_this4.splitter.css("right",size+"px");_this4.mainscreencontent.css("right",size+12+"px")};this.saveVisibility=function(){if(window.UI){window.UI.save_pref("xsidebar-visible",$("body").hasClass("xsidebar-visible")?1:0)}};this.toggle=function(){if(_this4.isVisible()){_this4.hide()}else{_this4.show();_this4.setSize()}_this4.saveVisibility()};this.onSplitterDragStart=function(){$("#mailpreviewframe").append($("<div>").attr("id","xsidebar-preview-frame-overlay"));if(bw.konq||bw.chrome||bw.safari){document.body.style.webkitUserSelect="none"}_this4.draggingSplitter=true};this.onSplitterDrag=function(event){if(_this4.draggingSplitter){_this4.setSize(_this4.mainscreen.width()-event.pageX)}};this.onSplitterDragStop=function(event){if(!_this4.draggingSplitter){return}$("#xsidebar-preview-frame-overlay").remove();if(bw.konq||bw.chrome||bw.safari){document.body.style.webkitUserSelect="auto"}_this4.draggingSplitter=false;_this4.setSize(_this4.validateSize(_this4.mainscreen.width()-event.pageX));if(window.UI){window.UI.save_pref("xsidebar-size",_this4.sidebar.width())}};this.toggleBox=function(id,element){var parent=$(element).parents(".box-wrap");if(parent.hasClass("collapsed")){parent.find(".box-content").slideDown(200,function(){parent.removeClass("collapsed");xsidebar.saveToggleBox()})}else{parent.find(".box-content").slideUp(200,function(){parent.addClass("collapsed");xsidebar.saveToggleBox()})}};this.saveToggleBox=function(){var collapsed=[];$("#xsidebar .box-wrap").each(function(){if($(this).hasClass("collapsed")){collapsed.push($(this).attr("data-name"))}});rcmail.save_pref({name:"xsidebar_collapsed",value:collapsed})}}function xsidebarElastic(){var _this5=this;this.initialized=false;this.splitter=false;this.initialize=function(){_this5.sidebar=$("#xsidebar");if(!_this5.sidebar.length||_this5.initialized){return}_this5.initialized=true;$("#xsidebar-inner").sortable({delay:100,distance:10,placeholder:"placeholder",stop:function stop(){var order=[];$("#xsidebar .box-wrap").each(function(){order.push($(this).attr("data-name"))});rcmail.save_pref({name:"xsidebar_order",value:order.join(",")})}});var sidebarVisible=Cookies.get("xsidebar-visible");if(sidebarVisible!==undefined){sidebarVisible=parseInt(sidebarVisible)}else{if(rcmail.env.xsidebarVisible!==undefined){sidebarVisible=!!rcmail.env.xsidebarVisible}else{sidebarVisible=true}}if(sidebarVisible){_this5.show()}};this.isVisible=function(){return $("body").hasClass("xsidebar-visible")};this.show=function(){$("body").addClass("xsidebar-visible")};this.hide=function(){$("body").removeClass("xsidebar-visible")};this.showMobile=function(){$("body").addClass("xsidebar-mobile-visible")};this.hideMobile=function(){$("body").removeClass("xsidebar-mobile-visible")};this.saveVisibility=function(){Cookies.set("xsidebar-visible",_this5.isVisible()?1:0)};this.toggle=function(){if(_this5.isVisible()){_this5.hide()}else{_this5.show()}_this5.saveVisibility()};this.toggleBox=function(id,element){var parent=$(element).parents(".box-wrap");if(parent.hasClass("collapsed")){parent.find(".box-content").slideDown(200,function(){parent.removeClass("collapsed");xsidebar.saveToggleBox()})}else{parent.find(".box-content").slideUp(200,function(){parent.addClass("collapsed");xsidebar.saveToggleBox()})}};this.saveToggleBox=function(){var collapsed=[];$("#xsidebar .box-wrap").each(function(){if($(this).hasClass("collapsed")){collapsed.push($(this).attr("data-name"))}});rcmail.save_pref({name:"xsidebar_collapsed",value:collapsed})}}