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

Feature request: destroy method for all jQuery plugins #7166

Closed
retan opened this issue Mar 5, 2013 · 8 comments
Closed

Feature request: destroy method for all jQuery plugins #7166

retan opened this issue Mar 5, 2013 · 8 comments

Comments

@retan
Copy link

retan commented Mar 5, 2013

Hello

I've been struggling with this problem - the lack of destroy method, especially for Carousel - for a few evenings now. At first I tried to solve it from the outside of the plugins, in the script calling the plugins, trying to remove all elements, data, and events, that the plugins attach but with no luck (always at runtime some errors occur).

This evening, when I took a look inside boostrap.js., I have noticed, that most event handlers are attached without a namespace. This makes it difficult to track and unbind all events, that the plugins are attaching.

Why the need for destroy method? In my case I want some plugins (especially Carousel) to switch on and off, depending on the size of the window (on for wide window, off for narrow window). The state should be updated as the user resizes the window. And I don't want the running in background when they are not needed.

For the time being, I guess I will rewrite a bit my copy of bootstrap.js, adding the namespaces to event attachments, and some simple destroy, but I would appreciate if this feature would be available by default.

Regards
Oliwer

@mdo
Copy link
Member

mdo commented Mar 6, 2013

Please search next time: #6315.

@mdo mdo closed this as completed Mar 6, 2013
@retan
Copy link
Author

retan commented Mar 7, 2013

Sorry. I searched but I didn't see this one.

But I'm afraid the solution mentioned in this post isn't a a solution to my
problem or the lack of destroy method.
First of all, unbinding the "data-api" namespace deactivates all the
bootstrap plugins. In other words, this isn't allowing to deactivate the
selectively.
Secondly, I can see some event attachments in the JS code, that are not
using this namespace, in particular the ones attached with "one" method.
In case of carousel there is still the "setTimeout", which is not cancelled
unless you call the "pause" method.

All in all... what is written in the mentioned post is not a complete
solution, but a workaround that is not entirely solving the problem.
And I wasn't asking for solution, I was making a suggestion, a "feature
request".

Sorry for this tone.
I love what you have done with bootstrap. I'm using it for the first time
and I learned much working with it. But it irritates me when I see clearly,
that in such a great piece of code are some issues, that seem to be
completely overlook or disregarded.

Regards

Oliwer Hawlicki

e-mail: [email protected]
tel.kom.: +48 692 316 814

On 6 March 2013 18:55, Mark Otto [email protected] wrote:

Please search next time: #6315#6315
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7166#issuecomment-14515333
.

@meleyal
Copy link
Contributor

meleyal commented Apr 11, 2013

First of all, unbinding the "data-api" namespace deactivates all the
bootstrap plugins.

I think you can unbind e.g. just the typeahead events with:

$(document).off('.typeahead.data-api')

http://docs.jquery.com/Namespaced_Events

@retan
Copy link
Author

retan commented Apr 11, 2013

Maybe in case of typeahead that would work. But not with carousel.
Carousel is setting "setinterval" to invoke a function changing the slides.
Event if you unbinde the namespace, the "setinterval" is still running,
trying to change the slides. It becomes a mess if the slides where removed
with jQ.

I repeat again. Unbinding events is not a way to destroy a plugin (it's
just a step in destroying it). In case of carousel it doesn't even
deactivate it.

Pozdrawiam

Oliwer Hawlicki

e-mail: [email protected]
tel.kom.: +48 692 316 814

On 11 April 2013 10:40, William Meleyal [email protected] wrote:

First of all, unbinding the "data-api" namespace deactivates all the
bootstrap plugins.

I think you can unbind e.g. just the typeahead events with:

$(document).off('.typeahead.data-api')

http://docs.jquery.com/Namespaced_Events


Reply to this email directly or view it on GitHubhttps://github.com//issues/7166#issuecomment-16222670
.

@phkavitha
Copy link

@retan , Did you find the solution to deactivate the bootstrap carousel plugin?

@retan
Copy link
Author

retan commented Oct 10, 2013

Hi

Yes I did. Be aware that I was working with 2.3.0 version (not the current
3.0.0).
What I did is not exactly deactivating, but rather destroying the carousel.

In short...
I made some changes in bootstrap.js file. Frow what I can see (unfortunatly
it was so long ago, that I don't remember much), I've added to all event
atachments the "carousel" namespace, though I think I didn't use this
feature in the end (for deactivating).

Instead in the main.js file:
var $c = $('.carousel');
....
$c.carousel('pause');
$(window).off('.carousel');
$c.each(function() {
$(this).removeData('carousel');
});

The pause method involeves calling "clearInterval()" (whithout doing it,
the function set with "setInterval" would be fired after deactivation).
I don't remember if the "$(window).off('.carousel')" was necessary. When I
now look at the code I don't see any events attached by the plugin to the
window object (you can try without it).
And at the end removing data with "removeData".

At that time I was looking for a quick solution so it's a bit of a mess,
but obviously it could be done better, for example by adding a proper
"destroy" method to the plugin.

Good luck!

Oliwer Hawlicki

On 10 October 2013 15:36, phkavitha [email protected] wrote:

@retan https://github.com/retan , Did you find the solution to
deactivate the bootstrap carousel plugin?


Reply to this email directly or view it on GitHubhttps://github.com//issues/7166#issuecomment-26053712
.

@phkavitha
Copy link

@retan , Thanks for your help. I did tried your solution. In fact, the carousel gets stopped. But, when I take the heap snapshot, I can find the whole carousel html under Detached DOM tree.

@retan
Copy link
Author

retan commented Oct 21, 2013

Hello

I'm afraid, that there is no. At that time I didn't have time to write one.
What I have written about only deactivates the carousel.

Pozdrawiam

Oliwer Hawlicki

e-mail: [email protected]
tel.kom.: +48 692 316 814

On 21 October 2013 07:17, phkavitha [email protected] wrote:

@retan https://github.com/retan , Thanks for your help. I did tried
your solution. In fact, the carousel gets stopped. But, when I take the
heap snapshot, I can find the whole carousel html under Detached DOM tree.
Is there a single method, with which can unbind all the javascript events
and destroy the plugin?


Reply to this email directly or view it on GitHubhttps://github.com//issues/7166#issuecomment-26693344
.

@twbs twbs locked and limited conversation to collaborators Apr 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants