3 // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/
4 var SplitView = View.extend({
5 _className: 'SplitView',
6 splitbarClass: 'splitview-splitbar',
7 activeClass: 'splitview-active',
8 overlayClass: 'splitview-overlay',
17 init: function(element, model) {
18 this._super(element, model, null);
19 this.element.css('position', 'relative');
20 this._resizingSubviews = false;
22 this.views = $(">*", this.element[0]).css({
23 position: 'absolute', // positioned inside splitter container
24 'z-index': 1, // splitbar is positioned above
25 '-moz-outline-style': 'none', // don't show dotted outline
29 this.leftView = $(this.views[0]);
30 this.rightView = $(this.views[1]);
32 this.splitbar = $(this.views[2] || '<div></div>')
33 .insertAfter(this.leftView)
36 'user-select': 'none',
37 '-webkit-user-select': 'none',
38 '-khtml-user-select': 'none',
39 '-moz-user-select': 'none',
42 .attr('unselectable', 'on')
43 .addClass(this.splitbarClass)
44 .bind('mousedown.splitview', this.beginResize.bind(this));
46 this._splitbarWidth = this.splitbar.outerWidth();
48 // Solomon's algorithm ;-)
49 this.resplit(this.element.width() / 2);
52 beginResize: function(event) {
53 this.zombie = this.zombie || this.splitbar.clone(false).insertAfter(this.leftView);
54 this.overlay = this.overlay || $('<div></div>').addClass(this.overlayClass).css({
56 width: this.element.width(),
57 height: this.element.height(),
58 top: this.element.position().top,
59 left: this.element.position().left
60 }).appendTo(this.element);
61 this.views.css("-webkit-user-select", "none"); // Safari selects A/B text on a move
62 this.splitbar.addClass(this.activeClass);
63 this.leftViewOffset = this.leftView[0].offsetWidth - event.pageX;
66 .bind('mousemove.splitview', this.resizeChanged.bind(this))
67 .bind('mouseup.splitview', this.endResize.bind(this));
70 resizeChanged: function(event) {
71 var newPosition = event.pageX + this.leftViewOffset;
72 newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
73 this.splitbar.css('left', newPosition);
76 endResize: function(event) {
77 var newPosition = event.pageX + this.leftViewOffset;
80 this.overlay.remove();
82 this.resplit(newPosition);
85 .unbind('mousemove.splitview')
86 .unbind('mouseup.splitview');
89 resized: function(event) {
90 if (!this._resizingSubviews) {
91 this.resplit(Math.min(this.leftView.width(), this.element.width() - this._splitbarWidth));
95 resplit: function(newPosition) {
96 newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
97 this.splitbar.css('left', newPosition);
103 left: newPosition + this._splitbarWidth,
104 width: this.element.width() - newPosition - this._splitbarWidth
106 if (!$.browser.msie) {
107 this._resizingSubviews = true;
108 $(window).trigger('resize');
109 this._resizingSubviews = false;
113 dispose: function() {
114 this.splitter.unbind('mousedown.splitview');