mir3z / texthighlighter

-- NO LONGER MAINTAINED -- TextHighlighter allows you to highlight text on web pages.
http://mir3z.github.com/texthighlighter/
MIT License
230 stars 101 forks source link

destroy() method doesn't work to me #18

Open TomThak opened 8 years ago

TomThak commented 8 years ago

Hello, is there any possibility to create demo with .destroy() method?

I tried to initialize the plug in on click and I would like to have off button to switch it off, so I tried destroy() method, but it did not stop highlighting. Once I switch it on, I cannot switch it off. I would like to have it like "higlight pen" button on my page and when you select this tool you can highlight text. If you switch it of, it should not highlight anymore until you selet the tool again.

example:

jQuery('#textHighlightHandlerOn').click(function(e){ e.preventDefault(); hltr = new TextHighlighter(sandbox); }); jQuery('#textHighlightHandlerOff').click(function(e){ e.preventDefault(); hltr.destroy(); });

Thanks for the details!

papadako commented 6 years ago

Hi there, we seem to have the same problem. We call destroy() but the events for highlighting are still triggered. Anyone have any clue about this problem (it seems that mir3z is not maintaining this project anymore...)?.

nhulongctk10 commented 6 years ago

I also got the same problem. @@

EstudoParaValer commented 3 years ago

You can use a method (which I don't know if it's the most suitable), but I had the same problem and now I've managed to solve it. The method is as follows:

"Your instance" .doHighlight = () => {};

If you prefer, before deleting, simply store the "doHighlight" function in a variable beforehand. Thus, to restore, simply assign the content of the variable to "doHighlight". Example: Before: var MyFunction = "Your instance" .doHighlight; "Your instance" .doHighlight = () => {};

After "Your instance" .doHighlight = MyFunction; In Brazil, we call this "Gambiarra"