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