Skip to content
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

Scroll spy with dinamically loaded content #41

Closed
r0610205 opened this issue May 28, 2014 · 4 comments
Closed

Scroll spy with dinamically loaded content #41

r0610205 opened this issue May 28, 2014 · 4 comments

Comments

@r0610205
Copy link

If the template containing scrolling markup is loaded dynamically, then scroll spy stops working after template was reloaded for the first time.

Example at http://plnkr.co/edit/FdECKs0ARM89qEB5xitv?p=preview demonstrates simple navigation between two documents, which of those represented by the same layout. If user clicks on 'Document 1', scroll spy works and active class is assigned to the links. However if user clicks on 'Document 2', scroll spy stops working. Only page reload can help.

What happens here is that on dynamic reload container is destroyed while the context remains. I didn't figure out yet why exactly this happens. If it cannot be fixed I can suggest extend condition (!context.container) in addSpy function. In the example above, after user clicks on the second link context.container is not empty, it just not attached to the DOM.

@oblador
Copy link
Owner

oblador commented May 29, 2014

Solved your case, but there might be other uses with ui-router that still has issues. It was firing events like crazy so I just skipped them and resorted to only $locationChangeSuccess. If you have a failing example (most likely if state changes but not location), please post a new plunker :-)

@r0610205
Copy link
Author

Please, see example without ui-router:
http://plnkr.co/edit/C5YZ6ZHVjGpsR0GXkUWu?p=preview

In this case template including scroll spy is loaded via ngInclude and thus does not change location.

Here is the plunker that works with ui-router as well as with the example above.
http://plnkr.co/edit/OnhOIoNw7q14fPcNm1dY?p=preview
It contains only one change against original code (before fix #41). See line 282 in plunker:

if (!context.container || (context.container && !$.contains(document.documentElement, context.container[0]))) {

This line provides rebinding anytime container does not exist in DOM.

@oblador
Copy link
Owner

oblador commented May 29, 2014

Your plunker introduces a jQuery dependency which I'm not comfortable with. Reverted previous changes and used a pure js implementation instead.

@r0610205
Copy link
Author

It is better without jQuery for sure. Thanks!

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

No branches or pull requests

2 participants