enyo / opentip

Opentip is an open source javascript tooltip based on the protoype framework.
http://www.opentip.org
1.25k stars 401 forks source link

does hide() also destroy? #41

Closed bmcgin closed 11 years ago

bmcgin commented 11 years ago

If the tool tip is created programmatically, and shown on create and then hidden on keydown, will the tool tip also be destroyed automatically when hidden?

I am using Opentip for form validation so when an error is detected, new Opentip() is called and then when the user starts to type, the tool tip hides.

This one page has many form fields in many tab groups. The browser stays at one url for hours. Tabs and html windows ajax dynamic content as needed.

Guess the point is "new Opentip()" might be called hundreds of times so unless these are getting destroyed or there is a better way to show the tool tip, this might present a memory leak.

Do i need to worry about this or does Opentip handle it?

enyo commented 11 years ago

Good question. I had a very similar discussion recently #35 where I argued that having the possibility to remove the actual DOM elements was something I'd like to implement in the near future, but have been convinced that performing DOM manipulation on the Opentips is more important – but that conflicts with your needs.

For now: Opentip HTML elements are only created when they are shown and not when the Opentip is created. So your save creating lots of Opentips. But right now the HTML elements are never removed (I figured that removing + readding the HTML elements is more expensive than just hiding them).

Would a "removeElementsOnHide" option satisfy your needs?

bmcgin commented 11 years ago

Adding the option "removeElementsOnHIde" would be a great solution. I was wondering if I needed to set something to null or if there was a procedure to follow. I haven't looked at the code as it's working great.

enyo commented 11 years ago

Ok. It's not really on top of my priority list though. If you have performance issues and need this to be done sooner than later just bump this issue.

bmcgin commented 11 years ago

Thank you for considering adding it.

By the way, I really like the Native option of the code. Thank you for making this work without the use of a framework. This was a huge reason I tried opentip.

enyo commented 11 years ago

Thanks :) It caused a lot of headaches

enyo commented 11 years ago

Oh no... I just realised that I lied. Some basic elements are always inserted when an Opentip is constructed... :-/ I'll have a look at it.

enyo commented 11 years ago

removeElementsOnHide is now a valid option.

bmcgin commented 11 years ago

Wow that was fast. Thank you!!!! I'll try it out today.

Jogrin commented 11 years ago

First of all, congratulation for your great job.. i would like to ask you one thing about Opentip, and more specifically about the destruction of the element. The removeElementsOnHide function is great, but is it possibile to ask a function for destroy the element not only when is hided? Because i use the cache and the function above it's not useful to me in this case..

enyo commented 11 years ago

What do you mean? You can't just delete the elements when it's visible obviously. But you can look at the source and look for "Removing HTML elements." to see how they are removed. You can just do that anytime you want. Just make sure that the tooltip isn't visible.

Jogrin commented 11 years ago

I think I explained myself badly, i don't want to destroy the element when it's visible, i meant that it will be useful add a function, for example "destroy", to destroy the element so it can be substitute by another (useful for repeated ajax call when the target changes its state), or an "update content" function, is only a suggestion obviously, currently i do it looking at the source of "Removing HTML elements".

enyo commented 11 years ago

There is a .setContent() method. You can set options.cache to false as well so it will be redrawn every time, and fetch the AJAX content every time.

Jogrin commented 11 years ago

done it, thanks

fluxsaas commented 9 years ago

Hey,

the global namespace Opentip.tips keeps track of the tooltips despite the fact, that we use the option 'removeElementsOnHide', right?

After using my onPageApp (quite heavily) for around 5 minutes i have ~ 400 tooltips created. I have also DOM elements removed from the page but still the tooltips availabale in the Opentip.tips list.

Do you have a trick to cleanup those tooltips completely to avoid memory leaks?

jchevreau commented 8 years ago

Hey,

I have had the same issues, where i run a check every 2 seconds on a page. This is not only increasing the Openytip.tips array but it also keep on adding loads of containers which makes the shadow go overboard. I have just digged into the script and added a fix, very simple but it sorted me out. I am using the opentip-native js file and i have also changed the default attribute that it adds onto the element, i.e. data-id to data-otid as i am already using data-id.

So the fix is (opentip-native.js line +- 1444):

Opentip.findElements = function(){ .... for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[i]; **//-_ check if the element has been covered already, if so, ignore and jump to the next element if(element.getAttribute('data-otid') !== null) { continue; }** } ... }

Next version, it would be great that the above solution can be implemented as well as allowing the user to change the default attribute as data-id may well be used.

Hope it helps.

Cheers