improving the biceps of getStyle(). Now if you pass it a null object, it will not die. r=cr5 (Closes #1051)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7888 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -215,23 +215,27 @@ OpenLayers.Element = {
|
|||||||
*/
|
*/
|
||||||
getStyle: function(element, style) {
|
getStyle: function(element, style) {
|
||||||
element = OpenLayers.Util.getElement(element);
|
element = OpenLayers.Util.getElement(element);
|
||||||
var value = element.style[OpenLayers.String.camelize(style)];
|
|
||||||
if (!value) {
|
var value = null;
|
||||||
if (document.defaultView &&
|
if (element && element.style) {
|
||||||
document.defaultView.getComputedStyle) {
|
value = element.style[OpenLayers.String.camelize(style)];
|
||||||
|
if (!value) {
|
||||||
var css = document.defaultView.getComputedStyle(element, null);
|
if (document.defaultView &&
|
||||||
value = css ? css.getPropertyValue(style) : null;
|
document.defaultView.getComputedStyle) {
|
||||||
} else if (element.currentStyle) {
|
|
||||||
value = element.currentStyle[OpenLayers.String.camelize(style)];
|
var css = document.defaultView.getComputedStyle(element, null);
|
||||||
|
value = css ? css.getPropertyValue(style) : null;
|
||||||
|
} else if (element.currentStyle) {
|
||||||
|
value = element.currentStyle[OpenLayers.String.camelize(style)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var positions = ['left', 'top', 'right', 'bottom'];
|
||||||
|
if (window.opera &&
|
||||||
|
(OpenLayers.Util.indexOf(positions,style) != -1) &&
|
||||||
|
(OpenLayers.Element.getStyle(element, 'position') == 'static')) {
|
||||||
|
value = 'auto';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var positions = ['left', 'top', 'right', 'bottom'];
|
|
||||||
if (window.opera &&
|
|
||||||
(OpenLayers.Util.indexOf(positions,style) != -1) &&
|
|
||||||
(OpenLayers.Element.getStyle(element, 'position') == 'static')) {
|
|
||||||
value = 'auto';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value == 'auto' ? null : value;
|
return value == 'auto' ? null : value;
|
||||||
|
|||||||
@@ -1066,12 +1066,7 @@ OpenLayers.Util.pagePosition = function(forElement) {
|
|||||||
while(element) {
|
while(element) {
|
||||||
|
|
||||||
if(element == document.body) {
|
if(element == document.body) {
|
||||||
// FIXME: IE, when passed 'window' as the forElement, treats it as
|
if(OpenLayers.Element.getStyle(child, 'position') == 'absolute') {
|
||||||
// equal to document.body, but window.style fails, so getStyle
|
|
||||||
// fails, so we are paranoid and check this here. This check should
|
|
||||||
// probably move into element.getStyle in 2.6.
|
|
||||||
if(child && child.style &&
|
|
||||||
OpenLayers.Element.getStyle(child, 'position') == 'absolute') {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,13 +219,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Element_getStyle(t) {
|
function test_Element_getStyle(t) {
|
||||||
t.plan(4);
|
t.plan(5);
|
||||||
|
|
||||||
//tests for this function are not 100% complete... there is some funky
|
//tests for this function are not 100% complete... there is some funky
|
||||||
// business going on in there with
|
// business going on in there with
|
||||||
// * document.defaultView (moz/ff I believe)
|
// * document.defaultView (moz/ff I believe)
|
||||||
// but I cant seem to find a good way to test them.
|
// but I cant seem to find a good way to test them.
|
||||||
//
|
//
|
||||||
|
t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null");
|
||||||
|
|
||||||
var elem = document.getElementById("elemID");
|
var elem = document.getElementById("elemID");
|
||||||
elem.style.chickenHead = {}
|
elem.style.chickenHead = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user