You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andrew Geery <an...@gmail.com> on 2012/03/14 21:34:47 UTC

weird interaction between ModalWindow and jQuery mousedown binding

I'm using the jQuery Multiselector (
http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ ) with Wicket
1.4.19 (via jqWicket 0.6).  The multi-selector was straightforward to
integrate with Wicket and use on a regular page.

Using it in a ModalWindow was a little trickier because you have to
manually add the JS + CSS to the header of the ModalWindow (which jqWicket
takes care of for you on a regular page).

Here's my problem:

When I click outside of a multi-selector component on a regular page, the
multiselector closes.  However, when I click outside of a multi-selector in
the containing ModalWindow, it does not.

I've traced the problem back to the following line in the multiselector
(the self.close() method simply closes/rolls up the multiselector options):

           $(document).bind('mousedown.multiselect', function (e) {
                if (self._isOpen && !$.contains(self.menu[0], e.target) &&
!$.contains(self.button[0], e.target) && e.target !== self.button[0]) {
                    self.close();
                }
           });

I've verified that the mousedown bind does indeed happen in both the
regular page and in the ModalWindow.

The difference is that, on a regular page, the handler function is called
when I click anywhere on the page (i.e., jQuery detects the mousdown
event).  However, in the ModalWindow, the handler is not called when I
click in the ModalWindow (i.e., jQuery does not detect the mousedown event
in the context of the ModalWindow).  To make things more interesting, the
handler is called if I click on the page *outside* of the ModalWindow.

Is there anything in a ModalWindow that would make jQuery bind not work for
mousedown events that target the ModalWindow itself?

Thanks
Andrew

Re: weird interaction between ModalWindow and jQuery mousedown binding

Posted by Andrew Geery <an...@gmail.com>.
Line 749 of modal.js seems to have the answer that, yes, mousedown events
don't bubble out of a ModalWindow -- am I reading that correctly?

"<div class=\"w_content_1\" onmousedown=\"if (Wicket.Browser.isSafari()) {
event.ignore = true; } else { Wicket.stopEvent(event); } \">"+

Thanks
Andrew

On Wed, Mar 14, 2012 at 4:34 PM, Andrew Geery <an...@gmail.com>wrote:

> I'm using the jQuery Multiselector (
> http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ ) with
> Wicket 1.4.19 (via jqWicket 0.6).  The multi-selector was straightforward
> to integrate with Wicket and use on a regular page.
>
> Using it in a ModalWindow was a little trickier because you have to
> manually add the JS + CSS to the header of the ModalWindow (which jqWicket
> takes care of for you on a regular page).
>
>  Here's my problem:
>
> When I click outside of a multi-selector component on a regular page, the
> multiselector closes.  However, when I click outside of a multi-selector in
> the containing ModalWindow, it does not.
>
> I've traced the problem back to the following line in the multiselector
> (the self.close() method simply closes/rolls up the multiselector options):
>
>            $(document).bind('mousedown.multiselect', function (e) {
>                 if (self._isOpen && !$.contains(self.menu[0], e.target) &&
> !$.contains(self.button[0], e.target) && e.target !== self.button[0]) {
>                     self.close();
>                 }
>            });
>
> I've verified that the mousedown bind does indeed happen in both the
> regular page and in the ModalWindow.
>
> The difference is that, on a regular page, the handler function is called
> when I click anywhere on the page (i.e., jQuery detects the mousdown
> event).  However, in the ModalWindow, the handler is not called when I
> click in the ModalWindow (i.e., jQuery does not detect the mousedown event
> in the context of the ModalWindow).  To make things more interesting, the
> handler is called if I click on the page *outside* of the ModalWindow.
>
> Is there anything in a ModalWindow that would make jQuery bind not work
> for mousedown events that target the ModalWindow itself?
>
> Thanks
> Andrew
>
>