From b91ecde0a7d60185d47493c455e9fec3666d483a Mon Sep 17 00:00:00 2001 From: Brant Burnett Date: Fri, 29 Jan 2010 18:38:21 +0000 Subject: 'Changed --- tests/unit/core/core.html | 13 ++++++++++++- tests/unit/core/core.js | 13 +++++++++++-- ui/jquery.ui.core.js | 30 ++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/tests/unit/core/core.html b/tests/unit/core/core.html index 0b2235a99..1e6f49d33 100644 --- a/tests/unit/core/core.html +++ b/tests/unit/core/core.html @@ -14,6 +14,11 @@ + + @@ -95,9 +100,15 @@
-
+
+
+
+
+
+
+
diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 23292671a..c94241f19 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -49,11 +49,20 @@ test('focus', function() { }); test('zIndex', function() { - var el = $('#zIndexAutoWithParent'); + var el = $('#zIndexAutoWithParent'), + parent = el.parent(); equals(el.zIndex(), 100, 'zIndex traverses up to find value'); - equals(el.zIndex(200), el, 'zIndex setter is chainable'); + equals(parent.zIndex(200), parent, 'zIndex setter is chainable'); equals(el.zIndex(), 200, 'zIndex setter changed zIndex'); + el = $('#zIndexAutoWithParentViaCSS'); + equals(el.zIndex(), 0, 'zIndex traverses up to find CSS value, not found because not positioned'); + + el = $('#zIndexAutoWithParentViaCSSPositioned'); + equals(el.zIndex(), 100, 'zIndex traverses up to find CSS value'); + el.parent().zIndex(200); + equals(el.zIndex(), 200, 'zIndex setter changed zIndex, overriding CSS'); + equals($('#zIndexAutoNoParent').zIndex(), 0, 'zIndex never explicitly set in hierarchy'); }); diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js index 934210348..2f238a01c 100644 --- a/ui/jquery.ui.core.js +++ b/ui/jquery.ui.core.js @@ -149,17 +149,27 @@ $.fn.extend({ if (zIndex !== undefined) { return this.css('zIndex', zIndex); } - - var elem = this[0]; - while (elem && elem.style) { - // IE returns 0 when zIndex is not specified - // other browsers return an empty string - // we ignore the case of nested elements with an explicit value of 0 - //
- if (elem.style.zIndex !== '' && elem.style.zIndex !== 0) { - return +elem.style.zIndex; + + if (this.length) { + var elem = $(this[0]), position, value; + while (elem.length && elem[0] !== document) { + // Ignore z-index if position is set to a value where z-index is ignored by the browser + // This makes behavior of this function consistent across browsers + // WebKit always returns auto if the element is positioned + position = elem.css('position'); + if (position == 'absolute' || position == 'relative' || position == 'fixed') + { + // IE returns 0 when zIndex is not specified + // other browsers return a string + // we ignore the case of nested elements with an explicit value of 0 + //
+ value = parseInt(elem.css('zIndex')); + if (!isNaN(value) && value != 0) { + return value; + } + } + elem = elem.parent(); } - elem = elem.parentNode; } return 0; -- cgit v1.2.3