// 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')) return key + '-width';
- return key;
+ if (key.include('border')) key = key + '-width';
+ return key.camelize();
}
/**
// Either way, it means the element is the width it needs to be
// in order to report an accurate height.
newWidth = getPixelValue(width);
- } else if (positionedWidth && (position === 'absolute' || position === 'fixed')) {
- newWidth = getPixelValue(positionedWidth);
+ } else if (width && (position === 'absolute' || position === 'fixed')) {
+ newWidth = getPixelValue(width);
} else {
// If not, that means the element's width depends upon the width of
// its parent.
},
/**
+ * Element.Layout#toObject([keys...]) -> Object
+ * - keys (String): A space-separated list of keys to include.
+ *
+ * Converts the layout hash to a plain object of key/value pairs,
+ * optionally including only the given keys.
+ *
+ * Keys can be passed into this method as individual arguments _or_
+ * separated by spaces within a string.
+ **/
+ toObject: function() {
+ var args = $A(arguments);
+ var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
+ args.join(' ').split(' ');
+ var obj = {};
+ keys.each( function(key) {
+ // Key needs to be a valid Element.Layout property.
+ if (!Element.Layout.PROPERTIES.include(key)) return;
+ var value = this.get(key);
+ if (value != null) obj[key] = value;
+ }, this);
+ return obj;
+ },
+
+ /**
+ * Element.Layout#toHash([keys...]) -> Hash
+ * - keys (String): A space-separated list of keys to include.
+ *
+ * Converts the layout hash to an ordinary hash of key/value pairs,
+ * optionally including only the given keys.
+ *
+ * Keys can be passed into this method as individual arguments _or_
+ * separated by spaces within a string.
+ **/
+ toHash: function() {
+ var obj = this.toObject.apply(this, arguments);
+ return new Hash(obj);
+ },
+
+ /**
* Element.Layout#toCSS([keys...]) -> Object
* - keys (String): A space-separated list of keys to include.
*
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;
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;
},
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;
},
}
var offsetParent = getOffsetParent(element);
- var eOffset = element.viewportOffset(), pOffset =
- offsetParent.viewportOffset();
+ var eOffset = element.viewportOffset(),
+ pOffset = offsetParent.viewportOffset();
- var offset = eOffset.relativeTo(pOffset);
- var layout = element.get('layout');
+ var offset = eOffset.relativeTo(pOffset);
+ var layout = element.getLayout();
element.store('prototype_absolutize_original_styles', {
left: element.getStyle('left'),
Element.addMethods({
getLayout: getLayout
});
-
+
function isBody(element) {
return element.nodeName.toUpperCase() === 'BODY';
}
});
}
})();
+