splitter.min.js
4.2 KB
/**
* Roundcube splitter GUI class
*
* @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.
*
* @constructor
*/
function rcube_splitter(t){this.p1id=t.p1,this.p2id=t.p2,this.id=t.id||this.p1id+"_"+this.p2id+"_splitter",this.orientation=t.orientation,this.horizontal="horizontal"==this.orientation||"h"==this.orientation,this.pos=t.start?+t.start:0,this.relative=!!t.relative,this.drag_active=!1,this.callback=t.callback;var e=this;function s(t){e.drag_active=!0,(bw.konq||bw.chrome||bw.safari)&&(document.body.style.webkitUserSelect="none"),e.p1pos=e.relative?$(e.p1).position():$(e.p1).offset(),e.p2pos=e.relative?$(e.p2).position():$(e.p2).offset(),$(document).on("mousemove."+e.id,i).on("mouseup."+e.id,o),$("iframe").each(function(){$('<div class="iframe-splitter-fix"></div>').css({background:"#fff",width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1e3}).css($(this).offset()).appendTo("body")})}function i(t){return e.drag_active&&(window.clearTimeout(e.ts),e.ts=window.setTimeout(function(){!function(t){var i=rcube_event.get_mouse_pos(t);e.relative&&(t=$(e.p1.parentNode).offset(),i.x-=t.left,i.y-=t.top);e.horizontal?i.y-1.5*e.layer.height>e.p1pos.top&&i.y+1.5*e.layer.height<e.p2pos.top+e.p2.offsetHeight&&(e.pos=i.y,e.resize()):i.x-1.5*e.layer.width>e.p1pos.left&&i.x+1.5*e.layer.width<e.p2pos.left+e.p2.offsetWidth&&(e.pos=i.x,e.resize());e.p1pos=e.relative?$(e.p1).position():$(e.p1).offset(),e.p2pos=e.relative?$(e.p2).position():$(e.p2).offset()}(t)},1)),!1}function o(t){return e.drag_active=!1,(bw.konq||bw.chrome||bw.safari)&&(document.body.style.webkitUserSelect="auto"),$(document).off("."+e.id),$("div.iframe-splitter-fix").remove(),e.set_cookie(),"function"==typeof e.callback&&e.callback(e),!!bw.safari||rcube_event.cancel(t)}function h(t){var i;e.horizontal?(i=parseInt(e.p2.parentNode.offsetHeight,10)-parseInt(e.p2.style.top,10),e.p2.style.height=(0<i?i:0)+"px"):(i=parseInt(e.p2.parentNode.offsetWidth,10)-parseInt(e.p2.style.left,10),e.p2.style.width=(0<i?i:0)+"px")}this.init=function(){var t;this.p1=document.getElementById(this.p1id),this.p2=document.getElementById(this.p2id),this.p1pos=this.relative?$(this.p1).position():$(this.p1).offset(),this.p2pos=this.relative?$(this.p2).position():$(this.p2).offset(),this.horizontal?(t=this.p1pos.top+this.p1.offsetHeight,this.layer=new rcube_layer(this.id,{x:0,y:t,height:10,width:"100%",vis:1,parent:this.p1.parentNode})):(i=this.p1pos.left+this.p1.offsetWidth,this.layer=new rcube_layer(this.id,{x:i,y:0,width:10,height:"100%",vis:1,parent:this.p1.parentNode})),this.elm=this.layer.elm,this.elm.className="splitter "+(this.horizontal?"splitter-h":"splitter-v"),this.elm.unselectable="on",$(this.elm).mousedown(s),$(window).resize(function(t){t.target===window&&e.resize()}),bw.ie&&$(window).resize(h);var i=rcmail.get_cookie(this.id);i&&!isNaN(i)?(this.pos=parseFloat(i),this.resize()):this.pos&&(this.resize(),this.set_cookie())},this.resize=function(){var t,i;this.horizontal?(t=this.layer.height,this.p1.style.height=Math.floor(this.pos-this.p1pos.top-t/2)+"px",this.p2.style.top=Math.ceil(this.pos+t/2)+"px",this.layer.move(this.layer.x,Math.round(this.pos-t/2+1)),bw.ie&&(i=parseInt(this.p2.parentNode.offsetHeight,10)-parseInt(this.p2.style.top,10),this.p2.style.height=(0<i?i:0)+"px")):(i=$(window).width()-$(this.p1).offset().left-150,i=Math.min(this.pos,i),this.p1.style.width=Math.floor(i-this.p1pos.left-this.layer.width/2)+"px",this.p2.style.left=Math.ceil(i+this.layer.width/2)+"px",this.layer.move(Math.round(i-this.layer.width/2+1),this.layer.y),bw.ie&&(i=parseInt(this.p2.parentNode.offsetWidth,10)-parseInt(this.p2.style.left,10),this.p2.style.width=(0<i?i:0)+"px")),$(this.p2).resize(),$(this.p1).resize()},this.set_cookie=function(){var t=new Date;t.setYear(t.getFullYear()+1),rcmail.set_cookie(this.id,this.pos,t)}}