scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 58 Rev 125
Line 1... Line 1...
1 define( [ 1 define([
2 "./core", 2 "./core",
-   3 "./var/strundefined",
3 "./core/access", 4 "./core/access",
4 "./var/document", -  
5 "./var/documentElement", -  
6 "./css/var/rnumnonpx", 5 "./css/var/rnumnonpx",
7 "./css/curCSS", 6 "./css/curCSS",
8 "./css/addGetHookIf", 7 "./css/addGetHookIf",
9 "./css/support", 8 "./css/support",
Line 10... Line 9...
10   9  
11 "./core/init", 10 "./core/init",
12 "./css", 11 "./css",
13 "./selector" // contains 12 "./selector" // contains
Line 14... Line 13...
14 ], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) { 13 ], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) {
Line 15... Line 14...
15   14  
16 "use strict"; 15 var docElem = window.document.documentElement;
17   16  
18 /** 17 /**
Line 36... Line 35...
36   35  
37 curOffset = curElem.offset(); 36 curOffset = curElem.offset();
38 curCSSTop = jQuery.css( elem, "top" ); 37 curCSSTop = jQuery.css( elem, "top" );
39 curCSSLeft = jQuery.css( elem, "left" ); 38 curCSSLeft = jQuery.css( elem, "left" );
40 calculatePosition = ( position === "absolute" || position === "fixed" ) && 39 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
Line 41... Line 40...
41 ( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1; 40 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
42   41  
43 // Need to be able to calculate position if either 42 // Need to be able to calculate position if either
44 // top or left is auto and position is either absolute or fixed 43 // top or left is auto and position is either absolute or fixed
Line 51... Line 50...
51 curTop = parseFloat( curCSSTop ) || 0; 50 curTop = parseFloat( curCSSTop ) || 0;
52 curLeft = parseFloat( curCSSLeft ) || 0; 51 curLeft = parseFloat( curCSSLeft ) || 0;
53 } 52 }
Line 54... Line 53...
54   53  
55 if ( jQuery.isFunction( options ) ) { -  
56   -  
57 // Use jQuery.extend here to allow modification of coordinates argument (gh-1848) 54 if ( jQuery.isFunction( options ) ) {
58 options = options.call( elem, i, jQuery.extend( {}, curOffset ) ); 55 options = options.call( elem, i, curOffset );
Line 59... Line 56...
59 } 56 }
60   57  
61 if ( options.top != null ) { 58 if ( options.top != null ) {
Line 72... Line 69...
72 curElem.css( props ); 69 curElem.css( props );
73 } 70 }
74 } 71 }
75 }; 72 };
Line 76... Line 73...
76   73  
77 jQuery.fn.extend( { 74 jQuery.fn.extend({
78 offset: function( options ) { -  
79   -  
80 // Preserve chaining for setter 75 offset: function( options ) {
81 if ( arguments.length ) { 76 if ( arguments.length ) {
82 return options === undefined ? 77 return options === undefined ?
83 this : 78 this :
84 this.each( function( i ) { 79 this.each(function( i ) {
85 jQuery.offset.setOffset( this, options, i ); 80 jQuery.offset.setOffset( this, options, i );
86 } ); 81 });
Line 87... Line 82...
87 } 82 }
88   83  
-   84 var docElem, win,
-   85 elem = this[ 0 ],
Line 89... Line 86...
89 var docElem, win, rect, doc, 86 box = { top: 0, left: 0 },
90 elem = this[ 0 ]; 87 doc = elem && elem.ownerDocument;
91   88  
Line 92... Line -...
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) 89 if ( !doc ) {
Line 106... Line -...
106 if ( rect.width || rect.height ) { -  
107 doc = elem.ownerDocument; 90 return;
108 win = getWindow( doc ); 91 }
109 docElem = doc.documentElement; 92  
110   93 docElem = doc.documentElement;
Line 111... Line 94...
111 return { 94  
-   95 // Make sure it's not a disconnected DOM node
-   96 if ( !jQuery.contains( docElem, elem ) ) {
-   97 return box;
-   98 }
-   99  
112 top: rect.top + win.pageYOffset - docElem.clientTop, 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();
113 left: rect.left + win.pageXOffset - docElem.clientLeft 104 }
Line 114... Line 105...
114 }; 105 win = getWindow( doc );
115 } 106 return {
116   107 top: box.top + win.pageYOffset - docElem.clientTop,
Line 125... Line 116...
125   116  
126 var offsetParent, offset, 117 var offsetParent, offset,
127 elem = this[ 0 ], 118 elem = this[ 0 ],
Line 128... Line 119...
128 parentOffset = { top: 0, left: 0 }; 119 parentOffset = { top: 0, left: 0 };
129   -  
130 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, 120  
131 // because it is its only offset parent -  
132 if ( jQuery.css( elem, "position" ) === "fixed" ) { 121 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
133   122 if ( jQuery.css( elem, "position" ) === "fixed" ) {
Line 134... Line 123...
134 // Assume getBoundingClientRect is there when computed position is fixed 123 // Assume getBoundingClientRect is there when computed position is fixed
135 offset = elem.getBoundingClientRect(); -  
136   124 offset = elem.getBoundingClientRect();
137 } else { 125  
Line 138... Line 126...
138   126 } else {
139 // Get *real* offsetParent 127 // Get *real* offsetParent
140 offsetParent = this.offsetParent(); 128 offsetParent = this.offsetParent();
141   129  
142 // Get correct offsets 130 // Get correct offsets
Line 143... Line 131...
143 offset = this.offset(); 131 offset = this.offset();
144 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) { -  
145 parentOffset = offsetParent.offset(); 132 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
146 } 133 parentOffset = offsetParent.offset();
147   -  
148 // Add offsetParent borders 134 }
Line 149... Line 135...
149 parentOffset = { 135  
150 top: parentOffset.top + jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ), 136 // Add offsetParent borders
151 left: parentOffset.left + jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ) 137 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
152 }; 138 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
153 } 139 }
154   140  
Line 155... Line -...
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 141 // Subtract parent offsets and element margins
166 // 3) For body or html element, i.e. in case of the html node - it will return itself 142 return {
167 // 143 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
Line 168... Line 144...
168 // but those exceptions were never presented as a real life use-cases 144 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
169 // and might be considered as more preferable results. 145 };
170 // 146 },
Line 171... Line 147...
171 // This logic, however, is not guaranteed and can change at any point in the future 147  
172 offsetParent: function() { 148 offsetParent: function() {
173 return this.map( function() { 149 return this.map(function() {
174 var offsetParent = this.offsetParent; 150 var offsetParent = this.offsetParent || docElem;
Line 175... Line 151...
175   151  
176 while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { 152 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
177 offsetParent = offsetParent.offsetParent; 153 offsetParent = offsetParent.offsetParent;
Line 194... Line 170...
194 return win ? win[ prop ] : elem[ method ]; 170 return win ? win[ prop ] : elem[ method ];
195 } 171 }
Line 196... Line 172...
196   172  
197 if ( win ) { 173 if ( win ) {
198 win.scrollTo( 174 win.scrollTo(
199 !top ? val : win.pageXOffset, 175 !top ? val : window.pageXOffset,
200 top ? val : win.pageYOffset 176 top ? val : window.pageYOffset
Line 201... Line 177...
201 ); 177 );
202   178  
203 } else { 179 } else {
204 elem[ method ] = val; 180 elem[ method ] = val;
205 } 181 }
206 }, method, val, arguments.length ); 182 }, method, val, arguments.length, null );
Line 207... Line 183...
207 }; 183 };
208 } ); 184 });
209   185  
210 // Support: Safari <=7 - 9.1, Chrome <=37 - 49 186 // Support: Safari<7+, Chrome<37+
211 // Add the top/left cssHooks using jQuery.fn.position 187 // Add the top/left cssHooks using jQuery.fn.position
212 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084 188 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
213 // Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347 189 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
214 // getComputedStyle returns percent when specified for top/left/bottom/right; 190 // 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 191 // rather than make the css module depend on the offset module, just check for it here
216 jQuery.each( [ "top", "left" ], function( i, prop ) { 192 jQuery.each( [ "top", "left" ], function( i, prop ) {
217 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition, 193 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
218 function( elem, computed ) { -  
219 if ( computed ) { 194 function( elem, computed ) {
220 computed = curCSS( elem, prop ); 195 if ( computed ) {
221   196 computed = curCSS( elem, prop );
222 // If curCSS returns percentage, fallback to offset 197 // If curCSS returns percentage, fallback to offset
223 return rnumnonpx.test( computed ) ? 198 return rnumnonpx.test( computed ) ?
224 jQuery( elem ).position()[ prop ] + "px" : 199 jQuery( elem ).position()[ prop ] + "px" :
225 computed; 200 computed;
226 } 201 }
Line 227... Line 202...
227 } 202 }
228 ); 203 );