0

I'm having 2 issues with a JQuery dialog widget that I'm trying to solve.

1) When the dialog is modal, on some computer screens (where the zoom & resolution can vary) the dialog introduces scroll bars to the document. There's obviously an overlay just under the dialog box, and I'm assuming that that's what's causing the scrollbars to appear. Do you know how I can avoid that from happening i) at all resolutions and ii) at any zoom

2) For a particular dialog, I want to make the 'Enter' button produce a default action. The code I've tried so far is below, but I can't make it work. To be clear, I've already looked at the solutions here. And the div is certainly focused on opening. But I keep getting these console errors in Chrome, when I press [Enter].

    FOCUS set
    ...

    event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.

This is the code I've tried so far:

    var opts =    {      
      modal: true,
      open: function() {
        $(this).focus();
      }, 
      focus: function(event, ui) {
        console.log('FOCUS set');

        $(this)
          .keyup(function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            if (code == 10 || code == 13) alert('Enter key was pressed.');
            e.preventDefault();
            console.log('key pressed.');
          });
      },
      ...
    }

    $('#mydiv').dialog(opts);

1 Answer 1

1

Here is solution for closing using Enter:

http://jsfiddle.net/J9KvV/

JavaScript

$(document).ready(function () {
    $('#dialog').dialog();
    $(document).keydown(function (event) {
        var dialog = $('#dialog');
        if (dialog.dialog('isOpen')) {
            if (event.keyCode === 13) {
                dialog.dialog('close');
            }
        }
    });
});

HTML

<div id="dialog" title="Header">
My Window
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that did it. I didn't realise you had to put the keydown event handler on the entire document itself. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.