How can I order a complete jQuery suite?

I need to get the topmost ".ui-dialog" element in a wrapped set.

My first thought was to do something like this:

var topDialog = $(".ui-dialog").orderBy("[style*=z-index]").eq(0);

Is there a better way to do this than writing a loop to check the values?

Edit: Just to clarify ... I need to be able to get the topmost element at any given point during the life of the page (after opening and closing several dialog boxes). Nick Craver’s response to using the maxZ variable does not work, since the variable does not decrease when deleting dialogs.

Here is the loop that I use when I close a dialog that seems ugly to me:

// Enable printing of the top-most dialog or #page
if ($(".ui-dialog").length > 0) {

    var top = $(".ui-dialog").first();

    $(".ui-dialog").each(function () {
        if ($(this).css("z-index") > top.css("z-index")) {
            top = $(this);
        }
    });

    top.removeClass("dont-print");

} else {

    $("#page").removeClass("dont-print");

}
+3
source share
3

, z-index , : $.ui.dialog.maxZ, , .

, , ( ), :

var topDialog = $(".ui-dialog").filter(function() { 
                  return $(this).css("z-index") == $.ui.dialog.maxZ;
                });

.

+5

:)

jQuery.expr[':'].highestModal = function(node) {
    return $(node).css('z-index') == $.ui.dialog.maxZ;
};

(, : P upvote!)

...

$('.ui-dialog:highestModal');
+2
    function clearUiMaxZ() {
        setTimeout(function() {
            $.ui.dialog.overlay.maxZ = 0;
            $.ui.dialog.maxZ = 0;
        }, 100);
    }

Call this function in dialog closing, it will reset maxZ.

0
source

Source: https://habr.com/ru/post/1777365/


All Articles