New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup fails to open when built on its own #5742

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

Comments

Projects
None yet
2 participants
@gabrielschulhof
Contributor

gabrielschulhof commented Mar 8, 2013

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

This comment has been minimized.

Show comment
Hide comment
@gabrielschulhof

gabrielschulhof Mar 8, 2013

Contributor

For now, I've opted for solution 2.

Contributor

gabrielschulhof commented Mar 8, 2013

For now, I've opted for solution 2.

@dmethvin

This comment has been minimized.

Show comment
Hide comment
@dmethvin

dmethvin Mar 8, 2013

Member

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?

Member

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

This comment has been minimized.

Show comment
Hide comment
@gabrielschulhof

gabrielschulhof Mar 9, 2013

Contributor

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

Contributor

gabrielschulhof commented Mar 9, 2013

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

@gabrielschulhof

This comment has been minimized.

Show comment
Hide comment
@gabrielschulhof

gabrielschulhof Mar 9, 2013

Contributor

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 ...

Contributor

gabrielschulhof commented Mar 9, 2013

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

This comment has been minimized.

Show comment
Hide comment
@gabrielschulhof

gabrielschulhof Mar 9, 2013

Contributor

@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()

Contributor

gabrielschulhof commented Mar 9, 2013

@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 join this conversation on GitHub. Already have an account? Sign in to comment