c5169e0e
Renato De Donato
a new hope
|
1
|
define([
|
74249687
Luigi Serra
Cross browser con...
|
2
|
"./core",
|
c5169e0e
Renato De Donato
a new hope
|
3
|
"./var/strundefined",
|
74249687
Luigi Serra
Cross browser con...
|
4
|
"./core/access",
|
74249687
Luigi Serra
Cross browser con...
|
5
6
7
8
9
10
11
12
|
"./css/var/rnumnonpx",
"./css/curCSS",
"./css/addGetHookIf",
"./css/support",
"./core/init",
"./css",
"./selector" // contains
|
c5169e0e
Renato De Donato
a new hope
|
13
14
15
|
], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) {
var docElem = window.document.documentElement;
|
74249687
Luigi Serra
Cross browser con...
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
/**
* Gets a window from an element
*/
function getWindow( elem ) {
return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
}
jQuery.offset = {
setOffset: function( elem, options, i ) {
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
position = jQuery.css( elem, "position" ),
curElem = jQuery( elem ),
props = {};
// Set position first, in-case top/left are set even on static elem
if ( position === "static" ) {
elem.style.position = "relative";
}
curOffset = curElem.offset();
curCSSTop = jQuery.css( elem, "top" );
curCSSLeft = jQuery.css( elem, "left" );
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
c5169e0e
Renato De Donato
a new hope
|
40
|
( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
|
74249687
Luigi Serra
Cross browser con...
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Need to be able to calculate position if either
// top or left is auto and position is either absolute or fixed
if ( calculatePosition ) {
curPosition = curElem.position();
curTop = curPosition.top;
curLeft = curPosition.left;
} else {
curTop = parseFloat( curCSSTop ) || 0;
curLeft = parseFloat( curCSSLeft ) || 0;
}
if ( jQuery.isFunction( options ) ) {
|
c5169e0e
Renato De Donato
a new hope
|
55
|
options = options.call( elem, i, curOffset );
|
74249687
Luigi Serra
Cross browser con...
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
}
if ( options.top != null ) {
props.top = ( options.top - curOffset.top ) + curTop;
}
if ( options.left != null ) {
props.left = ( options.left - curOffset.left ) + curLeft;
}
if ( "using" in options ) {
options.using.call( elem, props );
} else {
curElem.css( props );
}
}
};
|
c5169e0e
Renato De Donato
a new hope
|
74
|
jQuery.fn.extend({
|
74249687
Luigi Serra
Cross browser con...
|
75
76
77
78
|
offset: function( options ) {
if ( arguments.length ) {
return options === undefined ?
this :
|
c5169e0e
Renato De Donato
a new hope
|
79
|
this.each(function( i ) {
|
74249687
Luigi Serra
Cross browser con...
|
80
|
jQuery.offset.setOffset( this, options, i );
|
c5169e0e
Renato De Donato
a new hope
|
81
|
});
|
74249687
Luigi Serra
Cross browser con...
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
}
var docElem, win,
elem = this[ 0 ],
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
|
c5169e0e
Renato De Donato
a new hope
|
100
101
102
103
104
|
// Support: BlackBerry 5, iOS 3 (original iPhone)
// If we don't have gBCR, just use 0,0 rather than error
if ( typeof elem.getBoundingClientRect !== strundefined ) {
box = elem.getBoundingClientRect();
}
|
74249687
Luigi Serra
Cross browser con...
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
win = getWindow( doc );
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
},
position: function() {
if ( !this[ 0 ] ) {
return;
}
var offsetParent, offset,
elem = this[ 0 ],
parentOffset = { top: 0, left: 0 };
|
c5169e0e
Renato De Donato
a new hope
|
121
|
// Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
|
74249687
Luigi Serra
Cross browser con...
|
122
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
74249687
Luigi Serra
Cross browser con...
|
123
124
125
126
|
// Assume getBoundingClientRect is there when computed position is fixed
offset = elem.getBoundingClientRect();
} else {
|
74249687
Luigi Serra
Cross browser con...
|
127
128
129
130
131
132
133
134
135
136
|
// Get *real* offsetParent
offsetParent = this.offsetParent();
// Get correct offsets
offset = this.offset();
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
parentOffset = offsetParent.offset();
}
// Add offsetParent borders
|
c5169e0e
Renato De Donato
a new hope
|
137
138
|
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
|
74249687
Luigi Serra
Cross browser con...
|
139
140
141
142
143
144
145
146
147
|
}
// Subtract parent offsets and element margins
return {
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
};
},
|
74249687
Luigi Serra
Cross browser con...
|
148
|
offsetParent: function() {
|
c5169e0e
Renato De Donato
a new hope
|
149
150
|
return this.map(function() {
var offsetParent = this.offsetParent || docElem;
|
74249687
Luigi Serra
Cross browser con...
|
151
|
|
c5169e0e
Renato De Donato
a new hope
|
152
|
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
153
154
155
|
offsetParent = offsetParent.offsetParent;
}
|
c5169e0e
Renato De Donato
a new hope
|
156
157
|
return offsetParent || docElem;
});
|
74249687
Luigi Serra
Cross browser con...
|
158
|
}
|
c5169e0e
Renato De Donato
a new hope
|
159
|
});
|
74249687
Luigi Serra
Cross browser con...
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Create scrollLeft and scrollTop methods
jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
var top = "pageYOffset" === prop;
jQuery.fn[ method ] = function( val ) {
return access( this, function( elem, method, val ) {
var win = getWindow( elem );
if ( val === undefined ) {
return win ? win[ prop ] : elem[ method ];
}
if ( win ) {
win.scrollTo(
|
c5169e0e
Renato De Donato
a new hope
|
175
176
|
!top ? val : window.pageXOffset,
top ? val : window.pageYOffset
|
74249687
Luigi Serra
Cross browser con...
|
177
178
179
180
181
|
);
} else {
elem[ method ] = val;
}
|
c5169e0e
Renato De Donato
a new hope
|
182
|
}, method, val, arguments.length, null );
|
74249687
Luigi Serra
Cross browser con...
|
183
|
};
|
c5169e0e
Renato De Donato
a new hope
|
184
|
});
|
74249687
Luigi Serra
Cross browser con...
|
185
|
|
c5169e0e
Renato De Donato
a new hope
|
186
|
// Support: Safari<7+, Chrome<37+
|
74249687
Luigi Serra
Cross browser con...
|
187
188
189
190
191
192
193
194
195
196
|
// Add the top/left cssHooks using jQuery.fn.position
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
// Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
// getComputedStyle returns percent when specified for top/left/bottom/right;
// rather than make the css module depend on the offset module, just check for it here
jQuery.each( [ "top", "left" ], function( i, prop ) {
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
function( elem, computed ) {
if ( computed ) {
computed = curCSS( elem, prop );
|
74249687
Luigi Serra
Cross browser con...
|
197
198
199
200
201
202
203
|
// If curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :
computed;
}
}
);
|
c5169e0e
Renato De Donato
a new hope
|
204
|
});
|
74249687
Luigi Serra
Cross browser con...
|
205
206
|
return jQuery;
|
c5169e0e
Renato De Donato
a new hope
|
207
|
});
|