diff --git a/bonzo.js b/bonzo.js index f4a3925..a31c5e1 100644 --- a/bonzo.js +++ b/bonzo.js @@ -781,7 +781,11 @@ * @return {Bonzo|number} */ , offset: function (opt_x, opt_y) { - if (typeof opt_x == 'number' || typeof opt_y == 'number') { + if (typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) { + return this.each(function (el) { + xy(el, opt_x.top, opt_y.left) + }) + } else if (typeof opt_x == 'number' || typeof opt_y == 'number') { return this.each(function (el) { xy(el, opt_x, opt_y) }) diff --git a/src/bonzo.js b/src/bonzo.js index 13e3deb..b10bbc1 100644 --- a/src/bonzo.js +++ b/src/bonzo.js @@ -776,7 +776,12 @@ * @return {Bonzo|number} */ , offset: function (opt_x, opt_y) { - if (typeof opt_x == 'number' || typeof opt_y == 'number') { + console.log('offset',arguments) + if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) { + return this.each(function (el) { + xy(el, opt_x.left, opt_x.top) + }) + } else if (typeof opt_x == 'number' || typeof opt_y == 'number') { return this.each(function (el) { xy(el, opt_x, opt_y) }) diff --git a/tests/layout-test.js b/tests/layout-test.js index c5caa67..2d4a48f 100644 --- a/tests/layout-test.js +++ b/tests/layout-test.js @@ -1,7 +1,7 @@ /*global sink:true start:true Q:true dom:true $:true bowser:true ender:true*/ sink('Layout', function (test, ok) { - test('offsets', 6, function () { + test('offsets', 10, function () { var $el = $(dom.create('
')).css({ position: 'absolute', left: '50px', @@ -18,6 +18,15 @@ sink('Layout', function (test, ok) { $el.offset(0, 0) ok($el.offset().top === 0, 'setting "0" doesnt become falsy') ok($el.offset().left === 0, 'setting "0" doesnt become falsy') + + $el.offset({ left: 100 }) + $el.offset({ top: -100 }) + ok($el.offset().left == 100, 'after offset({ left: 100 })') + ok($el.offset().top == -100, 'after offset({ top: -100 })') + + $el.offset({ left: -200, top: 200 }) + ok($el.offset().left == -200, 'after offset({ left: -200, top: 200 })') + ok($el.offset().top == 200, 'after offset({ left: -200, top: 200 })') }) test('offset + scroll', 2, function () {