summaryrefslogtreecommitdiff
path: root/frontend/delta/js/MochiKit/Position.js
Unidiff
Diffstat (limited to 'frontend/delta/js/MochiKit/Position.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/MochiKit/Position.js241
1 files changed, 241 insertions, 0 deletions
diff --git a/frontend/delta/js/MochiKit/Position.js b/frontend/delta/js/MochiKit/Position.js
new file mode 100644
index 0000000..e5f4543
--- a/dev/null
+++ b/frontend/delta/js/MochiKit/Position.js
@@ -0,0 +1,241 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24/***
25
26MochiKit.Position 1.5
27
28See <http://mochikit.com/> for documentation, downloads, license, etc.
29
30(c) 2005-2006 Bob Ippolito and others. All rights Reserved.
31
32***/
33
34MochiKit.Base.module(MochiKit, 'Position', '1.5', ['Base', 'DOM', 'Style']);
35
36MochiKit.Base.update(MochiKit.Position, {
37 // Don't export from this module
38 __export__: false,
39
40 // set to true if needed, warning: firefox performance problems
41 // NOT neeeded for page scrolling, only if draggable contained in
42 // scrollable elements
43 includeScrollOffsets: false,
44
45 /** @id MochiKit.Position.prepare */
46 prepare: function () {
47 var deltaX = window.pageXOffset
48 || document.documentElement.scrollLeft
49 || document.body.scrollLeft
50 || 0;
51 var deltaY = window.pageYOffset
52 || document.documentElement.scrollTop
53 || document.body.scrollTop
54 || 0;
55 this.windowOffset = new MochiKit.Style.Coordinates(deltaX, deltaY);
56 },
57
58 /** @id MochiKit.Position.cumulativeOffset */
59 cumulativeOffset: function (element) {
60 var valueT = 0;
61 var valueL = 0;
62 do {
63 valueT += element.offsetTop || 0;
64 valueL += element.offsetLeft || 0;
65 element = element.offsetParent;
66 } while (element);
67 return new MochiKit.Style.Coordinates(valueL, valueT);
68 },
69
70 /** @id MochiKit.Position.realOffset */
71 realOffset: function (element) {
72 var valueT = 0;
73 var valueL = 0;
74 do {
75 valueT += element.scrollTop || 0;
76 valueL += element.scrollLeft || 0;
77 element = element.parentNode;
78 } while (element);
79 return new MochiKit.Style.Coordinates(valueL, valueT);
80 },
81
82 /** @id MochiKit.Position.within */
83 within: function (element, x, y) {
84 if (this.includeScrollOffsets) {
85 return this.withinIncludingScrolloffsets(element, x, y);
86 }
87 this.xcomp = x;
88 this.ycomp = y;
89 this.offset = this.cumulativeOffset(element);
90 if (element.style.position == "fixed") {
91 this.offset.x += this.windowOffset.x;
92 this.offset.y += this.windowOffset.y;
93 }
94
95 return (y >= this.offset.y &&
96 y < this.offset.y + element.offsetHeight &&
97 x >= this.offset.x &&
98 x < this.offset.x + element.offsetWidth);
99 },
100
101 /** @id MochiKit.Position.withinIncludingScrolloffsets */
102 withinIncludingScrolloffsets: function (element, x, y) {
103 var offsetcache = this.realOffset(element);
104
105 this.xcomp = x + offsetcache.x - this.windowOffset.x;
106 this.ycomp = y + offsetcache.y - this.windowOffset.y;
107 this.offset = this.cumulativeOffset(element);
108
109 return (this.ycomp >= this.offset.y &&
110 this.ycomp < this.offset.y + element.offsetHeight &&
111 this.xcomp >= this.offset.x &&
112 this.xcomp < this.offset.x + element.offsetWidth);
113 },
114
115 // within must be called directly before
116 /** @id MochiKit.Position.overlap */
117 overlap: function (mode, element) {
118 if (!mode) {
119 return 0;
120 }
121 if (mode == 'vertical') {
122 return ((this.offset.y + element.offsetHeight) - this.ycomp) /
123 element.offsetHeight;
124 }
125 if (mode == 'horizontal') {
126 return ((this.offset.x + element.offsetWidth) - this.xcomp) /
127 element.offsetWidth;
128 }
129 },
130
131 /** @id MochiKit.Position.absolutize */
132 absolutize: function (element) {
133 element = MochiKit.DOM.getElement(element);
134 if (element.style.position == 'absolute') {
135 return;
136 }
137 MochiKit.Position.prepare();
138
139 var offsets = MochiKit.Position.positionedOffset(element);
140 var width = element.clientWidth;
141 var height = element.clientHeight;
142
143 var oldStyle = {
144 'position': element.style.position,
145 'left': offsets.x - parseFloat(element.style.left || 0),
146 'top': offsets.y - parseFloat(element.style.top || 0),
147 'width': element.style.width,
148 'height': element.style.height
149 };
150
151 element.style.position = 'absolute';
152 element.style.top = offsets.y + 'px';
153 element.style.left = offsets.x + 'px';
154 element.style.width = width + 'px';
155 element.style.height = height + 'px';
156
157 return oldStyle;
158 },
159
160 /** @id MochiKit.Position.positionedOffset */
161 positionedOffset: function (element) {
162 var valueT = 0, valueL = 0;
163 do {
164 valueT += element.offsetTop || 0;
165 valueL += element.offsetLeft || 0;
166 element = element.offsetParent;
167 if (element) {
168 var p = MochiKit.Style.getStyle(element, 'position');
169 if (p == 'relative' || p == 'absolute') {
170 break;
171 }
172 }
173 } while (element);
174 return new MochiKit.Style.Coordinates(valueL, valueT);
175 },
176
177 /** @id MochiKit.Position.relativize */
178 relativize: function (element, oldPos) {
179 element = MochiKit.DOM.getElement(element);
180 if (element.style.position == 'relative') {
181 return;
182 }
183 MochiKit.Position.prepare();
184
185 var top = parseFloat(element.style.top || 0) -
186 (oldPos['top'] || 0);
187 var left = parseFloat(element.style.left || 0) -
188 (oldPos['left'] || 0);
189
190 element.style.position = oldPos['position'];
191 element.style.top = top + 'px';
192 element.style.left = left + 'px';
193 element.style.width = oldPos['width'];
194 element.style.height = oldPos['height'];
195 },
196
197 /** @id MochiKit.Position.clone */
198 clone: function (source, target) {
199 source = MochiKit.DOM.getElement(source);
200 target = MochiKit.DOM.getElement(target);
201 target.style.position = 'absolute';
202 var offsets = this.cumulativeOffset(source);
203 target.style.top = offsets.y + 'px';
204 target.style.left = offsets.x + 'px';
205 target.style.width = source.offsetWidth + 'px';
206 target.style.height = source.offsetHeight + 'px';
207 },
208
209 /** @id MochiKit.Position.page */
210 page: function (forElement) {
211 var valueT = 0;
212 var valueL = 0;
213
214 var element = forElement;
215 do {
216 valueT += element.offsetTop || 0;
217 valueL += element.offsetLeft || 0;
218
219 // Safari fix
220 if (element.offsetParent == document.body && MochiKit.Style.getStyle(element, 'position') == 'absolute') {
221 break;
222 }
223 } while (element = element.offsetParent);
224
225 element = forElement;
226 do {
227 valueT -= element.scrollTop || 0;
228 valueL -= element.scrollLeft || 0;
229 } while (element = element.parentNode);
230
231 return new MochiKit.Style.Coordinates(valueL, valueT);
232 }
233});
234
235MochiKit.Position.__new__ = function (win) {
236 MochiKit.Base.nameFunctions(this);
237};
238
239MochiKit.Position.__new__(this);
240
241MochiKit.Base._exportSymbols(this, MochiKit.Position);