3 var SplitView = Class.extend({
4 leftPanelClass: 'splitview-left-panel',
5 rightPanelClass: 'splitview-right-panel',
6 splitterClass: 'splitview-splitter',
7 overlayClass: 'splitview-overlay',
10 init: function(element) {
11 this.element = $(element);
12 this.leftPanel = $(this.leftPanelClass, element);
13 this.rightPanel = $(this.rightPanelClass, element);
14 this.splitter = $(this.splitterClass, element);
15 this.overlay = this._createOverlay(this.overlayClass);
17 this.splitter.bind('mousedown.splitview', this.beginResize.bind(this));
20 _createOverlay: function(cssClass) {
21 var pos = this.root.position();
28 width: this.root.width(),
29 height: this.root.height()
32 .appendTo(this.element);
35 beginResize: function(event) {
36 this.hotspotX = event.pageX - this.splitter.position().left;
39 .bind('mousemove.splitview', this.resizeChanged.bind(this))
40 .bind('mouseup.splitview', this.endResize.bind(this));
46 resizeChanged: function(event) {
47 var old_width = this.overlay.width();
48 var delta = event.pageX + this.hotspotX - old_width;
50 if(old_width + delta < 12) delta = 12 - old_width;
51 if(old_width + delta > $(window).width()) {
52 delta = $(window).width() - old_width;
55 this.overlay.css({'width': old_width + delta});
57 if(this.overlay.next) {
58 var left = parseInt(this.overlay.next.css('left'), 10);
59 this.overlay.next.css('left', left+delta);
64 endResize: function(event) {
66 .unbind('mousemove.splitview')
67 .unbind('mouseup.splitview');
83 this.splitter.unbind('mousedown.splitview');