Permalink
Browse files

Fix bugs in layout.js. Add tests for `Element.Layout#toCSS`, `#toObje…

…ct`, and `#toHash`.
  • Loading branch information...
1 parent 08a6188 commit eb263577c45eb2e6b839dc1260e5fd4fad996618 @savetheclocktower savetheclocktower committed Apr 23, 2010
Showing with 31 additions and 9 deletions.
  1. +2 −0 CHANGELOG
  2. +8 −7 src/dom/layout.js
  3. +21 −2 test/unit/layout_test.js
View
@@ -1,3 +1,5 @@
+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)
Make `Element.Layout#toCSS` return camelized property names, as expected by `Element.setStyle`. [#1021 state:resolved] (njakobsen, Andrew Dupont)
View
@@ -94,7 +94,7 @@
// Converts the layout hash property names back to the CSS equivalents.
// For now, only the border properties differ.
function cssNameFor(key) {
- if (key.includes('border')) key = key + '-width';
+ if (key.include('border')) key = key + '-width';
return key.camelize();
}
@@ -358,7 +358,7 @@
if (!Element.Layout.PROPERTIES.include(key)) return;
var value = this.get(key);
if (value != null) obj[key] = value;
- });
+ }, this);
return obj;
},
@@ -398,6 +398,7 @@
var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
args.join(' ').split(' ');
var css = {};
+
keys.each( function(key) {
// Key needs to be a valid Element.Layout property...
if (!Element.Layout.PROPERTIES.include(key)) return;
@@ -407,8 +408,8 @@
var value = this.get(key);
// Unless the value is null, add 'px' to the end and add it to the
// returned object.
- if (value) css[cssNameFor(key)] = value + 'px';
- });
+ if (value != null) css[cssNameFor(key)] = value + 'px';
+ }, this);
return css;
},
@@ -443,12 +444,12 @@
var bTop = this.get('border-top'),
bBottom = this.get('border-bottom');
-
+
var pTop = this.get('padding-top'),
pBottom = this.get('padding-bottom');
-
+
if (!this._preComputing) this._end();
-
+
return bHeight - bTop - bBottom - pTop - pBottom;
},
View
@@ -12,8 +12,6 @@ function isDisplayed(element) {
}
new Test.Unit.Runner({
- setup: function() {
- },
'test preCompute argument of layout': function() {
var preComputedLayout = $('box1').getLayout(true),
normalLayout = $('box1').getLayout();
@@ -95,5 +93,26 @@ new Test.Unit.Runner({
this.assertEqual(0, layout.get('top'), 'top');
this.assertIdentical($('box6_parent'), $('box6').getOffsetParent());
+ },
+
+ 'test #toCSS, #toObject, #toHash': function() {
+ var layout = $('box6').getLayout();
+ var top = layout.get('top');
+
+ var cssObject = layout.toCSS('top');
+
+ this.assert('top' in cssObject,
+ "layout object should have 'top' property");
+
+ cssObject = layout.toCSS('top left bottom');
+
+ $w('top left bottom').each( function(prop) {
+ this.assert(prop in cssObject, "layout object should have '" +
+ prop + "' property");
+ }, this);
+
+ var obj = layout.toObject('top');
+ this.assert('top' in obj,
+ "object should have 'top' property");
}
});

0 comments on commit eb26357

Please sign in to comment.