Révision 503b3f7b
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.position.js | ||
---|---|---|
1 |
/* |
|
2 |
* jQuery UI Position 1.8.11 |
|
1 |
/*! |
|
2 |
* jQuery UI Position 1.10.2 |
|
3 |
* http://jqueryui.com |
|
3 | 4 |
* |
4 |
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
|
5 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
5 |
* Copyright 2013 jQuery Foundation and other contributors
|
|
6 |
* Released under the MIT license.
|
|
6 | 7 |
* http://jquery.org/license |
7 | 8 |
* |
8 |
* http://docs.jquery.com/UI/Position
|
|
9 |
* http://api.jqueryui.com/position/
|
|
9 | 10 |
*/ |
10 | 11 |
(function( $, undefined ) { |
11 | 12 |
|
12 | 13 |
$.ui = $.ui || {}; |
13 | 14 |
|
14 |
var horizontalPositions = /left|center|right/, |
|
15 |
verticalPositions = /top|center|bottom/, |
|
16 |
center = "center", |
|
17 |
_position = $.fn.position, |
|
18 |
_offset = $.fn.offset; |
|
15 |
var cachedScrollbarWidth, |
|
16 |
max = Math.max, |
|
17 |
abs = Math.abs, |
|
18 |
round = Math.round, |
|
19 |
rhorizontal = /left|center|right/, |
|
20 |
rvertical = /top|center|bottom/, |
|
21 |
roffset = /[\+\-]\d+(\.[\d]+)?%?/, |
|
22 |
rposition = /^\w+/, |
|
23 |
rpercent = /%$/, |
|
24 |
_position = $.fn.position; |
|
25 |
|
|
26 |
function getOffsets( offsets, width, height ) { |
|
27 |
return [ |
|
28 |
parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ), |
|
29 |
parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 ) |
|
30 |
]; |
|
31 |
} |
|
32 |
|
|
33 |
function parseCss( element, property ) { |
|
34 |
return parseInt( $.css( element, property ), 10 ) || 0; |
|
35 |
} |
|
36 |
|
|
37 |
function getDimensions( elem ) { |
|
38 |
var raw = elem[0]; |
|
39 |
if ( raw.nodeType === 9 ) { |
|
40 |
return { |
|
41 |
width: elem.width(), |
|
42 |
height: elem.height(), |
|
43 |
offset: { top: 0, left: 0 } |
|
44 |
}; |
|
45 |
} |
|
46 |
if ( $.isWindow( raw ) ) { |
|
47 |
return { |
|
48 |
width: elem.width(), |
|
49 |
height: elem.height(), |
|
50 |
offset: { top: elem.scrollTop(), left: elem.scrollLeft() } |
|
51 |
}; |
|
52 |
} |
|
53 |
if ( raw.preventDefault ) { |
|
54 |
return { |
|
55 |
width: 0, |
|
56 |
height: 0, |
|
57 |
offset: { top: raw.pageY, left: raw.pageX } |
|
58 |
}; |
|
59 |
} |
|
60 |
return { |
|
61 |
width: elem.outerWidth(), |
|
62 |
height: elem.outerHeight(), |
|
63 |
offset: elem.offset() |
|
64 |
}; |
|
65 |
} |
|
66 |
|
|
67 |
$.position = { |
|
68 |
scrollbarWidth: function() { |
|
69 |
if ( cachedScrollbarWidth !== undefined ) { |
|
70 |
return cachedScrollbarWidth; |
|
71 |
} |
|
72 |
var w1, w2, |
|
73 |
div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ), |
|
74 |
innerDiv = div.children()[0]; |
|
75 |
|
|
76 |
$( "body" ).append( div ); |
|
77 |
w1 = innerDiv.offsetWidth; |
|
78 |
div.css( "overflow", "scroll" ); |
|
79 |
|
|
80 |
w2 = innerDiv.offsetWidth; |
|
81 |
|
|
82 |
if ( w1 === w2 ) { |
|
83 |
w2 = div[0].clientWidth; |
|
84 |
} |
|
85 |
|
|
86 |
div.remove(); |
|
87 |
|
|
88 |
return (cachedScrollbarWidth = w1 - w2); |
|
89 |
}, |
|
90 |
getScrollInfo: function( within ) { |
|
91 |
var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ), |
|
92 |
overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ), |
|
93 |
hasOverflowX = overflowX === "scroll" || |
|
94 |
( overflowX === "auto" && within.width < within.element[0].scrollWidth ), |
|
95 |
hasOverflowY = overflowY === "scroll" || |
|
96 |
( overflowY === "auto" && within.height < within.element[0].scrollHeight ); |
|
97 |
return { |
|
98 |
width: hasOverflowY ? $.position.scrollbarWidth() : 0, |
|
99 |
height: hasOverflowX ? $.position.scrollbarWidth() : 0 |
|
100 |
}; |
|
101 |
}, |
|
102 |
getWithinInfo: function( element ) { |
|
103 |
var withinElement = $( element || window ), |
|
104 |
isWindow = $.isWindow( withinElement[0] ); |
|
105 |
return { |
|
106 |
element: withinElement, |
|
107 |
isWindow: isWindow, |
|
108 |
offset: withinElement.offset() || { left: 0, top: 0 }, |
|
109 |
scrollLeft: withinElement.scrollLeft(), |
|
110 |
scrollTop: withinElement.scrollTop(), |
|
111 |
width: isWindow ? withinElement.width() : withinElement.outerWidth(), |
|
112 |
height: isWindow ? withinElement.height() : withinElement.outerHeight() |
|
113 |
}; |
|
114 |
} |
|
115 |
}; |
|
19 | 116 |
|
20 | 117 |
$.fn.position = function( options ) { |
21 | 118 |
if ( !options || !options.of ) { |
... | ... | |
25 | 122 |
// make a copy, we don't want to modify arguments |
26 | 123 |
options = $.extend( {}, options ); |
27 | 124 |
|
28 |
var target = $( options.of ), |
|
29 |
targetElem = target[0], |
|
125 |
var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions, |
|
126 |
target = $( options.of ), |
|
127 |
within = $.position.getWithinInfo( options.within ), |
|
128 |
scrollInfo = $.position.getScrollInfo( within ), |
|
30 | 129 |
collision = ( options.collision || "flip" ).split( " " ), |
31 |
offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ], |
|
32 |
targetWidth, |
|
33 |
targetHeight, |
|
34 |
basePosition; |
|
35 |
|
|
36 |
if ( targetElem.nodeType === 9 ) { |
|
37 |
targetWidth = target.width(); |
|
38 |
targetHeight = target.height(); |
|
39 |
basePosition = { top: 0, left: 0 }; |
|
40 |
// TODO: use $.isWindow() in 1.9 |
|
41 |
} else if ( targetElem.setTimeout ) { |
|
42 |
targetWidth = target.width(); |
|
43 |
targetHeight = target.height(); |
|
44 |
basePosition = { top: target.scrollTop(), left: target.scrollLeft() }; |
|
45 |
} else if ( targetElem.preventDefault ) { |
|
130 |
offsets = {}; |
|
131 |
|
|
132 |
dimensions = getDimensions( target ); |
|
133 |
if ( target[0].preventDefault ) { |
|
46 | 134 |
// force left top to allow flipping |
47 | 135 |
options.at = "left top"; |
48 |
targetWidth = targetHeight = 0; |
|
49 |
basePosition = { top: options.of.pageY, left: options.of.pageX }; |
|
50 |
} else { |
|
51 |
targetWidth = target.outerWidth(); |
|
52 |
targetHeight = target.outerHeight(); |
|
53 |
basePosition = target.offset(); |
|
54 | 136 |
} |
137 |
targetWidth = dimensions.width; |
|
138 |
targetHeight = dimensions.height; |
|
139 |
targetOffset = dimensions.offset; |
|
140 |
// clone to reuse original targetOffset later |
|
141 |
basePosition = $.extend( {}, targetOffset ); |
|
55 | 142 |
|
56 |
// force my and at to have valid horizontal and veritcal positions
|
|
57 |
// if a value is missing or invalid, it will be converted to center
|
|
143 |
// force my and at to have valid horizontal and vertical positions
|
|
144 |
// if a value is missing or invalid, it will be converted to center |
|
58 | 145 |
$.each( [ "my", "at" ], function() { |
59 |
var pos = ( options[this] || "" ).split( " " ); |
|
146 |
var pos = ( options[ this ] || "" ).split( " " ), |
|
147 |
horizontalOffset, |
|
148 |
verticalOffset; |
|
149 |
|
|
60 | 150 |
if ( pos.length === 1) { |
61 |
pos = horizontalPositions.test( pos[0] ) ?
|
|
62 |
pos.concat( [center] ) :
|
|
63 |
verticalPositions.test( pos[0] ) ?
|
|
64 |
[ center ].concat( pos ) :
|
|
65 |
[ center, center ];
|
|
151 |
pos = rhorizontal.test( pos[ 0 ] ) ?
|
|
152 |
pos.concat( [ "center" ] ) :
|
|
153 |
rvertical.test( pos[ 0 ] ) ?
|
|
154 |
[ "center" ].concat( pos ) :
|
|
155 |
[ "center", "center" ];
|
|
66 | 156 |
} |
67 |
pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center; |
|
68 |
pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center; |
|
69 |
options[ this ] = pos; |
|
157 |
pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center"; |
|
158 |
pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center"; |
|
159 |
|
|
160 |
// calculate offsets |
|
161 |
horizontalOffset = roffset.exec( pos[ 0 ] ); |
|
162 |
verticalOffset = roffset.exec( pos[ 1 ] ); |
|
163 |
offsets[ this ] = [ |
|
164 |
horizontalOffset ? horizontalOffset[ 0 ] : 0, |
|
165 |
verticalOffset ? verticalOffset[ 0 ] : 0 |
|
166 |
]; |
|
167 |
|
|
168 |
// reduce to just the positions without the offsets |
|
169 |
options[ this ] = [ |
|
170 |
rposition.exec( pos[ 0 ] )[ 0 ], |
|
171 |
rposition.exec( pos[ 1 ] )[ 0 ] |
|
172 |
]; |
|
70 | 173 |
}); |
71 | 174 |
|
72 | 175 |
// normalize collision option |
... | ... | |
74 | 177 |
collision[ 1 ] = collision[ 0 ]; |
75 | 178 |
} |
76 | 179 |
|
77 |
// normalize offset option |
|
78 |
offset[ 0 ] = parseInt( offset[0], 10 ) || 0; |
|
79 |
if ( offset.length === 1 ) { |
|
80 |
offset[ 1 ] = offset[ 0 ]; |
|
81 |
} |
|
82 |
offset[ 1 ] = parseInt( offset[1], 10 ) || 0; |
|
83 |
|
|
84 |
if ( options.at[0] === "right" ) { |
|
180 |
if ( options.at[ 0 ] === "right" ) { |
|
85 | 181 |
basePosition.left += targetWidth; |
86 |
} else if ( options.at[0] === center ) {
|
|
182 |
} else if ( options.at[ 0 ] === "center" ) {
|
|
87 | 183 |
basePosition.left += targetWidth / 2; |
88 | 184 |
} |
89 | 185 |
|
90 |
if ( options.at[1] === "bottom" ) {
|
|
186 |
if ( options.at[ 1 ] === "bottom" ) {
|
|
91 | 187 |
basePosition.top += targetHeight; |
92 |
} else if ( options.at[1] === center ) {
|
|
188 |
} else if ( options.at[ 1 ] === "center" ) {
|
|
93 | 189 |
basePosition.top += targetHeight / 2; |
94 | 190 |
} |
95 | 191 |
|
96 |
basePosition.left += offset[ 0 ]; |
|
97 |
basePosition.top += offset[ 1 ]; |
|
192 |
atOffset = getOffsets( offsets.at, targetWidth, targetHeight ); |
|
193 |
basePosition.left += atOffset[ 0 ]; |
|
194 |
basePosition.top += atOffset[ 1 ]; |
|
98 | 195 |
|
99 | 196 |
return this.each(function() { |
100 |
var elem = $( this ), |
|
197 |
var collisionPosition, using, |
|
198 |
elem = $( this ), |
|
101 | 199 |
elemWidth = elem.outerWidth(), |
102 | 200 |
elemHeight = elem.outerHeight(), |
103 |
marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0, |
|
104 |
marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0, |
|
105 |
collisionWidth = elemWidth + marginLeft + |
|
106 |
( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ), |
|
107 |
collisionHeight = elemHeight + marginTop + |
|
108 |
( parseInt( $.curCSS( this, "marginBottom", true ) ) || 0 ), |
|
201 |
marginLeft = parseCss( this, "marginLeft" ), |
|
202 |
marginTop = parseCss( this, "marginTop" ), |
|
203 |
collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width, |
|
204 |
collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height, |
|
109 | 205 |
position = $.extend( {}, basePosition ), |
110 |
collisionPosition;
|
|
206 |
myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
|
|
111 | 207 |
|
112 |
if ( options.my[0] === "right" ) {
|
|
208 |
if ( options.my[ 0 ] === "right" ) {
|
|
113 | 209 |
position.left -= elemWidth; |
114 |
} else if ( options.my[0] === center ) {
|
|
210 |
} else if ( options.my[ 0 ] === "center" ) {
|
|
115 | 211 |
position.left -= elemWidth / 2; |
116 | 212 |
} |
117 | 213 |
|
118 |
if ( options.my[1] === "bottom" ) {
|
|
214 |
if ( options.my[ 1 ] === "bottom" ) {
|
|
119 | 215 |
position.top -= elemHeight; |
120 |
} else if ( options.my[1] === center ) {
|
|
216 |
} else if ( options.my[ 1 ] === "center" ) {
|
|
121 | 217 |
position.top -= elemHeight / 2; |
122 | 218 |
} |
123 | 219 |
|
124 |
// prevent fractions (see #5280) |
|
125 |
position.left = Math.round( position.left ); |
|
126 |
position.top = Math.round( position.top ); |
|
220 |
position.left += myOffset[ 0 ]; |
|
221 |
position.top += myOffset[ 1 ]; |
|
222 |
|
|
223 |
// if the browser doesn't support fractions, then round for consistent results |
|
224 |
if ( !$.support.offsetFractions ) { |
|
225 |
position.left = round( position.left ); |
|
226 |
position.top = round( position.top ); |
|
227 |
} |
|
127 | 228 |
|
128 | 229 |
collisionPosition = { |
129 |
left: position.left - marginLeft,
|
|
130 |
top: position.top - marginTop
|
|
230 |
marginLeft: marginLeft,
|
|
231 |
marginTop: marginTop
|
|
131 | 232 |
}; |
132 | 233 |
|
133 | 234 |
$.each( [ "left", "top" ], function( i, dir ) { |
134 |
if ( $.ui.position[ collision[i] ] ) {
|
|
135 |
$.ui.position[ collision[i] ][ dir ]( position, {
|
|
235 |
if ( $.ui.position[ collision[ i ] ] ) {
|
|
236 |
$.ui.position[ collision[ i ] ][ dir ]( position, {
|
|
136 | 237 |
targetWidth: targetWidth, |
137 | 238 |
targetHeight: targetHeight, |
138 | 239 |
elemWidth: elemWidth, |
... | ... | |
140 | 241 |
collisionPosition: collisionPosition, |
141 | 242 |
collisionWidth: collisionWidth, |
142 | 243 |
collisionHeight: collisionHeight, |
143 |
offset: offset,
|
|
244 |
offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
|
|
144 | 245 |
my: options.my, |
145 |
at: options.at |
|
246 |
at: options.at, |
|
247 |
within: within, |
|
248 |
elem : elem |
|
146 | 249 |
}); |
147 | 250 |
} |
148 | 251 |
}); |
149 | 252 |
|
150 |
if ( $.fn.bgiframe ) { |
|
151 |
elem.bgiframe(); |
|
253 |
if ( options.using ) { |
|
254 |
// adds feedback as second argument to using callback, if present |
|
255 |
using = function( props ) { |
|
256 |
var left = targetOffset.left - position.left, |
|
257 |
right = left + targetWidth - elemWidth, |
|
258 |
top = targetOffset.top - position.top, |
|
259 |
bottom = top + targetHeight - elemHeight, |
|
260 |
feedback = { |
|
261 |
target: { |
|
262 |
element: target, |
|
263 |
left: targetOffset.left, |
|
264 |
top: targetOffset.top, |
|
265 |
width: targetWidth, |
|
266 |
height: targetHeight |
|
267 |
}, |
|
268 |
element: { |
|
269 |
element: elem, |
|
270 |
left: position.left, |
|
271 |
top: position.top, |
|
272 |
width: elemWidth, |
|
273 |
height: elemHeight |
|
274 |
}, |
|
275 |
horizontal: right < 0 ? "left" : left > 0 ? "right" : "center", |
|
276 |
vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle" |
|
277 |
}; |
|
278 |
if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) { |
|
279 |
feedback.horizontal = "center"; |
|
280 |
} |
|
281 |
if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) { |
|
282 |
feedback.vertical = "middle"; |
|
283 |
} |
|
284 |
if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) { |
|
285 |
feedback.important = "horizontal"; |
|
286 |
} else { |
|
287 |
feedback.important = "vertical"; |
|
288 |
} |
|
289 |
options.using.call( this, props, feedback ); |
|
290 |
}; |
|
152 | 291 |
} |
153 |
elem.offset( $.extend( position, { using: options.using } ) ); |
|
292 |
|
|
293 |
elem.offset( $.extend( position, { using: using } ) ); |
|
154 | 294 |
}); |
155 | 295 |
}; |
156 | 296 |
|
157 | 297 |
$.ui.position = { |
158 | 298 |
fit: { |
159 | 299 |
left: function( position, data ) { |
160 |
var win = $( window ), |
|
161 |
over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(); |
|
162 |
position.left = over > 0 ? position.left - over : Math.max( position.left - data.collisionPosition.left, position.left ); |
|
300 |
var within = data.within, |
|
301 |
withinOffset = within.isWindow ? within.scrollLeft : within.offset.left, |
|
302 |
outerWidth = within.width, |
|
303 |
collisionPosLeft = position.left - data.collisionPosition.marginLeft, |
|
304 |
overLeft = withinOffset - collisionPosLeft, |
|
305 |
overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset, |
|
306 |
newOverRight; |
|
307 |
|
|
308 |
// element is wider than within |
|
309 |
if ( data.collisionWidth > outerWidth ) { |
|
310 |
// element is initially over the left side of within |
|
311 |
if ( overLeft > 0 && overRight <= 0 ) { |
|
312 |
newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset; |
|
313 |
position.left += overLeft - newOverRight; |
|
314 |
// element is initially over right side of within |
|
315 |
} else if ( overRight > 0 && overLeft <= 0 ) { |
|
316 |
position.left = withinOffset; |
|
317 |
// element is initially over both left and right sides of within |
|
318 |
} else { |
|
319 |
if ( overLeft > overRight ) { |
|
320 |
position.left = withinOffset + outerWidth - data.collisionWidth; |
|
321 |
} else { |
|
322 |
position.left = withinOffset; |
|
323 |
} |
|
324 |
} |
|
325 |
// too far left -> align with left edge |
|
326 |
} else if ( overLeft > 0 ) { |
|
327 |
position.left += overLeft; |
|
328 |
// too far right -> align with right edge |
|
329 |
} else if ( overRight > 0 ) { |
|
330 |
position.left -= overRight; |
|
331 |
// adjust based on position and margin |
|
332 |
} else { |
|
333 |
position.left = max( position.left - collisionPosLeft, position.left ); |
|
334 |
} |
|
163 | 335 |
}, |
164 | 336 |
top: function( position, data ) { |
165 |
var win = $( window ), |
|
166 |
over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(); |
|
167 |
position.top = over > 0 ? position.top - over : Math.max( position.top - data.collisionPosition.top, position.top ); |
|
337 |
var within = data.within, |
|
338 |
withinOffset = within.isWindow ? within.scrollTop : within.offset.top, |
|
339 |
outerHeight = data.within.height, |
|
340 |
collisionPosTop = position.top - data.collisionPosition.marginTop, |
|
341 |
overTop = withinOffset - collisionPosTop, |
|
342 |
overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset, |
|
343 |
newOverBottom; |
|
344 |
|
|
345 |
// element is taller than within |
|
346 |
if ( data.collisionHeight > outerHeight ) { |
|
347 |
// element is initially over the top of within |
|
348 |
if ( overTop > 0 && overBottom <= 0 ) { |
|
349 |
newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset; |
|
350 |
position.top += overTop - newOverBottom; |
|
351 |
// element is initially over bottom of within |
|
352 |
} else if ( overBottom > 0 && overTop <= 0 ) { |
|
353 |
position.top = withinOffset; |
|
354 |
// element is initially over both top and bottom of within |
|
355 |
} else { |
|
356 |
if ( overTop > overBottom ) { |
|
357 |
position.top = withinOffset + outerHeight - data.collisionHeight; |
|
358 |
} else { |
|
359 |
position.top = withinOffset; |
|
360 |
} |
|
361 |
} |
|
362 |
// too far up -> align with top |
|
363 |
} else if ( overTop > 0 ) { |
|
364 |
position.top += overTop; |
|
365 |
// too far down -> align with bottom edge |
|
366 |
} else if ( overBottom > 0 ) { |
|
367 |
position.top -= overBottom; |
|
368 |
// adjust based on position and margin |
|
369 |
} else { |
|
370 |
position.top = max( position.top - collisionPosTop, position.top ); |
|
371 |
} |
|
168 | 372 |
} |
169 | 373 |
}, |
170 |
|
|
171 | 374 |
flip: { |
172 | 375 |
left: function( position, data ) { |
173 |
if ( data.at[0] === center ) { |
|
174 |
return; |
|
175 |
} |
|
176 |
var win = $( window ), |
|
177 |
over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(), |
|
376 |
var within = data.within, |
|
377 |
withinOffset = within.offset.left + within.scrollLeft, |
|
378 |
outerWidth = within.width, |
|
379 |
offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left, |
|
380 |
collisionPosLeft = position.left - data.collisionPosition.marginLeft, |
|
381 |
overLeft = collisionPosLeft - offsetLeft, |
|
382 |
overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft, |
|
178 | 383 |
myOffset = data.my[ 0 ] === "left" ? |
179 | 384 |
-data.elemWidth : |
180 | 385 |
data.my[ 0 ] === "right" ? |
... | ... | |
182 | 387 |
0, |
183 | 388 |
atOffset = data.at[ 0 ] === "left" ? |
184 | 389 |
data.targetWidth : |
185 |
-data.targetWidth, |
|
186 |
offset = -2 * data.offset[ 0 ]; |
|
187 |
position.left += data.collisionPosition.left < 0 ? |
|
188 |
myOffset + atOffset + offset : |
|
189 |
over > 0 ? |
|
190 |
myOffset + atOffset + offset : |
|
191 |
0; |
|
390 |
data.at[ 0 ] === "right" ? |
|
391 |
-data.targetWidth : |
|
392 |
0, |
|
393 |
offset = -2 * data.offset[ 0 ], |
|
394 |
newOverRight, |
|
395 |
newOverLeft; |
|
396 |
|
|
397 |
if ( overLeft < 0 ) { |
|
398 |
newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset; |
|
399 |
if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) { |
|
400 |
position.left += myOffset + atOffset + offset; |
|
401 |
} |
|
402 |
} |
|
403 |
else if ( overRight > 0 ) { |
|
404 |
newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft; |
|
405 |
if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) { |
|
406 |
position.left += myOffset + atOffset + offset; |
|
407 |
} |
|
408 |
} |
|
192 | 409 |
}, |
193 | 410 |
top: function( position, data ) { |
194 |
if ( data.at[1] === center ) { |
|
195 |
return; |
|
196 |
} |
|
197 |
var win = $( window ), |
|
198 |
over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(), |
|
199 |
myOffset = data.my[ 1 ] === "top" ? |
|
411 |
var within = data.within, |
|
412 |
withinOffset = within.offset.top + within.scrollTop, |
|
413 |
outerHeight = within.height, |
|
414 |
offsetTop = within.isWindow ? within.scrollTop : within.offset.top, |
|
415 |
collisionPosTop = position.top - data.collisionPosition.marginTop, |
|
416 |
overTop = collisionPosTop - offsetTop, |
|
417 |
overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop, |
|
418 |
top = data.my[ 1 ] === "top", |
|
419 |
myOffset = top ? |
|
200 | 420 |
-data.elemHeight : |
201 | 421 |
data.my[ 1 ] === "bottom" ? |
202 | 422 |
data.elemHeight : |
203 | 423 |
0, |
204 | 424 |
atOffset = data.at[ 1 ] === "top" ? |
205 | 425 |
data.targetHeight : |
206 |
-data.targetHeight, |
|
207 |
offset = -2 * data.offset[ 1 ]; |
|
208 |
position.top += data.collisionPosition.top < 0 ? |
|
209 |
myOffset + atOffset + offset : |
|
210 |
over > 0 ? |
|
211 |
myOffset + atOffset + offset : |
|
212 |
0; |
|
426 |
data.at[ 1 ] === "bottom" ? |
|
427 |
-data.targetHeight : |
|
428 |
0, |
|
429 |
offset = -2 * data.offset[ 1 ], |
|
430 |
newOverTop, |
|
431 |
newOverBottom; |
|
432 |
if ( overTop < 0 ) { |
|
433 |
newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset; |
|
434 |
if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) { |
|
435 |
position.top += myOffset + atOffset + offset; |
|
436 |
} |
|
437 |
} |
|
438 |
else if ( overBottom > 0 ) { |
|
439 |
newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop; |
|
440 |
if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) { |
|
441 |
position.top += myOffset + atOffset + offset; |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |
}, |
|
446 |
flipfit: { |
|
447 |
left: function() { |
|
448 |
$.ui.position.flip.left.apply( this, arguments ); |
|
449 |
$.ui.position.fit.left.apply( this, arguments ); |
|
450 |
}, |
|
451 |
top: function() { |
|
452 |
$.ui.position.flip.top.apply( this, arguments ); |
|
453 |
$.ui.position.fit.top.apply( this, arguments ); |
|
213 | 454 |
} |
214 | 455 |
} |
215 | 456 |
}; |
216 | 457 |
|
217 |
// offset setter from jQuery 1.4 |
|
218 |
if ( !$.offset.setOffset ) { |
|
219 |
$.offset.setOffset = function( elem, options ) { |
|
220 |
// set position first, in-case top/left are set even on static elem |
|
221 |
if ( /static/.test( $.curCSS( elem, "position" ) ) ) { |
|
222 |
elem.style.position = "relative"; |
|
223 |
} |
|
224 |
var curElem = $( elem ), |
|
225 |
curOffset = curElem.offset(), |
|
226 |
curTop = parseInt( $.curCSS( elem, "top", true ), 10 ) || 0, |
|
227 |
curLeft = parseInt( $.curCSS( elem, "left", true ), 10) || 0, |
|
228 |
props = { |
|
229 |
top: (options.top - curOffset.top) + curTop, |
|
230 |
left: (options.left - curOffset.left) + curLeft |
|
231 |
}; |
|
232 |
|
|
233 |
if ( 'using' in options ) { |
|
234 |
options.using.call( elem, props ); |
|
235 |
} else { |
|
236 |
curElem.css( props ); |
|
237 |
} |
|
238 |
}; |
|
458 |
// fraction support test |
|
459 |
(function () { |
|
460 |
var testElement, testElementParent, testElementStyle, offsetLeft, i, |
|
461 |
body = document.getElementsByTagName( "body" )[ 0 ], |
|
462 |
div = document.createElement( "div" ); |
|
239 | 463 |
|
240 |
$.fn.offset = function( options ) {
|
|
241 |
var elem = this[ 0 ];
|
|
242 |
if ( !elem || !elem.ownerDocument ) { return null; }
|
|
243 |
if ( options ) {
|
|
244 |
return this.each(function() {
|
|
245 |
$.offset.setOffset( this, options );
|
|
246 |
});
|
|
247 |
}
|
|
248 |
return _offset.call( this );
|
|
464 |
//Create a "fake body" for testing based on method used in jQuery.support
|
|
465 |
testElement = document.createElement( body ? "div" : "body" );
|
|
466 |
testElementStyle = {
|
|
467 |
visibility: "hidden",
|
|
468 |
width: 0,
|
|
469 |
height: 0,
|
|
470 |
border: 0,
|
|
471 |
margin: 0,
|
|
472 |
background: "none"
|
|
249 | 473 |
}; |
250 |
} |
|
474 |
if ( body ) { |
|
475 |
$.extend( testElementStyle, { |
|
476 |
position: "absolute", |
|
477 |
left: "-1000px", |
|
478 |
top: "-1000px" |
|
479 |
}); |
|
480 |
} |
|
481 |
for ( i in testElementStyle ) { |
|
482 |
testElement.style[ i ] = testElementStyle[ i ]; |
|
483 |
} |
|
484 |
testElement.appendChild( div ); |
|
485 |
testElementParent = body || document.documentElement; |
|
486 |
testElementParent.insertBefore( testElement, testElementParent.firstChild ); |
|
487 |
|
|
488 |
div.style.cssText = "position: absolute; left: 10.7432222px;"; |
|
489 |
|
|
490 |
offsetLeft = $( div ).offset().left; |
|
491 |
$.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11; |
|
492 |
|
|
493 |
testElement.innerHTML = ""; |
|
494 |
testElementParent.removeChild( testElement ); |
|
495 |
})(); |
|
251 | 496 |
|
252 |
}( jQuery )); |
|
497 |
}( jQuery ) ); |
Formats disponibles : Unified diff
Weekly update of contrib modules