3 // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/
 
   4 var SplitView = View.extend({
 
   5   splitbarClass: 'splitview-splitbar',
 
   6   activeClass: 'splitview-active',
 
   7   overlayClass: 'splitview-overlay',
 
  16   init: function(element, model) {
 
  17     this.element = $(element).css('position', 'relative');
 
  19     this.views = $(">*", this.element[0]).css({
 
  20         position: 'absolute',                     // positioned inside splitter container
 
  21         'z-index': 1,                                           // splitbar is positioned above
 
  22         '-moz-outline-style': 'none',   // don't show dotted outline
 
  26     this.leftView = $(this.views[0]);
 
  27     this.rightView = $(this.views[1]);
 
  28     this.splitbar = $(this.views[2] || '<div></div>')
 
  29       .insertAfter(this.leftView)
 
  32         'user-select': 'none',
 
  33         '-webkit-user-select': 'none',
 
  34         '-khtml-user-select': 'none',
 
  35         '-moz-user-select': 'none',
 
  38       .attr('unselectable', 'on')
 
  39       .addClass(this.splitbarClass)
 
  40       .bind('mousedown.splitview', this.beginResize.bind(this));
 
  42     this._splitbarWidth = this.splitbar.outerWidth();
 
  44     // Solomon's algorithm ;-)
 
  45     this.resplit(this.element.width() / 2);
 
  48   beginResize: function(event) {
 
  49     this.zombie = this.zombie || this.splitbar.clone(false).insertAfter(this.leftView);
 
  50     this.overlay = this.overlay || $('<div></div>').addClass(this.overlayClass).css({
 
  52         width: this.element.width(),
 
  53         height: this.element.height(),
 
  54         top: this.element.position().top,
 
  55         left: this.element.position().left
 
  56       }).appendTo(this.element);
 
  57     this.views.css("-webkit-user-select", "none"); // Safari selects A/B text on a move
 
  58     this.splitbar.addClass(this.activeClass);
 
  59     this.leftViewOffset = this.leftView[0].offsetWidth - event.pageX;
 
  62       .bind('mousemove.splitview', this.resizeChanged.bind(this))
 
  63       .bind('mouseup.splitview', this.endResize.bind(this));
 
  66   resizeChanged: function(event) {
 
  67     var newPosition = event.pageX + this.leftViewOffset;
 
  68     newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
 
  69     this.splitbar.css('left', newPosition);
 
  72   endResize: function(event) {
 
  73     var newPosition = event.pageX + this.leftViewOffset;
 
  76     this.overlay.remove();
 
  78     this.resplit(newPosition);
 
  81       .unbind('mousemove.splitview')
 
  82       .unbind('mouseup.splitview');
 
  85   resplit: function(newPosition) {
 
  86     newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth));
 
  87     this.splitbar.css('left', newPosition);
 
  93       left: newPosition + this._splitbarWidth,
 
  94       width: this.element.width() - newPosition - this._splitbarWidth
 
  96     if (!$.browser.msie) {
 
  97                   this.views.trigger("resize");
 
 101   dispose: function() {
 
 102     this.splitter.unbind('mousedown.splitview');