richardscarrott / jquery-ui-carousel

jQuery RS Carousel is a responsive and touch-enabled carousel written on top of jQuery and the jQuery UI Widget Factory providing a full and familiar API in less than 2.6kB minified and gzipped.
http://richardscarrott.github.io/jquery-ui-carousel/
192 stars 56 forks source link

Empty carousel causes null error on refresh call #7

Closed atomgiant closed 13 years ago

atomgiant commented 13 years ago

We have an empty carousel list that we dynamically add elements to. We add the elements and then call refresh() so jquery ui carousel can refresh all of its internal data. However, this always fails if the carousel had no elements in the _getPos function call with this error:

this.elements.items.eq(this.itemIndex).position() is null

This is because the itemIndex is set to a negative value.

I was able to fix this by changing this line to remove the leading else so the itemIndex will always be set to 0 if it is negative:

https://github.com/richardscarrott/jquery-ui-carousel/blob/master/js/jquery.ui.carousel.js#L522

Could you make this change in the core jquery.ui.carousel?

Thanks, Tom

richardscarrott commented 13 years ago

I've given the carousel a much needed update so much of it's core functionality has been rewritten. This means the widget factory's disable and enable methods are now supported and consequently it'll no longer error when the carousel is empty.

There are some notable changes with this update meaning the continuous extension is now working however the noOfRows option has been dropped and the touch extension isn't working with the new code just yet.

You can take a look at the latest here: http://www.richardscarrott.co.uk/assets/javascript/jquery/ui-carousel/demo/

Cheers, Rich