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