Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions swiper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('swiper', [])
.directive('swiper', function ($parse) {
.directive('swiper', function ($parse, $timeout) {
return {
scope: true,
link: function(scope, element, attrs) {
Expand All @@ -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));
});
}
};
}
});