Hello,
completedSlide :function(el, ev){
carouselRef.remove();
What is the best way to integrate 3rd party plugins to a controller? Specifically, I want to add and remove them through a controller so that they do not cause memory leaks. I also would like to be able to have multiple instances of the plugin.
Using Twitter Bootstrap's carousel.js as an example.
My approach thus far has been to rewrite such plugin and turn it into a jmvc/canjs controller, so that I could prevent memory leaks by simply calling controller.destroy(). However, I am wondering if there is a more efficient way of removing plugins with out having to refactor them.
I would like to be able to create a controller rwdcarousel.js, and then with in the controller instantiate the plugin on an element of the mustache template I have loaded.
init : function(){
....
var carouselRef = $('#elementINmustacheTemplate').carousel();
carouselRef.bind('slide', this.carouselSlide)
carouselRef.bind('slid', this.completedSlide);
}
carouselSlide :function(el, ev){
I would like to be able to create a controller rwdcarousel.js, and then with in the controller instantiate the plugin on an element of the mustache template I have loaded.
init : function(){
....
var carouselRef = $('#elementINmustacheTemplate').carousel();
carouselRef.bind('slide', this.carouselSlide)
carouselRef.bind('slid', this.completedSlide);
}
carouselSlide :function(el, ev){
}
completedSlide :function(el, ev){
}
destroy:function(){
carouselRef.unbind('slide', this.carouselSlide)
carouselRef.unbind('slide', this. completedSlide)destroy:function(){
carouselRef.unbind('slide', this.carouselSlide)
carouselRef.remove();
}
Using this approach would I
- prevent memory leaks when destroying the controller that holds the reference to the controller.
- even though I have uses steal to load the plugin carousel.js and then created new carousel instance on specific elements, will each of these
carousel instances retain their own scope... so that if I have multiple rwdcarousel controllers that have their own 'carousel' instance, each event triggered by a carousel instance will only be handled by its containing rwdcarousel controller.
- prevent memory leaks when destroying the controller that holds the reference to the controller.
- even though I have uses steal to load the plugin carousel.js and then created new carousel instance on specific elements, will each of these
carousel instances retain their own scope... so that if I have multiple rwdcarousel controllers that have their own 'carousel' instance, each event triggered by a carousel instance will only be handled by its containing rwdcarousel controller.
If more clarification is need, I can rephrase my question...
Thanks...
Thanks...