@@ -29,10 +29,41 @@ function getOffsets( offsets, width, height ) {
29
29
parseInt ( offsets [ 1 ] , 10 ) * ( rpercent . test ( offsets [ 1 ] ) ? height / 100 : 1 )
30
30
] ;
31
31
}
32
+
32
33
function parseCss ( element , property ) {
33
34
return parseInt ( $ . css ( element , property ) , 10 ) || 0 ;
34
35
}
35
36
37
+ function getDimensions ( elem ) {
38
+ var raw = elem [ 0 ] ;
39
+ if ( raw . nodeType === 9 ) {
40
+ return {
41
+ width : elem . width ( ) ,
42
+ height : elem . height ( ) ,
43
+ offset : { top : 0 , left : 0 }
44
+ } ;
45
+ }
46
+ if ( $ . isWindow ( raw ) ) {
47
+ return {
48
+ width : elem . width ( ) ,
49
+ height : elem . height ( ) ,
50
+ offset : { top : elem . scrollTop ( ) , left : elem . scrollLeft ( ) }
51
+ } ;
52
+ }
53
+ if ( raw . preventDefault ) {
54
+ return {
55
+ width : 0 ,
56
+ height : 0 ,
57
+ offset : { top : raw . pageY , left : raw . pageX }
58
+ } ;
59
+ }
60
+ return {
61
+ width : elem . outerWidth ( ) ,
62
+ height : elem . outerHeight ( ) ,
63
+ offset : elem . offset ( )
64
+ } ;
65
+ }
66
+
36
67
$ . position = {
37
68
scrollbarWidth : function ( ) {
38
69
if ( cachedScrollbarWidth !== undefined ) {
@@ -91,32 +122,21 @@ $.fn.position = function( options ) {
91
122
// make a copy, we don't want to modify arguments
92
123
options = $ . extend ( { } , options ) ;
93
124
94
- var atOffset , targetWidth , targetHeight , targetOffset , basePosition ,
125
+ var atOffset , targetWidth , targetHeight , targetOffset , basePosition , dimensions ,
95
126
target = $ ( options . of ) ,
96
127
within = $ . position . getWithinInfo ( options . within ) ,
97
128
scrollInfo = $ . position . getScrollInfo ( within ) ,
98
- targetElem = target [ 0 ] ,
99
129
collision = ( options . collision || "flip" ) . split ( " " ) ,
100
130
offsets = { } ;
101
131
102
- if ( targetElem . nodeType === 9 ) {
103
- targetWidth = target . width ( ) ;
104
- targetHeight = target . height ( ) ;
105
- targetOffset = { top : 0 , left : 0 } ;
106
- } else if ( $ . isWindow ( targetElem ) ) {
107
- targetWidth = target . width ( ) ;
108
- targetHeight = target . height ( ) ;
109
- targetOffset = { top : target . scrollTop ( ) , left : target . scrollLeft ( ) } ;
110
- } else if ( targetElem . preventDefault ) {
132
+ dimensions = getDimensions ( target ) ;
133
+ if ( target [ 0 ] . preventDefault ) {
111
134
// force left top to allow flipping
112
135
options . at = "left top" ;
113
- targetWidth = targetHeight = 0 ;
114
- targetOffset = { top : targetElem . pageY , left : targetElem . pageX } ;
115
- } else {
116
- targetWidth = target . outerWidth ( ) ;
117
- targetHeight = target . outerHeight ( ) ;
118
- targetOffset = target . offset ( ) ;
119
136
}
137
+ targetWidth = dimensions . width ;
138
+ targetHeight = dimensions . height ;
139
+ targetOffset = dimensions . offset ;
120
140
// clone to reuse original targetOffset later
121
141
basePosition = $ . extend ( { } , targetOffset ) ;
122
142
0 commit comments