mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix for custom attr handles duck-punching the boolean attr handle
Conflicts: src/attributes/attr.js
This commit is contained in:
parent
a7a3b8ce1b
commit
01d5a1a1c9
@ -6,7 +6,8 @@ define([
|
|||||||
"../support"
|
"../support"
|
||||||
], function( jQuery, rnotwhite, strundefined ) {
|
], function( jQuery, rnotwhite, strundefined ) {
|
||||||
|
|
||||||
var nodeHook, boolHook;
|
var nodeHook, boolHook,
|
||||||
|
attrHandle = jQuery.expr.attrHandle;
|
||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
attr: function( name, value ) {
|
attr: function( name, value ) {
|
||||||
@ -120,23 +121,19 @@ boolHook = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
|
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
|
||||||
var getter = jQuery.expr.attrHandle[ name ] || jQuery.find.attr;
|
var getter = attrHandle[ name ] || jQuery.find.attr;
|
||||||
|
|
||||||
jQuery.expr.attrHandle[ name ] = function( elem, name, isXML ) {
|
|
||||||
var fn = jQuery.expr.attrHandle[ name ],
|
|
||||||
ret = isXML ?
|
|
||||||
undefined :
|
|
||||||
/* jshint eqeqeq: false */
|
|
||||||
// Temporarily disable this handler to check existence
|
|
||||||
(jQuery.expr.attrHandle[ name ] = undefined) !=
|
|
||||||
getter( elem, name, isXML ) ?
|
|
||||||
|
|
||||||
|
attrHandle[ name ] = function( elem, name, isXML ) {
|
||||||
|
var ret, handle;
|
||||||
|
if ( !isXML ) {
|
||||||
|
// Avoid an infinite loop by temporarily removing this function from the getter
|
||||||
|
handle = attrHandle[ name ];
|
||||||
|
attrHandle[ name ] = ret;
|
||||||
|
ret = getter( elem, name, isXML ) != null ?
|
||||||
name.toLowerCase() :
|
name.toLowerCase() :
|
||||||
null;
|
null;
|
||||||
|
attrHandle[ name ] = handle;
|
||||||
// Restore handler
|
}
|
||||||
jQuery.expr.attrHandle[ name ] = fn;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -470,6 +470,20 @@ test( "attr(String, Object)", function() {
|
|||||||
equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
|
equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "attr - extending the boolean attrHandle", function() {
|
||||||
|
expect( 1 );
|
||||||
|
var called = false,
|
||||||
|
_handle = jQuery.expr.attrHandle.checked || $.noop;
|
||||||
|
jQuery.expr.attrHandle.checked = function() {
|
||||||
|
called = true;
|
||||||
|
_handle.apply( this, arguments );
|
||||||
|
};
|
||||||
|
jQuery( "input" ).attr( "checked" );
|
||||||
|
called = false;
|
||||||
|
jQuery( "input" ).attr( "checked" );
|
||||||
|
ok( called, "The boolean attrHandle does not drop custom attrHandles" );
|
||||||
|
});
|
||||||
|
|
||||||
test( "attr(String, Object) - Loaded via XML document", function() {
|
test( "attr(String, Object) - Loaded via XML document", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var xml = createDashboardXML(),
|
var xml = createDashboardXML(),
|
||||||
|
Loading…
Reference in New Issue
Block a user