X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ff3ac103aa103b9b5cb56e71a6782c9ca98acf94..36387dac2e103ca656be9dc65fabb936f80191d1:/project/static/js/views/split.js diff --git a/project/static/js/views/split.js b/project/static/js/views/split.js index 8e6fa20b..30eda4ab 100644 --- a/project/static/js/views/split.js +++ b/project/static/js/views/split.js @@ -1,7 +1,8 @@ -/*globals Class*/ +/*globals View*/ // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/ -var SplitView = Class.extend({ +var SplitView = View.extend({ + _className: 'SplitView', splitbarClass: 'splitview-splitbar', activeClass: 'splitview-active', overlayClass: 'splitview-overlay', @@ -14,8 +15,10 @@ var SplitView = Class.extend({ _splitbarWidth: 0, init: function(element, model) { - this.element = $(element).css('position', 'relative'); - this.model = model; + this._super(element, model, null); + this.element.css('position', 'relative'); + this._resizingSubviews = false; + this.views = $(">*", this.element[0]).css({ position: 'absolute', // positioned inside splitter container 'z-index': 1, // splitbar is positioned above @@ -25,6 +28,7 @@ var SplitView = Class.extend({ this.leftView = $(this.views[0]); this.rightView = $(this.views[1]); + this.splitbar = $(this.views[2] || '
') .insertAfter(this.leftView) .css({ @@ -82,6 +86,12 @@ var SplitView = Class.extend({ .unbind('mouseup.splitview'); }, + resized: function(event) { + if (!this._resizingSubviews) { + this.resplit(Math.min(this.leftView.width(), this.element.width() - this._splitbarWidth)); + } + }, + resplit: function(newPosition) { newPosition = Math.max(0, Math.min(newPosition, this.element.width() - this._splitbarWidth)); this.splitbar.css('left', newPosition); @@ -94,12 +104,15 @@ var SplitView = Class.extend({ width: this.element.width() - newPosition - this._splitbarWidth }); if (!$.browser.msie) { - this.views.trigger("resize"); + this._resizingSubviews = true; + $(window).trigger('resize'); + this._resizingSubviews = false; } }, dispose: function() { this.splitter.unbind('mousedown.splitview'); + this._super(); } });