Skip to content

Commit

Permalink
Fix issue where Element.Layout#get would fail to interpret negative…
Browse files Browse the repository at this point in the history
… pixel values. (Sebastien Gruhier, Andrew Dupont)
  • Loading branch information
savetheclocktower committed May 4, 2010
1 parent 2434892 commit 38e85b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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)
Expand Down
2 changes: 1 addition & 1 deletion src/dom/layout.js
Expand Up @@ -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)) {

This comment has been minimized.

Copy link
@kangax

kangax May 4, 2010

Collaborator

What's the purpose of non-capturing group here? Why not just -?

This comment has been minimized.

Copy link
@savetheclocktower

savetheclocktower May 4, 2010

Author Collaborator

Force of habit. :-)

return window.parseFloat(value);
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/fixtures/layout.html
@@ -1,3 +1,15 @@
<div id="box_with_negative_margins">
<p>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.</p>
</div> <!-- #box_with_negative_margins -->

<style type="text/css" media="screen">
#box_with_negative_margins {
margin: -10px;
margin-right: 2px;
margin-left: -3px;
}
</style>


<!-- Absolutely-positioned element with BODY as offset parent. -->
<div id="box1">
Expand Down
8 changes: 8 additions & 0 deletions test/unit/layout_test.js
Expand Up @@ -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();

Expand Down

0 comments on commit 38e85b8

Please sign in to comment.