/** * RoundCube splitter GUI class * * @constructor */ function rcube_splitter(attrib) { this.p1id = attrib.p1; this.p2id = attrib.p2; this.id = attrib.id ? attrib.id : this.p1id + '_' + this.p2id + '_splitter'; this.orientation = attrib.orientation; this.horizontal = (this.orientation == 'horizontal' || this.orientation == 'h'); this.offset = bw.ie6 ? 2 : 0; this.pos = attrib.start ? attrib.start * 1 : 0; this.relative = attrib.relative ? true : false; this.drag_active = false; this.init = function() { this.p1 = document.getElementById(this.p1id); this.p2 = document.getElementById(this.p2id); // create and position the handle for this splitter this.p1pos = rcube_get_object_pos(this.p1, this.relative); this.p2pos = rcube_get_object_pos(this.p2, this.relative); if (this.horizontal) { var top = this.p1pos.y + this.p1.offsetHeight; this.layer = new rcube_layer(this.id, {x: 0, y: top, height: 10, width: '100%', vis: 1, parent: this.p1.parentNode}); } else { var left = this.p1pos.x + this.p1.offsetWidth; this.layer = new rcube_layer(this.id, {x: left, 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'; // add the mouse event listeners rcube_event.add_listener({element: this.elm, event:'mousedown', object:this, method:'onDragStart'}); if (bw.ie) rcube_event.add_listener({element: window, event:'resize', object:this, method:'onResize'}); // read saved position from cookie var cookie = bw.get_cookie(this.id); if (cookie) { var param = cookie.split(':'); for (var i=0, p; i this.p1pos.y) && ((pos.y + this.layer.height * 1.5) < (this.p2pos.y + this.p2.offsetHeight))) { this.pos = pos.y; this.resize(); } } else { if (((pos.x - this.layer.width * 1.5) > this.p1pos.x) && ((pos.x + this.layer.width * 1.5) < (this.p2pos.x + this.p2.offsetWidth))) { this.pos = pos.x; this.resize(); } } this.p1pos = rcube_get_object_pos(this.p1, this.relative); this.p2pos = rcube_get_object_pos(this.p2, this.relative); return false; }; /** * Handler for mouseup events */ this.onDragStop = function(e) { // cancel the listening for drag events rcube_event.remove_listener({element:document, event:'mousemove', object:this, method:'onDrag'}); rcube_event.remove_listener({element:document, event:'mouseup', object:this, method:'onDragStop'}); this.drag_active = false; var iframes = document.getElementsByTagName('IFRAME'); for (var n in iframes) { var iframedoc; if (iframes[n].contentDocument) iframedoc = iframes[n].contentDocument; else if (iframes[n].contentWindow) iframedoc = iframes[n].contentWindow.document; else if (iframes[n].document) iframedoc = iframes[n].document; if (iframedoc) { if (this.iframe_events[n]) { if (iframedoc.removeEventListener) iframedoc.removeEventListener('mousemove', this.iframe_events[n], false); else if (iframedoc.detachEvent) iframedoc.detachEvent('onmousemove', this.iframe_events[n]); else iframedoc['onmousemove'] = null; } rcube_event.remove_listener({element:iframedoc, event:'mouseup', object:this, method:'onDragStop'}); } } this.set_cookie(); return bw.safari ? true : rcube_event.cancel(e); }; /** * Handler for window resize events */ this.onResize = function(e) { if (this.horizontal) this.p2.style.height = (parseInt(this.p2.parentNode.offsetHeight) - parseInt(this.p2.style.top))+'px'; else this.p2.style.width = (parseInt(this.p2.parentNode.offsetWidth) - parseInt(this.p2.style.left))+'px'; }; this.set_cookie = function() { // save state in cookie var exp = new Date(); exp.setYear(exp.getFullYear() + 1); bw.set_cookie(this.id, 'pos='+this.pos, exp); } } // end class rcube_splitter