Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
/*
2
 * jQuery UI Position 1.8.5
3
 *
4
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
6
 * http://jquery.org/license
7
 *
8
 * http://docs.jquery.com/UI/Position
9
 */
10
(function( $, undefined ) {
11
 
12
$.ui = $.ui || {};
13
 
14
var horizontalPositions = /left|center|right/,
15
	verticalPositions = /top|center|bottom/,
16
	center = "center",
17
	_position = $.fn.position,
18
	_offset = $.fn.offset;
19
 
20
$.fn.position = function( options ) {
21
	if ( !options || !options.of ) {
22
		return _position.apply( this, arguments );
23
	}
24
 
25
	// make a copy, we don't want to modify arguments
26
	options = $.extend( {}, options );
27
 
28
	var target = $( options.of ),
29
		targetElem = target[0],
30
		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
	} else if ( targetElem.scrollTo && targetElem.document ) {
41
		targetWidth = target.width();
42
		targetHeight = target.height();
43
		basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
44
	} else if ( targetElem.preventDefault ) {
45
		// force left top to allow flipping
46
		options.at = "left top";
47
		targetWidth = targetHeight = 0;
48
		basePosition = { top: options.of.pageY, left: options.of.pageX };
49
	} else {
50
		targetWidth = target.outerWidth();
51
		targetHeight = target.outerHeight();
52
		basePosition = target.offset();
53
	}
54
 
55
	// force my and at to have valid horizontal and veritcal positions
56
	// if a value is missing or invalid, it will be converted to center
57
	$.each( [ "my", "at" ], function() {
58
		var pos = ( options[this] || "" ).split( " " );
59
		if ( pos.length === 1) {
60
			pos = horizontalPositions.test( pos[0] ) ?
61
				pos.concat( [center] ) :
62
				verticalPositions.test( pos[0] ) ?
63
					[ center ].concat( pos ) :
64
					[ center, center ];
65
		}
66
		pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center;
67
		pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center;
68
		options[ this ] = pos;
69
	});
70
 
71
	// normalize collision option
72
	if ( collision.length === 1 ) {
73
		collision[ 1 ] = collision[ 0 ];
74
	}
75
 
76
	// normalize offset option
77
	offset[ 0 ] = parseInt( offset[0], 10 ) || 0;
78
	if ( offset.length === 1 ) {
79
		offset[ 1 ] = offset[ 0 ];
80
	}
81
	offset[ 1 ] = parseInt( offset[1], 10 ) || 0;
82
 
83
	if ( options.at[0] === "right" ) {
84
		basePosition.left += targetWidth;
85
	} else if (options.at[0] === center ) {
86
		basePosition.left += targetWidth / 2;
87
	}
88
 
89
	if ( options.at[1] === "bottom" ) {
90
		basePosition.top += targetHeight;
91
	} else if ( options.at[1] === center ) {
92
		basePosition.top += targetHeight / 2;
93
	}
94
 
95
	basePosition.left += offset[ 0 ];
96
	basePosition.top += offset[ 1 ];
97
 
98
	return this.each(function() {
99
		var elem = $( this ),
100
			elemWidth = elem.outerWidth(),
101
			elemHeight = elem.outerHeight(),
102
			marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0,
103
			marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0,
104
			collisionWidth = elemWidth + marginLeft +
105
				parseInt( $.curCSS( this, "marginRight", true ) ) || 0,
106
			collisionHeight = elemHeight + marginTop +
107
				parseInt( $.curCSS( this, "marginBottom", true ) ) || 0,
108
			position = $.extend( {}, basePosition ),
109
			collisionPosition;
110
 
111
		if ( options.my[0] === "right" ) {
112
			position.left -= elemWidth;
113
		} else if ( options.my[0] === center ) {
114
			position.left -= elemWidth / 2;
115
		}
116
 
117
		if ( options.my[1] === "bottom" ) {
118
			position.top -= elemHeight;
119
		} else if ( options.my[1] === center ) {
120
			position.top -= elemHeight / 2;
121
		}
122
 
123
		// prevent fractions (see #5280)
124
		position.left = parseInt( position.left );
125
		position.top = parseInt( position.top );
126
 
127
		collisionPosition = {
128
			left: position.left - marginLeft,
129
			top: position.top - marginTop
130
		};
131
 
132
		$.each( [ "left", "top" ], function( i, dir ) {
133
			if ( $.ui.position[ collision[i] ] ) {
134
				$.ui.position[ collision[i] ][ dir ]( position, {
135
					targetWidth: targetWidth,
136
					targetHeight: targetHeight,
137
					elemWidth: elemWidth,
138
					elemHeight: elemHeight,
139
					collisionPosition: collisionPosition,
140
					collisionWidth: collisionWidth,
141
					collisionHeight: collisionHeight,
142
					offset: offset,
143
					my: options.my,
144
					at: options.at
145
				});
146
			}
147
		});
148
 
149
		if ( $.fn.bgiframe ) {
150
			elem.bgiframe();
151
		}
152
		elem.offset( $.extend( position, { using: options.using } ) );
153
	});
154
};
155
 
156
$.ui.position = {
157
	fit: {
158
		left: function( position, data ) {
159
			var win = $( window ),
160
				over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft();
161
			position.left = over > 0 ? position.left - over : Math.max( position.left - data.collisionPosition.left, position.left );
162
		},
163
		top: function( position, data ) {
164
			var win = $( window ),
165
				over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop();
166
			position.top = over > 0 ? position.top - over : Math.max( position.top - data.collisionPosition.top, position.top );
167
		}
168
	},
169
 
170
	flip: {
171
		left: function( position, data ) {
172
			if ( data.at[0] === center ) {
173
				return;
174
			}
175
			var win = $( window ),
176
				over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(),
177
				myOffset = data.my[ 0 ] === "left" ?
178
					-data.elemWidth :
179
					data.my[ 0 ] === "right" ?
180
						data.elemWidth :
181
						0,
182
				atOffset = data.at[ 0 ] === "left" ?
183
					data.targetWidth :
184
					-data.targetWidth,
185
				offset = -2 * data.offset[ 0 ];
186
			position.left += data.collisionPosition.left < 0 ?
187
				myOffset + atOffset + offset :
188
				over > 0 ?
189
					myOffset + atOffset + offset :
190
					0;
191
		},
192
		top: function( position, data ) {
193
			if ( data.at[1] === center ) {
194
				return;
195
			}
196
			var win = $( window ),
197
				over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(),
198
				myOffset = data.my[ 1 ] === "top" ?
199
					-data.elemHeight :
200
					data.my[ 1 ] === "bottom" ?
201
						data.elemHeight :
202
						0,
203
				atOffset = data.at[ 1 ] === "top" ?
204
					data.targetHeight :
205
					-data.targetHeight,
206
				offset = -2 * data.offset[ 1 ];
207
			position.top += data.collisionPosition.top < 0 ?
208
				myOffset + atOffset + offset :
209
				over > 0 ?
210
					myOffset + atOffset + offset :
211
					0;
212
		}
213
	}
214
};
215
 
216
// offset setter from jQuery 1.4
217
if ( !$.offset.setOffset ) {
218
	$.offset.setOffset = function( elem, options ) {
219
		// set position first, in-case top/left are set even on static elem
220
		if ( /static/.test( $.curCSS( elem, "position" ) ) ) {
221
			elem.style.position = "relative";
222
		}
223
		var curElem   = $( elem ),
224
			curOffset = curElem.offset(),
225
			curTop    = parseInt( $.curCSS( elem, "top",  true ), 10 ) || 0,
226
			curLeft   = parseInt( $.curCSS( elem, "left", true ), 10)  || 0,
227
			props     = {
228
				top:  (options.top  - curOffset.top)  + curTop,
229
				left: (options.left - curOffset.left) + curLeft
230
			};
231
 
232
		if ( 'using' in options ) {
233
			options.using.call( elem, props );
234
		} else {
235
			curElem.css( props );
236
		}
237
	};
238
 
239
	$.fn.offset = function( options ) {
240
		var elem = this[ 0 ];
241
		if ( !elem || !elem.ownerDocument ) { return null; }
242
		if ( options ) {
243
			return this.each(function() {
244
				$.offset.setOffset( this, options );
245
			});
246
		}
247
		return _offset.call( this );
248
	};
249
}
250
 
251
}( jQuery ));