scratch – Blame information for rev 125

Subversion Repositories:
Rev:
Rev Author Line No. Line
125 office 1 define([
58 office 2 "./core",
125 office 3 "./var/strundefined",
58 office 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
125 office 13 ], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) {
58 office 14  
125 office 15 var docElem = window.document.documentElement;
58 office 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" ) &&
125 office 40 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
58 office 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 ) ) {
125 office 55 options = options.call( elem, i, curOffset );
58 office 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  
125 office 74 jQuery.fn.extend({
58 office 75 offset: function( options ) {
76 if ( arguments.length ) {
77 return options === undefined ?
78 this :
125 office 79 this.each(function( i ) {
58 office 80 jQuery.offset.setOffset( this, options, i );
125 office 81 });
58 office 82 }
83  
125 office 84 var docElem, win,
85 elem = this[ 0 ],
86 box = { top: 0, left: 0 },
87 doc = elem && elem.ownerDocument;
58 office 88  
125 office 89 if ( !doc ) {
58 office 90 return;
91 }
92  
125 office 93 docElem = doc.documentElement;
94  
95 // Make sure it's not a disconnected DOM node
96 if ( !jQuery.contains( docElem, elem ) ) {
97 return box;
58 office 98 }
99  
125 office 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();
58 office 104 }
125 office 105 win = getWindow( doc );
106 return {
107 top: box.top + win.pageYOffset - docElem.clientTop,
108 left: box.left + win.pageXOffset - docElem.clientLeft
109 };
58 office 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  
125 office 121 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
58 office 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
125 office 137 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
138 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
58 office 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() {
125 office 149 return this.map(function() {
150 var offsetParent = this.offsetParent || docElem;
58 office 151  
125 office 152 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
58 office 153 offsetParent = offsetParent.offsetParent;
154 }
155  
125 office 156 return offsetParent || docElem;
157 });
58 office 158 }
125 office 159 });
58 office 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(
125 office 175 !top ? val : window.pageXOffset,
176 top ? val : window.pageYOffset
58 office 177 );
178  
179 } else {
180 elem[ method ] = val;
181 }
125 office 182 }, method, val, arguments.length, null );
58 office 183 };
125 office 184 });
58 office 185  
125 office 186 // Support: Safari<7+, Chrome<37+
58 office 187 // Add the top/left cssHooks using jQuery.fn.position
188 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
125 office 189 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
58 office 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 );
125 office 204 });
58 office 205  
206 return jQuery;
125 office 207 });