From 5c5ef4d21bc0b4862b31b0b96aab9373357140e1 Mon Sep 17 00:00:00 2001 From: zuber Date: Wed, 23 Sep 2009 11:51:03 +0200 Subject: [PATCH] Dodanie podstawowego widoku split.js. --- project/static/js/views/split.js | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 project/static/js/views/split.js diff --git a/project/static/js/views/split.js b/project/static/js/views/split.js new file mode 100644 index 00000000..84f48ead --- /dev/null +++ b/project/static/js/views/split.js @@ -0,0 +1,86 @@ +/*globals Class*/ + +var SplitView = Class.extend({ + leftPanelClass: 'splitview-left-panel', + rightPanelClass: 'splitview-right-panel', + splitterClass: 'splitview-splitter', + overlayClass: 'splitview-overlay', + element: null, + + init: function(element) { + this.element = $(element); + this.leftPanel = $(this.leftPanelClass, element); + this.rightPanel = $(this.rightPanelClass, element); + this.splitter = $(this.splitterClass, element); + this.overlay = this._createOverlay(this.overlayClass); + + this.splitter.bind('mousedown.splitview', this.beginResize.bind(this)); + }, + + _createOverlay: function(cssClass) { + var pos = this.root.position(); + return $('
') + .addClass(cssClass) + .css({ + position: 'absolute', + left: pos.left, + top: pos.top, + width: this.root.width(), + height: this.root.height() + }) + .hide() + .appendTo(this.element); + }, + + beginResize: function(event) { + this.hotspotX = event.pageX - this.splitter.position().left; + + $(document) + .bind('mousemove.splitview', this.resizeChanged.bind(this)) + .bind('mouseup.splitview', this.endResize.bind(this)); + + this.overlay.show(); + return false; + }, + + resizeChanged: function(event) { + var old_width = this.overlay.width(); + var delta = event.pageX + this.hotspotX - old_width; + + if(old_width + delta < 12) delta = 12 - old_width; + if(old_width + delta > $(window).width()) { + delta = $(window).width() - old_width; + } + + this.overlay.css({'width': old_width + delta}); + + if(this.overlay.next) { + var left = parseInt(this.overlay.next.css('left'), 10); + this.overlay.next.css('left', left+delta); + } + return false; + }, + + endResize: function(event) { + $(document) + .unbind('mousemove.splitview') + .unbind('mouseup.splitview'); + + this.leftPanel.css({ + left: 0, + right: this.hotspotX + }); + + this.rightPanel.css({ + left: this.hotspotX, + right: 0 + }); + + this.overlay.hide(); + }, + + dispose: function() { + this.splitter.unbind('mousedown.splitview'); + } +}); + -- 2.20.1