From 5e89481ab851e28380f10675f6620345150c3007 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 5 Aug 2009 13:30:55 +0000 Subject: [PATCH] Added zIndex method. Fixes #4709 - Add zIndex setter/getter method. --- tests/unit/core/core.html | 5 +++++ tests/unit/core/core.js | 9 +++++++++ ui/ui.core.js | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/tests/unit/core/core.html b/tests/unit/core/core.html index f6c3bccd8..71d06b29a 100644 --- a/tests/unit/core/core.html +++ b/tests/unit/core/core.html @@ -93,6 +93,11 @@
+ +
+
+
+
diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 96a197aa5..f26257053 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -48,4 +48,13 @@ test('focus', function() { other.focus(); }); +test('zIndex', function() { + var el = $('#zIndexAutoWithParent'); + equals(el.zIndex(), 100, 'zIndex traverses up to find value'); + equals(el.zIndex(200), el, 'zIndex setter is chainable'); + equals(el.zIndex(), 200, 'zIndex setter changed zIndex'); + + equals($('#zIndexAutoNoParent').zIndex(), 0, 'zIndex never explicitly set in hierarchy'); +}); + })(jQuery); diff --git a/ui/ui.core.js b/ui/ui.core.js index 0e8be9abe..e166f0f06 100644 --- a/ui/ui.core.js +++ b/ui/ui.core.js @@ -184,6 +184,26 @@ $.fn.extend({ } return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent; + }, + + zIndex: function(zIndex) { + 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; + } + elem = elem.parentNode; + } + + return 0; } }); -- 2.39.5