Query now throws no warnings under strict mode in Firefox (ticket #922). In fixing this, revision [1771] was discovered and reverted (no API changes are being added in at this time), and a couple un-functioning test cases were fixed (array comparisions were being done for objects).

This commit is contained in:
John Resig 2007-04-29 18:39:07 +00:00
parent e95a6cc746
commit 74a8e20623
5 changed files with 80 additions and 80 deletions

View file

@ -171,7 +171,7 @@ function ok(a, msg) {
*/ */
function isSet(a, b, msg) { function isSet(a, b, msg) {
var ret = true; var ret = true;
if ( a && b && a.length == b.length ) { if ( a && b && a.length != undefined && a.length == b.length ) {
for ( var i = 0; i < a.length; i++ ) for ( var i = 0; i < a.length; i++ )
if ( a[i] != b[i] ) if ( a[i] != b[i] )
ret = false; ret = false;
@ -183,18 +183,40 @@ function isSet(a, b, msg) {
_config.Test.push( [ ret, msg ] ); _config.Test.push( [ ret, msg ] );
} }
/**
* Asserts that two objects are equivalent
*/
function isObj(a, b, msg) {
var ret = true;
if ( a && b ) {
for ( var i in a )
if ( a[i] != b[i] )
ret = false;
for ( i in b )
if ( a[i] != b[i] )
ret = false;
} else
ret = false;
_config.Test.push( [ ret, msg ] );
}
function serialArray( a ) { function serialArray( a ) {
var r = []; var r = [];
for ( var i = 0; i < a.length; i++ ) {
var str = a[i].nodeName; if ( a && a.length )
if ( str ) { for ( var i = 0; i < a.length; i++ ) {
str = str.toLowerCase(); var str = a[i].nodeName;
if ( a[i].id ) if ( str ) {
str += "#" + a[i].id; str = str.toLowerCase();
} else if ( a[i].id )
str = a[i]; str += "#" + a[i].id;
r.push( str ); } else
} str = a[i];
r.push( str );
}
return "[ " + r.join(", ") + " ]" return "[ " + r.join(", ") + " ]"
} }

View file

@ -129,7 +129,7 @@ jQuery.event = {
// Handle triggering a single element // Handle triggering a single element
else { else {
var val, ret, fn = jQuery.isFunction( element[ type ] ); var val, ret, fn = jQuery.isFunction( element[ type ] || null );
// Pass along a fake event // Pass along a fake event
data.unshift( this.fix({ type: type, target: element }) ); data.unshift( this.fix({ type: type, target: element }) );
@ -146,19 +146,18 @@ jQuery.event = {
}, },
handle: function(event) { handle: function(event) {
// returned undefined or false
var val;
// Handle the second event of a trigger and when // Handle the second event of a trigger and when
// an event is called after a page has unloaded // an event is called after a page has unloaded
if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return; if ( typeof jQuery == "undefined" || jQuery.event.triggered )
return val;
// Empty object is for triggered events with no data // Empty object is for triggered events with no data
event = jQuery.event.fix( event || window.event || {} ); event = jQuery.event.fix( event || window.event || {} );
// returned undefined or false var c = this.$events[event.type], args = [].slice.call( arguments, 1 );
var returnValue;
var c = this.$events[event.type];
var args = [].slice.call( arguments, 1 );
args.unshift( event ); args.unshift( event );
for ( var j in c ) { for ( var j in c ) {
@ -170,14 +169,16 @@ jQuery.event = {
if ( c[j].apply( this, args ) === false ) { if ( c[j].apply( this, args ) === false ) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
returnValue = false; val = false;
} }
} }
// Clean up added properties in IE to prevent memory leak // Clean up added properties in IE to prevent memory leak
if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null; if (jQuery.browser.msie)
event.target = event.preventDefault = event.stopPropagation =
event.handler = event.data = null;
return returnValue; return val;
}, },
fix: function(event) { fix: function(event) {
@ -415,7 +416,7 @@ jQuery.fn.extend({
return this.click(function(e) { return this.click(function(e) {
// Figure out which function to execute // Figure out which function to execute
this.lastToggle = this.lastToggle == 0 ? 1 : 0; this.lastToggle = 0 == this.lastToggle ? 1 : 0;
// Make sure that clicks stop // Make sure that clicks stop
e.preventDefault(); e.preventDefault();

View file

@ -363,7 +363,7 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element'); ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
reset(); reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
$('#sap').append(document.getElementById('first')); $('#sap').append(document.getElementById('first'));
ok( expected == $('#sap').text(), "Check for appending of element" ); ok( expected == $('#sap').text(), "Check for appending of element" );
@ -422,7 +422,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element'); ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
reset(); reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
$(document.getElementById('first')).appendTo('#sap'); $(document.getElementById('first')).appendTo('#sap');
ok( expected == $('#sap').text(), "Check for appending of element" ); ok( expected == $('#sap').text(), "Check for appending of element" );
@ -449,7 +449,7 @@ test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element'); ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
reset(); reset();
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
$('#sap').prepend(document.getElementById('first')); $('#sap').prepend(document.getElementById('first'));
ok( expected == $('#sap').text(), "Check for prepending of element" ); ok( expected == $('#sap').text(), "Check for prepending of element" );
@ -472,7 +472,7 @@ test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element'); ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
reset(); reset();
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
$(document.getElementById('first')).prependTo('#sap'); $(document.getElementById('first')).prependTo('#sap');
ok( expected == $('#sap').text(), "Check for prepending of element" ); ok( expected == $('#sap').text(), "Check for prepending of element" );
@ -637,8 +637,8 @@ test("$.extend(Object, Object)", function() {
optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }; merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
jQuery.extend(settings, options); jQuery.extend(settings, options);
isSet( settings, merged, "Check if extended: settings must be extended" ); isObj( settings, merged, "Check if extended: settings must be extended" );
isSet ( options, optionsCopy, "Check if not modified: options must not be modified" ); isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
}); });
test("$.extend(Object, Object, Object, Object)", function() { test("$.extend(Object, Object, Object, Object)", function() {
@ -651,10 +651,10 @@ test("$.extend(Object, Object, Object, Object)", function() {
options2Copy = { xstring2: "xx", xxx: "newstringx" }, options2Copy = { xstring2: "xx", xxx: "newstringx" },
merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
var settings = jQuery.extend({}, defaults, options1, options2); var settings = jQuery.extend({}, defaults, options1, options2);
isSet( settings, merged, "Check if extended: settings must be extended" ); isObj( settings, merged, "Check if extended: settings must be extended" );
isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" ); isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" ); isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
}); });
test("val()", function() { test("val()", function() {

38
src/jquery/jquery.js vendored
View file

@ -840,7 +840,7 @@ jQuery.fn = jQuery.prototype = {
*/ */
clone: function(deep) { clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){ return this.pushStack( jQuery.map( this, function(a){
var a = a.cloneNode( deep != undefined ? deep : true ); a = a.cloneNode( deep != undefined ? deep : true );
a.$events = null; // drop $events expando to avoid firing incorrect events a.$events = null; // drop $events expando to avoid firing incorrect events
return a; return a;
}) ); }) );
@ -1178,10 +1178,6 @@ jQuery.fn = jQuery.prototype = {
* Extend one object with one or more others, returning the original, * Extend one object with one or more others, returning the original,
* modified, object. This is a great utility for simple inheritance. * modified, object. This is a great utility for simple inheritance.
* *
* There is also an optional collision resolution function. Any time the target and
* merged object both contain a key this function is called. This may be used to create
* a recursive merge. (See example) Unless you know what this is, you probably don't care.
*
* @example var settings = { validate: false, limit: 5, name: "foo" }; * @example var settings = { validate: false, limit: 5, name: "foo" };
* var options = { validate: true, name: "bar" }; * var options = { validate: true, name: "bar" };
* jQuery.extend(settings, options); * jQuery.extend(settings, options);
@ -1194,19 +1190,8 @@ jQuery.fn = jQuery.prototype = {
* @result settings == { validate: true, limit: 5, name: "bar" } * @result settings == { validate: true, limit: 5, name: "bar" }
* @desc Merge defaults and options, without modifying the defaults * @desc Merge defaults and options, without modifying the defaults
* *
* @example var defaults = { validate: false, limit: 5, name: "foo", nested: {depth: false} };
* var options = { validate: true, name: "bar", nested: {depth: true} };
* var collision_resolver_fn = function(target, mergee) {
* // combine nested Objects, in this case the object being merged takes priority
* return jQuery.extend({}, target, mergee);
* }
* var settings = jQuery.extend({}, collision_resolver_fn, defaults, options);
* @result settings == { validate: true, limit: 5, name: "bar" }
* @desc Recursively merge defaults and options, without modifying the defaults
*
* @name $.extend * @name $.extend
* @param Object target The object to extend * @param Object target The object to extend
* @param Function (optional) collision resolution function. Hook to extend the merging behavior of $.extend(). See example.
* @param Object prop1 The object that will be merged into the first. * @param Object prop1 The object that will be merged into the first.
* @param Object propN (optional) More objects to merge into the first * @param Object propN (optional) More objects to merge into the first
* @type Object * @type Object
@ -1214,26 +1199,17 @@ jQuery.fn = jQuery.prototype = {
*/ */
jQuery.extend = jQuery.fn.extend = function() { jQuery.extend = jQuery.fn.extend = function() {
// copy reference to target object // copy reference to target object
var resolver, prop, target = arguments[0], var target = arguments[0], a = 1;
a = 1;
// extend jQuery itself if only one argument is passed // extend jQuery itself if only one argument is passed
if ( arguments.length == 1 ) { if ( arguments.length == 1 ) {
target = this; target = this;
a = 0; a = 0;
} else if (jQuery.isFunction(arguments[a])) {
resolver = arguments[a++];
} }
var prop;
while (prop = arguments[a++]) while ( (prop = arguments[a++]) != null )
// Extend the base object // Extend the base object
for ( var i in prop ) { for ( var i in prop ) target[i] = prop[i];
if (resolver && target[i] && prop[i]) {
target[i] = resolver(target[i], prop[i]);
} else {
target[i] = prop[i];
}
}
// Return the modified object // Return the modified object
return target; return target;
@ -1528,7 +1504,7 @@ jQuery.extend({
arg = jQuery.makeArray( div.childNodes ); arg = jQuery.makeArray( div.childNodes );
} }
if ( arg.length === 0 && !jQuery(arg).is("form, select") ) if ( 0 === arg.length && !jQuery(arg).is("form, select") )
return; return;
if ( arg[0] == undefined || jQuery(arg).is("form, select") ) if ( arg[0] == undefined || jQuery(arg).is("form, select") )
@ -1663,7 +1639,7 @@ jQuery.extend({
var r = [], num = jQuery.mergeNum++; var r = [], num = jQuery.mergeNum++;
for ( var i = 0, fl = first.length; i < fl; i++ ) for ( var i = 0, fl = first.length; i < fl; i++ )
if ( first[i].mergeNum != num ) { if ( num != first[i].mergeNum ) {
first[i].mergeNum = num; first[i].mergeNum = num;
r.push(first[i]); r.push(first[i]);
} }

View file

@ -27,8 +27,8 @@ jQuery.extend({
contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0", contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
// Visibility // Visibility
visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"', visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"', hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
// Form attributes // Form attributes
enabled: "!a.disabled", enabled: "!a.disabled",
@ -37,15 +37,15 @@ jQuery.extend({
selected: "a.selected||jQuery.attr(a,'selected')", selected: "a.selected||jQuery.attr(a,'selected')",
// Form elements // Form elements
text: "a.type=='text'", text: "'text'==a.type",
radio: "a.type=='radio'", radio: "'radio'==a.type",
checkbox: "a.type=='checkbox'", checkbox: "'checkbox'==a.type",
file: "a.type=='file'", file: "'file'==a.type",
password: "a.type=='password'", password: "'password'==a.type",
submit: "a.type=='submit'", submit: "'submit'==a.type",
image: "a.type=='image'", image: "'image'==a.type",
reset: "a.type=='reset'", reset: "'reset'==a.type",
button: 'a.type=="button"||jQuery.nodeName(a,"button")', button: '"button"==a.type||jQuery.nodeName(a,"button")',
input: "/input|select|textarea|button/i.test(a.nodeName)" input: "/input|select|textarea|button/i.test(a.nodeName)"
}, },
".": "jQuery.className.has(a,m[2])", ".": "jQuery.className.has(a,m[2])",
@ -62,7 +62,7 @@ jQuery.extend({
_resort: function(m){ _resort: function(m){
return ["", m[1], m[3], m[2], m[5]]; return ["", m[1], m[3], m[2], m[5]];
}, },
_prefix: "z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);" _prefix: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);"
}, },
"[": "jQuery.find(m[2],a).length" "[": "jQuery.find(m[2],a).length"
}, },
@ -194,7 +194,7 @@ jQuery.extend({
// Handle multiple expressions // Handle multiple expressions
if ( !t.indexOf(",") ) { if ( !t.indexOf(",") ) {
// Clean the result set // Clean the result set
if ( ret[0] == context ) ret.shift(); if ( context == ret[0] ) ret.shift();
// Merge the result sets // Merge the result sets
done = jQuery.merge( done, ret ); done = jQuery.merge( done, ret );
@ -292,7 +292,7 @@ jQuery.extend({
ret = []; ret = [];
// Remove the root context // Remove the root context
if ( ret && ret[0] == context ) if ( ret && context == ret[0] )
ret.shift(); ret.shift();
// And combine the results // And combine the results
@ -408,8 +408,9 @@ jQuery.extend({
for ( ; cur; cur = cur[dir] ) { for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType == 1 ) num++; if ( cur.nodeType == 1 ) num++;
if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem || if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
result == "odd" && num % 2 == 1 && cur == elem ) return cur; result == "odd" && num % 2 == 1 && cur == elem ) break;
} }
return cur;
}, },
/** /**