r2850 - positionTo: updated tests.
Author: scott.gonzalez
Date: Mon Jun 29 19:26:20 2009
New Revision: 2850
Modified:
branches/dev/positionTo/tests/unit/positionTo/positionTo.html
branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js
branches/dev/positionTo/ui/ui.positionTo.js
Log:
positionTo: updated tests.
Modified: branches/dev/positionTo/tests/unit/positionTo/positionTo.html
==============================================================================
--- branches/dev/positionTo/tests/unit/positionTo/positionTo.html (original)
+++ branches/dev/positionTo/tests/unit/positionTo/positionTo.html Mon Jun
29 19:26:20 2009
@@ -18,7 +18,7 @@
<div id="main" style="top: 0; left: 0;">
<div id="el1" style="position: absolute; width: 3px; height: 3px;"></div>
<div id="el2" style="position: absolute; width: 3px; height: 3px;"></div>
- <div id="parent" style="width: 3px; height: 3px; top: 4px; left:
4px;"></div>
+ <div id="parent" style="position: absolute; width: 3px; height: 3px; top:
4px; left: 4px;"></div>
</div>
<div style="position: absolute; top: 0px; left: 0px">
Modified: branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js
==============================================================================
--- branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js
(original)
+++ branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js Mon
Jun 29 19:26:20 2009
@@ -3,57 +3,63 @@
*/
(function($) {
- test("basics1", function() {
- $("#elx").positionTo({ of: "#parentx" });
- same($("#elx").offset(), {top:7, left:4})
- })
+test('basics - single element', function() {
+ $("#elx").positionTo({ my: 'left top', at: 'left top', of: '#parentx' });
+ same($("#elx").offset(), { top: 4, left: 4 });
- test("basics2", function() {
- var elements = $("#el1, #el2");
- var result = elements.positionTo({
- of: "#parent"
- });
- same(result, elements);
- var expected = { top: 7, left: 4 };
- same(elements.filter(":first").offset(), expected);
- same(elements.filter(":last").offset(), expected);
- })
-
- test("positions", function() {
- var definitions = [];
- var offsets = {
- left: 0,
- center: 1,
- right: 2,
- top: 0,
- middle: 1,
- bottom: 2
- }
- var start = {left: 4, top: 4};
- $.each([0, 1], function(my) {
- $.each(["top", "middle", "bottom"], function(vindex, vertical) {
- $.each(["left", "center", "right"], function(hindex, horizontal) {
- definitions.push({
- my: my ? horizontal + " " + vertical : undefined,
- at: !my ? horizontal + " " + vertical : undefined,
- result: {
- top: my ? start.top - offsets[vertical] : start.top +
offsets[vertical],
- left: my ? start.left - offsets[horizontal] : start.left +
offsets[horizontal]
- }
- });
+ $("#elx").positionTo({ my: 'left top', at: 'left bottom', of: '#parentx'
});
+ same($("#elx").offset(), { top: 7, left: 4 });
+});
+
+test('basics - multiple elements', function() {
+ var elements = $('#el1, #el2');
+ var result = elements.positionTo({
+ my: 'left top',
+ at: 'left bottom',
+ of: '#parent'
+ });
+
+ same(result, elements);
+ var expected = {top: 7, left: 4};
+ elements.each(function() {
+ same($(this).offset(), expected);
+ });
+});
+
+test('positions', function() {
+ var definitions = [];
+ var offsets = {
+ left: 0,
+ center: 1.5,
+ right: 3,
+ top: 0,
+ middle: 1.5,
+ bottom: 3
+ };
+ var start = { left: 4, top: 4 };
+ $.each([0, 1], function(my) {
+ $.each(["top", "middle", "bottom"], function(vindex, vertical) {
+ $.each(["left", "center", "right"], function(hindex, horizontal) {
+ definitions.push({
+ my: my ? horizontal + " " + vertical : 'left top',
+ at: !my ? horizontal + " " + vertical : 'left top',
+ result: {
+ top: my ? start.top - offsets[vertical] : start.top +
offsets[vertical],
+ left: my ? start.left - offsets[horizontal] : start.left +
offsets[horizontal]
+ }
});
});
});
- var el = $("#el1"),
- parent = $("#parent");
- $.each(definitions, function(index, definition) {
- el.positionTo({
- my: definition.my || "left top",
- at: definition.at || "left top",
- of: parent
- });
- same(el.offset(), definition.result, "Position via " +
jsDump.parse({my:definition.my, at:definition.at}));
+ });
+ var el = $("#el1");
+ $.each(definitions, function(index, definition) {
+ el.positionTo({
+ my: definition.my,
+ at: definition.at,
+ of: '#parent'
});
- })
+ same(el.offset(), definition.result, "Position via " +
jsDump.parse({my:definition.my, at:definition.at}));
+ });
+});
})(jQuery);
Modified: branches/dev/positionTo/ui/ui.positionTo.js
==============================================================================
--- branches/dev/positionTo/ui/ui.positionTo.js (original)
+++ branches/dev/positionTo/ui/ui.positionTo.js Mon Jun 29 19:26:20 2009
@@ -27,7 +27,7 @@
height: target.outerHeight()
},
- offset = options.offset.replace(/px/gi, '').split(' '),
+// offset = options.offset.replace(/px/gi, '').split(' '),
position = targetProps.offset;
$.each(['my', 'at'], function() {