Skip to content
Permalink
Browse files

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

  • Loading branch information
scottgonzalez committed Aug 5, 2009
1 parent 44d3893 commit 5e89481ab851e28380f10675f6620345150c3007
Showing with 34 additions and 0 deletions.
  1. +5 −0 tests/unit/core/core.html
  2. +9 −0 tests/unit/core/core.js
  3. +20 −0 ui/ui.core.js
@@ -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>
@@ -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);
@@ -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;
}
});

0 comments on commit 5e89481

Please sign in to comment.
You can’t perform that action at this time.