aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/core/core.html5
-rw-r--r--tests/unit/core/core.js9
-rw-r--r--ui/ui.core.js20
3 files changed, 34 insertions, 0 deletions
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 @@
</div>
<div id="aria"></div>
+
+ <div id="zIndex100" style="z-index: 100;">
+ <div id="zIndexAutoWithParent"></div>
+ </div>
+ <div id="zIndexAutoNoParent"></div>
</div>
</body>
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
+ // <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;
}
});