r3031 committed - Added zIndex method. Fixes #4709 - Add zIndex setter/getter method.

r3031 committed - Added zIndex method. Fixes #4709 - Add zIndex setter/getter method.


Revision: 3031
Author: scott.gonzalez
Date: Wed Aug 5 06:30:55 2009
Log: Added zIndex method. Fixes #4709 - Add zIndex setter/getter method.
http://code.google.com/p/jquery-ui/source/detail?r=3031
Modified:
/trunk/tests/unit/core/core.html
/trunk/tests/unit/core/core.js
/trunk/ui/ui.core.js
=======================================
--- /trunk/tests/unit/core/core.html    Wed May 27 10:50:56 2009
+++ /trunk/tests/unit/core/core.html    Wed Aug 5 06:30:55 2009
@@ -93,6 +93,11 @@
    </div>
    <div id="aria"></div>
+
+    <div id="zIndex100" style="z-index: 100;">
+        <div id="zIndexAutoWithParent"></div>
+    </div>
+    <div id="zIndexAutoNoParent"></div>
</div>
</body>
=======================================
--- /trunk/tests/unit/core/core.js    Sat Apr 18 06:04:07 2009
+++ /trunk/tests/unit/core/core.js    Wed Aug 5 06:30:55 2009
@@ -48,4 +48,13 @@
    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);
=======================================
--- /trunk/ui/ui.core.js    Fri Jul 10 17:30:46 2009
+++ /trunk/ui/ui.core.js    Wed Aug 5 06:30:55 2009
@@ -184,6 +184,26 @@
        }
        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
+            // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
+            if (elem.style.zIndex !== '' && elem.style.zIndex !== 0) {
+                return +elem.style.zIndex;
+            }
+            elem = elem.parentNode;
+        }
+
+        return 0;
    }
});