3 // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/
4 var SplitView = Class.extend({
5 splitbarClass: 'splitview-splitbar',
6 activeClass: 'splitview-active',
14 init: function(element) {
15 this.element = $(element).css('position', 'relative');
16 this.views = $(">*", this.element[0]).css({
17 position: 'absolute', // positioned inside splitter container
18 'z-index': 1, // splitbar is positioned above
19 '-moz-outline-style': 'none', // don't show dotted outline
23 this.leftView = $(this.views[0]);
24 this.rightView = $(this.views[1]);
25 this.splitbar = $(this.views[2] || '<div></div>')
26 .insertAfter(this.leftView)
29 'user-select': 'none',
30 '-webkit-user-select': 'none',
31 '-khtml-user-select': 'none',
32 '-moz-user-select': 'none',
35 .attr('unselectable', 'on')
36 .addClass(this.splitbarClass)
37 .bind('mousedown.splitview', this.beginResize.bind(this));
39 this._splitbarWidth = this.splitbar.outerWidth();
41 // Solomon's algorithm ;-)
42 this.resplit(this.element.width() / 2);
45 beginResize: function(event) {
46 this.zombie = this.zombie || this.splitbar.clone(false).insertAfter(this.leftView);
47 this.views.css("-webkit-user-select", "none"); // Safari selects A/B text on a move
48 this.splitbar.addClass(this.activeClass);
49 this.leftViewOffset = this.leftView[0].offsetWidth - event.pageX;
52 .bind('mousemove.splitview', this.resizeChanged.bind(this))
53 .bind('mouseup.splitview', this.endResize.bind(this));
56 resizeChanged: function(event) {
57 var newPosition = event.pageX + this.leftViewOffset;
58 newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
59 this.splitbar.css('left', newPosition);
62 endResize: function(event) {
63 var newPosition = event.pageX + this.leftViewOffset;
66 this.resplit(newPosition);
69 .unbind('mousemove.splitview')
70 .unbind('mouseup.splitview');
73 resplit: function(newPosition) {
74 newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
75 this.splitbar.css('left', newPosition);
81 left: newPosition + this._splitbarWidth,
82 width: this.element.width() - newPosition - this._splitbarWidth
84 if (!$.browser.msie) {
85 this.views.trigger("resize");
90 this.splitter.unbind('mousedown.splitview');