No ticket. Abstract conditional hook definition.

This commit is contained in:
Michał Gołębiowski
2013-09-11 02:45:11 +02:00
parent 4ded9be72a
commit 0b9f034382
3 changed files with 52 additions and 40 deletions

View File

@@ -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;