corrade-nucleus-nucleons – Blame information for rev 20

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