(function() { if ( !jQuery.fn.width ) { return; } module("dimensions", { teardown: moduleTeardown }); function pass( val ) { return val; } function fn( 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 */ function testWidth( val ) { expect(9); var $div, blah; $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": "" }); 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 correct." ); return width + 1; }); equal( $div.width(), 31, "Make sure value was modified correctly." ); }); function testHeight( val ) { expect(9); var $div, blah; $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": "" }); 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 correct." ); return height + 1; }); equal( $div.height(), 31, "Make sure value was modified correctly." ); }); test("innerWidth()", function() { expect(6); var $div, div, winWidth = jQuery( window ).width(), docWidth = jQuery( document ).width(); equal(jQuery(window).innerWidth(), winWidth, "Test on window"); equal(jQuery(document).innerWidth(), docWidth, "Test on document"); $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": "" }); div = jQuery( "
a | |
a |