Skip to content

[Misc] Updated the method to call init() using newer XWiki API#2

Open
wthrajat wants to merge 1 commit intoxwiki-contrib:masterfrom
wthrajat:master
Open

[Misc] Updated the method to call init() using newer XWiki API#2
wthrajat wants to merge 1 commit intoxwiki-contrib:masterfrom
wthrajat:master

Conversation

@wthrajat
Copy link
Member

@wthrajat wthrajat commented Aug 3, 2023

This PR doesn't change anything except for using a shorter method to first check for DOM loaded and then for DOM updated.
Idea credits: @mflorea

This calls init:

  • first when DOM is ready: $(init)
  • then each time DOM is updated: .on('xwiki:dom:updated', init);

Similar usecase: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-war/src/main/webapp/resources/uicomponents/widgets/tree.js#L32

See: https://api.jquery.com/jquery/#jQuery3

Copy link
Member

@9inpachi 9inpachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I have one minor comment.

leafletCommons.updateURLWithMapState();
});

$(init).on('xwiki:dom:updated', init);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is inside the init function. It won't work because the init function will never be called and even if it's called like this, it will result in an infinite recursion.

You can move this statement outside the scope of the init function and it should work just fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@9inpachi is right. This line needs to be moved below, outside the init function.

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

Successfully merging this pull request may close these issues.

3 participants