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

Dynamic content #62

Closed
Aspie96 opened this issue Jun 27, 2016 · 9 comments
Closed

Dynamic content #62

Aspie96 opened this issue Jun 27, 2016 · 9 comments
Labels
community question all in for feedback

Comments

@Aspie96
Copy link

Aspie96 commented Jun 27, 2016

Hi, still me.
I know it would require some major modifications, but is support for dynamic content planned to be implemented?

The code contains scripts like:

var Tooltips = document.querySelectorAll('[data-toggle=tooltip]'), i = 0, tpl = Tooltips.length;
for (i;i<tpl;i++){  
    var item = Tooltips[i], options = {};
    options.animation = item.getAttribute('data-animation');
    options.placement = item.getAttribute('data-placement');
    options.duration = item.getAttribute('data-duration');
    options.delay = item.getAttribute('data-delay');
    new Tooltip(item,options);
}

The problem with that is that it will not work with dinamically added content (which many sites use).

There are already some events attached to document, such as in:

document.addEventListener('click', this.close, false);

There should be only one event handler for clicks, attached to the document, so that it can work with dynamic content as well.

Although the code would need to be modified in different places, it should not be a big problem per se.
The problem is when there is a FOR cycle like the one I quoted before (which, of course, could not be done), but there should be some kind of work-around for each specific case.

Thank you very much in advance!

@thednp
Copy link
Owner

thednp commented Jun 27, 2016

It has been discussed before, this cannot work.

@thednp thednp closed this as completed Jun 27, 2016
@Aspie96
Copy link
Author

Aspie96 commented Jun 28, 2016

In my case, thouhg, I have to edit the content of the page using innerHTML (because I use templates).

Is there any workaround to make it work in this case?

@thednp
Copy link
Owner

thednp commented Jun 28, 2016

There is no workaround, there's only the hard way, re-init the functions you need via

new Tooltip('selector');

and you are fine.

UPDATE: you should hook this on the page update or your event to add more items to the page.

@Aspie96
Copy link
Author

Aspie96 commented Apr 14, 2017

Just in case someone wants to check it out too:

https://github.com/Aspie96/bootstrap.native.dynamic

@mathieuleclaire
Copy link

@Aspie96 You're lib is really cool, thanks ! I had typically the problem of generating tabs dynamically and I did find any options to run them properly at runtime. This work properly without any modification of my code.

@Aspie96
Copy link
Author

Aspie96 commented Apr 19, 2017

Thank you, mate!

As for the reasons NOT to use my library, read this:
#102 (comment)

I am not suggesting that you should not use it, of course (I shared it precisely so that you could use it), but I am saying that you should check that out first.

@mathieuleclaire
Copy link

What do you mean, it renders the page slower ?

@thednp
Copy link
Owner

thednp commented Apr 19, 2017

No, but the JavaScript runtime is much slower, and gets even slower the more elements you append to the document, a quick info on that here (I hope I didn't missclick the link)

@Aspie96
Copy link
Author

Aspie96 commented Apr 19, 2017

Still, I am using my version on my own website and it works perfectly (and, of course, many many people use jQuery or other libraries), so it might be a completely fine solution from what you wanna do.

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

No branches or pull requests

3 participants