with display block");
});
- var speeds = {
+ speeds = {
"null speed": null,
"undefined speed": undefined,
"false speed": false
@@ -65,7 +65,7 @@ test("show()", 27, function () {
jQuery.each(speeds, function(name, speed) {
var pass = true;
div.hide().show(speed).each(function() {
- if ( this.style.display == "none" ) {
+ if ( this.style.display === "none" ) {
pass = false;
}
});
@@ -86,10 +86,10 @@ test("show()", 27, function () {
// #show-tests * is set display: none in CSS
jQuery("#qunit-fixture").append("
");
- var old = jQuery("#test-table").show().css("display") !== "table";
+ old = jQuery("#test-table").show().css("display") !== "table";
jQuery("#test-table").remove();
- var test = {
+ test = {
"div" : "block",
"p" : "block",
"a" : "inline",
@@ -126,11 +126,12 @@ test("show(Number) - other displays", function() {
// #show-tests * is set display: none in CSS
jQuery("#qunit-fixture").append("
");
- var old = jQuery("#test-table").show().css("display") !== "table",
+ var test,
+ old = jQuery("#test-table").show().css("display") !== "table",
num = 0;
jQuery("#test-table").remove();
- var test = {
+ test = {
"div" : "block",
"p" : "block",
"a" : "inline",
@@ -195,8 +196,8 @@ test("Persist correct display value", function() {
test("animate(Hash, Object, Function)", function() {
expect(1);
stop();
- var hash = {opacity: "show"};
- var hashCopy = jQuery.extend({}, hash);
+ var hash = {opacity: "show"},
+ hashCopy = jQuery.extend({}, hash);
jQuery("#foo").animate(hash, 0, function() {
equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
start();
@@ -310,13 +311,14 @@ test("animate table width/height", function() {
test("animate table-row width/height", function() {
expect(3);
stop();
- var tr = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html("
")
- .find("tr");
+ var displayMode,
+ tr = jQuery("#table")
+ .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .html("
")
+ .find("tr");
// IE<8 uses "block" instead of the correct display type
- var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
+ displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
tr.animate({ width: 10, height: 10 }, 100, function() {
equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
@@ -329,13 +331,14 @@ test("animate table-row width/height", function() {
test("animate table-cell width/height", function() {
expect(3);
stop();
- var td = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html("
")
- .find("td");
+ var displayMode,
+ td = jQuery("#table")
+ .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .html("
")
+ .find("td");
// IE<8 uses "block" instead of the correct display type
- var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
+ displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
td.animate({ width: 10, height: 10 }, 100, function() {
equal( jQuery(this).css("display"), displayMode, "display mode is correct" );
@@ -445,7 +448,7 @@ asyncTest( "animate option { queue: 'name' }", function() {
equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
}
- }).queue( "name", function( next ) {
+ }).queue( "name", function() {
// last callback function
deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
@@ -466,7 +469,9 @@ asyncTest( "animate option { queue: 'name' }", function() {
test("animate with no properties", function() {
expect(2);
- var divs = jQuery("div"), count = 0;
+ var foo,
+ divs = jQuery("div"),
+ count = 0;
divs.animate({}, function(){
count++;
@@ -476,7 +481,7 @@ test("animate with no properties", function() {
stop();
- var foo = jQuery("#foo");
+ foo = jQuery("#foo");
foo.animate({});
foo.animate({top: 10}, 100, function(){
@@ -490,7 +495,9 @@ test("animate duration 0", function() {
stop();
- var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
+ var $elem,
+ $elems = jQuery([{ a:0 },{ a:0 }]),
+ counter = 0;
equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
@@ -522,7 +529,7 @@ test("animate duration 0", function() {
start();
});
- var $elem = jQuery("
");
$elem.show(0, function(){
ok(true, "Show callback with no duration");
});
@@ -562,7 +569,8 @@ test("stop()", function() {
expect( 4 );
stop();
- var $foo = jQuery("#foo"),
+ var $one, $two,
+ $foo = jQuery("#foo"),
tests = 2,
w = 0;
@@ -586,8 +594,8 @@ test("stop()", function() {
}, 100);
}, 100);
- var $one = jQuery("#fadein");
- var $two = jQuery("#show");
+ $one = jQuery("#fadein");
+ $two = jQuery("#show");
$one.fadeTo(100, 0, function() {
$one.stop();
});
@@ -640,8 +648,8 @@ test("stop(clearQueue)", function() {
expect(4);
stop();
- var $foo = jQuery("#foo");
- var w = 0;
+ var $foo = jQuery("#foo"),
+ w = 0;
$foo.hide().css( "width", 200 ).css("width");
$foo.animate({ "width": "show" }, 1000);
@@ -649,11 +657,11 @@ test("stop(clearQueue)", function() {
$foo.animate({ "width": "show" }, 1000);
setTimeout(function(){
var nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
$foo.stop(true);
nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "Stop didn't reset the animation " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
equal( $foo.queue().length, 0, "The animation queue was cleared" );
setTimeout(function(){
@@ -667,8 +675,8 @@ test("stop(clearQueue, gotoEnd)", function() {
expect(1);
stop();
- var $foo = jQuery("#foo");
- var w = 0;
+ var $foo = jQuery("#foo"),
+ w = 0;
$foo.hide().css( "width", 200 ).css("width");
$foo.animate({ width: "show" }, 1000);
@@ -677,7 +685,7 @@ test("stop(clearQueue, gotoEnd)", function() {
$foo.animate({ width: "hide" }, 1000);
setTimeout(function(){
var nw = $foo.css("width");
- ok( parseFloat( nw ) != w, "An animation occurred " + nw + " " + w + "px");
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
$foo.stop(false, true);
nw = $foo.css("width");
@@ -872,66 +880,67 @@ jQuery.each({
},
"100": function( elem, prop ) {
jQuery( elem ).addClass( "wide" + prop );
- return prop == "opacity" ? 1 : 100;
+ return prop === "opacity" ? 1 : 100;
},
"50": function( elem, prop ) {
- return prop == "opacity" ? 0.50 : 50;
+ return prop === "opacity" ? 0.50 : 50;
},
- "0": function( elem, prop ) {
+ "0": function( elem ) {
jQuery( elem ).addClass( "noback" );
return 0;
}
}, function( tn, t ) {
test(fn + " to " + tn, function() {
- var elem = jQuery.makeTest( fn + " to " + tn );
-
- var t_w = t( elem, "width" );
- var f_w = f( elem, "width" );
- var t_h = t( elem, "height" );
- var f_h = f( elem, "height" );
- var t_o = t( elem, "opacity" );
- var f_o = f( elem, "opacity" );
+ var num, anim,
+ elem = jQuery.makeTest( fn + " to " + tn ),
+ t_w = t( elem, "width" ),
+ f_w = f( elem, "width" ),
+ t_h = t( elem, "height" ),
+ f_h = f( elem, "height" ),
+ t_o = t( elem, "opacity" ),
+ f_o = f( elem, "opacity" );
if ( f_o === "" ) {
f_o = 1;
}
- var num = 0;
+ num = 0;
// TODO: uncrowd this
- if ( t_h == "show" ) {num++;}
- if ( t_w == "show" ) {num++;}
- if ( t_w == "hide" || t_w == "show" ) {num++;}
- if ( t_h == "hide" || t_h == "show" ) {num++;}
- if ( t_o == "hide" || t_o == "show" ) {num++;}
- if ( t_w == "hide" ) {num++;}
- if ( t_o.constructor == Number ) {num += 2;}
- if ( t_w.constructor == Number ) {num += 2;}
- if ( t_h.constructor == Number ) {num +=2;}
+ if ( t_h === "show" ) {num++;}
+ if ( t_w === "show" ) {num++;}
+ if ( t_w === "hide" || t_w === "show" ) {num++;}
+ if ( t_h === "hide" || t_h === "show" ) {num++;}
+ if ( t_o === "hide" || t_o === "show" ) {num++;}
+ if ( t_w === "hide" ) {num++;}
+ if ( t_o.constructor === Number ) {num += 2;}
+ if ( t_w.constructor === Number ) {num += 2;}
+ if ( t_h.constructor === Number ) {num +=2;}
expect( num );
stop();
- var anim = { width: t_w, height: t_h, opacity: t_o };
+ anim = { width: t_w, height: t_h, opacity: t_o };
elem.animate(anim, 50);
jQuery.when( elem ).done(function( elem ) {
+ var cur_o, cur_w, cur_h, old_h;
elem = elem[ 0 ];
- if ( t_w == "show" ) {
+ if ( t_w === "show" ) {
equal( elem.style.display, "block", "Showing, display should block: " + elem.style.display );
}
- if ( t_w == "hide" || t_w == "show" ) {
+ if ( t_w === "hide" || t_w === "show" ) {
ok( f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf( f_w ) === 0, "Width must be reset to " + f_w + ": " + elem.style.width );
}
- if ( t_h == "hide" || t_h == "show" ) {
+ if ( t_h === "hide" || t_h === "show" ) {
ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
}
- var cur_o = jQuery.style(elem, "opacity");
+ cur_o = jQuery.style(elem, "opacity");
if ( f_o !== jQuery.css(elem, "opacity") ) {
f_o = f( elem, "opacity" );
@@ -947,38 +956,38 @@ jQuery.each({
cur_o = 1;
}
- if ( t_o == "hide" || t_o == "show" ) {
+ if ( t_o === "hide" || t_o === "show" ) {
equal( cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o );
}
- if ( t_w == "hide" ) {
+ if ( t_w === "hide" ) {
equal( elem.style.display, "none", "Hiding, display should be none: " + elem.style.display );
}
- if ( t_o.constructor == Number ) {
+ if ( t_o.constructor === Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
- ok( jQuery.css(elem, "opacity") !== "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
+ ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
- if ( t_w.constructor == Number ) {
+ if ( t_w.constructor === Number ) {
equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
- var cur_w = jQuery.css( elem,"width" );
+ cur_w = jQuery.css( elem,"width" );
- ok( elem.style.width !== "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
+ ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
- if ( t_h.constructor == Number ) {
+ if ( t_h.constructor === Number ) {
equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
- var cur_h = jQuery.css( elem,"height" );
+ cur_h = jQuery.css( elem,"height" );
- ok( elem.style.height !== "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
+ ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
- if ( t_h == "show" ) {
- var old_h = jQuery.css( elem, "height" );
+ if ( t_h === "show" ) {
+ old_h = jQuery.css( elem, "height" );
jQuery( elem ).append("
and some more...");
if ( /Auto/.test( fn ) ) {
@@ -1364,7 +1373,8 @@ test("Do not append px to 'fill-opacity' #9548", 1, function() {
// Start 1.8 Animation tests
asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
- var testObject = {
+ var animation,
+ testObject = {
"foo": 0,
"bar": 1,
"width": 100
@@ -1375,7 +1385,7 @@ asyncTest( "jQuery.Animation( object, props, opts )", 4, function() {
"width": 200
};
- var animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
+ animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
animation.done(function() {
for ( var prop in testDest ) {
equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
@@ -2008,7 +2018,7 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
});
test( ".finish() calls finish of custom queue functions", function() {
- function queueTester( next ) {
+ function queueTester() {
}
var div = jQuery( "
" );
diff --git a/test/unit/event.js b/test/unit/event.js
index 1a1a5652e..9ea75fb81 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -6,12 +6,12 @@ test("null or undefined handler", function() {
try {
jQuery("#firstp").on( "click", null );
ok(true, "Passing a null handler will not throw an exception");
- } catch (e) {}
+ } catch ( e ) {}
try {
jQuery("#firstp").on( "click", undefined );
ok(true, "Passing an undefined handler will not throw an exception");
- } catch (e) {}
+ } catch ( e ) {}
});
test("on() with non-null,defined data", function() {
@@ -41,7 +41,7 @@ test("Handler changes and .trigger() order", function() {
path = "";
markup
- .find( "*" ).addBack().on( "click", function( e ) {
+ .find( "*" ).addBack().on( "click", function() {
path += this.nodeName.toLowerCase() + " ";
})
.filter( "b" ).on( "click", function( e ) {
@@ -60,7 +60,9 @@ test("Handler changes and .trigger() order", function() {
test("on(), with data", function() {
expect(4);
- var handler = function(event) {
+ var test, handler, handler2;
+
+ handler = function(event) {
ok( event.data, "on() with data, check passed data exists" );
equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
};
@@ -68,8 +70,8 @@ test("on(), with data", function() {
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
- var test = function(){};
- var handler2 = function(event) {
+ test = function(){};
+ handler2 = function(event) {
equal( event.data, test, "on() with function data, Check value of passed data" );
};
jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2);
@@ -99,17 +101,18 @@ test("on(), with data, trigger with data", function() {
test("on(), multiple events at once", function() {
expect(2);
- var clickCounter = 0,
+ var handler,
+ clickCounter = 0,
mouseoverCounter = 0;
- var handler = function(event) {
- if (event.type == "click") {
+ handler = function(event) {
+ if (event.type === "click") {
clickCounter += 1;
}
- else if (event.type == "mouseover") {
+ else if (event.type === "mouseover") {
mouseoverCounter += 1;
}
-
};
+
jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover");
equal( clickCounter, 1, "on() with multiple events at once" );
equal( mouseoverCounter, 1, "on() with multiple events at once" );
@@ -119,7 +122,7 @@ test("on(), five events at once", function() {
expect(1);
var count = 0,
- handler = function(event) {
+ handler = function() {
count++;
};
@@ -134,9 +137,10 @@ test("on(), five events at once", function() {
test("on(), multiple events at once and namespaces", function() {
expect(7);
- var cur, obj = {};
+ var cur, div,
+ obj = {};
- var div = jQuery("
").on("focusin.a", function(e) {
+ div = jQuery("
").on("focusin.a", function(e) {
equal( e.type, cur, "Verify right single event was fired." );
});
@@ -178,7 +182,7 @@ test("on(), namespace with special add", function() {
expect(27);
var i = 0,
- div = jQuery("
").appendTo("#qunit-fixture").on( "test", function(e) {
+ div = jQuery("
").appendTo("#qunit-fixture").on( "test", function() {
ok( true, "Test event fired." );
});
@@ -227,7 +231,7 @@ test("on(), namespace with special add", function() {
// Should trigger 4
div.off("test");
- div = jQuery("
").on( "test", function( e ) {
+ div = jQuery("
").on( "test", function() {
ok( true, "Test event fired." );
});
@@ -248,23 +252,22 @@ test("on(), no data", function() {
test("on/one/off(Object)", function(){
expect(6);
- var clickCounter = 0, mouseoverCounter = 0;
- function handler(event) {
- if (event.type == "click") {
+ var $elem,
+ clickCounter = 0,
+ mouseoverCounter = 0;
+ function handler(event) {
+ if (event.type === "click") {
clickCounter++;
- }
- else if (event.type == "mouseover") {
+ } else if (event.type === "mouseover") {
mouseoverCounter++;
}
-
}
function handlerWithData(event) {
- if (event.type == "click") {
+ if (event.type === "click") {
clickCounter += event.data;
- }
- else if (event.type == "mouseover") {
+ } else if (event.type === "mouseover") {
mouseoverCounter += event.data;
}
}
@@ -273,7 +276,7 @@ test("on/one/off(Object)", function(){
$elem.trigger("click").trigger("mouseover");
}
- var $elem = jQuery("#firstp")
+ $elem = jQuery("#firstp")
// Regular bind
.on({
"click":handler,
@@ -307,12 +310,13 @@ test("on/one/off(Object)", function(){
test("on/off(Object), on/off(Object, String)", function() {
expect(6);
- var clickCounter = 0,
+ var events,
+ clickCounter = 0,
mouseoverCounter = 0,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);
- var events = {
+ events = {
"click": function( event ) {
clickCounter += ( event.data || 1 );
},
@@ -357,7 +361,7 @@ test("on immediate propagation", function() {
lastClick = "click1";
e.stopImmediatePropagation();
});
- jQuery( document ).on( "click", "#firstp a", function(e) {
+ jQuery( document ).on( "click", "#firstp a", function() {
lastClick = "click2";
});
$a.trigger( "click" );
@@ -369,7 +373,7 @@ test("on immediate propagation", function() {
lastClick = "click1";
e.stopImmediatePropagation();
});
- $p.on( "click", "a", function(e) {
+ $p.on( "click", "a", function() {
lastClick = "click2";
});
$a.trigger( "click" );
@@ -409,7 +413,7 @@ test("on bubbling, isDefaultPrevented", function() {
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
- $anchor2.on( "click", function(e) {
+ $anchor2.on( "click", function() {
// Let the default action occur
});
$main.on("click", "#foo", function(e) {
@@ -445,7 +449,7 @@ test("on(), trigger change on select", function() {
test("on(), namespaced events, cloned events", 18, function() {
var firstp = jQuery( "#firstp" );
- firstp.on("custom.test",function(e){
+ firstp.on("custom.test",function(){
ok(false, "Custom event triggered");
});
@@ -507,22 +511,22 @@ test("on(), multi-namespaced events", function() {
];
function check(name, msg){
- deepEqual(name, order.shift(), msg);
+ deepEqual( name, order.shift(), msg );
}
- jQuery("#firstp").on("custom.test",function(e){
+ jQuery("#firstp").on("custom.test",function() {
check("custom.test", "Custom event triggered");
});
- jQuery("#firstp").on("custom.test2",function(e){
+ jQuery("#firstp").on("custom.test2",function() {
check("custom.test2", "Custom event triggered");
});
- jQuery("#firstp").on("click.test",function(e){
+ jQuery("#firstp").on("click.test",function() {
check("click.test", "Normal click triggered");
});
- jQuery("#firstp").on("click.test.abc",function(e){
+ jQuery("#firstp").on("click.test.abc",function() {
check("click.test.abc", "Namespaced click triggered");
});
@@ -611,7 +615,7 @@ test("on(), with different this object", function() {
expect(4);
var thisObject = { myThis: true },
data = { myData: true },
- handler1 = function( event ) {
+ handler1 = function() {
equal( this, thisObject, "on() with different this object" );
},
handler2 = function( event ) {
@@ -630,7 +634,7 @@ test("on(name, false), off(name, false)", function() {
expect(3);
var main = 0;
- jQuery("#qunit-fixture").on("click", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", function(){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
@@ -653,7 +657,7 @@ test("on(name, selector, false), off(name, selector, false)", function() {
var main = 0;
- jQuery("#qunit-fixture").on("click", "#ap", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", "#ap", function(){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
@@ -672,7 +676,8 @@ test("on(name, selector, false), off(name, selector, false)", function() {
test("on()/trigger()/off() on plain object", function() {
expect( 7 );
- var obj = {};
+ var events,
+ obj = {};
// Make sure it doesn't complain when no events are found
jQuery(obj).trigger("test");
@@ -689,7 +694,7 @@ test("on()/trigger()/off() on plain object", function() {
}
});
- var events = jQuery._data(obj, "events");
+ events = jQuery._data(obj, "events");
ok( events, "Object has events bound." );
equal( obj["events"], undefined, "Events object on plain objects is not events" );
equal( obj["test"], undefined, "Make sure that test event is not on the plain object." );
@@ -716,8 +721,8 @@ test("on()/trigger()/off() on plain object", function() {
test("off(type)", function() {
expect( 1 );
- var $elem = jQuery("#firstp"),
- message;
+ var message, func,
+ $elem = jQuery("#firstp");
function error(){
ok( false, message );
@@ -751,7 +756,7 @@ test("off(type)", function() {
jQuery( document ).on( "click", function(){
ok( true, "called handler after selective removal");
});
- var func = function(){ };
+ func = function() {};
jQuery( document )
.on( "click", func )
.off( "click", func )
@@ -800,8 +805,8 @@ if ( jQuery.fn.hover ) {
expect(1);
var times = 0,
- handler1 = function( event ) { ++times; },
- handler2 = function( event ) { ++times; };
+ handler1 = function() { ++times; },
+ handler2 = function() { ++times; };
jQuery("#firstp")
.hover(handler1, handler2)
@@ -876,7 +881,8 @@ if ( jQuery.fn.click ) {
test("trigger() shortcuts", function() {
expect(6);
- var elem = jQuery("
Change location").prependTo("#firstUL");
+ var counter, clickCounter,
+ elem = jQuery("
Change location").prependTo("#firstUL");
elem.find("a").on("click", function() {
var close = jQuery("spanx", this); // same with jQuery(this).find("span");
equal( close.length, 0, "Context element does not exist, length must be zero" );
@@ -891,15 +897,15 @@ if ( jQuery.fn.click ) {
ok( true, "click event handler for checkbox gets fired twice, see #815" );
}).click();
- var counter = 0;
- jQuery("#firstp")[0].onclick = function(event) {
+ counter = 0;
+ jQuery("#firstp")[0].onclick = function() {
counter++;
};
jQuery("#firstp").click();
equal( counter, 1, "Check that click, triggers onclick event handler also" );
- var clickCounter = 0;
- jQuery("#simon1")[0].onclick = function(event) {
+ clickCounter = 0;
+ jQuery("#simon1")[0].onclick = function() {
clickCounter++;
};
jQuery("#simon1").click();
@@ -925,11 +931,11 @@ test("trigger() bubbling", function() {
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery(window).on("click", function(e){ win++; });
- jQuery(document).on("click", function(e){ if ( e.target !== document) { doc++; } });
- jQuery("html").on("click", function(e){ html++; });
- jQuery("body").on("click", function(e){ body++; });
- jQuery("#qunit-fixture").on("click", function(e){ main++; });
+ jQuery(window).on("click", function(){ win++; });
+ jQuery(document).on("click", function( e ){ if ( e.target !== document) { doc++; } });
+ jQuery("html").on("click", function(){ html++; });
+ jQuery("body").on("click", function(){ body++; });
+ jQuery("#qunit-fixture").on("click", function(){ main++; });
jQuery("#ap").on("click", function(){ ap++; return false; });
jQuery("html").trigger("click");
@@ -968,7 +974,8 @@ test("trigger() bubbling", function() {
test("trigger(type, [data], [fn])", function() {
expect(16);
- var handler = function(event, a, b, c) {
+ var $elem, pass, form, elem2,
+ handler = function(event, a, b, c) {
equal( event.type, "click", "check passed data" );
equal( a, 1, "check passed data" );
equal( b, "2", "check passed data" );
@@ -976,7 +983,7 @@ test("trigger(type, [data], [fn])", function() {
return "test";
};
- var $elem = jQuery("#firstp");
+ $elem = jQuery("#firstp");
// Simulate a "native" click
$elem[0].click = function(){
@@ -1011,12 +1018,12 @@ test("trigger(type, [data], [fn])", function() {
// Triggers 5
equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
- var pass = true, elem2;
+ pass = true;
try {
elem2 = jQuery("#form input").eq(0);
elem2.get(0).style.display = "none";
elem2.trigger("focus");
- } catch(e) {
+ } catch( e ) {
pass = false;
}
ok( pass, "Trigger focus on hidden element" );
@@ -1024,12 +1031,12 @@ test("trigger(type, [data], [fn])", function() {
pass = true;
try {
jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test");
- } catch (e) {
+ } catch ( e ) {
pass = false;
}
ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
- var form = jQuery("
").appendTo("body");
+ form = jQuery("
").appendTo("body");
// Make sure it can be prevented locally
form.on( "submit", function(){
@@ -1126,13 +1133,14 @@ test( "change event bubbles on copied forms (#11796)", function(){
test("trigger(eventObject, [data], [fn])", function() {
expect(28);
- var $parent = jQuery("
").appendTo("body"),
+ var event,
+ $parent = jQuery("
").appendTo("body"),
$child = jQuery("
foo
").appendTo( $parent );
$parent.get( 0 ).style.display = "none";
- var event = jQuery.Event("noNew");
- ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
+ event = jQuery.Event("noNew");
+ ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" );
equal( event.type, "noNew", "Verify its type" );
equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
@@ -1149,7 +1157,7 @@ test("trigger(eventObject, [data], [fn])", function() {
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
- $parent.on("foo",function(e){
+ $parent.on("foo",function( e ) {
// Tries bubbling
equal( e.type, "foo", "Verify event type when passed passing an event object" );
equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
@@ -1470,7 +1478,8 @@ test("jQuery.Event properties", function(){
test(".on()/.off()", function() {
expect(65);
- var submit = 0, div = 0, livea = 0, liveb = 0;
+ var event, clicked, hash, called, livec, lived, livee,
+ submit = 0, div = 0, livea = 0, liveb = 0;
jQuery("#body").on("submit", "#qunit-fixture div", function(){ submit++; return false; });
jQuery("#body").on("click", "#qunit-fixture div", function(){ div++; });
@@ -1535,7 +1544,7 @@ test(".on()/.off()", function() {
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").on("click", "div#nothiddendivchild", function(e){ liveb++; e.stopPropagation(); });
+ jQuery("#body").on("click", "div#nothiddendivchild", function( e ){ liveb++; e.stopPropagation(); });
jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "stopPropagation Click on inner div" );
equal( div, 1, "stopPropagation Click on inner div" );
@@ -1544,7 +1553,7 @@ test(".on()/.off()", function() {
// Make sure click events only fire with primary click
submit = 0; div = 0; livea = 0; liveb = 0;
- var event = jQuery.Event("click");
+ event = jQuery.Event("click");
event.button = 1;
jQuery("div#nothiddendiv").trigger(event);
@@ -1556,8 +1565,8 @@ test(".on()/.off()", function() {
jQuery("#body").off("submit", "#qunit-fixture div");
// Test binding with a different context
- var clicked = 0;
- jQuery("#qunit-fixture").on("click", "#foo", function(e){ clicked++; });
+ clicked = 0;
+ jQuery("#qunit-fixture").on("click", "#foo", function(){ clicked++; });
jQuery("#qunit-fixture div").trigger("click");
jQuery("#foo").trigger("click");
jQuery("#qunit-fixture").trigger("click");
@@ -1570,7 +1579,7 @@ test(".on()/.off()", function() {
equal( clicked, 2, "off with a context");
// Test binding with event data
- jQuery("#body").on("click", "#foo", true, function(e){ equal( e.data, true, "on with event data" ); });
+ jQuery("#body").on("click", "#foo", true, function( e ){ equal( e.data, true, "on with event data" ); });
jQuery("#foo").trigger("click");
jQuery("#body").off("click", "#foo");
@@ -1580,7 +1589,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "#foo");
// Test binding with different this object
- jQuery("#body").on("click", "#foo", jQuery.proxy(function(e){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
+ jQuery("#body").on("click", "#foo", jQuery.proxy(function(){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
jQuery("#foo").trigger("click");
jQuery("#body").off("click", "#foo");
@@ -1595,7 +1604,7 @@ test(".on()/.off()", function() {
// Verify that return false prevents default action
jQuery("#body").on("click", "#anchor2", function(){ return false; });
- var hash = window.location.hash;
+ hash = window.location.hash;
jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "return false worked" );
jQuery("#body").off("click", "#anchor2");
@@ -1608,7 +1617,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "#anchor2");
// Test binding the same handler to multiple points
- var called = 0;
+ called = 0;
function callback(){ called++; return false; }
jQuery("#body").on("click", "#nothiddendiv", callback);
@@ -1652,10 +1661,10 @@ test(".on()/.off()", function() {
// Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler
- var livec = 0;
+ livec = 0;
jQuery("#nothiddendivchild").html("
");
- jQuery("#body").on("click", "#nothiddendivchild", function(e){ jQuery("#nothiddendivchild").html(""); });
+ jQuery("#body").on("click", "#nothiddendivchild", function(){ jQuery("#nothiddendivchild").html(""); });
jQuery("#body").on("click", "#nothiddendivchild", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").trigger("click");
@@ -1667,7 +1676,8 @@ test(".on()/.off()", function() {
// Verify that .live() occurs and cancel bubble in the same order as
// we would expect .on() and .click() without delegation
- var lived = 0, livee = 0;
+ lived = 0;
+ livee = 0;
// bind one pair in one order
jQuery("#body").on("click", "span#liveSpan1 a", function(){ lived++; return false; });
@@ -1691,7 +1701,7 @@ test(".on()/.off()", function() {
jQuery("#body").off("click", "**");
// Test this, target and currentTarget are correct
- jQuery("#body").on("click", "span#liveSpan1", function(e){
+ jQuery("#body").on("click", "span#liveSpan1", function( e ) {
equal( this.id, "liveSpan1", "Check the this within a on handler" );
equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" );
equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" );
@@ -1705,7 +1715,7 @@ test(".on()/.off()", function() {
// Work with deep selectors
livee = 0;
- function clickB(){ livee++; }
+ function clickB() { livee++; }
jQuery("#body").on("click", "#nothiddendiv div", function(){ livee++; });
jQuery("#body").on("click", "#nothiddendiv div", clickB);
@@ -1793,7 +1803,7 @@ test( "delegated event with selector matching Object.prototype property (#13203)
var matched = 0;
- jQuery("#foo").on( "click", "toString", function( e ) {
+ jQuery("#foo").on( "click", "toString", function() {
matched++;
});
@@ -1842,8 +1852,8 @@ test("off all bound delegated events", function(){
test("on with multiple delegated events", function(){
expect(1);
- var count = 0;
- var div = jQuery("#body");
+ var count = 0,
+ div = jQuery("#body");
div.on("click submit", "div#nothiddendivchild", function(){ count++; });
@@ -1858,17 +1868,21 @@ test("on with multiple delegated events", function(){
test("delegated on with change", function(){
expect(8);
- var selectChange = 0, checkboxChange = 0;
+ var select, checkbox, checkboxFunction,
+ text, textChange, oldTextVal,
+ password, passwordChange, oldPasswordVal,
+ selectChange = 0,
+ checkboxChange = 0;
- var select = jQuery("select[name='S1']");
+ select = jQuery("select[name='S1']");
jQuery("#body").on("change", "select[name='S1']", function() {
selectChange++;
});
- var checkbox = jQuery("#check2"),
- checkboxFunction = function(){
- checkboxChange++;
- };
+ checkbox = jQuery("#check2");
+ checkboxFunction = function(){
+ checkboxChange++;
+ };
jQuery("#body").on("change", "#check2", checkboxFunction);
// test click on select
@@ -1890,7 +1904,10 @@ test("delegated on with change", function(){
equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text
- var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
+ text = jQuery("#name");
+ textChange = 0;
+ oldTextVal = text.val();
+
jQuery("#body").on("change", "#name", function() {
textChange++;
});
@@ -1903,7 +1920,9 @@ test("delegated on with change", function(){
jQuery("#body").off("change", "#name");
// test blur/focus on password
- var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
+ password = jQuery("#name");
+ passwordChange = 0;
+ oldPasswordVal = password.val();
jQuery("#body").on("change", "#name", function() {
passwordChange++;
});
@@ -1964,7 +1983,7 @@ test("delegated off() with only namespaces", function() {
var $delegate = jQuery("#liveHandlerOrder"),
count = 0;
- $delegate.on("click.ns", "a", function(e) {
+ $delegate.on("click.ns", "a", function() {
count++;
});
@@ -1984,7 +2003,7 @@ test("Non DOM element events", function() {
var o = {};
- jQuery(o).on("nonelementobj", function(e) {
+ jQuery(o).on("nonelementobj", function() {
ok( true, "Event on non-DOM object triggered" );
});
@@ -2065,9 +2084,8 @@ test("custom events with colons (#3533, #8272)", function() {
test(".on and .off", function() {
expect(9);
- var counter, mixfn;
-
- var $onandoff = jQuery("
").appendTo("body");
+ var counter, mixfn, data,
+ $onandoff = jQuery("
").appendTo("body");
// Simple case
jQuery( "#onandoff" )
@@ -2156,7 +2174,7 @@ test(".on and .off", function() {
.off( "click cluck" );
// We should have removed all the event handlers ... kinda hacky way to check this
- var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
+ data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
equal( data["events"], undefined, "no events left" );
$onandoff.remove();
@@ -2236,10 +2254,9 @@ test("special on name mapping", function() {
test(".on and .off, selective mixed removal (#10705)", function() {
expect(7);
- var clockout = 0,
- timingx = function( e ) {
- ok( true, "triggered " + e.type );
- };
+ var timingx = function( e ) {
+ ok( true, "triggered " + e.type );
+ };
jQuery( "
Strange Pursuit
" )
.on( "click", timingx )
@@ -2276,7 +2293,7 @@ test("clone() delegated events (#11076)", function() {
expect(3);
var counter = { "center": 0, "fold": 0, "centerfold": 0 },
- clicked = function( event ) {
+ clicked = function() {
counter[ jQuery(this).text().replace(/\s+/, "") ]++;
},
table =
@@ -2327,9 +2344,9 @@ test("checkbox state (#3827)", function() {
test("focus-blur order (#12868)", function() {
expect( 5 );
- var $text = jQuery("#text1"),
- $radio = jQuery("#radio1").trigger("focus"),
- order;
+ var order,
+ $text = jQuery("#text1"),
+ $radio = jQuery("#radio1").trigger("focus");
// IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
// IE's browser window must be topmost for this to work properly!!
@@ -2394,7 +2411,7 @@ test("fixHooks extensions", function() {
$fixture.off( "click" );
jQuery.event.fixHooks.click = {
- filter: function( event, originalEvent ) {
+ filter: function( event ) {
event.blurrinessLevel = 42;
return event;
}
@@ -2505,19 +2522,17 @@ if ( hasPHP ) {
test("change handler should be detached from element", function() {
expect( 2 );
- var $fixture = jQuery( "
" ).appendTo( "body" );
-
- var originRemoveEvent = jQuery.removeEvent;
-
- var wrapperRemoveEvent = function(elem, type, handle){
- equal("change", type, "Event handler for 'change' event should be removed");
- equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
- originRemoveEvent(elem, type, handle);
- };
+ var $fixture = jQuery( "
" ).appendTo( "body" ),
+ originRemoveEvent = jQuery.removeEvent,
+ wrapperRemoveEvent = function(elem, type, handle){
+ equal("change", type, "Event handler for 'change' event should be removed");
+ equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
+ originRemoveEvent(elem, type, handle);
+ };
jQuery.removeEvent = wrapperRemoveEvent ;
- $fixture.on( "change", function( event ) {});
+ $fixture.on( "change", function() {});
$fixture.off( "change" );
$fixture.remove();
@@ -2559,7 +2574,7 @@ test( "Namespace preserved when passed an Event (#12739)", function() {
});
}
})
- .on( "foo.bar2", function( e ) {
+ .on( "foo.bar2", function() {
ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id );
});
@@ -2589,11 +2604,11 @@ test( "make sure events cloned correctly", 18, function() {
ok( result, "Change on original child element though delegation is fired" );
});
- p.on("click", function( event, result ) {
+ p.on("click", function() {
ok( true, "Click on original child element is fired" );
});
- checkbox.on("change", function( event, result ) {
+ checkbox.on("change", function() {
ok( true, "Change on original child element is fired" );
});
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index a15c4c5ad..8a32dac20 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -3,19 +3,19 @@ module( "manipulation", {
});
// Ensure that an extended Array prototype doesn't break jQuery
-Array.prototype.arrayProtoFn = function( arg ) {
+Array.prototype.arrayProtoFn = function() {
throw("arrayProtoFn should not be called");
};
-var manipulationBareObj = function( value ) {
+function manipulationBareObj( value ) {
return value;
-};
+}
-var manipulationFunctionReturningObj = function( value ) {
- return (function() {
+function manipulationFunctionReturningObj( value ) {
+ return function() {
return value;
- });
-};
+ };
+}
/*
======== local reference =======
@@ -62,7 +62,7 @@ test( "text(undefined)", function() {
equal( jQuery("#foo").text("
").append( valueObj("option
") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
-};
+}
test( "append(String|Element|Array
|jQuery)", function() {
testAppend( manipulationBareObj );
@@ -577,7 +577,7 @@ test( "appendTo(String|Element|Array|jQuery)", function() {
equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
});
-var testPrepend = function( val ) {
+function testPrepend( val ) {
expect( 6 );
@@ -608,7 +608,7 @@ var testPrepend = function( val ) {
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) );
equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
-};
+}
test( "prepend(String|Element|Array|jQuery)", function() {
testPrepend( manipulationBareObj );
@@ -707,7 +707,7 @@ test( "prependTo(String|Element|Array|jQuery)", function() {
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
});
-var testBefore = function( val ) {
+function testBefore( val ) {
expect( 7 );
@@ -740,7 +740,7 @@ var testBefore = function( val ) {
set = jQuery("").before("test");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
-};
+}
test( "before(String|Element|Array|jQuery)", function() {
testBefore( manipulationBareObj );
@@ -813,7 +813,7 @@ test( "insertBefore(String|Element|Array|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
});
-var testAfter = function( val ) {
+function testAfter( val ) {
expect( 7 );
@@ -846,7 +846,7 @@ var testAfter = function( val ) {
set = jQuery("").before("test");
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
-};
+}
test( "after(String|Element|Array|jQuery)", function() {
testAfter( manipulationBareObj );
@@ -882,7 +882,7 @@ test( "insertAfter(String|Element|Array|jQuery)", function() {
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
});
-var testReplaceWith = function( val ) {
+function testReplaceWith( val ) {
var tmp, y, child, child2, set, non_existent, $div,
expected = 23;
@@ -970,7 +970,7 @@ var testReplaceWith = function( val ) {
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." );
return expected;
-};
+}
test( "replaceWith(String|Element|Array|jQuery)", function() {
testReplaceWith( manipulationBareObj );
@@ -1271,13 +1271,13 @@ test( "html() on empty set", function() {
strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
});
-var childNodeNames = function( node ) {
+function childNodeNames( node ) {
return jQuery.map( node.childNodes, function( child ) {
return child.nodeName.toUpperCase();
}).join(" ");
-};
+}
-var testHtml = function( valueObj ) {
+function testHtml( valueObj ) {
expect( 37 );
var actual, expected, tmp,
@@ -1381,7 +1381,7 @@ var testHtml = function( valueObj ) {
QUnit.reset();
fixture.html( valueObj( fixture.text() ) );
ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
-};
+}
test( "html(String)", function() {
testHtml( manipulationBareObj );
@@ -1484,7 +1484,7 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
ok( expected.test( $content.html() ), "html()" );
});
-var testRemove = function( method ) {
+function testRemove( method ) {
var markup, div,
first = jQuery("#ap").children().first();
@@ -1494,7 +1494,7 @@ var testRemove = function( method ) {
ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
equal( jQuery("#ap").children().length, 0, "Check remove" );
- equal( first.data("foo"), method == "remove" ? null : "bar", "first data" );
+ equal( first.data("foo"), method === "remove" ? null : "bar", "first data" );
QUnit.reset();
jQuery("#ap").children()[ method ]("a");
@@ -1526,7 +1526,7 @@ var testRemove = function( method ) {
if (method === "detach") {
first.remove();
}
-};
+}
test( "remove()", 11, function() {
testRemove("remove");
@@ -1746,7 +1746,7 @@ test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
}
// Bind an event
- $section.on( "click", function( event ) {
+ $section.on( "click", function() {
ok( true, "clone fired event" );
});
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 0d8bcc726..f1e33bd4b 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -94,8 +94,10 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
testIframe("offset/absolute", "absolute", function( $ ) {
expect(178);
+ var tests, offset;
+
// get offset tests
- var tests = [
+ tests = [
{ "id": "#absolute-1", "top": 1, "left": 1 },
{ "id": "#absolute-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": 9, "left": 9 },
@@ -120,7 +122,7 @@ testIframe("offset/absolute", "absolute", function( $ ) {
});
// test #5781
- var offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
+ offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
@@ -179,11 +181,13 @@ testIframe("offset/absolute", "absolute", function( $ ) {
testIframe("offset/relative", "relative", function( $ ) {
expect(60);
+ var ie, tests;
+
// IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#relative-1").offset().top === 6;
+ ie = $("#relative-1").offset().top === 6;
// get offset
- var tests = [
+ tests = [
{ "id": "#relative-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#relative-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#relative-2", "top": ie ? 141 : 142, "left": 27 }
@@ -238,14 +242,15 @@ testIframe("offset/relative", "relative", function( $ ) {
});
testIframe("offset/static", "static", function( $ ) {
-
- // IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#static-1").offset().top === 6;
-
expect( 80 );
+ var ie, tests;
+
+ // IE is collapsing the top margin of 1px; detect and adjust accordingly
+ ie = $("#static-1").offset().top === 6;
+
// get offset
- var tests = [
+ tests = [
{ "id": "#static-1", "top": ie ? 6 : 7, "left": 7 },
{ "id": "#static-1-1", "top": ie ? 13 : 15, "left": 15 },
{ "id": "#static-1-1-1", "top": ie ? 20 : 23, "left": 23 },
@@ -306,12 +311,14 @@ testIframe("offset/static", "static", function( $ ) {
});
testIframe("offset/fixed", "fixed", function( $ ) {
- // IE is collapsing the top margin of 1px; detect and adjust accordingly
- var ie = $("#fixed-1").position().top === 2;
-
expect(34);
- var tests = [
+ var ie, tests, $noTopLeft;
+
+ // IE is collapsing the top margin of 1px; detect and adjust accordingly
+ ie = $("#fixed-1").position().top === 2;
+
+ tests = [
{
"id": "#fixed-1",
"offsetTop": 1001,
@@ -382,7 +389,7 @@ testIframe("offset/fixed", "fixed", function( $ ) {
});
// Bug 8316
- var $noTopLeft = $("#fixed-no-top-left");
+ $noTopLeft = $("#fixed-no-top-left");
if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
@@ -487,15 +494,17 @@ test("chaining", function() {
test("offsetParent", function(){
expect(13);
- var body = jQuery("body").offsetParent();
+ var body, header, div, area;
+
+ body = jQuery("body").offsetParent();
equal( body.length, 1, "Only one offsetParent found." );
equal( body[0], document.documentElement, "The html element is the offsetParent of the body." );
- var header = jQuery("#qunit").offsetParent();
+ header = jQuery("#qunit").offsetParent();
equal( header.length, 1, "Only one offsetParent found." );
equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." );
- var div = jQuery("#nothiddendivchild").offsetParent();
+ div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
@@ -510,7 +519,7 @@ test("offsetParent", function(){
equal( div[0], document.documentElement, "The html element is the offsetParent of the body." );
equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
- var area = jQuery("#imgmap area").offsetParent();
+ area = jQuery("#imgmap area").offsetParent();
equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("").css({ "position": "absolute" }).appendTo("body");
@@ -524,8 +533,9 @@ test("fractions (see #7730 and #7885)", function() {
jQuery("body").append("
");
- var expected = { "top": 1000, "left": 1000 };
- var div = jQuery("#fractions");
+ var result,
+ expected = { "top": 1000, "left": 1000 },
+ div = jQuery("#fractions");
div.css({
"position": "absolute",
@@ -537,7 +547,7 @@ test("fractions (see #7730 and #7885)", function() {
div.offset(expected);
- var result = div.offset();
+ result = div.offset();
equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" );
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 5328d608a..f60d802fb 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,12 +1,11 @@
module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 14, function() {
- var counter = 0;
-
stop();
var $div = jQuery({}),
- defer;
+ counter = 0;
+
$div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
});
@@ -56,8 +55,8 @@ test( "queue() with other types", 14, function() {
test("queue(name) passes in the next item in the queue as a parameter", function() {
expect(2);
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing");
@@ -76,8 +75,8 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
expect(3);
stop();
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
div.queue(function(next) {
equal(++counter, 1, "Dequeueing");
@@ -148,14 +147,14 @@ test("clearQueue(name) clears the queue", function() {
stop();
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
- div.queue("foo", function(next) {
+ div.queue("foo", function( next ) {
counter++;
jQuery(this).clearQueue("foo");
next();
- }).queue("foo", function( next ) {
+ }).queue("foo", function() {
counter++;
});
@@ -172,14 +171,14 @@ test("clearQueue(name) clears the queue", function() {
test("clearQueue() clears the fx queue", function() {
expect(1);
- var div = jQuery({});
- var counter = 0;
+ var div = jQuery({}),
+ counter = 0;
- div.queue(function(next) {
+ div.queue(function( next ) {
counter++;
var self = this;
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
- }).queue(function( next ) {
+ }).queue(function() {
counter++;
});
@@ -251,8 +250,8 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res
test( ".promise(obj)", function() {
expect(2);
- var obj = {};
- var promise = jQuery( "#foo" ).promise( "promise", obj );
+ var obj = {},
+ promise = jQuery( "#foo" ).promise( "promise", obj );
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
strictEqual( promise, obj, ".promise(type, obj) returns obj" );
diff --git a/test/unit/serialize.js b/test/unit/serialize.js
index 63607a323..39e7d777e 100644
--- a/test/unit/serialize.js
+++ b/test/unit/serialize.js
@@ -3,9 +3,11 @@ module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() {
expect(22);
+ var params, settings;
+
equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" );
- var params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
+ params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined};
@@ -37,7 +39,7 @@ test("jQuery.param()", function() {
// #7945
equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
- var settings = { traditional: true };
+ settings = { traditional: true };
if ( jQuery.ajaxSettings ) {
jQuery.ajaxSetup( settings );
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index b600e130b..d99de436a 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -418,49 +418,54 @@ test("not(jQuery)", function() {
test("has(Element)", function() {
expect(3);
+ var obj, detached, multipleParent;
- var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
+ obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
- var detached = jQuery("
");
+ detached = jQuery("
");
deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
+ multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
});
test("has(Selector)", function() {
expect( 5 );
- var obj = jQuery("#qunit-fixture").has("#sndp");
+ var obj, detached, multipleParent, multipleHas;
+
+ obj = jQuery("#qunit-fixture").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
- var detached = jQuery("
");
+ detached = jQuery("
");
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
+ multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
- var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
+ multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("has(Arrayish)", function() {
expect(4);
- var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
+ var simple, detached, multipleParent, multipleHas;
+
+ simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
- var detached = jQuery("
");
+ detached = jQuery("
");
deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
- var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
+ multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
- var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
+ multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
@@ -478,6 +483,7 @@ test("siblings([String])", function() {
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" );
deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
+
var set = q("sndp", "en", "sap");
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
@@ -626,9 +632,11 @@ test("prevUntil([String])", function() {
test("contents()", function() {
expect(12);
+ var ibody, c;
+
equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" );
- var ibody = jQuery("#loadediframe").contents()[0].body;
+ ibody = jQuery("#loadediframe").contents()[0].body;
ok( ibody, "Check existence of IFrame body" );
equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
@@ -651,13 +659,16 @@ test("contents()", function() {
equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
// using contents will get comments regular, text, and comment nodes
- var c = jQuery("#nonnodes").contents().contents();
+ c = jQuery("#nonnodes").contents().contents();
equal( c.length, 1, "Check node,textnode,comment contents is just one" );
equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
});
test("add(String|Element|Array|undefined)", function() {
expect( 15 );
+
+ var divs, tmp, x, notDefined;
+
deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
@@ -671,15 +682,15 @@ test("add(String|Element|Array|undefined)", function() {
// use jQuery([]).add(form.elements) instead.
//equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
- var divs = jQuery("
").add("#sndp");
+ divs = jQuery("
").add("#sndp");
ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
divs = jQuery("#sndp").add("
");
ok( !divs[1].parentNode, "Sort with the disconnected node last." );
- var tmp = jQuery("
");
+ tmp = jQuery("
");
- var x = jQuery([]).add(jQuery("
xxx
").appendTo(tmp)).add(jQuery("
xxx
").appendTo(tmp));
+ x = jQuery([]).add(jQuery("
xxx
").appendTo(tmp)).add(jQuery("
xxx
").appendTo(tmp));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
@@ -695,7 +706,6 @@ test("add(String|Element|Array|undefined)", function() {
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
- var notDefined;
equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
@@ -726,14 +736,15 @@ test("eq('-1') #10616", function() {
test("index(no arg) #10977", function() {
expect(2);
+ var $list, fragment, div;
- var $list = jQuery("
");
+ $list = jQuery("
");
jQuery("#qunit-fixture").append( $list );
strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" );
$list.remove();
- var fragment = document.createDocumentFragment(),
- div = fragment.appendChild( document.createElement("div") );
+ fragment = document.createDocumentFragment();
+ div = fragment.appendChild( document.createElement("div") );
equal( jQuery( div ).index(), 0, "If jQuery#index called on element whose parent is fragment, it still should work correctly" );
});
diff --git a/test/unit/wrap.js b/test/unit/wrap.js
index 1775aafb6..3de1c7931 100644
--- a/test/unit/wrap.js
+++ b/test/unit/wrap.js
@@ -9,17 +9,17 @@ module( "wrap", {
});
// See test/unit/manipulation.js for explanation about these 2 functions
-var manipulationBareObj = function( value ) {
+function manipulationBareObj( value ) {
return value;
-};
+}
-var manipulationFunctionReturningObj = function( value ) {
- return (function() {
+function manipulationFunctionReturningObj( value ) {
+ return function() {
return value;
- });
-};
+ };
+}
-var testWrap = function( val ) {
+function testWrap( val ) {
expect( 19 );
@@ -99,7 +99,7 @@ var testWrap = function( val ) {
// clean up attached elements
QUnit.reset();
-};
+}
test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj );
@@ -136,7 +136,7 @@ test( "wrap(String) consecutive elements (#10177)", function() {
});
});
-var testWrapAll = function( val ) {
+function testWrapAll( val ) {
expect( 8 );
@@ -160,17 +160,18 @@ var testWrapAll = function( val ) {
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
-};
+}
test( "wrapAll(String|Element)", function() {
testWrapAll( manipulationBareObj );
});
-var testWrapInner = function( val ) {
+function testWrapInner( val ) {
expect( 11 );
- var num;
+ var num,
+ div = jQuery("
");
num = jQuery("#first").children().length;
jQuery("#first").wrapInner( val("
") );
@@ -193,11 +194,10 @@ var testWrapInner = function( val ) {
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
- var div = jQuery("
");
div.wrapInner( val("
") );
equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
-};
+}
test( "wrapInner(String|Element)", function() {
testWrapInner( manipulationBareObj );