Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blocking background content and focus on modal dialog

Tags:

jquery

I am trying to block the background with my two jquery modal dialogs until the user closes the window. Any idea on how to achieve this?

By "blocking the background" I mean disabling the other elements on the page (i.e. making other elements unclickable).

Here is my code below:

            // sign up dialog
        $( "#aboutus_dialog" ).dialog({
            autoOpen: false,
            show: "fadein",
            hide: "fadeout"
        });

        // sign up dialog
        $( "#signup_dialog" ).dialog({
            autoOpen: false,
            show: "fadein",
            hide: "fadeout"
        });     

        // about us modal
        $('#aboutus').click(function() { 
            modal: true,
            $("#aboutus_dialog").dialog("open");
            return false;
        });

        // about us modal
        $('#signup').click(function() { 
            $("#signup_dialog").dialog("open");
            return false;
        });
    });
like image 981
methuselah Avatar asked Jun 25 '12 22:06

methuselah


People also ask

How do you keep focus within modal dialog?

tab, shift + tab and enter key and focus should be trapped inside modal and should not go out after pressing tab key multiple times.

How do I disable background when pop modal is open?

The key idea is to have pointer-events: none; for the body when modal is open. But the specific elements you want to be interacted with should have e.g. pointer-events: auto; . In the example you can click both buttons when dialog is hidden, but only Toggle Dialog button when dialog is shown.

How can restrict the Tab key press only within the modal popup?

Using aria-modal="true" replaces the need to add aria-hidden="true" for elements that should be hidden from screen readers and not receive keyboard focus outside the modal while the modal is open.

What does modal dialog do?

Definition: A modal dialog is a dialog that appears on top of the main content and moves the system into a special mode requiring user interaction. This dialog disables the main content until the user explicitly interacts with the modal dialog.


2 Answers

Is this what you're looking for

http://jqueryui.com/demos/dialog/#modal

It does block the background you have the view source button. Do you have any overlay at all?

Try setting it manually(not recommended but rather trough css) :

$(".ui-widget-overlay").attr('style','background-color: #000; opacity:1; z-index:1000;');

And of course setting the modal option to true.

If the color is too strong decrease the opacity accordingly.

like image 143
ant Avatar answered Sep 17 '22 17:09

ant


when i changed modal value to 'true' (in angular js) all background elements got disabled.here is my code attached:

    var options = {
                    autoOpen : false,
                    modal : true,
                    close : function(event, ui) {
                        console.log("Predefined close");
                    }
                 };

    dialogService.open("myDialog" + k, "dialogTemplateload.html", model, options)
    .then(
            function(result) {
                console.log("Close");
                console.log(result);
            },
            function(error) {
                console.log("Cancelled");
            }
        );
like image 36
Greeshma Avatar answered Sep 18 '22 17:09

Greeshma