Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demos/position/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@
<select id="collision_horizontal">
<option value="flip">flip</option>
<option value="fit">fit</option>
<option value="flipfit">flipfit</option>
<option value="none">none</option>
</select>
<select id="collision_vertical">
<option value="flip">flip</option>
<option value="fit">fit</option>
<option value="flipfit">flipfit</option>
<option value="none">none</option>
</select>
</div>
Expand Down
54 changes: 29 additions & 25 deletions tests/unit/position/position.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script src="../testsuite.js"></script>

<script src="position_core.js"></script>
<script src="position_core_within.js"></script>
<script src="position_core_within.js"></script>

<script src="../swarminject.js"></script>
</head>
Expand All @@ -36,30 +36,34 @@ <h2 id="qunit-userAgent"></h2>
-->

<div id="qunit-fixture" style="top: 0; left: 0; z-index:1">
<div id="within-container">
<div id="el1" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div>
<div id="el2" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div>
<div id="parent" style="position: absolute; width: 6px; height: 6px; top: 4px; left: 4px; line-height: 6px;"></div>

<div style="position: absolute; top: 0px; left: 0px">
<div id="elx" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div id="parentx" style="position: absolute; width: 20px; height: 20px; top: 40px; left: 40px;"></div>
</div>

<div style="position: absolute; top: 200px; left: 100px;">
<div id="el-offset-100-200" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div style="position: absolute; top: 100px; left: 50px;">
<div id="el-two-offset-150-300" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div id="el-fixed" style="position: fixed; top: 200px; left: 200px;"></div>
</div>
</div>

<div style="position: absolute; height: 5000px; width: 5000px;"></div>

<div id="bug-5280" style="height: 30px; width: 201px;">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>
<div id="within-container">
<div id="el1" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div>
<div id="el2" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div>
<div id="parent" style="position: absolute; width: 6px; height: 6px; top: 4px; left: 4px; line-height: 6px;"></div>

<div style="position: absolute; top: 0px; left: 0px">
<div id="elx" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div id="parentx" style="position: absolute; width: 20px; height: 20px; top: 40px; left: 40px;"></div>
</div>

<div style="position: absolute; top: 200px; left: 100px;">
<div id="el-offset-100-200" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div style="position: absolute; top: 100px; left: 50px;">
<div id="el-two-offset-150-300" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div>
<div id="el-fixed" style="position: fixed; top: 200px; left: 200px;"></div>
</div>
</div>

<div style="position: absolute; height: 5000px; width: 5000px;"></div>

<div id="bug-5280" style="height: 30px; width: 201px;">
<div style="width: 50px; height: 10px;"></div>
</div>

<div id="fractions-parent" style="position: absolute; left: 10.7432222px; top: 10.532325px; height: 30px; width: 201px;">
<div id="fractions-element"></div>
</div>
</div>
</div>

</body>
Expand Down
72 changes: 41 additions & 31 deletions tests/unit/position/position_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,28 +332,28 @@ test( "collision: fit, window scrolled", function() {
test( "collision: flip, no offset", function() {
collisionTest({
collision: "flip"
}, { top: -10, left: -10 }, "left top" );
}, { top: $( window ).height(), left: $( window ).width() }, "left top" );

collisionTest2({
collision: "flip"
}, { top: $( window ).height(), left: $( window ).width() }, "right bottom" );
}, { top: -10, left: -10 }, "right bottom" );
});

test( "collision: flip, with offset", function() {
collisionTest({
collision: "flip",
at: "right+2 bottom+3"
}, { top: -13, left: -12 }, "left top, with offset added" );
}, { top: $( window ).height() + 3, left: $( window ).width() + 2 }, "left top, with offset added" );

collisionTest2({
collision: "flip",
at: "left+2 top+3"
}, { top: $( window ).height() - 3, left: $( window ).width() - 2 }, "bottom, positive offset" );
}, { top: -7, left: -8 }, "bottom, positive offset" );

collisionTest2({
collision: "flip",
at: "left-2 top-3"
}, { top: $( window ).height() + 3, left: $( window ).width() + 2 }, "right bottom, negative offset" );
}, { top: -13, left: -12 }, "right bottom, negative offset" );
});

test( "collision: none, no offset", function() {
Expand Down Expand Up @@ -427,12 +427,12 @@ test( "collision: flip, with margin", function() {
collisionTest({
collision: "flip",
at: "left top"
}, { top: $( window ).height() - 10, left: $( window ).width() - 10 }, "left top" );
}, { top: 0, left: 0 }, "left top" );

collisionTest2({
collision: "flip",
at: "right bottom"
}, { top: 0, left: 0 }, "right bottom" );
}, { top: $( window ).height() - 10, left: $( window ).width() - 10 }, "right bottom" );
});

test( "addClass: flipped left", function() {
Expand All @@ -443,15 +443,15 @@ test( "addClass: flipped left", function() {
at: "right center"
});

same( elem.hasClass( 'ui-flipped-left' ), true, 'Has ui-flipped-left class' );
same( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' );

elem.position( {
my: "right center",
of: window,
collision: "flip",
at: "left center"
})

same( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' );
});

Expand All @@ -463,8 +463,8 @@ test( "addClass: flipped top", function() {
at: "right bottom"
});

same( elem.hasClass( 'ui-flipped-top' ), true, 'Has ui-flipped-top class' );
same( elem.hasClass( 'ui-flipped-top' ), false, 'Has ui-flipped-top class' );

elem.position( {
my: "left bottom",
of: window,
Expand All @@ -483,7 +483,7 @@ test( "addClass: flipped right", function() {
at: "left center"
});

same( elem.hasClass( 'ui-flipped-right' ), true, 'Has ui-flipped-right class' );
same( elem.hasClass( 'ui-flipped-right' ), false, 'Has ui-flipped-right class' );

elem.position( {
my: "left center",
Expand All @@ -504,8 +504,8 @@ test( "addClass: flipped bottom", function() {
at: "right top"
});

same( elem.hasClass( 'ui-flipped-bottom' ), true, 'Has ui-flipped-bottom class' );
same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Has ui-flipped-bottom class' );

elem.position( {
my: "left top",
of: window,
Expand All @@ -516,22 +516,32 @@ test( "addClass: flipped bottom", function() {
same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Removed ui-flipped-bottom class' );
});

//test( "bug #5280: consistent results (avoid fractional values)", function() {
// var wrapper = $( "#bug-5280" ),
// elem = wrapper.children(),
// offset1 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset(),
// offset2 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset();
// same( offset1, offset2 );
//});
test( "fractions", function() {
$( "#fractions-element" ).position({
my: "left top",
at: "left top",
of: "#fractions-parent",
collision: "none"
});
same( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" );
});

test( "bug #5280: consistent results (avoid fractional values)", function() {
var wrapper = $( "#bug-5280" ),
elem = wrapper.children(),
offset1 = elem.position({
my: "center",
at: "center",
of: wrapper,
collision: "none"
}).offset(),
offset2 = elem.position({
my: "center",
at: "center",
of: wrapper,
collision: "none"
}).offset();
same( offset1, offset2 );
});

}( jQuery ) );
Loading