2
* Copyright 2009 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS-IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
function makeDraggable(jqueryNodes, eventHandler) {
19
jqueryNodes.each(function() {
23
function dragStart(evt) {
28
if (eventHandler('dragstart', evt, state) !== false) {
29
$(document).bind('mousemove', dragUpdate);
30
$(document).bind('mouseup', dragEnd);
35
function dragUpdate(evt) {
39
eventHandler('dragupdate', evt, state);
43
function dragEnd(evt) {
49
eventHandler('dragend', evt, state);
52
$(document).unbind('mousemove', dragUpdate);
53
$(document).unbind('mouseup', dragEnd);
58
node.bind('mousedown', dragStart);
62
function makeResizableVPane(top, sep, bottom, minTop, minBottom) {
63
if (minTop === undefined) minTop = 0;
64
if (minBottom === undefined) minBottom = 0;
66
makeDraggable($(sep), function(eType, evt, state) {
67
if (eType == 'dragstart') {
68
state.startY = evt.pageY;
69
state.topHeight = $(top).height();
70
state.bottomHeight = $(bottom).height();
71
state.minTop = minTop;
72
state.maxTop = (state.topHeight + state.bottomHeight) - minBottom;
74
else if (eType == 'dragupdate') {
75
var change = evt.pageY - state.startY;
77
var topHeight = state.topHeight + change;
78
if (topHeight < state.minTop) { topHeight = state.minTop; }
79
if (topHeight > state.maxTop) { topHeight = state.maxTop; }
80
change = topHeight - state.topHeight;
82
var bottomHeight = state.bottomHeight - change;
83
var sepHeight = $(sep).height();
85
var totalHeight = topHeight + sepHeight + bottomHeight;
86
topHeight = 100.0 * topHeight / totalHeight;
87
sepHeight = 100.0 * sepHeight / totalHeight;
88
bottomHeight = 100.0 * bottomHeight / totalHeight;
90
$(top).css('bottom', 'auto');
91
$(top).css('height', topHeight + "%");
92
$(sep).css('top', topHeight + "%");
93
$(bottom).css('top', (topHeight + sepHeight) + '%');
94
$(bottom).css('height', 'auto');
99
function makeResizableHPane(left, sep, right, minLeft, minRight, sepWidth, sepOffset) {
100
if (minLeft === undefined) minLeft = 0;
101
if (minRight === undefined) minRight = 0;
103
makeDraggable($(sep), function(eType, evt, state) {
104
if (eType == 'dragstart') {
105
state.startX = evt.pageX;
106
state.leftWidth = $(left).width();
107
state.rightWidth = $(right).width();
108
state.minLeft = minLeft;
109
state.maxLeft = (state.leftWidth + state.rightWidth) - minRight;
110
} else if (eType == 'dragend' || eType == 'dragupdate') {
111
var change = evt.pageX - state.startX;
113
var leftWidth = state.leftWidth + change;
114
if (leftWidth < state.minLeft) { leftWidth = state.minLeft; }
115
if (leftWidth > state.maxLeft) { leftWidth = state.maxLeft; }
116
change = leftWidth - state.leftWidth;
118
var rightWidth = state.rightWidth - change;
119
newSepWidth = sepWidth;
120
if (newSepWidth == undefined)
121
newSepWidth = $(sep).width();
122
newSepOffset = sepOffset;
123
if (newSepOffset == undefined)
127
if (rightWidth != minRight || state.lastRightWidth == undefined) {
128
state.lastRightWidth = rightWidth;
129
rightWidth = minRight;
131
rightWidth = state.lastRightWidth;
132
state.lastRightWidth = minRight;
134
change = state.rightWidth - rightWidth;
135
leftWidth = change + state.leftWidth;
138
var totalWidth = leftWidth + newSepWidth + rightWidth;
139
leftWidth = 100.0 * leftWidth / totalWidth;
140
newSepWidth = 100.0 * newSepWidth / totalWidth;
141
newSepOffset = 100.0 * newSepOffset / totalWidth;
142
rightWidth = 100.0 * rightWidth / totalWidth;
144
$(left).css('right', 'auto');
145
$(left).css('width', leftWidth + "%");
146
$(sep).css('left', (leftWidth + newSepOffset) + "%");
147
$(right).css('left', (leftWidth + newSepWidth) + '%');
148
$(right).css('width', 'auto');