Add logic to Element#getStyle in Opera that fixes inaccurate reporting of computed 'width' and 'height' properties. [Andrew Dupont]
This commit is contained in:
parent
3e82a712d1
commit
ae76169baf
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Add logic to Element#getStyle in Opera that fixes inaccurate reporting of computed 'width' and 'height' properties. [Andrew Dupont]
|
||||
|
||||
* Ensure that an Ajax.Request's parameters option can be a Hash. Closes #10172. [kangax, sam]
|
||||
|
||||
* Ensure no comment nodes are returned in Selector queries (IE improperly returns comment nodes on getElementsByTagName("*")). Change Element#descendants to use Element#getElementsBySelector in order to avoid this issue. Closes #10220. [Jeff Gobel, Andrew Dupont]
|
||||
|
58
src/dom.js
58
src/dom.js
@ -705,22 +705,46 @@ if (!document.createRange || Prototype.Browser.Opera) {
|
||||
}
|
||||
|
||||
if (Prototype.Browser.Opera) {
|
||||
Element.Methods._getStyle = Element.Methods.getStyle;
|
||||
Element.Methods.getStyle = function(element, style) {
|
||||
switch(style) {
|
||||
case 'left':
|
||||
case 'top':
|
||||
case 'right':
|
||||
case 'bottom':
|
||||
if (Element._getStyle(element, 'position') == 'static') return null;
|
||||
default: return Element._getStyle(element, style);
|
||||
Element.Methods.getStyle = Element.Methods.getStyle.wrap(
|
||||
function(proceed, element, style) {
|
||||
switch (style) {
|
||||
case 'left': case 'top': case 'right': case 'bottom':
|
||||
if (proceed(element, 'position') === 'static') return null;
|
||||
case 'height': case 'width':
|
||||
// returns '0px' for hidden elements; we want it to return null
|
||||
if (!Element.visible(element)) return null;
|
||||
|
||||
// returns the border-box dimensions rather than the content-box
|
||||
// dimensions, so we subtract padding and borders from the value
|
||||
var dim = parseInt(proceed(element, style), 10);
|
||||
|
||||
if (dim !== element['offset' + style.capitalize()])
|
||||
return dim + 'px';
|
||||
|
||||
var properties;
|
||||
if (style === 'height') {
|
||||
properties = ['border-top-width', 'padding-top',
|
||||
'padding-bottom', 'border-bottom-width'];
|
||||
}
|
||||
else {
|
||||
properties = ['border-left-width', 'padding-left',
|
||||
'padding-right', 'border-right-width'];
|
||||
}
|
||||
return properties.inject(dim, function(memo, property) {
|
||||
var val = proceed(element, property);
|
||||
return val === null ? memo : memo - parseInt(val, 10);
|
||||
}) + 'px';
|
||||
default: return proceed(element, style);
|
||||
}
|
||||
}
|
||||
};
|
||||
Element.Methods._readAttribute = Element.Methods.readAttribute;
|
||||
Element.Methods.readAttribute = function(element, attribute) {
|
||||
if (attribute == 'title') return element.title;
|
||||
return Element._readAttribute(element, attribute);
|
||||
};
|
||||
);
|
||||
|
||||
Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
|
||||
function(proceed, element, attribute) {
|
||||
if (attribute === 'title') return element.title;
|
||||
return proceed(element, attribute);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
else if (Prototype.Browser.IE) {
|
||||
@ -891,7 +915,7 @@ else if (Prototype.Browser.WebKit) {
|
||||
};
|
||||
|
||||
// Safari returns margins on body which is incorrect if the child is absolutely
|
||||
// positioned. For performance reasons, redefine Position.cumulativeOffset for
|
||||
// positioned. For performance reasons, redefine Element#cumulativeOffset for
|
||||
// KHTML/WebKit only.
|
||||
Element.Methods.cumulativeOffset = function(element) {
|
||||
var valueT = 0, valueL = 0;
|
||||
@ -1049,7 +1073,7 @@ if (!Prototype.BrowserFeatures.ElementExtensions &&
|
||||
Element.extend = (function() {
|
||||
if (Prototype.BrowserFeatures.SpecificElementExtensions)
|
||||
return Prototype.K;
|
||||
|
||||
|
||||
var Methods = { }, ByTag = Element.Methods.ByTag;
|
||||
|
||||
var extend = Object.extend(function(element) {
|
||||
|
Loading…
Reference in New Issue
Block a user