From 38e85b86dd5d218fe735afab969b87ac58983b77 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Tue, 4 May 2010 10:33:40 -0500 Subject: [PATCH] Fix issue where `Element.Layout#get` would fail to interpret negative pixel values. (Sebastien Gruhier, Andrew Dupont) --- CHANGELOG | 2 ++ src/dom/layout.js | 2 +- test/unit/fixtures/layout.html | 12 ++++++++++++ test/unit/layout_test.js | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4b4032aa2..dc415ca9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +Fix issue where `Element.Layout#get` would fail to interpret negative pixel values. (Sebastien Gruhier, Andrew Dupont) + Fix bugs in layout.js. Add tests for `Element.Layout#toCSS`, `#toObject`, and `#toHash`. (RStankov, Andrew Dupont) Add `Element.Layout#toObject` and `Element.Layout.toHash`. (Andrew Dupont) diff --git a/src/dom/layout.js b/src/dom/layout.js index 37e2dccc3..9f1d026cc 100644 --- a/src/dom/layout.js +++ b/src/dom/layout.js @@ -25,7 +25,7 @@ // Non-IE browsers will always return pixels if possible. // (We use parseFloat instead of parseInt because Firefox can return // non-integer pixel values.) - if ((/^\d+(\.\d+)?(px)?$/i).test(value)) { + if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) { return window.parseFloat(value); } diff --git a/test/unit/fixtures/layout.html b/test/unit/fixtures/layout.html index 5921e38ee..80c615b6d 100644 --- a/test/unit/fixtures/layout.html +++ b/test/unit/fixtures/layout.html @@ -1,3 +1,15 @@ +
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+
+ + +
diff --git a/test/unit/layout_test.js b/test/unit/layout_test.js index 278afee74..dbdeb8b7b 100644 --- a/test/unit/layout_test.js +++ b/test/unit/layout_test.js @@ -48,6 +48,14 @@ new Test.Unit.Runner({ this.assert(!isDisplayed($('box3')), 'box should still be hidden'); }, + 'test layout on elements with negative margins': function() { + var layout = $('box_with_negative_margins').getLayout(); + + this.assertEqual(-10, layout.get('margin-top') ); + this.assertEqual( -3, layout.get('margin-left') ); + this.assertEqual( 2, layout.get('margin-right')); + }, + 'test layout on elements with display: none and width: auto': function() { var layout = $('box3').getLayout();