Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Popup fails to open when built on its own #5742

Closed
gabrielschulhof opened this issue Mar 8, 2013 · 5 comments
Closed

Popup fails to open when built on its own #5742

gabrielschulhof opened this issue Mar 8, 2013 · 5 comments

Comments

@gabrielschulhof
Copy link

Steps to reproduce:

  1. grunt js:compile --modules=widgets/popup
  2. Create a page that contains the resulting code.
  3. Attempt to open the popup - for example, from the console with $( "#thePopup" ).popup( "open" );

At this point, the popup fails to appear on the screen. The reason:

The popup attaches to "beforenavigate", and completes its opening sequence in response to the event.

Unfortunately, when build without init, the library does not call _registerInternalEvents(), which would cause a "navigate" binding to be added which, in turn, would cause the navigate special event's setup function to be called.

Popup uses "beforenavigate" before it attaches to navigate. "beforenavigate" is emitted by the navigate event code in addition to the navigate event. However, since it first attaches to "beforenavigate" and only then to "navigate", it never attaches to "navigate", meaning that, unless init runs as part of library load, the "navigate" event will not be initialized, and thus the popup will never receive the "beforenavigate" event it needs to complete the opening sequence.

Possible solutions:

  1. Popup depends on init. This is bad because there's no reason for this, other than to have init run _registerInternalEvents, which attaches a permanent navigate handler, causing the event to become initialized.
  2. $.mobile.document.one( "navigate", $.noop ); before attaching to beforenavigate. This is not an elegant solution.
  3. Initialize the "navigate" event even if somebody attaches to "beforenavigate" and not "navigate". I'm not sure how to accomplish this.
@gabrielschulhof
Copy link
Author

For now, I've opted for solution 2.

@dmethvin
Copy link
Contributor

dmethvin commented Mar 8, 2013

You could define jQuery.event.special.beforenavigate with setup/teardown functions so that you only do the attaching to navigate if beforenavigate is used. Does that help?

@gabrielschulhof
Copy link
Author

Now, to figure out why it also fails to close ...

@gabrielschulhof
Copy link
Author

It fails to close because it hooks up to the body to receive nav events, however, nav events are fired on the window. When there is no page life cycle handler, pagebeforechange events are not fired on the body, so the popup does not react at all. Solution? Forget about this.options.container, and listen on the window. Let's see if this has any negative consequences ...

@gabrielschulhof
Copy link
Author

@dmethvin
I think I'm going to define jQuery.event.special.beforenavigate with a setup that consists of $( window ).on( "navigate", someFunctionThatsANoopDeclaredInsideTheNavigateEventModulesIIFE );

The teardown will be the same, but with .off()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants