vovik (owner)

Revisions

gist: 211453 Download_button fork
public
Public Clone URL: git://gist.github.com/211453.git
Embed All Files: show embed
jQuery.fn.zIndices.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* usage example:
* $('body').zIndices()
*
* Returns a hash with z-indices as keys whose corresponding
* values are elements with that z-index set. Any z-index <z>
* having more than one element will also be in the hash
* under the key '!<z>' (to be sorted together near the top),
* as well as the regular key, '<z>'.
*/
jQuery.fn.zIndices = function() {
    var indices = {};
    
    this.each(function() {
        var fn = arguments.callee;
        $(this).contents().each(function() {
            var z = NaN;
            if (this.style) {
                z = parseInt(this.style.zIndex);
            }
            if (!isNaN(z)) {
                if (typeof indices[z] === 'undefined') {
                    indices[z] = [this];
                } else {
                    indices[z].push(this);
                }
            }
            fn.apply($(this));
        });
    });
    
    return indices;
}