Skip to content

Commit 80d45a6

Browse files
committed
Fix #12840: remove undocumented parameter "pass" from .attr. Close jquerygh-1017.
1 parent 53cb49c commit 80d45a6

File tree

3 files changed

+33
-105
lines changed

3 files changed

+33
-105
lines changed

src/attributes.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ jQuery.extend({
280280
}
281281
},
282282

283-
attr: function( elem, name, value, pass ) {
283+
attr: function( elem, name, value ) {
284284
var ret, hooks, notxml,
285285
nType = elem.nodeType;
286286

@@ -289,10 +289,6 @@ jQuery.extend({
289289
return;
290290
}
291291

292-
if ( pass && jQuery.isFunction( jQuery.fn[ name ] ) ) {
293-
return jQuery( elem )[ name ]( value );
294-
}
295-
296292
// Fallback to prop when attributes are not supported
297293
if ( typeof elem.getAttribute === "undefined" ) {
298294
return jQuery.prop( elem, name, value );
@@ -311,17 +307,16 @@ jQuery.extend({
311307

312308
if ( value === null ) {
313309
jQuery.removeAttr( elem, name );
314-
return;
315310

316-
} else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
311+
} else if ( hooks && notxml && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
317312
return ret;
318313

319314
} else {
320315
elem.setAttribute( name, value + "" );
321316
return value;
322317
}
323318

324-
} else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
319+
} else if ( hooks && notxml && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
325320
return ret;
326321

327322
} else {

src/core.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ var
8484
jQuery.fn = jQuery.prototype = {
8585
constructor: jQuery,
8686
init: function( selector, context, rootjQuery ) {
87-
var match, elem, doc;
87+
var match, elem;
8888

89-
// Handle $(""), $(null), $(undefined), $(false)
89+
// HANDLE: $(""), $(null), $(undefined), $(false)
9090
if ( !selector ) {
9191
return this;
9292
}
9393

94-
// Handle $(DOMElement)
94+
// HANDLE: $(DOMElement)
9595
if ( selector.nodeType ) {
9696
this.context = this[0] = selector;
9797
this.length = 1;
@@ -114,15 +114,29 @@ jQuery.fn = jQuery.prototype = {
114114
// HANDLE: $(html) -> $(array)
115115
if ( match[1] ) {
116116
context = context instanceof jQuery ? context[0] : context;
117-
doc = ( context && context.nodeType ? context.ownerDocument || context : document );
118117

119118
// scripts is true for back-compat
120-
selector = jQuery.parseHTML( match[1], doc, true );
119+
jQuery.merge( this, jQuery.parseHTML(
120+
match[1],
121+
context && context.nodeType ? context.ownerDocument || context : document,
122+
true
123+
) );
124+
125+
// HANDLE: $(html, props)
121126
if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
122-
this.attr.call( selector, context, true );
127+
for ( match in context ) {
128+
// Properties of context are called as methods if possible
129+
if ( jQuery.isFunction( this[ match ] ) ) {
130+
this[ match ]( context[ match ] );
131+
132+
// ...and otherwise set as attributes
133+
} else {
134+
this.attr( match, context[ match ] );
135+
}
136+
}
123137
}
124138

125-
return jQuery.merge( this, selector );
139+
return this;
126140

127141
// HANDLE: $(#id)
128142
} else {
@@ -768,23 +782,22 @@ jQuery.extend({
768782

769783
// Multifunctional method to get and set values of a collection
770784
// The value/s can optionally be executed if it's a function
771-
access: function( elems, fn, key, value, chainable, emptyGet, pass ) {
772-
var exec,
785+
access: function( elems, fn, key, value, chainable, emptyGet ) {
786+
var i = 0,
787+
length = elems.length,
773788
bulk = key == null,
774-
i = 0,
775-
length = elems.length;
789+
exec = value !== undefined && jQuery.isFunction( value );
776790

777791
// Sets many values
778792
if ( key && typeof key === "object" ) {
793+
chainable = true;
779794
for ( i in key ) {
780-
jQuery.access( elems, fn, i, key[i], 1, emptyGet, value );
795+
jQuery.access( elems, fn, i, key[i], true, emptyGet );
781796
}
782-
chainable = 1;
783797

784798
// Sets one value
785799
} else if ( value !== undefined ) {
786-
// Optionally, function values get executed if exec is true
787-
exec = pass === undefined && jQuery.isFunction( value );
800+
chainable = true;
788801

789802
if ( bulk ) {
790803
// Bulk operations only iterate when executing function values
@@ -802,12 +815,10 @@ jQuery.extend({
802815
}
803816

804817
if ( fn ) {
805-
for (; i < length; i++ ) {
806-
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
818+
for ( ; i < length; i++ ) {
819+
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value );
807820
}
808821
}
809-
810-
chainable = 1;
811822
}
812823

813824
return chainable ?

test/unit/attributes.js

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -435,84 +435,6 @@ test( "attr(String, Object)", function() {
435435
equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
436436
});
437437

438-
test( "attr(jquery_method)", function() {
439-
440-
var $elem = jQuery("<div />"),
441-
elem = $elem[ 0 ],
442-
expected = 2,
443-
attrObj = {};
444-
445-
if ( jQuery.fn.width ) {
446-
expected += 2;
447-
attrObj["width"] = 10;
448-
}
449-
450-
if ( jQuery.fn.offset ) {
451-
expected += 2;
452-
attrObj["offset"] = {
453-
"top": 1,
454-
"left": 0
455-
};
456-
}
457-
458-
if ( jQuery.css ) {
459-
expected += 3;
460-
attrObj["css"] = {
461-
"paddingLeft": 1,
462-
"paddingRight": 1
463-
};
464-
}
465-
466-
expect( expected );
467-
468-
// one at a time
469-
$elem.attr({
470-
"html": "foo"
471-
}, true );
472-
equal( elem.innerHTML, "foo", "attr(html)" );
473-
474-
$elem.attr({
475-
"text": "bar"
476-
}, true );
477-
equal( elem.innerHTML, "bar", "attr(text)" );
478-
479-
// Multiple attributes
480-
$elem.attr( attrObj, true );
481-
482-
if ( jQuery.fn.width ) {
483-
equal( elem.style.width, "10px", "attr({width:})" );
484-
485-
$elem.attr( {
486-
"height": 10
487-
}, true );
488-
equal( elem.style.height, "10px", "attr(height)" );
489-
}
490-
491-
if ( jQuery.fn.offset ) {
492-
equal( elem.style.top, "1px", "attr({offset:})" );
493-
494-
$elem.attr({
495-
offset: {
496-
top: 1,
497-
left: 1
498-
}
499-
}, true );
500-
equal( elem.style.left, "1px", "attr(offset)" );
501-
}
502-
503-
if ( jQuery.css ) {
504-
equal( elem.style.paddingLeft, "1px", "attr({css:})" );
505-
equal( elem.style.paddingRight, "1px", "attr({css:})" );
506-
507-
$elem.attr({
508-
"css": {
509-
"color": "red"
510-
}
511-
}, true );
512-
ok( /^(#ff0000|red)$/i.test( elem.style.color ), "attr(css)" );
513-
}
514-
});
515-
516438
test( "attr(String, Object) - Loaded via XML document", function() {
517439
expect( 2 );
518440
var xml = createDashboardXML();

0 commit comments

Comments
 (0)