roundcube_themes/classic/splitter.min.js

27 lines
4.2 KiB
JavaScript

/**
* 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(d){function f(b){a.drag_active=!0;if(bw.konq||bw.chrome||bw.safari)document.body.style.webkitUserSelect="none";a.p1pos=a.relative?$(a.p1).position():$(a.p1).offset();a.p2pos=a.relative?$(a.p2).position():$(a.p2).offset();$(document).on("mousemove."+a.id,g).on("mouseup."+a.id,h);$("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 g(b){if(!a.drag_active)return!1;window.clearTimeout(a.ts);a.ts=window.setTimeout(function(){var c=rcube_event.get_mouse_pos(b);if(a.relative){var e=$(a.p1.parentNode).offset();c.x-=e.left;c.y-=e.top}a.horizontal?c.y-1.5*a.layer.height>a.p1pos.top&&c.y+1.5*a.layer.height<a.p2pos.top+a.p2.offsetHeight&&(a.pos=c.y,a.resize()):c.x-1.5*a.layer.width>a.p1pos.left&&c.x+1.5*a.layer.width<a.p2pos.left+a.p2.offsetWidth&&(a.pos=c.x,a.resize());a.p1pos=a.relative?$(a.p1).position():$(a.p1).offset();
a.p2pos=a.relative?$(a.p2).position():$(a.p2).offset()},1);return!1}function h(b){a.drag_active=!1;if(bw.konq||bw.chrome||bw.safari)document.body.style.webkitUserSelect="auto";$(document).off("."+a.id);$("div.iframe-splitter-fix").remove();a.set_cookie();"function"==typeof a.callback&&a.callback(a);return bw.safari?!0:rcube_event.cancel(b)}function k(b){a.horizontal?(b=parseInt(a.p2.parentNode.offsetHeight,10)-parseInt(a.p2.style.top,10),a.p2.style.height=(0<b?b:0)+"px"):(b=parseInt(a.p2.parentNode.offsetWidth,
10)-parseInt(a.p2.style.left,10),a.p2.style.width=(0<b?b:0)+"px")}this.p1id=d.p1;this.p2id=d.p2;this.id=d.id?d.id:this.p1id+"_"+this.p2id+"_splitter";this.orientation=d.orientation;this.horizontal="horizontal"==this.orientation||"h"==this.orientation;this.pos=d.start?1*d.start:0;this.relative=d.relative?!0:!1;this.drag_active=!1;this.callback=d.callback;var a=this;this.init=function(){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.layer=this.horizontal?new rcube_layer(this.id,{x:0,y:this.p1pos.top+this.p1.offsetHeight,height:10,width:"100%",vis:1,parent:this.p1.parentNode}):new rcube_layer(this.id,{x:this.p1pos.left+this.p1.offsetWidth,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(f);
$(window).resize(function(c){c.target===window&&a.resize()});bw.ie&&$(window).resize(k);var b=rcmail.get_cookie(this.id);b&&!isNaN(b)?(this.pos=parseFloat(b),this.resize()):this.pos&&(this.resize(),this.set_cookie())};this.resize=function(){if(this.horizontal){var b=this.layer.height;this.p1.style.height=Math.floor(this.pos-this.p1pos.top-b/2)+"px";this.p2.style.top=Math.ceil(this.pos+b/2)+"px";this.layer.move(this.layer.x,Math.round(this.pos-b/2+1));bw.ie&&(b=parseInt(this.p2.parentNode.offsetHeight,
10)-parseInt(this.p2.style.top,10),this.p2.style.height=(0<b?b:0)+"px")}else b=$(window).width()-$(this.p1).offset().left-150,b=Math.min(this.pos,b),this.p1.style.width=Math.floor(b-this.p1pos.left-this.layer.width/2)+"px",this.p2.style.left=Math.ceil(b+this.layer.width/2)+"px",this.layer.move(Math.round(b-this.layer.width/2+1),this.layer.y),bw.ie&&(b=parseInt(this.p2.parentNode.offsetWidth,10)-parseInt(this.p2.style.left,10),this.p2.style.width=(0<b?b:0)+"px");$(this.p2).resize();$(this.p1).resize()};
this.set_cookie=function(){var b=new Date;b.setYear(b.getFullYear()+1);rcmail.set_cookie(this.id,this.pos,b)}};