forked from sayedabdelgleel/angularjs-swipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswiper.js
executable file
·45 lines (41 loc) · 1.27 KB
/
swiper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
angular.module('swiper', [])
.directive('swiper', function ($parse, $timeout) {
return {
scope: true,
link: function(scope, element, attrs) {
element.addClass('swipe');
var config = {};
if ( attrs.auto ) {
config.auto = parseInt(attrs.auto,10);
}
if ( attrs.startSlide ) {
config.startSlide = parseInt(attrs.startSlide,10);
}
if ( attrs.speed ) {
config.speed = parseInt(attrs.speed,10);
}
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';
$timeout(function ()
{
var setter = $parse(swiperProperty).assign;
setter(scope, new Swipe(element[0], config));
});
}
}
});