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

does hide() also destroy? #41

Closed
bmcgin opened this issue Mar 13, 2013 · 15 comments
Closed

does hide() also destroy? #41

bmcgin opened this issue Mar 13, 2013 · 15 comments

Comments

@bmcgin
Copy link

bmcgin commented Mar 13, 2013

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
Copy link
Owner

enyo commented Mar 14, 2013

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
Copy link
Author

bmcgin commented Mar 14, 2013

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
Copy link
Owner

enyo commented Mar 14, 2013

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
Copy link
Author

bmcgin commented Mar 14, 2013

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
Copy link
Owner

enyo commented Mar 14, 2013

Thanks :) It caused a lot of headaches

@enyo
Copy link
Owner

enyo commented Mar 14, 2013

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
Copy link
Owner

enyo commented Mar 16, 2013

removeElementsOnHide is now a valid option.

@bmcgin
Copy link
Author

bmcgin commented Mar 16, 2013

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

@Jogrin
Copy link

Jogrin commented Apr 3, 2013

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
Copy link
Owner

enyo commented Apr 3, 2013

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
Copy link

Jogrin commented Apr 3, 2013

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
Copy link
Owner

enyo commented Apr 3, 2013

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
Copy link

Jogrin commented Apr 8, 2013

done it, thanks

@fluxsaas
Copy link

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
Copy link

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

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

5 participants