2015-04-06 14:56:48 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
|
|
|
"lib/common",
|
2015-07-15 22:14:26 +00:00
|
|
|
"ui/form",
|
2015-07-16 00:30:36 +00:00
|
|
|
"ui/labels",
|
|
|
|
"ui/unique-id"
|
2015-04-06 14:56:48 +00:00
|
|
|
], function( $, common ) {
|
2008-09-20 17:42:04 +00:00
|
|
|
|
2012-04-30 00:13:34 +00:00
|
|
|
module( "core - jQuery extensions" );
|
2008-11-07 13:49:23 +00:00
|
|
|
|
2015-04-06 14:56:48 +00:00
|
|
|
common.testJshint( "core" );
|
2012-04-30 00:22:31 +00:00
|
|
|
|
2010-07-22 02:17:52 +00:00
|
|
|
test( "innerWidth - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.innerWidth(), 122, "getter passthru" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.innerWidth(), 122, "getter passthru when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "innerWidth - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.innerWidth( 120 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 98, "width set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.innerWidth( 100 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 78, "width set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "innerHeight - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.innerHeight(), 70, "getter passthru" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.innerHeight(), 70, "getter passthru when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "innerHeight - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.innerHeight( 60 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 40, "height set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.innerHeight( 50 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 30, "height set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerWidth - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.outerWidth(), 140, "getter passthru" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.outerWidth(), 140, "getter passthru when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerWidth - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.outerWidth( 130 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 90, "width set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.outerWidth( 120 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 80, "width set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerWidth(true) - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2015-08-21 04:14:57 +00:00
|
|
|
equal( el.outerWidth( true ), 154, "getter passthru w/ margin" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2015-08-21 04:14:57 +00:00
|
|
|
equal( el.outerWidth( true ), 154, "getter passthru w/ margin when hidden" );
|
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerWidth(true) - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.outerWidth( 130, true );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 76, "width set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.outerWidth( 120, true );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.width(), 66, "width set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerHeight - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.outerHeight(), 86, "getter passthru" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.outerHeight(), 86, "getter passthru when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerHeight - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.outerHeight( 80 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 44, "height set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.outerHeight( 70 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 34, "height set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerHeight(true) - getter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
2015-08-21 04:14:57 +00:00
|
|
|
equal( el.outerHeight( true ), 98, "getter passthru w/ margin" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
2015-08-21 04:14:57 +00:00
|
|
|
equal( el.outerHeight( true ), 98, "getter passthru w/ margin when hidden" );
|
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
|
|
|
test( "outerHeight(true) - setter", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2010-07-22 02:17:52 +00:00
|
|
|
var el = $( "#dimensions" );
|
|
|
|
|
|
|
|
el.outerHeight( 90, true );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 42, "height set properly" );
|
2010-07-22 02:17:52 +00:00
|
|
|
el.hide();
|
|
|
|
el.outerHeight( 80, true );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( el.height(), 32, "height set properly when hidden" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2010-07-22 02:17:52 +00:00
|
|
|
|
2012-05-30 01:55:43 +00:00
|
|
|
test( "uniqueId / removeUniqueId", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
2012-05-30 01:55:43 +00:00
|
|
|
var el = $( "img" ).eq( 0 );
|
2015-03-23 22:42:23 +00:00
|
|
|
equal( el.attr( "id" ), null, "element has no initial id" );
|
2012-05-30 01:55:43 +00:00
|
|
|
el.uniqueId();
|
|
|
|
ok( /ui-id-\d+$/.test( el.attr( "id" ) ), "element has generated id" );
|
|
|
|
el.removeUniqueId();
|
2015-03-23 22:42:23 +00:00
|
|
|
equal( el.attr( "id" ), null, "unique id has been removed from element" );
|
2015-08-21 04:14:57 +00:00
|
|
|
} );
|
2012-05-30 01:55:43 +00:00
|
|
|
|
2015-04-27 03:38:21 +00:00
|
|
|
test( "Labels", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
|
|
|
|
var dom = $( "#labels-fragment" );
|
|
|
|
|
|
|
|
function testLabels( testType ) {
|
|
|
|
var labels = dom.find( "#test" ).labels();
|
|
|
|
var found = labels.map( function() {
|
|
|
|
|
|
|
|
// Support: Core 1.9 Only
|
|
|
|
// We use $.trim() because core 1.9.x silently fails when white space is present
|
|
|
|
return $.trim( $( this ).text() );
|
|
|
|
} ).get();
|
|
|
|
|
|
|
|
deepEqual( found, expected,
|
|
|
|
".labels() finds all labels in " + testType + ", and sorts them in DOM order" );
|
|
|
|
}
|
|
|
|
|
|
|
|
testLabels( "the DOM" );
|
|
|
|
|
|
|
|
// Detach the dom to test on a fragment
|
|
|
|
dom.detach();
|
|
|
|
testLabels( "document fragments" );
|
|
|
|
} );
|
|
|
|
|
|
|
|
( function() {
|
|
|
|
var domAttached = $( "#form-test" );
|
|
|
|
var domDetached = $( "#form-test-detached" ).detach();
|
|
|
|
|
|
|
|
function testForm( name, dom ) {
|
|
|
|
var inputs = dom.find( "input" );
|
|
|
|
|
|
|
|
inputs.each( function() {
|
|
|
|
var input = $( this );
|
|
|
|
|
|
|
|
asyncTest( name + this.id.replace( /_/g, " " ), function() {
|
|
|
|
expect( 1 );
|
|
|
|
var form = input.form();
|
|
|
|
|
|
|
|
// If input has a form the value should reset to "" if not it should be "changed"
|
|
|
|
var value = form.length ? "" : "changed";
|
|
|
|
|
|
|
|
input.val( "changed" );
|
|
|
|
|
|
|
|
// If there is a form we reset just that. If there is not a form, reset every form.
|
|
|
|
// The idea is if a form is found resetting that form should reset the input.
|
|
|
|
// If no form is found no amount of resetting should change the value.
|
|
|
|
( form.length ? form : dom.find( "form" ).addBack( "form" ) ).each( function() {
|
|
|
|
this.reset();
|
|
|
|
} );
|
|
|
|
|
|
|
|
setTimeout( function() {
|
|
|
|
equal( input.val(), value, "Proper form found for #" + input.attr( "id" ) );
|
|
|
|
start();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
testForm( "form: attached: ", domAttached );
|
|
|
|
testForm( "form: detached: ", domDetached );
|
|
|
|
} )();
|
2015-04-06 14:56:48 +00:00
|
|
|
} );
|