mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 13:14:59 -05:00
No ticket. Abstract conditional hook definition.
This commit is contained in:
@@ -6,6 +6,7 @@ var
|
||||
access = require( "./core/access" ),
|
||||
rnumnonpx = require( "./css/var/rnumnonpx" ),
|
||||
curCSS = require( "./css/curCSS" ),
|
||||
addGetHookIf = require( "./css/addGetHookIf" ),
|
||||
support = require( "./css/support" ),
|
||||
docElem = window.document.documentElement;
|
||||
|
||||
@@ -186,28 +187,17 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
|
||||
// getComputedStyle returns percent when specified for top/left/bottom/right
|
||||
// rather than make the css module depend on the offset module, we just check for it here
|
||||
jQuery.each( [ "top", "left" ], function( i, prop ) {
|
||||
jQuery.cssHooks[ prop ] = {
|
||||
get: function( elem, computed ) {
|
||||
if ( support.pixelPosition() ) {
|
||||
// Hook not needed, remove it.
|
||||
// Since there are no other hooks for prop, remove the whole object.
|
||||
delete jQuery.cssHooks[ prop ];
|
||||
return;
|
||||
addGetHookIf( jQuery.cssHooks[ prop ], support.pixelPosition,
|
||||
function ( elem, computed ) {
|
||||
if ( computed ) {
|
||||
computed = curCSS( elem, prop );
|
||||
// if curCSS returns percentage, fallback to offset
|
||||
return rnumnonpx.test( computed ) ?
|
||||
jQuery( elem ).position()[ prop ] + "px" :
|
||||
computed;
|
||||
}
|
||||
|
||||
jQuery.cssHooks[ prop ].get = function ( i, prop ) {
|
||||
if ( computed ) {
|
||||
computed = curCSS( elem, prop );
|
||||
// if curCSS returns percentage, fallback to offset
|
||||
return rnumnonpx.test( computed ) ?
|
||||
jQuery( elem ).position()[ prop ] + "px" :
|
||||
computed;
|
||||
}
|
||||
};
|
||||
|
||||
return jQuery.cssHooks[ prop ].get( i, prop );
|
||||
}
|
||||
};
|
||||
);
|
||||
});
|
||||
|
||||
return jQuery;
|
||||
|
||||
Reference in New Issue
Block a user