weird interaction between ModalWindow and jQuery mousedown binding

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

weird interaction between ModalWindow and jQuery mousedown binding

Andrew Geery
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
Reply | Threaded
Open this post in threaded view
|

Re: weird interaction between ModalWindow and jQuery mousedown binding

Andrew Geery
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 <[hidden email]>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
>
>