a1a3bc73
Luigi Serra
graphs updates
|
1
|
define( [
|
74249687
Luigi Serra
Cross browser con...
|
2
|
"./core",
|
74249687
Luigi Serra
Cross browser con...
|
3
|
"./core/access",
|
a1a3bc73
Luigi Serra
graphs updates
|
4
5
|
"./var/document",
"./var/documentElement",
|
74249687
Luigi Serra
Cross browser con...
|
6
7
8
9
10
11
12
13
|
"./css/var/rnumnonpx",
"./css/curCSS",
"./css/addGetHookIf",
"./css/support",
"./core/init",
"./css",
"./selector" // contains
|
a1a3bc73
Luigi Serra
graphs updates
|
14
|
], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) {
|
74249687
Luigi Serra
Cross browser con...
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/**
* Gets a window from an element
*/
function getWindow( elem ) {
return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
}
jQuery.offset = {
setOffset: function( elem, options, i ) {
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
position = jQuery.css( elem, "position" ),
curElem = jQuery( elem ),
props = {};
// Set position first, in-case top/left are set even on static elem
if ( position === "static" ) {
elem.style.position = "relative";
}
curOffset = curElem.offset();
curCSSTop = jQuery.css( elem, "top" );
curCSSLeft = jQuery.css( elem, "left" );
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
a1a3bc73
Luigi Serra
graphs updates
|
39
|
( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1;
|
74249687
Luigi Serra
Cross browser con...
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Need to be able to calculate position if either
// top or left is auto and position is either absolute or fixed
if ( calculatePosition ) {
curPosition = curElem.position();
curTop = curPosition.top;
curLeft = curPosition.left;
} else {
curTop = parseFloat( curCSSTop ) || 0;
curLeft = parseFloat( curCSSLeft ) || 0;
}
if ( jQuery.isFunction( options ) ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
54
55
56
|
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
74249687
Luigi Serra
Cross browser con...
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
}
if ( options.top != null ) {
props.top = ( options.top - curOffset.top ) + curTop;
}
if ( options.left != null ) {
props.left = ( options.left - curOffset.left ) + curLeft;
}
if ( "using" in options ) {
options.using.call( elem, props );
} else {
curElem.css( props );
}
}
};
|
a1a3bc73
Luigi Serra
graphs updates
|
75
|
jQuery.fn.extend( {
|
74249687
Luigi Serra
Cross browser con...
|
76
77
78
79
|
offset: function( options ) {
if ( arguments.length ) {
return options === undefined ?
this :
|
a1a3bc73
Luigi Serra
graphs updates
|
80
|
this.each( function( i ) {
|
74249687
Luigi Serra
Cross browser con...
|
81
|
jQuery.offset.setOffset( this, options, i );
|
a1a3bc73
Luigi Serra
graphs updates
|
82
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
}
var docElem, win,
elem = this[ 0 ],
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
101
|
box = elem.getBoundingClientRect();
|
74249687
Luigi Serra
Cross browser con...
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
win = getWindow( doc );
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
},
position: function() {
if ( !this[ 0 ] ) {
return;
}
var offsetParent, offset,
elem = this[ 0 ],
parentOffset = { top: 0, left: 0 };
|
a1a3bc73
Luigi Serra
graphs updates
|
118
119
|
// Fixed elements are offset from window (parentOffset = {top:0, left: 0},
// because it is its only offset parent
|
74249687
Luigi Serra
Cross browser con...
|
120
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
121
|
|
74249687
Luigi Serra
Cross browser con...
|
122
123
124
125
|
// Assume getBoundingClientRect is there when computed position is fixed
offset = elem.getBoundingClientRect();
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
126
|
|
74249687
Luigi Serra
Cross browser con...
|
127
128
129
130
131
132
133
134
135
136
|
// Get *real* offsetParent
offsetParent = this.offsetParent();
// Get correct offsets
offset = this.offset();
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
parentOffset = offsetParent.offset();
}
// Add offsetParent borders
|
a1a3bc73
Luigi Serra
graphs updates
|
137
138
139
140
141
|
// Subtract offsetParent scroll positions
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ) -
offsetParent.scrollTop();
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ) -
offsetParent.scrollLeft();
|
74249687
Luigi Serra
Cross browser con...
|
142
143
144
145
146
147
148
149
150
|
}
// Subtract parent offsets and element margins
return {
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
};
},
|
a1a3bc73
Luigi Serra
graphs updates
|
151
152
153
154
155
156
157
158
159
160
|
// This method will return documentElement in the following cases:
// 1) For the element inside the iframe without offsetParent, this method will return
// documentElement of the parent window
// 2) For the hidden or detached element
// 3) For body or html element, i.e. in case of the html node - it will return itself
//
// but those exceptions were never presented as a real life use-cases
// and might be considered as more preferable results.
//
// This logic, however, is not guaranteed and can change at any point in the future
|
74249687
Luigi Serra
Cross browser con...
|
161
|
offsetParent: function() {
|
a1a3bc73
Luigi Serra
graphs updates
|
162
163
|
return this.map( function() {
var offsetParent = this.offsetParent;
|
74249687
Luigi Serra
Cross browser con...
|
164
|
|
a1a3bc73
Luigi Serra
graphs updates
|
165
|
while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) {
|
74249687
Luigi Serra
Cross browser con...
|
166
167
168
|
offsetParent = offsetParent.offsetParent;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
169
170
|
return offsetParent || documentElement;
} );
|
74249687
Luigi Serra
Cross browser con...
|
171
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
172
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// Create scrollLeft and scrollTop methods
jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
var top = "pageYOffset" === prop;
jQuery.fn[ method ] = function( val ) {
return access( this, function( elem, method, val ) {
var win = getWindow( elem );
if ( val === undefined ) {
return win ? win[ prop ] : elem[ method ];
}
if ( win ) {
win.scrollTo(
|
a1a3bc73
Luigi Serra
graphs updates
|
188
189
|
!top ? val : win.pageXOffset,
top ? val : win.pageYOffset
|
74249687
Luigi Serra
Cross browser con...
|
190
191
192
193
194
|
);
} else {
elem[ method ] = val;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
195
|
}, method, val, arguments.length );
|
74249687
Luigi Serra
Cross browser con...
|
196
|
};
|
a1a3bc73
Luigi Serra
graphs updates
|
197
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
198
|
|
a1a3bc73
Luigi Serra
graphs updates
|
199
|
// Support: Safari<7-8+, Chrome<37-44+
|
74249687
Luigi Serra
Cross browser con...
|
200
201
202
203
204
205
206
207
208
209
|
// Add the top/left cssHooks using jQuery.fn.position
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
// Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
// getComputedStyle returns percent when specified for top/left/bottom/right;
// rather than make the css module depend on the offset module, just check for it here
jQuery.each( [ "top", "left" ], function( i, prop ) {
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
function( elem, computed ) {
if ( computed ) {
computed = curCSS( elem, prop );
|
a1a3bc73
Luigi Serra
graphs updates
|
210
|
|
74249687
Luigi Serra
Cross browser con...
|
211
212
213
214
215
216
217
|
// If curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :
computed;
}
}
);
|
a1a3bc73
Luigi Serra
graphs updates
|
218
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
219
220
|
return jQuery;
|
a1a3bc73
Luigi Serra
graphs updates
|
221
|
} );
|