~davewalker/etherpad/ubuntu-unlimited-max-users-and-revisions

« back to all changes in this revision

Viewing changes to etherpad/src/static/js/draggable.js

  • Committer: James Page
  • Date: 2011-04-13 08:00:43 UTC
  • Revision ID: james.page@canonical.com-20110413080043-eee2nq7y1v7cv2mp
* Refactoring to use native Ubuntu Java libraries. 
* debian/control:
  - use openjdk instead of sun's java
  - update maintainer
* debian/etherpad.init.orig, debian/etherpad.upstart:
  - move the init script out of the way
  - create a basic upstart script
  - note that the open office document conversion daemon was dropped
    from the upstart configuration; if this behavior is desired, please
    create a separate upstart job for it
* debian/rules:
  - just use basic dh_installinit, as it will pick up the new upstart job
* New release
* Changed maintainer to Packaging
* Fixed installation scripts
* Initial Release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2009 Google Inc.
 
3
 * 
 
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
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
 
15
 */
 
16
 
 
17
 
 
18
function makeDraggable(jqueryNodes, eventHandler) {
 
19
  jqueryNodes.each(function() {
 
20
    var node = $(this);
 
21
    var state = {};
 
22
    var inDrag = false;
 
23
    function dragStart(evt) {
 
24
      if (inDrag) {
 
25
        return;
 
26
      }
 
27
      inDrag = true;
 
28
      if (eventHandler('dragstart', evt, state) !== false) {
 
29
        $(document).bind('mousemove', dragUpdate);
 
30
        $(document).bind('mouseup', dragEnd);
 
31
      }
 
32
      evt.preventDefault();
 
33
      return false;
 
34
    }
 
35
    function dragUpdate(evt) {
 
36
      if (! inDrag) {
 
37
        return;
 
38
      }
 
39
      eventHandler('dragupdate', evt, state);
 
40
      evt.preventDefault();
 
41
      return false;
 
42
    }
 
43
    function dragEnd(evt) {
 
44
      if (! inDrag) {
 
45
        return;
 
46
      }
 
47
      inDrag = false;
 
48
      try {
 
49
        eventHandler('dragend', evt, state);
 
50
      }
 
51
      finally {
 
52
        $(document).unbind('mousemove', dragUpdate);
 
53
        $(document).unbind('mouseup', dragEnd);
 
54
        evt.preventDefault();
 
55
      }
 
56
      return false;
 
57
    }
 
58
    node.bind('mousedown', dragStart);
 
59
  });
 
60
}
 
61
 
 
62
function makeResizableVPane(top, sep, bottom, minTop, minBottom) {
 
63
  if (minTop === undefined) minTop = 0;
 
64
  if (minBottom === undefined) minBottom = 0;
 
65
 
 
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;
 
73
    }
 
74
    else if (eType == 'dragupdate') {
 
75
      var change = evt.pageY - state.startY;
 
76
 
 
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;
 
81
 
 
82
      var bottomHeight = state.bottomHeight - change;
 
83
      var sepHeight = $(sep).height();
 
84
 
 
85
      var totalHeight = topHeight + sepHeight + bottomHeight;
 
86
      topHeight = 100.0 * topHeight / totalHeight;
 
87
      sepHeight = 100.0 * sepHeight / totalHeight;
 
88
      bottomHeight = 100.0 * bottomHeight / totalHeight;
 
89
 
 
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');
 
95
    }
 
96
  });
 
97
}
 
98
 
 
99
function makeResizableHPane(left, sep, right, minLeft, minRight, sepWidth, sepOffset) {
 
100
  if (minLeft === undefined) minLeft = 0;
 
101
  if (minRight === undefined) minRight = 0;
 
102
 
 
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;
 
112
 
 
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;
 
117
 
 
118
      var rightWidth = state.rightWidth - change;
 
119
      newSepWidth = sepWidth;
 
120
      if (newSepWidth == undefined)
 
121
        newSepWidth = $(sep).width();
 
122
      newSepOffset = sepOffset;
 
123
      if (newSepOffset == undefined)
 
124
        newSepOffset = 0;
 
125
 
 
126
      if (change == 0) {
 
127
        if (rightWidth != minRight || state.lastRightWidth == undefined) {
 
128
          state.lastRightWidth = rightWidth;
 
129
          rightWidth = minRight;
 
130
        } else {
 
131
          rightWidth = state.lastRightWidth;
 
132
          state.lastRightWidth = minRight;
 
133
        }
 
134
        change = state.rightWidth - rightWidth;
 
135
        leftWidth = change +  state.leftWidth;
 
136
      }
 
137
 
 
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;
 
143
 
 
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');
 
149
    }
 
150
  });
 
151
}