Skip to content

Instantly share code, notes, and snippets.

@benhuson
Created March 28, 2012 18:00
Show Gist options
  • Save benhuson/2228781 to your computer and use it in GitHub Desktop.
Save benhuson/2228781 to your computer and use it in GitHub Desktop.
TouchCarousel - Detach
/* Detach carousel - same as destroy but content is not removed */
detach: function() {
this.stopAutoplay();
this._itemsWrapper.unbind(this._downEvent);
$(document).unbind(this._moveEvent).unbind(this._upEvent);
$(window).unbind(this._resizeEvent);
if(this.settings.keyboardNav) {
$(document).unbind("keydown.touchcarousel");
}
if (this._dragContainer.parent().hasClass('touchcarousel-wrapper')) {
this.setXPos(0);
this._dragContainer.unwrap();
}
},
@japborst
Copy link

Hi!

When using your detach function, which I missed in the official release - thanks for that - , I am getting the error:
4Uncaught TypeError: Cannot call method 'unbind' of undefined

I am using jQuery 1.7.2 and touchcarousel 1.0. I am calling your function using:
carouselInstance.detach();
and copy-pasted the function into the script, after the entire 'prev' function was declared. That should be ok, right?

You have any idea how to solve this? Thanks in advance!

Cheers

@benhuson
Copy link
Author

I added the detach function after the destroy function around line 666 in jquery.touchcarousel-1.0.js

Seems to work OK for me. Just have to make sure you only call it on an active version of the carousel?

@japborst
Copy link

japborst commented May 20, 2012 via email

@benhuson
Copy link
Author

Where about's in the minified version did you add it?
It won;t work if you just add it at the end I don't think.
You really need the non-minified version to do it

@japborst
Copy link

I added it after the 'prev' function was declared. Thus, right after: "{c=(this._jq2-1)_this._hs2}else{c=0}}else{c=d_this._hs2}}this.goTo(c,a)}," (just ctrl+f to find that)

@japborst
Copy link

I de-minified mine and I see where the problem lies. After minifying the functions _[something] have all be renamed to shorter ones, therefore e.g. _Itemswrapper does not exist, therefore you cannot unbind it.

@japborst
Copy link

I got it working, thanks for everything :) In addition I added the option to remove the pagingNav when present.

@benhuson
Copy link
Author

Cool, glad it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment