]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/offset.js
4c34fd0ef25e7661ba89752d642fce28ef9fe78d
12 "./selector" // contains
13 ], function( jQuery
, strundefined
, access
, rnumnonpx
, curCSS
, addGetHookIf
, support
) {
15 var docElem
= window
.document
.documentElement
;
18 * Gets a window from an element
20 function getWindow( elem
) {
21 return jQuery
.isWindow( elem
) ? elem : elem
.nodeType
=== 9 && elem
.defaultView
;
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
),
31 // Set position first, in-case top/left are set even on static elem
32 if ( position
=== "static" ) {
33 elem
.style
.position
= "relative";
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;
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
;
50 curTop
= parseFloat( curCSSTop
) || 0;
51 curLeft
= parseFloat( curCSSLeft
) || 0;
54 if ( jQuery
.isFunction( options
) ) {
55 options
= options
.call( elem
, i
, curOffset
);
58 if ( options
.top
!= null ) {
59 props
.top
= ( options
.top
- curOffset
.top
) + curTop
;
61 if ( options
.left
!= null ) {
62 props
.left
= ( options
.left
- curOffset
.left
) + curLeft
;
65 if ( "using" in options
) {
66 options
.using
.call( elem
, props
);
75 offset: function( options
) {
76 if ( arguments
.length
) {
77 return options
=== undefined ?
79 this.each(function( i
) {
80 jQuery
.offset
.setOffset( this, options
, i
);
86 box
= { top: 0, left: 0 },
87 doc
= elem
&& elem
.ownerDocument
;
93 docElem
= doc
.documentElement
;
95 // Make sure it's not a disconnected DOM node
96 if ( !jQuery
.contains( docElem
, elem
) ) {
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();
105 win
= getWindow( doc
);
107 top: box
.top
+ win
.pageYOffset
- docElem
.clientTop
,
108 left: box
.left
+ win
.pageXOffset
- docElem
.clientLeft
112 position: function() {
117 var offsetParent
, offset
,
119 parentOffset
= { top: 0, left: 0 };
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();
127 // Get *real* offsetParent
128 offsetParent
= this.offsetParent();
130 // Get correct offsets
131 offset
= this.offset();
132 if ( !jQuery
.nodeName( offsetParent
[ 0 ], "html" ) ) {
133 parentOffset
= offsetParent
.offset();
136 // Add offsetParent borders
137 parentOffset
.top
+= jQuery
.css( offsetParent
[ 0 ], "borderTopWidth", true );
138 parentOffset
.left
+= jQuery
.css( offsetParent
[ 0 ], "borderLeftWidth", true );
141 // Subtract parent offsets and element margins
143 top: offset
.top
- parentOffset
.top
- jQuery
.css( elem
, "marginTop", true ),
144 left: offset
.left
- parentOffset
.left
- jQuery
.css( elem
, "marginLeft", true )
148 offsetParent: function() {
149 return this.map(function() {
150 var offsetParent
= this.offsetParent
|| docElem
;
152 while ( offsetParent
&& ( !jQuery
.nodeName( offsetParent
, "html" ) && jQuery
.css( offsetParent
, "position" ) === "static" ) ) {
153 offsetParent
= offsetParent
.offsetParent
;
156 return offsetParent
|| docElem
;
161 // Create scrollLeft and scrollTop methods
162 jQuery
.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method
, prop
) {
163 var top
= "pageYOffset" === prop
;
165 jQuery
.fn
[ method
] = function( val
) {
166 return access( this, function( elem
, method
, val
) {
167 var win
= getWindow( elem
);
169 if ( val
=== undefined ) {
170 return win
? win
[ prop
] : elem
[ method
];
175 !top
? val : window
.pageXOffset
,
176 top
? val : window
.pageYOffset
180 elem
[ method
] = val
;
182 }, method
, val
, arguments
.length
, null );
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
) {
196 computed
= curCSS( elem
, prop
);
197 // If curCSS returns percentage, fallback to offset
198 return rnumnonpx
.test( computed
) ?
199 jQuery( elem
).position()[ prop
] + "px" :