ionic-Material Design , Codecanyon

This commit is contained in:
Carsten Hilmer
2016-08-22 12:59:56 +02:00
parent 7cd84fe179
commit 92601ec169
1440 changed files with 482763 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,326 @@
module( "callbacks", {
teardown: moduleTeardown
});
(function() {
var output,
addToOutput = function( string ) {
return function() {
output += string;
};
},
outputA = addToOutput("A"),
outputB = addToOutput("B"),
outputC = addToOutput("C"),
tests = {
"": "XABC X XABCABCC X XBB X XABA X XX",
"once": "XABC X X X X X XABA X XX",
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC XX",
"unique": "XABC X XABCA X XBB X XAB X X",
"stopOnFalse": "XABC X XABCABCC X XBB X XA X XX",
"once memory": "XABC XABC X XA X XA XABA XC XX",
"once unique": "XABC X X X X X XAB X X",
"once stopOnFalse": "XABC X X X X X XA X XX",
"memory unique": "XABC XA XABCA XA XBB XB XAB XC X",
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X XX",
"unique stopOnFalse": "XABC X XABCA X XBB X XA X X"
},
filters = {
"no filter": undefined,
"filter": function( fn ) {
return function() {
return fn.apply( this, arguments );
};
}
};
function showFlags( flags ) {
if ( typeof flags === "string" ) {
return "'" + flags + "'";
}
var output = [], key;
for ( key in flags ) {
output.push( "'" + key + "': " + flags[ key ] );
}
return "{ " + output.join( ", " ) + " }";
}
jQuery.each( tests, function( strFlags, resultString ) {
var objectFlags = {};
jQuery.each( strFlags.split( " " ), function() {
if ( this.length ) {
objectFlags[ this ] = true;
}
});
jQuery.each( filters, function( filterLabel, filter ) {
jQuery.each({
"string": strFlags,
"object": objectFlags
}, function( flagsTypes, flags ) {
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
expect( 21 );
// Give qunit a little breathing room
stop();
setTimeout( start, 0 );
var cblist,
results = resultString.split( /\s+/ );
// Basic binding and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function( str ) {
output += str;
});
cblist.fire("A");
strictEqual( output, "XA", "Basic binding and firing" );
strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
cblist.add(function( str ) {
output += str;
});
strictEqual( output, "X", "Adding a callback after disabling" );
cblist.fire("A");
strictEqual( output, "X", "Firing after disabling" );
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
});
cblist.fireWith( window, [ "A", "B" ] );
strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
});
cblist.fireWith();
// Basic binding, removing and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, outputB, outputC );
cblist.remove( outputB, outputC );
cblist.fire();
strictEqual( output, "XA", "Basic binding, removing and firing" );
// Empty
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA );
cblist.add( outputB );
cblist.add( outputC );
cblist.empty();
cblist.fire();
strictEqual( output, "X", "Empty" );
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function( str ) {
output += str;
});
cblist.lock();
cblist.add(function( str ) {
output += str;
});
cblist.fire("A");
cblist.add(function( str ) {
output += str;
});
strictEqual( output, "X", "Lock early" );
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
cblist.add( outputC );
outputA();
}, outputB );
cblist.fire();
strictEqual( output, results.shift(), "Proper ordering" );
// Add and fire again
output = "X";
cblist.add(function() {
cblist.add( outputC );
outputA();
}, outputB );
strictEqual( output, results.shift(), "Add after fire" );
output = "X";
cblist.fire();
strictEqual( output, results.shift(), "Fire again" );
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function( str ) {
output += str;
});
cblist.fire("A");
strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
cblist.add(function( str ) {
output += str;
});
strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
cblist.fire("B");
strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
cblist.add(function( str ) {
output += str;
});
strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, function() { return false; }, outputB );
cblist.add( outputA );
cblist.fire();
strictEqual( output, results.shift(), "Callback returning false" );
// Add another callback (to control lists with memory do not fire anymore)
output = "X";
cblist.add( outputC );
strictEqual( output, results.shift(), "Adding a callback after one returned false" );
// Callbacks are not iterated
output = "";
function handler( tmp ) {
output += "X";
}
handler.method = function() {
output += "!";
};
cblist = jQuery.Callbacks( flags );
cblist.add( handler );
cblist.add( handler );
cblist.fire();
strictEqual( output, results.shift(), "No callback iteration" );
});
});
});
});
})();
test( "jQuery.Callbacks( options ) - options are copied", function() {
expect( 1 );
var options = {
"unique": true
},
cb = jQuery.Callbacks( options ),
count = 0,
fn = function() {
ok( !( count++ ), "called once" );
};
options["unique"] = false;
cb.add( fn, fn );
cb.fire();
});
test( "jQuery.Callbacks.fireWith - arguments are copied", function() {
expect( 1 );
var cb = jQuery.Callbacks("memory"),
args = ["hello"];
cb.fireWith( null, args );
args[ 0 ] = "world";
cb.add(function( hello ) {
strictEqual( hello, "hello", "arguments are copied internally" );
});
});
test( "jQuery.Callbacks.remove - should remove all instances", function() {
expect( 1 );
var cb = jQuery.Callbacks();
function fn() {
ok( false, "function wasn't removed" );
}
cb.add( fn, fn, function() {
ok( true, "end of test" );
}).remove( fn ).fire();
});
test( "jQuery.Callbacks.has", function() {
expect( 13 );
var cb = jQuery.Callbacks();
function getA() {
return "A";
}
function getB() {
return "B";
}
function getC() {
return "C";
}
cb.add(getA, getB, getC);
strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" );
strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" );
cb.remove(getB);
strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" );
strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" );
cb.empty();
strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" );
strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" );
cb.add(getA, getB, function(){
strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" );
strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" );
}).fire();
strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" );
cb.disable();
strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" );
strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" );
cb = jQuery.Callbacks("unique");
cb.add(getA);
cb.add(getA);
strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock();
strictEqual( cb.has(), false, "locked() list is empty and returns false" );
});
test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() {
expect( 1 );
jQuery.Callbacks().add( "hello world" );
ok( true, "no stack overflow" );
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,636 @@
module("data", { teardown: moduleTeardown });
test("expando", function(){
expect(1);
equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando");
});
function dataTests (elem) {
var oldCacheLength, dataObj, internalDataObj, expected, actual;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
dataObj = jQuery.data(elem);
equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
dataObj["foo"] = "bar";
equal( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" );
jQuery.data(elem, "foo", "baz");
equal( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" );
equal( dataObj["foo"], "baz", "Changes made through jQuery.data propagate to referenced data object" );
jQuery.data(elem, "foo", undefined);
equal( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" );
jQuery.data(elem, "foo", null);
strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" );
jQuery.data(elem, "foo", "foo1");
jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" });
strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" );
equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" );
jQuery._data(elem, "foo", "foo2", true);
equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" );
internalDataObj = jQuery._data( elem );
ok( internalDataObj, "Internal data object exists" );
notStrictEqual( dataObj, internalDataObj, "Internal data object is not the same as user data object" );
strictEqual( elem.boom, undefined, "Data is never stored directly on the object" );
jQuery.removeData(elem, "foo");
strictEqual( jQuery.data(elem, "foo"), undefined, "jQuery.removeData removes single properties" );
jQuery.removeData(elem);
strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
jQuery.data(elem, "foo", "foo1");
jQuery._data(elem, "foo", "foo2");
equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" );
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
strictEqual( jQuery._data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" );
jQuery._data(elem, "foo", "foo2");
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
jQuery.removeData(elem, "foo");
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
}
test("jQuery.data(div)", 25, function() {
var div = document.createElement("div");
dataTests(div);
// We stored one key in the private data
// assert that nothing else was put in there, and that that
// one stayed there.
QUnit.expectJqData(div, "foo");
});
test("jQuery.data({})", 25, function() {
dataTests({});
});
test("jQuery.data(window)", 25, function() {
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
// transports/xhr.js
jQuery(window).unbind("unload");
dataTests(window);
});
test("jQuery.data(document)", 25, function() {
dataTests(document);
QUnit.expectJqData(document, "foo");
});
test("Expando cleanup", 4, function() {
var expected, actual,
div = document.createElement("div");
function assertExpandoAbsent(message) {
if (jQuery.support.deleteExpando) {
expected = false;
actual = jQuery.expando in div;
} else {
expected = null;
actual = div[ jQuery.expando ];
}
equal( actual, expected, message );
}
assertExpandoAbsent("There is no expando on new elements");
jQuery.data(div, "foo", 100);
jQuery.data(div, "bar", 200);
ok(jQuery.expando in div, "There is an expando on the element after using $.data()");
jQuery.removeData(div, "foo");
ok(jQuery.expando in div, "There is still an expando on the element after removing (some) of the data");
jQuery.removeData(div, "bar");
assertExpandoAbsent("Removing the last item in the data store deletes the expando");
// Clean up unattached element
jQuery(div).remove();
});
test("Data is not being set on comment and text nodes", function() {
expect(2);
ok( !jQuery.hasData( jQuery("<!-- comment -->").data("foo", 0) ) );
ok( !jQuery.hasData( jQuery("<span>text</span>").contents().data("foo", 0) ) );
});
test("jQuery.acceptData", function() {
expect(9);
ok( jQuery.acceptData( document ), "document" );
ok( jQuery.acceptData( document.documentElement ), "documentElement" );
ok( jQuery.acceptData( {} ), "object" );
ok( !jQuery.acceptData( document.createElement("embed") ), "embed" );
ok( !jQuery.acceptData( document.createElement("applet") ), "applet" );
var flash = document.createElement("object");
flash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
ok( jQuery.acceptData( flash ), "flash" );
var applet = document.createElement("object");
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
ok( !jQuery.acceptData( applet ), "applet" );
ok( !jQuery.acceptData( document.createComment("") ), "comment" );
ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
});
test(".data()", function() {
expect(5);
var div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success");
var dataObj = div.data();
deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
var nodiv = jQuery("#unfound");
equal( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" };
jQuery(obj).data("foo", "baz");
dataObj = jQuery.extend(true, {}, jQuery(obj).data());
deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
});
var testDataTypes = function( $obj ) {
jQuery.each({
"null": null,
"true": true,
"false": false,
"zero": 0,
"one": 1,
"empty string": "",
"empty array": [],
"array": [1],
"empty object": {},
"object": { foo: "bar" },
"date": new Date(),
"regex": /test/,
"function": function() {}
}, function( type, value ) {
strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type );
});
};
test("jQuery(Element).data(String, Object).data(String)", function() {
expect( 18 );
var parent = jQuery("<div><div></div></div>"),
div = parent.children();
strictEqual( div.data("test"), undefined, "No data exists initially" );
strictEqual( div.data("test", "success").data("test"), "success", "Data added" );
strictEqual( div.data("test", "overwritten").data("test"), "overwritten", "Data overwritten" );
strictEqual( div.data("test", undefined).data("test"), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)");
strictEqual( div.data("notexist"), undefined, "No data exists for unset key" );
testDataTypes( div );
parent.remove();
});
test("jQuery(plain Object).data(String, Object).data(String)", function() {
expect( 16 );
// #3748
var $obj = jQuery({ exists: true });
strictEqual( $obj.data("nothing"), undefined, "Non-existent data returns undefined");
strictEqual( $obj.data("exists"), undefined, "Object properties are not returned as data" );
testDataTypes( $obj );
// Clean up
$obj.removeData();
deepEqual( $obj[0], { exists: true }, "removeData does not clear the object" );
});
test("data-* attributes", function() {
expect(40);
var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
div.attr("data-attr", "exists");
equal( div.data("attr"), "exists", "Check for existing data-attr attribute" );
div.attr("data-attr", "exists2");
equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
div.data("attr", "internal").attr("data-attr", "external");
equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
div.remove();
child.appendTo("#qunit-fixture");
equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
child.data("myobj", "replaced");
equal( child.data("myobj"), "replaced", "Original data overwritten");
child.data("ignored", "cache");
equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
var prop,
obj = child.data(),
obj2 = dummy.data(),
check = [ "myobj", "ignored", "other" ],
num = 0,
num2 = 0;
dummy.remove();
for ( var i = 0, l = check.length; i < l; i++ ) {
ok( obj[ check[i] ], "Make sure data- property exists when calling data-." );
ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
}
for ( prop in obj ) {
num++;
}
equal( num, check.length, "Make sure that the right number of properties came through." );
for ( prop in obj2 ) {
num2++;
}
equal( num2, check.length, "Make sure that the right number of properties came through." );
child.attr("data-other", "newvalue");
equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );
child
.attr("data-true", "true")
.attr("data-false", "false")
.attr("data-five", "5")
.attr("data-point", "5.5")
.attr("data-pointe", "5.5E3")
.attr("data-grande", "5.574E9")
.attr("data-hexadecimal", "0x42")
.attr("data-pointbad", "5..5")
.attr("data-pointbad2", "-.")
.attr("data-bigassnum", "123456789123456789123456789")
.attr("data-badjson", "{123}")
.attr("data-badjson2", "[abc]")
.attr("data-empty", "")
.attr("data-space", " ")
.attr("data-null", "null")
.attr("data-string", "test");
strictEqual( child.data("true"), true, "Primitive true read from attribute");
strictEqual( child.data("false"), false, "Primitive false read from attribute");
strictEqual( child.data("five"), 5, "Primitive number read from attribute");
strictEqual( child.data("point"), 5.5, "Primitive number read from attribute");
strictEqual( child.data("pointe"), "5.5E3", "Floating point exponential number read from attribute");
strictEqual( child.data("grande"), "5.574E9", "Big exponential number read from attribute");
strictEqual( child.data("hexadecimal"), "0x42", "Hexadecimal number read from attribute");
strictEqual( child.data("pointbad"), "5..5", "Bad number read from attribute");
strictEqual( child.data("pointbad2"), "-.", "Bad number read from attribute");
strictEqual( child.data("bigassnum"), "123456789123456789123456789", "Bad bigass number read from attribute");
strictEqual( child.data("badjson"), "{123}", "Bad number read from attribute");
strictEqual( child.data("badjson2"), "[abc]", "Bad number read from attribute");
strictEqual( child.data("empty"), "", "Empty string read from attribute");
strictEqual( child.data("space"), " ", "Empty string read from attribute");
strictEqual( child.data("null"), null, "Primitive null read from attribute");
strictEqual( child.data("string"), "test", "Typical string read from attribute");
child.remove();
// tests from metadata plugin
function testData(index, elem) {
switch (index) {
case 0:
equal(jQuery(elem).data("foo"), "bar", "Check foo property");
equal(jQuery(elem).data("bar"), "baz", "Check baz property");
break;
case 1:
equal(jQuery(elem).data("test"), "bar", "Check test property");
equal(jQuery(elem).data("bar"), "baz", "Check bar property");
break;
case 2:
equal(jQuery(elem).data("zoooo"), "bar", "Check zoooo property");
deepEqual(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property");
break;
case 3:
equal(jQuery(elem).data("number"), true, "Check number property");
deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
break;
default:
ok(false, ["Assertion failed on index ", index, ", with data"].join(""));
}
}
var metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>",
elem = jQuery(metadata).appendTo("#qunit-fixture");
elem.find("li").each(testData);
elem.remove();
});
test(".data(Object)", function() {
expect(4);
var div = jQuery("<div/>");
div.data({ "test": "in", "test2": "in2" });
equal( div.data("test"), "in", "Verify setting an object in data" );
equal( div.data("test2"), "in2", "Verify setting an object in data" );
var obj = {test:"unset"},
jqobj = jQuery(obj);
jqobj.data("test", "unset");
jqobj.data({ "test": "in", "test2": "in2" });
equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" );
equal( obj["test2"], undefined, "Verify setting an object on an object does not extend the object" );
// manually clean up detached elements
div.remove();
});
test("jQuery.removeData", function() {
expect(10);
var div = jQuery("#foo")[0];
jQuery.data(div, "test", "testing");
jQuery.removeData(div, "test");
equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
jQuery.data(div, "test2", "testing");
jQuery.removeData( div );
ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." );
ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );
jQuery.data(div, {
test3: "testing",
test4: "testing"
});
jQuery.removeData( div, "test3 test4" );
ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete with spaces." );
jQuery.data(div, {
test3: "testing",
test4: "testing"
});
jQuery.removeData( div, [ "test3", "test4" ] );
ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete by array." );
jQuery.data(div, {
"test3 test4": "testing",
"test3": "testing"
});
jQuery.removeData( div, "test3 test4" );
ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" );
ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );
var obj = {};
jQuery.data(obj, "test", "testing");
equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
jQuery.removeData(obj, "test");
equal( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" );
jQuery.data( window, "BAD", true );
jQuery.removeData( window, "BAD" );
ok( !jQuery.data( window, "BAD" ), "Make sure that the value was not still set." );
});
test(".removeData()", function() {
expect(6);
var div = jQuery("#foo");
div.data("test", "testing");
div.removeData("test");
equal( div.data("test"), undefined, "Check removal of data" );
div.data("test", "testing");
div.data("test.foo", "testing2");
div.removeData("test.bar");
equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
equal( div.data("test"), "testing", "Make sure data is intact" );
div.removeData("test");
equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
equal( div.data("test"), undefined, "Make sure data is intact" );
div.removeData("test.foo");
equal( div.data("test.foo"), undefined, "Make sure data is intact" );
});
if (window.JSON && window.JSON.stringify) {
test("JSON serialization (#8108)", function () {
expect(1);
var obj = { "foo": "bar" };
jQuery.data(obj, "hidden", true);
equal( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
});
}
test("jQuery.data should follow html5 specification regarding camel casing", function() {
expect(10);
var div = jQuery("<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
.prependTo("body");
equal( div.data()["wTF"], "ftw", "Verify single letter data-* key" );
equal( div.data()["bigALittleA"], "bouncing-b", "Verify single letter mixed data-* key" );
equal( div.data()["foo"], "a", "Verify single word data-* key" );
equal( div.data()["fooBar"], "b", "Verify multiple word data-* key" );
equal( div.data()["fooBarBaz"], "c", "Verify multiple word data-* key" );
equal( div.data("foo"), "a", "Verify single word data-* key" );
equal( div.data("fooBar"), "b", "Verify multiple word data-* key" );
equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" );
div.data("foo-bar", "d");
equal( div.data("fooBar"), "d", "Verify updated data-* key" );
equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
div.remove();
});
test("jQuery.data should not miss data with preset hyphenated property names", function() {
expect(2);
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
test = {
"camelBar": "camelBar",
"hyphen-foo": "hyphen-foo"
};
div.data( test );
jQuery.each( test , function(i, k) {
equal( div.data(k), k, "data with property '"+k+"' was correctly found");
});
});
test("jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
datas = {
"non-empty": "a string",
"empty-string": "",
"one-value": 1,
"zero-value": 0,
"an-array": [],
"an-object": {},
"bool-true": true,
"bool-false": false,
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
"some-json": "{ \"foo\": \"bar\" }",
"num-1-middle": true,
"num-end-2": true,
"2-num-start": true
};
expect( 24 );
jQuery.each( datas, function( key, val ) {
div.data( key, val );
deepEqual( div.data( key ), val, "get: " + key );
deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
});
});
test("jQuery.data supports interoperable removal of hyphenated/camelCase properties", function() {
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
datas = {
"non-empty": "a string",
"empty-string": "",
"one-value": 1,
"zero-value": 0,
"an-array": [],
"an-object": {},
"bool-true": true,
"bool-false": false,
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
"some-json": "{ \"foo\": \"bar\" }"
};
expect( 27 );
jQuery.each( datas, function( key, val ) {
div.data( key, val );
deepEqual( div.data( key ), val, "get: " + key );
deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
div.removeData( key );
equal( div.data( key ), undefined, "get: " + key );
});
});
test( "jQuery.fn.removeData supports removal of hyphenated properties via array (#12786)", function( assert ) {
expect( 4 );
var div, plain, compare;
div = jQuery("<div>").appendTo("#qunit-fixture");
plain = jQuery({});
// When data is batch assigned (via plain object), the properties
// are not camel cased as they are with (property, value) calls
compare = {
// From batch assignment .data({ "a-a": 1 })
"a-a": 1,
// From property, value assignment .data( "b-b", 1 )
"bB": 1
};
// Mixed assignment
div.data({ "a-a": 1 }).data( "b-b", 1 );
plain.data({ "a-a": 1 }).data( "b-b", 1 );
deepEqual( div.data(), compare, "Data appears as expected. (div)" );
deepEqual( plain.data(), compare, "Data appears as expected. (plain)" );
div.removeData([ "a-a", "b-b" ]);
plain.removeData([ "a-a", "b-b" ]);
// NOTE: Timo's proposal for "propEqual" (or similar) would be nice here
deepEqual( div.data(), {}, "Data is empty. (div)" );
deepEqual( plain.data(), {}, "Data is empty. (plain)" );
});
// Test originally by Moschel
test("Triggering the removeData should not throw exceptions. (#10080)", function() {
expect(1);
stop();
var frame = jQuery("#loadediframe");
jQuery(frame[0].contentWindow).bind("unload", function() {
ok(true, "called unload");
start();
});
// change the url to trigger unload
frame.attr("src", "data/iframe.html?param=true");
});
test( "Only check element attributes once when calling .data() - #8909", function() {
expect( 2 );
var testing = {
"test": "testing",
"test2": "testing"
},
element = jQuery( "<div data-test='testing'>" ),
node = element[ 0 ];
// set an attribute using attr to ensure it
node.setAttribute( "data-test2", "testing" );
deepEqual( element.data(), testing, "Sanity Check" );
node.setAttribute( "data-test3", "testing" );
deepEqual( element.data(), testing, "The data didn't change even though the data-* attrs did" );
// clean up data cache
element.remove();
});
test( "JSON data- attributes can have newlines", function() {
expect(1);
var x = jQuery("<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>");
equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
x.remove();
});

View File

@@ -0,0 +1,440 @@
module( "deferred", {
teardown: moduleTeardown
});
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
function createDeferred( fn ) {
return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn );
}
test( "jQuery.Deferred" + withNew, function() {
expect( 23 );
var defer = createDeferred();
strictEqual( defer.pipe, defer.then, "pipe is an alias of then" );
createDeferred().resolve().done(function() {
ok( true, "Success on resolve" );
strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
}).fail(function() {
ok( false, "Error on resolve" );
}).always(function() {
ok( true, "Always callback on resolve" );
});
createDeferred().reject().done(function() {
ok( false, "Success on reject" );
}).fail(function() {
ok( true, "Error on reject" );
strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
}).always(function() {
ok( true, "Always callback on reject" );
});
createDeferred(function( defer ) {
ok( this === defer, "Defer passed as this & first argument" );
this.resolve("done");
}).done(function( value ) {
strictEqual( value, "done", "Passed function executed" );
});
createDeferred(function( defer ) {
var promise = defer.promise(),
func = function() {},
funcPromise = defer.promise( func );
strictEqual( defer.promise(), promise, "promise is always the same" );
strictEqual( funcPromise, func, "non objects get extended" );
jQuery.each( promise, function( key, value ) {
if ( !jQuery.isFunction( promise[ key ] ) ) {
ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
}
if ( promise[ key ] !== func[ key ] ) {
strictEqual( func[ key ], promise[ key ], key + " is the same" );
}
});
});
jQuery.expandedEach = jQuery.each;
jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
createDeferred(function( defer ) {
strictEqual( defer.state(), "pending", "pending after creation" );
var checked = 0;
defer.progress(function( value ) {
strictEqual( value, checked, "Progress: right value (" + value + ") received" );
});
for ( checked = 0; checked < 3; checked++ ) {
defer.notify( checked );
}
strictEqual( defer.state(), "pending", "pending after notification" );
defer[ change ]();
notStrictEqual( defer.state(), "pending", "not pending after " + change );
defer.notify();
});
});
});
});
test( "jQuery.Deferred - chainability", function() {
var defer = jQuery.Deferred();
expect( 10 );
jQuery.expandedEach = jQuery.each;
jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
var object = {
m: defer[ method ]
};
strictEqual( object.m(), object, method + " is chainable" );
});
});
test( "jQuery.Deferred.then - filtering (done)", function() {
expect( 4 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then(function( a, b ) {
return a * b;
});
piped.done(function( result ) {
value3 = result;
});
defer.done(function( a, b ) {
value1 = a;
value2 = b;
});
defer.resolve( 2, 3 );
strictEqual( value1, 2, "first resolve value ok" );
strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().reject().then(function() {
ok( false, "then should not be called on reject" );
});
jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) {
strictEqual( value, undefined, "then done callback can return undefined/null" );
});
});
test( "jQuery.Deferred.then - filtering (fail)", function() {
expect( 4 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
return a * b;
});
piped.fail(function( result ) {
value3 = result;
});
defer.fail(function( a, b ) {
value1 = a;
value2 = b;
});
defer.reject( 2, 3 );
strictEqual( value1, 2, "first reject value ok" );
strictEqual( value2, 3, "second reject value ok" );
strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().resolve().then( null, function() {
ok( false, "then should not be called on resolve" );
});
jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) {
strictEqual( value, undefined, "then fail callback can return undefined/null" );
});
});
test( "jQuery.Deferred.then - filtering (progress)", function() {
expect( 3 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
return a * b;
});
piped.progress(function( result ) {
value3 = result;
});
defer.progress(function( a, b ) {
value1 = a;
value2 = b;
});
defer.notify( 2, 3 );
strictEqual( value1, 2, "first progress value ok" );
strictEqual( value2, 3, "second progress value ok" );
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.then - deferred (done)", function() {
expect( 3 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then(function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.reject( a * b );
});
});
piped.fail(function( result ) {
value3 = result;
});
defer.done(function( a, b ) {
value1 = a;
value2 = b;
});
defer.resolve( 2, 3 );
strictEqual( value1, 2, "first resolve value ok" );
strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.then - deferred (fail)", function() {
expect( 3 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.resolve( a * b );
});
});
piped.done(function( result ) {
value3 = result;
});
defer.fail(function( a, b ) {
value1 = a;
value2 = b;
});
defer.reject( 2, 3 );
strictEqual( value1, 2, "first reject value ok" );
strictEqual( value2, 3, "second reject value ok" );
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.then - deferred (progress)", function() {
expect( 3 );
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.resolve( a * b );
});
});
piped.done(function( result ) {
value3 = result;
});
defer.progress(function( a, b ) {
value1 = a;
value2 = b;
});
defer.notify( 2, 3 );
strictEqual( value1, 2, "first progress value ok" );
strictEqual( value2, 3, "second progress value ok" );
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.then - context", function() {
expect( 7 );
var context = {};
jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
return value * 3;
}).done(function( value ) {
strictEqual( this, context, "custom context correctly propagated" );
strictEqual( value, 6, "proper value received" );
});
jQuery.Deferred().resolve().then(function() {
return jQuery.Deferred().resolveWith(context);
}).done(function() {
strictEqual( this, context, "custom context of returned deferred correctly propagated" );
});
var defer = jQuery.Deferred(),
piped = defer.then(function( value ) {
return value * 3;
});
defer.resolve( 2 );
piped.done(function( value ) {
strictEqual( this, piped, "default context gets updated to latest promise in the chain" );
strictEqual( value, 6, "proper value received" );
});
var defer2 = jQuery.Deferred(),
piped2 = defer2.then();
defer2.resolve( 2 );
piped2.done(function( value ) {
strictEqual( this, piped2, "default context gets updated to latest promise in the chain (without passing function)" );
strictEqual( value, 2, "proper value received (without passing function)" );
});
});
test( "jQuery.when", function() {
expect( 34 );
// Some other objects
jQuery.each({
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
"a number other than zero": 1,
"true": true,
"false": false,
"null": null,
"undefined": undefined,
"a plain object": {}
}, function( message, value ) {
ok(
jQuery.isFunction(
jQuery.when( value ).done(function( resolveValue ) {
strictEqual( this, window, "Context is the global object with " + message );
strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
}).promise
),
"Test " + message + " triggers the creation of a new Promise"
);
} );
ok(
jQuery.isFunction(
jQuery.when().done(function( resolveValue ) {
strictEqual( this, window, "Test the promise was resolved with window as its context" );
strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
}).promise
),
"Test calling when with no parameter triggers the creation of a new Promise"
);
var context = {};
jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
strictEqual( this, context, "when( promise ) propagates context" );
});
var cache;
jQuery.each([ 1, 2, 3 ], function( k, i ) {
jQuery.when( cache || jQuery.Deferred(function() {
this.resolve( i );
})
).done(function( value ) {
strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
});
});
});
test( "jQuery.when - joined", function() {
expect( 119 );
var deferreds = {
value: 1,
success: jQuery.Deferred().resolve( 1 ),
error: jQuery.Deferred().reject( 0 ),
futureSuccess: jQuery.Deferred().notify( true ),
futureError: jQuery.Deferred().notify( true ),
notify: jQuery.Deferred().notify( true )
},
willSucceed = {
value: true,
success: true,
futureSuccess: true
},
willError = {
error: true,
futureError: true
},
willNotify = {
futureSuccess: true,
futureError: true,
notify: true
};
jQuery.each( deferreds, function( id1, defer1 ) {
jQuery.each( deferreds, function( id2, defer2 ) {
var shouldResolve = willSucceed[ id1 ] && willSucceed[ id2 ],
shouldError = willError[ id1 ] || willError[ id2 ],
shouldNotify = willNotify[ id1 ] || willNotify[ id2 ],
expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
code = id1 + "/" + id2,
context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1.promise() : undefined,
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() : undefined;
jQuery.when( defer1, defer2 ).done(function( a, b ) {
if ( shouldResolve ) {
deepEqual( [ a, b ], expected, code + " => resolve" );
strictEqual( this[ 0 ], context1, code + " => first context OK" );
strictEqual( this[ 1 ], context2, code + " => second context OK" );
} else {
ok( false, code + " => resolve" );
}
}).fail(function( a, b ) {
if ( shouldError ) {
deepEqual( [ a, b ], expected, code + " => reject" );
} else {
ok( false, code + " => reject" );
}
}).progress(function( a, b ) {
deepEqual( [ a, b ], expectedNotify, code + " => progress" );
strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
});
});
});
deferreds.futureSuccess.resolve( 1 );
deferreds.futureError.reject( 0 );
});

