diff --git a/swiper.js b/swiper.js index 2350c4e..fdd3001 100755 --- a/swiper.js +++ b/swiper.js @@ -1,5 +1,5 @@ angular.module('swiper', []) -.directive('swiper', function ($parse) { +.directive('swiper', function ($parse, $timeout) { return { scope: true, link: function(scope, element, attrs) { @@ -16,19 +16,30 @@ angular.module('swiper', []) if ( attrs.speed ) { config.speed = parseInt(attrs.speed,10); } - if ( attrs.onSlideEnd ) { - var onSlideEnd = $parse(attrs.onSlideEnd); - config.callback = function(e, index, slide) { - scope.$apply(function() { - onSlideEnd(scope, { index: index, slide: slide}); - }); + var onSlideEnd; + if (attrs.onSlideEnd) + onSlideEnd = $parse(attrs.onSlideEnd); + + config.callback = function (e, index, slide) + { + // apply with timeout to avoid stuttering transitions + $timeout( + function () + { + // always apply to propagate swipes status change to angular + if (onSlideEnd) + onSlideEnd(scope, + { index: index, slide: slide}); + }, 10 + ); }; - } var swiperProperty = attrs.swiper || 'swiper'; - var swiper = new Swipe(element[0], config); - - scope[swiperProperty] = swiper; + $timeout(function () + { + var setter = $parse(swiperProperty).assign; + setter(scope, new Swipe(element[0], config)); + }); } - }; + } });