Skip to content

Commit 82e3b54

Browse files
committed
updating to jQueryUI position v1.10.0
1 parent cb5fac2 commit 82e3b54

File tree

1 file changed

+40
-60
lines changed

1 file changed

+40
-60
lines changed

src/jquery.ui.position.js

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*!
2-
* jQuery UI Position 1.9.0-RC1
2+
* jQuery UI Position v1.10.0
33
* http://jqueryui.com
44
*
5-
* Copyright 2012 jQuery Foundation and other contributors
5+
* Copyright 2013 jQuery Foundation and other contributors
66
* Released under the MIT license.
77
* http://jquery.org/license
88
*
9-
* http://docs.jquery.com/UI/Position
9+
* http://api.jqueryui.com/position/
1010
*/
1111
(function( $, undefined ) {
1212

@@ -29,10 +29,41 @@ function getOffsets( offsets, width, height ) {
2929
parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
3030
];
3131
}
32+
3233
function parseCss( element, property ) {
3334
return parseInt( $.css( element, property ), 10 ) || 0;
3435
}
3536

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+
3667
$.position = {
3768
scrollbarWidth: function() {
3869
if ( cachedScrollbarWidth !== undefined ) {
@@ -91,32 +122,21 @@ $.fn.position = function( options ) {
91122
// make a copy, we don't want to modify arguments
92123
options = $.extend( {}, options );
93124

94-
var atOffset, targetWidth, targetHeight, targetOffset, basePosition,
125+
var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
95126
target = $( options.of ),
96127
within = $.position.getWithinInfo( options.within ),
97128
scrollInfo = $.position.getScrollInfo( within ),
98-
targetElem = target[0],
99129
collision = ( options.collision || "flip" ).split( " " ),
100130
offsets = {};
101131

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 ) {
111134
// force left top to allow flipping
112135
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();
119136
}
137+
targetWidth = dimensions.width;
138+
targetHeight = dimensions.height;
139+
targetOffset = dimensions.offset;
120140
// clone to reuse original targetOffset later
121141
basePosition = $.extend( {}, targetOffset );
122142

@@ -230,10 +250,6 @@ $.fn.position = function( options ) {
230250
}
231251
});
232252

233-
if ( $.fn.bgiframe ) {
234-
elem.bgiframe();
235-
}
236-
237253
if ( options.using ) {
238254
// adds feedback as second argument to using callback, if present
239255
using = function( props ) {
@@ -478,40 +494,4 @@ $.ui.position = {
478494
testElementParent.removeChild( testElement );
479495
})();
480496

481-
// DEPRECATED
482-
if ( $.uiBackCompat !== false ) {
483-
// offset option
484-
(function( $ ) {
485-
var _position = $.fn.position;
486-
$.fn.position = function( options ) {
487-
if ( !options || !options.offset ) {
488-
return _position.call( this, options );
489-
}
490-
var offset = options.offset.split( " " ),
491-
at = options.at.split( " " );
492-
if ( offset.length === 1 ) {
493-
offset[ 1 ] = offset[ 0 ];
494-
}
495-
if ( /^\d/.test( offset[ 0 ] ) ) {
496-
offset[ 0 ] = "+" + offset[ 0 ];
497-
}
498-
if ( /^\d/.test( offset[ 1 ] ) ) {
499-
offset[ 1 ] = "+" + offset[ 1 ];
500-
}
501-
if ( at.length === 1 ) {
502-
if ( /left|center|right/.test( at[ 0 ] ) ) {
503-
at[ 1 ] = "center";
504-
} else {
505-
at[ 1 ] = at[ 0 ];
506-
at[ 0 ] = "center";
507-
}
508-
}
509-
return _position.call( this, $.extend( options, {
510-
at: at[ 0 ] + offset[ 0 ] + " " + at[ 1 ] + offset[ 1 ],
511-
offset: undefined
512-
} ) );
513-
};
514-
}( jQuery ) );
515-
}
516-
517497
}( jQuery ) );

0 commit comments

Comments
 (0)