View File

@@ -0,0 +1 @@
module("deprecated");

View File

@@ -0,0 +1,461 @@
if ( jQuery.fn.width ) {
module("dimensions", { teardown: moduleTeardown });
var pass = function( val ) {
return val;
};
var fn = function( val ) {
return function() {
return val;
};
};
/*
======== local reference =======
pass and fn can be used to test passing functions to setters
See testWidth below for an example
pass( value );
This function returns whatever value is passed in
fn( value );
Returns a function that returns the value
*/
var testWidth = function( val ) {
expect(9);
var $div = jQuery("#nothiddendiv");
$div.width( val(30) );
equal($div.width(), 30, "Test set to 30 correctly");
$div.hide();
equal($div.width(), 30, "Test hidden div");
$div.show();
$div.width( val(-1) ); // handle negative numbers by setting to 0 #11604
equal($div.width(), 0, "Test negative width normalized to 0");
$div.css("padding", "20px");
equal($div.width(), 0, "Test padding specified with pixels");
$div.css("border", "2px solid #fff");
equal($div.width(), 0, "Test border specified with pixels");
$div.css({ "display": "", "border": "", "padding": "" });
jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" });
equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
var blah = jQuery("blah");
equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
};
test("width()", function() {
testWidth( pass );
});
test("width(Function)", function() {
testWidth( fn );
});
test("width(Function(args))", function() {
expect( 2 );
var $div = jQuery("#nothiddendiv");
$div.width( 30 ).width(function(i, width) {
equal( width, 30, "Make sure previous value is corrrect." );
return width + 1;
});
equal( $div.width(), 31, "Make sure value was modified correctly." );
});
var testHeight = function( val ) {
expect(9);
var $div = jQuery("#nothiddendiv");
$div.height( val(30) );
equal($div.height(), 30, "Test set to 30 correctly");
$div.hide();
equal($div.height(), 30, "Test hidden div");
$div.show();
$div.height( val(-1) ); // handle negative numbers by setting to 0 #11604
equal($div.height(), 0, "Test negative height normalized to 0");
$div.css("padding", "20px");
equal($div.height(), 0, "Test padding specified with pixels");
$div.css("border", "2px solid #fff");
equal($div.height(), 0, "Test border specified with pixels");
$div.css({ "display": "", "border": "", "padding": "", "height": "1px" });
jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" });
equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
var blah = jQuery("blah");
equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( $div[0], "olddisplay" );
};
test("height()", function() {
testHeight( pass );
});
test("height(Function)", function() {
testHeight( fn );
});
test("height(Function(args))", function() {
expect( 2 );
var $div = jQuery("#nothiddendiv");
$div.height( 30 ).height(function(i, height) {
equal( height, 30, "Make sure previous value is corrrect." );
return height + 1;
});
equal( $div.height(), 31, "Make sure value was modified correctly." );
});
test("innerWidth()", function() {
expect(6);
var winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal(jQuery(window).innerWidth(), winWidth, "Test on window");
equal(jQuery(document).innerWidth(), docWidth, "Test on document");
var $div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
"border": "2px solid #fff",
"width": 30
});
equal($div.innerWidth(), 30, "Test with margin and border");
$div.css("padding", "20px");
equal($div.innerWidth(), 70, "Test with margin, border and padding");
$div.hide();
equal($div.innerWidth(), 70, "Test hidden div");
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove();
QUnit.expectJqData( $div[0], "olddisplay" );
});
test("innerHeight()", function() {
expect(6);
var winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
equal(jQuery(window).innerHeight(), winHeight, "Test on window");
equal(jQuery(document).innerHeight(), docHeight, "Test on document");
var $div = jQuery("#nothiddendiv");
// set styles
$div.css({
"margin": 10,
"border": "2px solid #fff",
"height": 30
});
equal($div.innerHeight(), 30, "Test with margin and border");
$div.css("padding", "20px");
equal($div.innerHeight(), 70, "Test with margin, border and padding");
$div.hide();
equal($div.innerHeight(), 70, "Test hidden div");
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove();
QUnit.expectJqData( $div[0], "olddisplay" );
});
test("outerWidth()", function() {
expect(11);
var winWidth = jQuery( window ).width(),
docWidth = jQuery( document ).width();
equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" );
equal( jQuery( window ).outerWidth( true ), winWidth, "Test on window with margin option" );
equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" );
equal( jQuery( document ).outerWidth( true ), docWidth, "Test on document with margin option" );
var $div = jQuery("#nothiddendiv");
$div.css("width", 30);
equal($div.outerWidth(), 30, "Test with only width set");
$div.css("padding", "20px");
equal($div.outerWidth(), 70, "Test with padding");
$div.css("border", "2px solid #fff");
equal($div.outerWidth(), 74, "Test with padding and border");
$div.css("margin", "10px");
equal($div.outerWidth(), 74, "Test with padding, border and margin without margin option");
$div.css("position", "absolute");
equal($div.outerWidth(true), 94, "Test with padding, border and margin with margin option");
$div.hide();
equal($div.outerWidth(true), 94, "Test hidden div with padding, border and margin with margin option");
// reset styles
$div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove();
QUnit.expectJqData( $div[0], "olddisplay" );
});
test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
expect(16);
// setup html
var $divNormal = jQuery("<div>").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
$divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
$divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
// tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #9441" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
});
test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
expect( 1 );
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
div = $div.get( 0 ),
runtimeStyle = div.runtimeStyle;
if ( runtimeStyle ) {
div.runtimeStyle.marginLeft = "12em";
div.runtimeStyle.left = "11em";
}
$div.outerWidth( true );
if ( runtimeStyle ) {
equal( div.runtimeStyle.left, "11em", "getting dimensions modifies runtimeStyle, see #9233" );
} else {
ok( true, "this browser doesnt support runtimeStyle, see #9233" );
}
$div.remove();
});
test( "table dimensions", 2, function() {
var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
tdElem = table.find("tr:eq(0) td:eq(0)"),
colElem = table.find("col:eq(1)").width( 300 );
table.find("td").css({ "margin": 0, "padding": 0 });
equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
equal( colElem.width(), 300, "col elements have width(), see #12243" );
});
test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function() {
expect(16);
// setup html
var $divNormal = jQuery("<div>").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
$divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
$divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
// tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
});
test("outerHeight()", function() {
expect(11);
var winHeight = jQuery( window ).height(),
docHeight = jQuery( document ).height();
equal( jQuery( window ).outerHeight(), winHeight, "Test on window without margin option" );
equal( jQuery( window ).outerHeight( true ), winHeight, "Test on window with margin option" );
equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" );
equal( jQuery( document ).outerHeight( true ), docHeight, "Test on document with margin option" );
var $div = jQuery("#nothiddendiv");
$div.css("height", 30);
equal($div.outerHeight(), 30, "Test with only width set");
$div.css("padding", "20px");
equal($div.outerHeight(), 70, "Test with padding");
$div.css("border", "2px solid #fff");
equal($div.outerHeight(), 74, "Test with padding and border");
$div.css("margin", "10px");
equal($div.outerHeight(), 74, "Test with padding, border and margin without margin option");
equal($div.outerHeight(true), 94, "Test with padding, border and margin with margin option");
$div.hide();
equal($div.outerHeight(true), 94, "Test hidden div with padding, border and margin with margin option");
// reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
var div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto
equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove();
QUnit.expectJqData( $div[0], "olddisplay" );
});
test("passing undefined is a setter #5571", function() {
expect(4);
equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)");
});
test( "getters on non elements should return null", function() {
expect( 8 );
var nonElem = jQuery("notAnElement");
strictEqual( nonElem.width(), null, ".width() is not null (#12283)" );
strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" );
strictEqual( nonElem.outerWidth(), null, ".outerWidth() is not null (#12283)" );
strictEqual( nonElem.outerWidth( true ), null, ".outerWidth(true) is not null (#12283)" );
strictEqual( nonElem.height(), null, ".height() is not null (#12283)" );
strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" );
});
test("setters with and without box-sizing:border-box", function(){
expect(20);
var el_bb = jQuery("<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>").appendTo("#qunit-fixture"),
el = jQuery("<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>").appendTo("#qunit-fixture"),
expected = 100;
equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
equal( el_bb.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" );
equal( el_bb.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" );
equal( el_bb.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" );
equal( el_bb.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" );
equal( el_bb.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" );
equal( el_bb.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" );
equal( el_bb.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
equal( el_bb.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
equal( el_bb.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
equal( el.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
equal( el.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" );
equal( el.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" );
equal( el.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" );
equal( el.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" );
equal( el.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" );
equal( el.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" );
equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
});
testIframe( "dimensions/documentSmall", "window vs. small document", function( jQuery, window, document ) {
// this test is practically tautological, but there is a bug in IE8
// with no simple workaround, so this test exposes the bug and works around it
if ( document.body.offsetWidth >= document.documentElement.offsetWidth ) {
expect( 2 );
equal( jQuery( document ).height(), jQuery( window ).height(), "document height matches window height" );
equal( jQuery( document ).width(), jQuery( window ).width(), "document width matches window width" );
} else {
// all tests should have at least one assertion
expect( 1 );
ok( true, "skipping test (conditions not satisfied)" );
}
});
testIframe( "dimensions/documentLarge", "window vs. large document", function( jQuery, window, document ) {
expect(2);
ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" );
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
});
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
module("exports", { teardown: moduleTeardown });
test("amdModule", function() {
expect(1);
equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,549 @@
(function() {
if ( !jQuery.fn.offset ) {
return;
}
var supportsScroll, supportsFixedPosition,
forceScroll = jQuery("<div/>").css({ width: 2000, height: 2000 }),
checkSupport = function() {
// Only run once
checkSupport = false;
var checkFixed = jQuery("<div/>").css({ position: "fixed", top: "20px" }).appendTo("#qunit-fixture");
// Must append to body because #qunit-fixture is hidden and elements inside it don't have a scrollTop
forceScroll.appendTo("body");
window.scrollTo( 200, 200 );
supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
forceScroll.detach();
// Safari subtracts parent border width here (which is 5px)
supportsFixedPosition = checkFixed[0].offsetTop === 20 || checkFixed[0].offsetTop === 15;
checkFixed.remove();
};
module("offset", { setup: function(){
if ( typeof checkSupport === "function" ) {
checkSupport();
}
// Force a scroll value on the main window to ensure incorrect results
// if offset is using the scroll offset of the parent window
forceScroll.appendTo("body");
window.scrollTo( 1, 1 );
forceScroll.detach();
}, teardown: moduleTeardown });
/*
Closure-compiler will roll static methods off of the jQuery object and so they will
not be passed with the jQuery object across the windows. To differentiate this, the
testIframe callbacks use the "$" symbol to refer to the jQuery object passed from
the iframe window and the "jQuery" symbol is used to access any static methods.
*/
test("empty set", function() {
expect(2);
strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
});
test("object without getBoundingClientRect", function() {
expect(2);
// Simulates a browser without gBCR on elements, we just want to return 0,0
var result = jQuery({ ownerDocument: document }).offset();
equal( result.top, 0, "Check top" );
equal( result.left, 0, "Check left" );
});
test("disconnected node", function() {
expect(2);
var result = jQuery( document.createElement("div") ).offset();
equal( result.top, 0, "Check top" );
equal( result.left, 0, "Check left" );
});
testIframe("offset/absolute", "absolute", function($, iframe) {
expect(4);
var doc = iframe.document,
tests;
// get offset
tests = [
{ "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
equal( jQuery( this["id"], doc ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( jQuery( this["id"], doc ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
});
// get position
tests = [
{ "id": "#absolute-1", "top": 0, "left": 0 }
];
jQuery.each( tests, function() {
equal( jQuery( this["id"], doc ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( jQuery( this["id"], doc ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
});
});
testIframe("offset/absolute", "absolute", function( $ ) {
expect(178);
// get offset tests
var 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 },
{ "id": "#absolute-2", "top": 20, "left": 20 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
});
// get position
tests = [
{ "id": "#absolute-1", "top": 0, "left": 0 },
{ "id": "#absolute-1-1", "top": 1, "left": 1 },
{ "id": "#absolute-1-1-1", "top": 1, "left": 1 },
{ "id": "#absolute-2", "top": 19, "left": 19 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
});
// test #5781
var 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." );
// set offset
tests = [
{ "id": "#absolute-2", "top": 30, "left": 30 },
{ "id": "#absolute-2", "top": 10, "left": 10 },
{ "id": "#absolute-2", "top": -1, "left": -1 },
{ "id": "#absolute-2", "top": 19, "left": 19 },
{ "id": "#absolute-1-1-1", "top": 15, "left": 15 },
{ "id": "#absolute-1-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": -1, "left": -1 },
{ "id": "#absolute-1-1-1", "top": 9, "left": 9 },
{ "id": "#absolute-1-1", "top": 10, "left": 10 },
{ "id": "#absolute-1-1", "top": 0, "left": 0 },
{ "id": "#absolute-1-1", "top": -1, "left": -1 },
{ "id": "#absolute-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1", "top": 2, "left": 2 },
{ "id": "#absolute-1", "top": 0, "left": 0 },
{ "id": "#absolute-1", "top": -1, "left": -1 },
{ "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
var top = this["top"], left = this["left"];
$( this["id"] ).offset(function(i, val){
equal( val.top, top, "Verify incoming top position." );
equal( val.left, left, "Verify incoming top position." );
return { "top": top + 1, "left": left + 1 };
});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + " })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + " })" );
$( this["id"] )
.offset({ "left": this["left"] + 2 })
.offset({ "top": this["top"] + 2 });
equal( $( this["id"] ).offset().top, this["top"] + 2, "Setting one property at a time." );
equal( $( this["id"] ).offset().left, this["left"] + 2, "Setting one property at a time." );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({
"top": props.top + 1,
"left": props.left + 1
});
}});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
});
});
testIframe("offset/relative", "relative", function( $ ) {
expect(60);
// IE is collapsing the top margin of 1px; detect and adjust accordingly
var ie = $("#relative-1").offset().top === 6;
// get offset
var 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 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
});
// get position
tests = [
{ "id": "#relative-1", "top": ie ? 5 : 6, "left": 6 },
{ "id": "#relative-1-1", "top": ie ? 4 : 5, "left": 5 },
{ "id": "#relative-2", "top": ie ? 140 : 141, "left": 26 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
});
// set offset
tests = [
{ "id": "#relative-2", "top": 200, "left": 50 },
{ "id": "#relative-2", "top": 100, "left": 10 },
{ "id": "#relative-2", "top": -5, "left": -5 },
{ "id": "#relative-2", "top": 142, "left": 27 },
{ "id": "#relative-1-1", "top": 100, "left": 100 },
{ "id": "#relative-1-1", "top": 5, "left": 5 },
{ "id": "#relative-1-1", "top": -1, "left": -1 },
{ "id": "#relative-1-1", "top": 15, "left": 15 },
{ "id": "#relative-1", "top": 100, "left": 100 },
{ "id": "#relative-1", "top": 0, "left": 0 },
{ "id": "#relative-1", "top": -1, "left": -1 },
{ "id": "#relative-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({
"top": props.top + 1,
"left": props.left + 1
});
}});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
});
});
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 );
// get offset
var 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 },
{ "id": "#static-2", "top": ie ? 121 : 122, left: 7 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
});
// get position
tests = [
{ "id": "#static-1", "top": ie ? 5 : 6, "left": 6 },
{ "id": "#static-1-1", "top": ie ? 12 : 14, "left": 14 },
{ "id": "#static-1-1-1", "top": ie ? 19 : 22, "left": 22 },
{ "id": "#static-2", "top": ie ? 120 : 121, "left": 6 }
];
jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["top"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["left"] +"').position().left" );
});
// set offset
tests = [
{ "id": "#static-2", "top": 200, "left": 200 },
{ "id": "#static-2", "top": 100, "left": 100 },
{ "id": "#static-2", "top": -2, "left": -2 },
{ "id": "#static-2", "top": 121, "left": 6 },
{ "id": "#static-1-1-1", "top": 50, "left": 50 },
{ "id": "#static-1-1-1", "top": 10, "left": 10 },
{ "id": "#static-1-1-1", "top": -1, "left": -1 },
{ "id": "#static-1-1-1", "top": 22, "left": 22 },
{ "id": "#static-1-1", "top": 25, "left": 25 },
{ "id": "#static-1-1", "top": 10, "left": 10 },
{ "id": "#static-1-1", "top": -3, "left": -3 },
{ "id": "#static-1-1", "top": 14, "left": 14 },
{ "id": "#static-1", "top": 30, "left": 30 },
{ "id": "#static-1", "top": 2, "left": 2 },
{ "id": "#static-1", "top": -2, "left": -2 },
{ "id": "#static-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({
"top": props.top + 1,
"left": props.left + 1
});
}});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
});
});
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 = [
{
"id": "#fixed-1",
"offsetTop": 1001,
"offsetLeft": 1001,
"positionTop": ie ? 2 : 0,
"positionLeft": ie ? 2 : 0
},
{
"id": "#fixed-2",
"offsetTop": 1021,
"offsetLeft": 1021,
"positionTop": ie ? 22 : 20,
"positionLeft": ie ? 22 : 20
}
];
jQuery.each( tests, function() {
if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
} else if ( window.supportsFixedPosition ) {
equal( $( this["id"] ).offset().top, this["offsetTop"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).position().top, this["positionTop"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).offset().left, this["offsetLeft"], "jQuery('" + this["id"] + "').offset().left" );
equal( $( this["id"] ).position().left, this["positionLeft"], "jQuery('" + this["id"] + "').position().left" );
} else {
// need to have same number of assertions
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
}
});
tests = [
{ "id": "#fixed-1", "top": 100, "left": 100 },
{ "id": "#fixed-1", "top": 0, "left": 0 },
{ "id": "#fixed-1", "top": -4, "left": -4 },
{ "id": "#fixed-2", "top": 200, "left": 200 },
{ "id": "#fixed-2", "top": 0, "left": 0 },
{ "id": "#fixed-2", "top": -5, "left": -5 }
];
jQuery.each( tests, function() {
if ( window.supportsFixedPosition ) {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({
"top": props.top + 1,
"left": props.left + 1
});
}});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
} else {
// need to have same number of assertions
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
}
});
// Bug 8316
var $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" );
} else {
// need to have same number of assertions
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
}
});
testIframe("offset/table", "table", function( $ ) {
expect(4);
equal( $("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
equal( $("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
equal( $("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
equal( $("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
});
testIframe("offset/scroll", "scroll", function( $, win ) {
expect(24);
// If we're going to bastardize the tests, let's just DO it
var ie = /msie [678]/i.test( navigator.userAgent );
if ( ie ) {
ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
} else {
equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" );
}
equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
if ( ie ) {
ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
} else {
equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
}
equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// scroll offset tests .scrollTop/Left
equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
equal( $("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equal( $("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// scroll method chaining
equal( $("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
equal( $("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
win.name = "test";
if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
} else {
equal( $(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
equal( $(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
equal( $(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
equal( $(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
}
// test jQuery using parent window/document
// jQuery reference here is in the iframe
window.scrollTo(0,0);
equal( $(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
equal( $(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equal( $(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equal( $(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects
notEqual( $().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
notEqual( $().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
notEqual( $().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
notEqual( $().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
});
testIframe("offset/body", "body", function( $ ) {
expect(4);
equal( $("body").offset().top, 1, "jQuery('#body').offset().top" );
equal( $("body").offset().left, 1, "jQuery('#body').offset().left" );
equal( $("#firstElement").position().left, 5, "$('#firstElement').position().left" );
equal( $("#firstElement").position().top, 5, "$('#firstElement').position().top" );
});
test("chaining", function() {
expect(3);
var coords = { "top": 1, "left": 1 };
equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
});
test("offsetParent", function(){
expect(13);
var 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();
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();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
jQuery("#nothiddendiv").css("position", "relative");
div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
div = jQuery("body, #nothiddendivchild").offsetParent();
equal( div.length, 2, "Two offsetParent found." );
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();
equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
equal( div.offsetParent()[0], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" );
div.remove();
});
test("fractions (see #7730 and #7885)", function() {
expect(2);
jQuery("body").append("<div id='fractions'/>");
var expected = { "top": 1000, "left": 1000 };
var div = jQuery("#fractions");
div.css({
"position": "absolute",
"left": "1000.7432222px",
"top": "1000.532325px",
"width": 100,
"height": 100
});
div.offset(expected);
var result = div.offset();
equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" );
div.remove();
});
})();

View File

@@ -0,0 +1,316 @@
module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 14, function() {
var counter = 0;
stop();
var $div = jQuery({}),
defer;
$div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
});
$div
.queue("foo",function(){
equal( ++counter, 1, "Dequeuing" );
jQuery.dequeue(this,"foo");
})
.queue("foo",function(){
equal( ++counter, 2, "Dequeuing" );
jQuery(this).dequeue("foo");
})
.queue("foo",function(){
equal( ++counter, 3, "Dequeuing" );
})
.queue("foo",function(){
equal( ++counter, 4, "Dequeuing" );
});
defer = $div.promise("foo").done(function() {
equal( counter, 4, "Testing previous call to dequeue in deferred" );
start();
});
equal( $div.queue("foo").length, 4, "Testing queue length" );
equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
$div.dequeue("foo");
equal( counter, 3, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 1, "Testing queue length" );
$div.dequeue("foo");
equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" );
$div.dequeue("foo");
equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" );
});
test("queue(name) passes in the next item in the queue as a parameter", function() {
expect(2);
var div = jQuery({});
var counter = 0;
div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing");
next();
}).queue("foo", function(next) {
equal(++counter, 2, "Next was called");
next();
}).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()");
});
div.dequeue("foo");
});
test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
expect(3);
stop();
var div = jQuery({});
var counter = 0;
div.queue(function(next) {
equal(++counter, 1, "Dequeueing");
var self = this;
setTimeout(function() { next(); }, 500);
}).queue(function(next) {
equal(++counter, 2, "Next was called");
next();
}).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()");
});
jQuery.when( div.promise("fx"), div ).done(function() {
equal(counter, 2, "Deferreds resolved");
start();
});
});
test("callbacks keep their place in the queue", function() {
expect(5);
stop();
var div = jQuery("<div>"),
counter = 0;
div.queue(function( next ) {
equal( ++counter, 1, "Queue/callback order: first called" );
setTimeout( next, 200 );
}).delay( 100 ).queue(function( next ) {
equal( ++counter, 2, "Queue/callback order: second called" );
jQuery( this ).delay( 100 ).queue(function( next ) {
equal( ++counter, 4, "Queue/callback order: fourth called" );
next();
});
next();
}).queue(function( next ) {
equal( ++counter, 3, "Queue/callback order: third called" );
next();
});
div.promise("fx").done(function() {
equal(counter, 4, "Deferreds resolved");
start();
});
});
test("delay()", function() {
expect(2);
stop();
var foo = jQuery({}), run = 0;
foo.delay(100).queue(function(){
run = 1;
ok( true, "The function was dequeued." );
start();
});
equal( run, 0, "The delay delayed the next function from running." );
});
test("clearQueue(name) clears the queue", function() {
expect(2);
stop();
var div = jQuery({});
var counter = 0;
div.queue("foo", function(next) {
counter++;
jQuery(this).clearQueue("foo");
next();
}).queue("foo", function(next) {
counter++;
});
div.promise("foo").done(function() {
ok( true, "dequeue resolves the deferred" );
start();
});
div.dequeue("foo");
equal(counter, 1, "the queue was cleared");
});
test("clearQueue() clears the fx queue", function() {
expect(1);
var div = jQuery({});
var counter = 0;
div.queue(function(next) {
counter++;
var self = this;
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
}).queue(function(next) {
counter++;
});
equal(counter, 1, "the queue was cleared");
div.removeData();
});
asyncTest( "fn.promise() - called when fx queue is empty", 3, function() {
var foo = jQuery( "#foo" ).clone().andSelf(),
promised = false;
foo.queue( function( next ) {
// called twice!
ok( !promised, "Promised hasn't been called" );
setTimeout( next, 10 );
});
foo.promise().done( function() {
ok( promised = true, "Promised" );
start();
});
});
asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function() {
var foo = jQuery( "#foo" ),
test;
foo.promise( "queue" ).done( function() {
strictEqual( test, undefined, "called immediately when queue was already empty" );
});
test = 1;
foo.queue( "queue", function( next ) {
strictEqual( test++, 1, "step one" );
setTimeout( next, 0 );
}).queue( "queue", function( next ) {
strictEqual( test++, 2, "step two" );
setTimeout( function() {
next();
strictEqual( test++, 4, "step four" );
start();
}, 10 );
}).promise( "queue" ).done( function() {
strictEqual( test++, 3, "step three" );
});
foo.dequeue( "queue" );
});
asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() {
var foo = jQuery( "#foo" ),
test = 1;
foo.animate({
top: 100
}, {
duration: 1,
queue: "queue",
complete: function() {
strictEqual( test++, 1, "step one" );
}
}).dequeue( "queue" );
foo.promise( "queue" ).done( function() {
strictEqual( test++, 2, "step two" );
start();
});
});
test( ".promise(obj)", function() {
expect(2);
var obj = {};
var 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" );
});
if ( jQuery.fn.stop ) {
test("delay() can be stopped", function() {
expect( 3 );
stop();
var done = {};
jQuery({})
.queue( "alternate", function( next ) {
done.alt1 = true;
ok( true, "This first function was dequeued" );
next();
})
.delay( 1000, "alternate" )
.queue( "alternate", function() {
done.alt2 = true;
ok( true, "The function was dequeued immediately, the delay was stopped" );
})
.dequeue( "alternate" )
// stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
.stop( "alternate", false, false )
// this test
.delay( 1 )
.queue(function() {
done.default1 = true;
ok( false, "This queue should never run" );
})
// stop( clearQueue ) should clear the queue
.stop( true, false );
deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
setTimeout(function() {
start();
}, 1500 );
});
asyncTest( "queue stop hooks", 2, function() {
var foo = jQuery( "#foo" );
foo.queue( function( next, hooks ) {
hooks.stop = function( gotoEnd ) {
equal( !!gotoEnd, false, "Stopped without gotoEnd" );
};
});
foo.stop();
foo.queue( function( next, hooks ) {
hooks.stop = function( gotoEnd ) {
equal( gotoEnd, true, "Stopped with gotoEnd" );
start();
};
});
foo.stop( false, true );
});
} // if ( jQuery.fn.stop )

View File

@@ -0,0 +1,185 @@
module("selector", { teardown: moduleTeardown });
/**
* This test page is for selector tests that require jQuery in order to do the selection
*/
test("element - jQuery only", function() {
expect( 7 );
var fixture = document.getElementById("qunit-fixture");
deepEqual( jQuery("p", fixture).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a Node context." );
deepEqual( jQuery("p", "#qunit-fixture").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a selector context." );
deepEqual( jQuery("p", jQuery("#qunit-fixture")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a jQuery object context." );
deepEqual( jQuery("#qunit-fixture").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context via .find()." );
ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" );
ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" );
// #7533
equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
});
test("class - jQuery only", function() {
expect( 4 );
deepEqual( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." );
});
test("attributes - jQuery only", function() {
expect( 6 );
t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] );
// #12523
deepEqual(
jQuery.find( "[title]", null, null, jQuery("#qunit-fixture a").get().concat( document.createTextNode("") ) ),
q("google"),
"Text nodes fail attribute tests without exception"
);
// #12600
ok(
jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>")
.prop( "value", "option" )
.is(":input[value='12600']"),
":input[value=foo] selects select by attribute"
);
ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"),
":input[value=foo] selects text input by attribute"
);
// #11115
ok( jQuery("<input type='checkbox' checked='checked'/>").prop( "checked", false ).is("[checked]"),
"[checked] selects by attribute (positive)"
);
ok( !jQuery("<input type='checkbox'/>").prop( "checked", true ).is("[checked]"),
"[checked] selects by attribute (negative)"
);
});
test("disconnected nodes", function() {
expect( 4 );
var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach();
equal( $opt.val(), "whipit", "option value" );
equal( $opt.is(":selected"), false, "unselected option" );
$opt.prop("selected", true);
equal( $opt.is(":selected"), true, "selected option" );
var $div = jQuery("<div/>");
equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
});
test("jQuery only - broken", 1, function() {
raises(function() {
// Setting context to null here somehow avoids QUnit's window.error handling
// making the e & e.message correct
// For whatever reason, without this,
// Sizzle.error will be called but no error will be seen in oldIE
jQuery.call( null, " <div/> " );
}, function( e ) {
return e.message.indexOf("Syntax error") >= 0;
}, "leading space invalid: $(' <div/> ')" );
});
testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) {
expect( 35 );
/**
* Returns an array of elements with the given IDs
* q & t are added here for the iFrame's context
*/
function q() {
var r = [],
i = 0;
for ( ; i < arguments.length; i++ ) {
r.push( document.getElementById( arguments[i] ) );
}
return r;
}
/**
* Asserts that a select matches the given IDs
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @param {String} a - Assertion name
* @param {String} b - Sizzle selector
* @param {Array} c - Array of ids to construct what is expected
*/
function t( a, b, c ) {
var f = jQuery(b).get(),
s = "",
i = 0;
for ( ; i < f.length; i++ ) {
s += (s && ",") + "'" + f[i].id + "'";
}
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
}
// ====== All known boolean attributes, including html5 booleans ======
// autobuffer, autofocus, autoplay, async, checked,
// compact, controls, declare, defer, disabled,
// formnovalidate, hidden, indeterminate (property only),
// ismap, itemscope, loop, multiple, muted, nohref, noresize,
// noshade, nowrap, novalidate, open, pubdate, readonly, required,
// reversed, scoped, seamless, selected, truespeed, visible (skipping visible attribute, which is on a barprop object)
t( "Attribute Exists", "[autobuffer]", ["video1"]);
t( "Attribute Exists", "[autofocus]", ["text1"]);
t( "Attribute Exists", "[autoplay]", ["video1"]);
t( "Attribute Exists", "[async]", ["script1"]);
t( "Attribute Exists", "[checked]", ["check1"]);
t( "Attribute Exists", "[compact]", ["dl"]);
t( "Attribute Exists", "[controls]", ["video1"]);
t( "Attribute Exists", "[declare]", ["object1"]);
t( "Attribute Exists", "[defer]", ["script1"]);
t( "Attribute Exists", "[disabled]", ["check1"]);
t( "Attribute Exists", "[formnovalidate]", ["form1"]);
t( "Attribute Exists", "[hidden]", ["div1"]);
t( "Attribute Exists", "[indeterminate]", []);
t( "Attribute Exists", "[ismap]", ["img1"]);
t( "Attribute Exists", "[itemscope]", ["div1"]);
// t( "Attribute Exists", "[loop]", ["video1"]); // IE 6/7 cannot differentiate here. loop is also used on img, input, and marquee tags as well as video/audio. getAttributeNode unfortunately also retrieves the property value.
t( "Attribute Exists", "[multiple]", ["select1"]);
t( "Attribute Exists", "[muted]", ["audio1"]);
// t( "Attribute Exists", "[nohref]", ["area1"]); // IE 6/7 keep this set to false regardless of presence. The attribute node is not retrievable.
t( "Attribute Exists", "[noresize]", ["textarea1"]);
t( "Attribute Exists", "[noshade]", ["hr1"]);
t( "Attribute Exists", "[nowrap]", ["td1", "div1"]);
t( "Attribute Exists", "[novalidate]", ["form1"]);
t( "Attribute Exists", "[open]", ["details1"]);
t( "Attribute Exists", "[pubdate]", ["article1"]);
t( "Attribute Exists", "[readonly]", ["text1"]);
t( "Attribute Exists", "[required]", ["text1"]);
t( "Attribute Exists", "[reversed]", ["ol1"]);
t( "Attribute Exists", "[scoped]", ["style1"]);
t( "Attribute Exists", "[seamless]", ["iframe1"]);
t( "Attribute Exists", "[selected]", ["option1"]);
t( "Attribute Exists", "[truespeed]", ["marquee1"]);
// Enumerated attributes (these are not boolean content attributes)
jQuery.expandedEach = jQuery.each;
jQuery.expandedEach([ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) {
t( "Enumerated attribute", "[" + val + "]", ["div1"]);
});
t( "Enumerated attribute", "[spellcheck]", ["span1"]);
// t( "tabindex selector does not retrieve all elements in IE6/7(#8473)", "form, [tabindex]", ["form1", "text1"] ); // sigh, FF12 QSA mistakenly includes video elements even though they have no tabindex attribute (see https://bugzilla.mozilla.org/show_bug.cgi?id=618737)
t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"] );
});
testIframe("selector/sizzle_cache", "Sizzle cache collides with multiple Sizzles on a page", function( jQuery, window, document ) {
var $cached = window["$cached"];
expect(3);
deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" );
equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" );
equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" );
});

View File

@@ -0,0 +1,146 @@
module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() {
expect(22);
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"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined};
equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
params = {"someName": [1, 2, 3], "regularThing": "blah" };
equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
params = {"foo": ["a", "b", "c"]};
equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
params = {"foo": ["baz", 42, "All your base are belong to us"] };
equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } };
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
params = { "a":[1,2], "b":{ "c":3, "d":[4,5], "e":{ "x":[6], "y":7, "z":[8,9] }, "f":true, "g":false, "h":undefined }, "i":[10,11], "j":true, "k":false, "l":[undefined,0], "m":"cowboy hat?" };
equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equal( decodeURIComponent( jQuery.param({ "a": [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], "e": { "f": [10], "g": [11,12], "h": 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// #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 };
if ( jQuery.ajaxSettings ) {
jQuery.ajaxSetup( settings );
} else {
jQuery.ajaxSettings = settings;
}
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 = {"someName": [1, 2, 3], "regularThing": "blah" };
equal( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
params = {"foo": ["a", "b", "c"]};
equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
params = {"foo[]":["baz", 42, "All your base are belong to us"]};
equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { "param1": null };
equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." );
params = {"test": {"length": 3, "foo": "bar"} };
equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
if ( jQuery.ajaxSettings === settings ) {
delete jQuery.ajaxSettings;
} else {
jQuery.ajaxSetup({ traditional: false });
}
});
test("jQuery.param() Constructed prop values", function() {
expect( 4 );
/** @constructor */
function Record() {
this["prop"] = "val";
}
var MyString = String,
MyNumber = Number,
params = { "test": new MyString("foo") };
equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
params = { "test": new MyNumber(5) };
equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
params = { "test": new Date() };
ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" );
// should allow non-native constructed objects
params = { "test": new Record() };
equal( jQuery.param( params, false ), jQuery.param({ "test": { "prop": "val" } }), "Allow non-native constructed objects" );
});
test("serialize()", function() {
expect(5);
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
jQuery("#search").after(
"<input type='email' id='html5email' name='email' value='dave@jquery.com' />" +
"<input type='number' id='html5number' name='number' value='43' />" +
"<input type='file' name='fileupload' />"
);
equal( jQuery("#form").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check form serialization as query string");
equal( jQuery("#form :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check input serialization as query string");
equal( jQuery("#testForm").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check form serialization as query string");
equal( jQuery("#testForm :input").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check input serialization as query string");
equal( jQuery("#form, #testForm").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Multiple form serialization as query string");
/* Temporarily disabled. Opera 10 has problems with form serialization.
equal( jQuery("#form, #testForm :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Mixed form/input serialization as query string");
*/
jQuery("#html5email, #html5number").remove();
});

View File

@@ -0,0 +1,384 @@
module("support", { teardown: moduleTeardown });
test("boxModel", function() {
expect( 1 );
equal( jQuery.support.boxModel, document.compatMode === "CSS1Compat" , "jQuery.support.boxModel is sort of tied to quirks mode but unstable since 1.8" );
});
test( "zoom of doom (#13089)", function() {
expect( 1 );
if ( jQuery.support.inlineBlockNeedsLayout ) {
ok( document.body.style.zoom, "Added a zoom to the body (#11048, #12869)" );
} else {
ok( !document.body.style.zoom, "No zoom added to the body" );
}
});
if ( jQuery.css ) {
testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9239)", "support/bodyBackground.html", function( color, support ) {
expect( 2 );
var i,
passed = true,
okValue = {
"#000000": true,
"rgb(0, 0, 0)": true
};
ok( okValue[ color ], "color was not reset (" + color + ")" );
for ( i in jQuery.support ) {
if ( jQuery.support[ i ] !== support[ i ] ) {
passed = false;
strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
}
}
for ( i in support ) {
if ( !( i in jQuery.support ) ) {
passed = false;
strictEqual( jQuery.support[ i ], support[ i ], "Unexpected property: " + i );
}
}
ok( passed, "Same support properties" );
});
}
testIframeWithCallback( "A background on the testElement does not cause IE8 to crash (#9823)", "support/testElementCrash.html", function() {
expect(1);
ok( true, "IE8 does not crash" );
});
testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlocks", "support/shrinkWrapBlocks.html", function( shrinkWrapBlocks ) {
expect( 1 );
strictEqual( shrinkWrapBlocks, jQuery.support.shrinkWrapBlocks, "jQuery.support.shrinkWrapBlocks properties are the same" );
});
(function() {
var expected,
userAgent = window.navigator.userAgent;
// These tests do not have to stay
// They are here to help with upcoming support changes for 1.8
if ( /chrome/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":true,
"optSelected":true,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":false,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":true,
"optDisabled":true,
"radioValue":true,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
} else if ( /opera.*version\/12\.1/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":true,
"optSelected":true,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":false,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":true,
"optDisabled":true,
"radioValue":false,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
} else if ( /msie 10\.0/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":true,
"optSelected":false,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":true,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":false,
"optDisabled":true,
"radioValue":false,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": false
};
} else if ( /msie 9\.0/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":true,
"optSelected":false,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":true,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":false,
"optDisabled":true,
"radioValue":false,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": false
};
} else if ( /msie 8\.0/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":false,
"tbody":true,
"htmlSerialize":false,
"style":false,
"hrefNormalized":true,
"opacity":false,
"cssFloat":false,
"checkOn":true,
"optSelected":false,
"getSetAttribute":true,
"enctype":true,
"html5Clone":false,
"submitBubbles":false,
"changeBubbles":false,
"focusinBubbles":true,
"deleteExpando":false,
"noCloneEvent":false,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":false,
"optDisabled":true,
"radioValue":false,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
} else if ( /msie 7\.0/i.test( userAgent ) ) {
expected = {
"ajax": true,
"appendChecked": false,
"boxModel": true,
"changeBubbles": false,
"checkClone": false,
"checkOn": true,
"cors": false,
"cssFloat": false,
"deleteExpando": false,
"doesNotIncludeMarginInBodyOffset": true,
"enctype": true,
"focusinBubbles": true,
"getSetAttribute": false,
"hrefNormalized": false,
"html5Clone": false,
"htmlSerialize": false,
"inlineBlockNeedsLayout": true,
"leadingWhitespace": false,
"noCloneChecked": false,
"noCloneEvent": false,
"opacity": false,
"optDisabled": true,
"optSelected": false,
"radioValue": false,
"reliableHiddenOffsets": false,
"reliableMarginRight": true,
"shrinkWrapBlocks": false,
"submitBubbles": false,
"tbody": false,
"style": false,
"clearCloneStyle": true
};
} else if ( /msie 6\.0/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":false,
"tbody":false,
"htmlSerialize":false,
"style":false,
"hrefNormalized":false,
"opacity":false,
"cssFloat":false,
"checkOn":true,
"optSelected":false,
"getSetAttribute":false,
"enctype":true,
"html5Clone":false,
"submitBubbles":false,
"changeBubbles":false,
"focusinBubbles":true,
"deleteExpando":false,
"noCloneEvent":false,
"inlineBlockNeedsLayout":true,
"shrinkWrapBlocks":true,
"reliableMarginRight":true,
"noCloneChecked":false,
"optDisabled":true,
"radioValue":false,
"checkClone":false,
"appendChecked":false,
"boxModel":true,
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
} else if ( /5\.1\.1 safari/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":false,
"optSelected":true,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":false,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":true,
"optDisabled":true,
"radioValue":true,
"checkClone":false,
"appendChecked":false,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
} else if ( /firefox/i.test( userAgent ) ) {
expected = {
"leadingWhitespace":true,
"tbody":true,
"htmlSerialize":true,
"style":true,
"hrefNormalized":true,
"opacity":true,
"cssFloat":true,
"checkOn":true,
"optSelected":true,
"getSetAttribute":true,
"enctype":true,
"html5Clone":true,
"submitBubbles":true,
"changeBubbles":true,
"focusinBubbles":false,
"deleteExpando":true,
"noCloneEvent":true,
"inlineBlockNeedsLayout":false,
"shrinkWrapBlocks":false,
"reliableMarginRight":true,
"noCloneChecked":true,
"optDisabled":true,
"radioValue":true,
"checkClone":true,
"appendChecked":true,
"boxModel":true,
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
"clearCloneStyle": true
};
}
if ( expected ) {
test("Verify that the support tests resolve as expected per browser", function() {
expect( 31 );
for ( var i in expected ) {
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
} else {
ok( true, "no ajax; skipping jQuery.support['" + i + "']" );
}
}
});
}
})();

View File

@@ -0,0 +1,667 @@
module("traversing", { teardown: moduleTeardown });
test( "find(String)", function() {
expect( 7 );
equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" );
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
equal( j.find("div").andSelf().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" );
deepEqual( jQuery("#qunit-fixture").find("> div").get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" );
deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q( "foo", "moretests" ), "find child elements" );
deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q( "sndp", "en", "sap" ), "find child elements" );
deepEqual( jQuery("#siblingTest, #siblingfirst").find("+ *").get(), q( "siblingnext", "fx-test-group" ), "ensure document order" );
});
test( "find(node|jQuery object)", function() {
expect( 12 );
var $foo = jQuery("#foo"),
$blog = jQuery(".blogTest"),
$first = jQuery("#first"),
$two = $blog.add( $first ),
$fooTwo = $foo.add( $blog );
equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
equal( $foo.find( $blog[ 0 ] ).text(), "Yahoo", "Find with blog node" );
equal( $foo.find( $first ).length, 0, "#first is not in #foo" );
equal( $foo.find( $first[ 0 ]).length, 0, "#first not in #foo (node)" );
ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
ok( $fooTwo.find( $blog[ 0 ] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
equal( $two.find( $foo ).length, 0, "Foo is not in two elements" );
equal( $two.find( $foo[ 0 ] ).length, 0, "Foo is not in two elements(node)" );
equal( $two.find( $first ).length, 0, "first is in the collection and not within two" );
equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
equal( $two.find( $foo[ 0 ] ).andSelf().length, 2, "find preserves the pushStack, see #12009" );
});
test("is(String|undefined)", function() {
expect(30);
ok( jQuery("#form").is("form"), "Check for element: A form must be a form" );
ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" );
ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" );
ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" );
ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" );
ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" );
ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" );
ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" );
ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" );
ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" );
// test is() with comma-seperated expressions
ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( !jQuery(window).is("a"), "Checking is on a window does not throw an exception(#10178)" );
ok( !jQuery(document).is("a"), "Checking is on a document does not throw an exception(#10178)" );
ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" );
});
test("is(jQuery)", function() {
expect(21);
ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" );
ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" );
ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" );
ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" );
ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" );
ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" );
ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" );
ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" );
ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" );
ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" );
ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" );
// Some raw elements
ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" );
ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" );
ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" );
ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" );
ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
});
test("is() with positional selectors", function() {
expect(23);
var html = jQuery(
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
).appendTo( "body" ),
isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
};
isit( "#posp", "#posp:first", true );
isit( "#posp", "#posp:eq(2)", false );
isit( "#posp", "#posp a:first", false );
isit( "#posp .firsta", "#posp a:first", true );
isit( "#posp .firsta", "#posp a:last", false );
isit( "#posp .firsta", "#posp a:even", true );
isit( "#posp .firsta", "#posp a:odd", false );
isit( "#posp .firsta", "#posp a:eq(0)", true );
isit( "#posp .firsta", "#posp a:eq(9)", false );
isit( "#posp .firsta", "#posp em:eq(0)", false );
isit( "#posp .firsta", "#posp em:first", false );
isit( "#posp .firsta", "#posp:first", false );
isit( "#posp .seconda", "#posp a:first", false );
isit( "#posp .seconda", "#posp a:last", true );
isit( "#posp .seconda", "#posp a:gt(0)", true );
isit( "#posp .seconda", "#posp a:lt(5)", true );
isit( "#posp .seconda", "#posp a:lt(1)", false );
isit( "#posp em", "#posp a:eq(0) em", true );
isit( "#posp em", "#posp a:lt(1) em", true );
isit( "#posp em", "#posp a:gt(1) em", false );
isit( "#posp em", "#posp a:first em", true );
isit( "#posp em", "#posp a em:last", true );
isit( "#posp em", "#posp a em:eq(2)", false );
html.remove();
});
test("index()", function() {
expect( 2 );
equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" );
equal( jQuery("<div/>").index(), -1, "Node without parent returns -1" );
});
test("index(Object|String|undefined)", function() {
expect(16);
var elements = jQuery([window, document]),
inputElements = jQuery("#radio1,#radio2,#check1,#check2");
// Passing a node
equal( elements.index(window), 0, "Check for index of elements" );
equal( elements.index(document), 1, "Check for index of elements" );
equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
equal( inputElements.index(window), -1, "Check for not found index" );
equal( inputElements.index(document), -1, "Check for not found index" );
// Passing a jQuery object
// enabled since [5500]
equal( elements.index( elements ), 0, "Pass in a jQuery object" );
equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" );
// Passing a selector or nothing
// enabled since [6330]
equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
equal( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" );
equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
equal( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" );
});
test("filter(Selector|undefined)", function() {
expect(9);
deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
});
test("filter(Function)", function() {
expect(2);
deepEqual( jQuery("#qunit-fixture p").filter(function() {
return !jQuery("a", this).length;
}).get(), q("sndp", "first"), "filter(Function)" );
deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length; }).get(), q("sndp", "first"), "filter(Function) using arg" );
});
test("filter(Element)", function() {
expect(1);
var element = document.getElementById("text1");
deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" );
});
test("filter(Array)", function() {
expect(1);
var elements = [ document.getElementById("text1") ];
deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
});
test("filter(jQuery)", function() {
expect(1);
var elements = jQuery("#text1");
deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
});
test("filter() with positional selectors", function() {
expect(19);
var html = jQuery( "" +
"<p id='posp'>" +
"<a class='firsta' href='#'>" +
"<em>first</em>" +
"</a>" +
"<a class='seconda' href='#'>" +
"<b>test</b>" +
"</a>" +
"<em></em>" +
"</p>" ).appendTo( "body" ),
filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
};
filterit( "#posp", "#posp:first", 1);
filterit( "#posp", "#posp:eq(2)", 0 );
filterit( "#posp", "#posp a:first", 0 );
// Keep in mind this is within the selection and
// not in relation to other elements (.is() is a different story)
filterit( "#posp .firsta", "#posp a:first", 1 );
filterit( "#posp .firsta", "#posp a:last", 1 );
filterit( "#posp .firsta", "#posp a:last-child", 0 );
filterit( "#posp .firsta", "#posp a:even", 1 );
filterit( "#posp .firsta", "#posp a:odd", 0 );
filterit( "#posp .firsta", "#posp a:eq(0)", 1 );
filterit( "#posp .firsta", "#posp a:eq(9)", 0 );
filterit( "#posp .firsta", "#posp em:eq(0)", 0 );
filterit( "#posp .firsta", "#posp em:first", 0 );
filterit( "#posp .firsta", "#posp:first", 0 );
filterit( "#posp .seconda", "#posp a:first", 1 );
filterit( "#posp .seconda", "#posp em:first", 0 );
filterit( "#posp .seconda", "#posp a:last", 1 );
filterit( "#posp .seconda", "#posp a:gt(0)", 0 );
filterit( "#posp .seconda", "#posp a:lt(5)", 1 );
filterit( "#posp .seconda", "#posp a:lt(1)", 1 );
html.remove();
});
test("closest()", function() {
expect( 14 );
deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" );
deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" );
deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
// Test .closest() limited by the context
var jq = jQuery("#nothiddendivchild");
deepEqual( jq.closest("html", document.body).get(), [], "Context limited." );
deepEqual( jq.closest("body", document.body).get(), [], "Context limited." );
deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
//Test that .closest() returns unique'd set
equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
// Test on disconnected node
equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
// Bug #7369
equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
ok( !jQuery(document).closest("#foo").length, "Calling closest on a document fails silently" );
});
test("closest(jQuery)", function() {
expect(8);
var $child = jQuery("#nothiddendivchild"),
$parent = jQuery("#nothiddendiv"),
$sibling = jQuery("#foo"),
$body = jQuery("body");
ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
equal( $child.closest( $sibling ).length, 0, "Sibling not a parent of child" );
equal( $child.closest( $sibling[0] ).length, 0, "Sibling not a parent of child :: node" );
ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
});
test("not(Selector|undefined)", function() {
expect(11);
equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
deepEqual(
jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(),
q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"),
"not('complex selector')"
);
deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
var all = jQuery("p").get();
deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect");
deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect");
deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect");
});
test("not(Element)", function() {
expect(1);
var selects = jQuery("#form select");
deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element");
});
test("not(Function)", function() {
expect(1);
deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length; }).get(), q("sndp", "first"), "not(Function)" );
});
test("not(Array)", function() {
expect(2);
equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
});
test("not(jQuery)", function() {
expect( 1 );
deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
});
test("has(Element)", function() {
expect(3);
var 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("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( obj.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");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
var 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");
deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("has(Arrayish)", function() {
expect(4);
var 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("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
var 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"));
deepEqual( simple.get(), q("qunit-fixture"), "Only adds elements once" );
});
test("addBack()", function() {
expect(5);
deepEqual( jQuery("#en").siblings().addBack().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
deepEqual( jQuery("#foo").children().addBack().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
deepEqual( jQuery("#sndp, #en").parent().addBack().get(), q("foo","sndp","en"), "Check for parent and self" );
deepEqual( jQuery("#groups").parents("p, div").addBack().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
deepEqual( jQuery("#select1 > option").filter(":first-child").addBack(":last-child").get(), q("option1a", "option1d"), "Should contain the last elems plus the *filtered* prior set elements" );
});
test("siblings([String])", function() {
expect(7);
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
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)" );
equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" );
});
test("children([String])", function() {
expect(3);
deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
});
test("parent([String])", function() {
expect(5);
equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
});
test("parents([String])", function() {
expect(5);
equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
});
test("parentsUntil([String])", function() {
expect(9);
var parents = jQuery("#groups").parents();
deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" );
equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
});
test("next([String])", function() {
expect(5);
equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
equal( jQuery("body").next().length, 0, "Simple next check, no match" );
});
test("prev([String])", function() {
expect(4);
equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
});
test("nextAll([String])", function() {
expect(4);
var elems = jQuery("#form").children();
deepEqual( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" );
deepEqual( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" );
deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" );
deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
});
test("prevAll([String])", function() {
expect(4);
var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
});
test("nextUntil([String])", function() {
expect(11);
var elems = jQuery("#form").children().slice( 2, 12 );
deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" );
equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" );
deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" );
deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" );
deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" );
deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" );
equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" );
deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
});
test("prevUntil([String])", function() {
expect(10);
var elems = jQuery("#area1").prevAll();
deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
deepEqual( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" );
equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" );
deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" );
deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" );
equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" );
});
test("contents()", function() {
expect(12);
equal( jQuery("#ap").contents().length, 9, "Check element contents" );
ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
var ibody = jQuery("#loadediframe").contents()[0].body;
ok( ibody, "Check existance of IFrame body" );
equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
jQuery(ibody).append("<div>init text</div>");
equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
equal( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
jQuery("div:last", ibody).text("div text");
equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
jQuery("div:last", ibody).remove();
equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
jQuery("table", ibody).remove();
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();
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 );
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" );
// We no longer support .add(form.elements), unfortunately.
// There is no way, in browsers, to reliably determine the difference
// between form.elements and form - and doing .add(form) and having it
// add the form elements is way to unexpected, so this gets the boot.
// ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
// For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
// 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("<div/>").add("#sndp");
ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
divs = jQuery("#sndp").add("<div/>");
ok( !divs[1].parentNode, "Sort with the disconnected node last." );
var tmp = jQuery("<div/>");
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
equal( x[0].id, "x1", "Check on-the-fly element1" );
equal( x[1].id, "x2", "Check on-the-fly element2" );
x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
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" );
equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" );
});
test("add(String, Context)", function() {
expect(6);
deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " );
deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" );
deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" );
var ctx = document.getElementById("firstp");
deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " );
deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" );
deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" );
});
test("eq('-1') #10616", function() {
expect(3);
var $divs = jQuery( "div" );
equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" );
equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" );
deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" );
});
test("index(no arg) #10977", function() {
expect(1);
var $list = jQuery("<ul id='indextest'><li>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
jQuery("#qunit-fixture").append( $list );
strictEqual ( jQuery( "#indextest li:not(.one,.two)" ).index() , 0, "No Argument Index Check" );
$list.remove();
});