1
+ var $ = require ( 'jquery' ) ;
1
2
var View = require ( 'ampersand-view' ) ;
2
3
3
4
var TourView = View . extend ( {
4
5
props : {
5
- tourCount : {
6
- type : 'number' ,
7
- default : 0
8
- } ,
9
- tourImages : {
10
- type : 'array' ,
11
- default : function ( ) {
12
- return [ 'f1.gif' , 'f2.gif' , 'f3.gif' , 'f4.gif' , 'f5.gif' ] ;
13
- }
14
- } ,
15
- tourImagesFolder : {
16
- type : 'string' ,
17
- default : './images/tour/'
6
+ isAnimating : { type : 'boolean' , default : true } ,
7
+ tourCount : { type : 'number' , default : 0 } ,
8
+ tourImages : { type : 'array' , default : function ( ) {
9
+ return [
10
+ { file : 'f1.gif' , duration : 4000 } ,
11
+ { file : 'f2.gif' , duration : 9000 } ,
12
+ { file : 'f3.gif' , duration : 9000 } ,
13
+ { file : 'f4.gif' , duration : 6000 } ,
14
+ { file : 'f5.gif' , duration : 9000 }
15
+ ] ;
18
16
}
17
+ } ,
18
+ tourImagesFolder : { type : 'string' , default : './images/tour/' }
19
19
} ,
20
-
21
20
template : require ( './index.jade' ) ,
22
21
events : {
23
22
'click #features ul' : 'showFeature' ,
@@ -27,39 +26,44 @@ var TourView = View.extend({
27
26
render : function ( ) {
28
27
var that = this ;
29
28
this . renderWithTemplate ( this ) ;
30
-
31
29
this . $featuresUL = this . query ( '#features ul' ) ;
32
30
this . $featuresLI = this . queryAll ( '#features li' ) ;
33
31
this . $animationGIF = this . query ( '#animation-gif' ) ;
34
32
this . $tourRemove = this . query ( '#tour-remove' ) ;
35
-
36
- this . playAuto = setInterval ( function ( ) {
37
- that . $featuresLI [ that . tourCount ] . className = '' ;
38
-
33
+ function showAnimation ( ) {
34
+ var duration = that . tourImages [ that . tourCount ] . duration ;
35
+ // deselect old
36
+ $ ( '#features li.selected' ) . removeClass ( 'selected' ) ;
37
+ // select new
38
+ that . $featuresLI [ that . tourCount ] . className = 'selected' ;
39
+ that . $animationGIF . src = that . tourImagesFolder + that . tourImages [ that . tourCount ] . file ;
39
40
if ( that . tourCount === 4 ) {
40
41
that . tourCount = 0 ;
41
42
} else {
42
43
that . tourCount ++ ;
43
44
}
44
- that . $featuresLI [ that . tourCount ] . className = 'selected' ;
45
- that . $animationGIF . src = that . tourImagesFolder + that . tourImages [ that . tourCount ] ;
46
- } , 1000 * 7 ) ;
45
+ if ( that . isAnimating ) {
46
+ setTimeout ( showAnimation , duration ) ;
47
+ }
48
+ }
49
+ showAnimation ( ) ;
47
50
} ,
48
-
49
51
showFeature : function ( ev ) {
52
+ this . isAnimating = false ;
50
53
var nCLick = ev . target . getAttribute ( 'data-n' ) ;
51
- if ( ! nCLick ) {
54
+ if ( nCLick === null ) {
52
55
return false ;
53
56
}
54
57
var nFeature = parseInt ( nCLick , 10 ) ;
55
- this . $featuresLI [ this . tourCount ] . className = '' ;
58
+ // deselect old
59
+ $ ( '#features li.selected' ) . removeClass ( 'selected' ) ;
60
+ // select new
56
61
ev . target . className = 'selected' ;
57
62
this . $animationGIF . src = this . tourImagesFolder + ev . target . id + '.gif' ;
58
63
this . tourCount = nFeature ;
59
- clearInterval ( this . playAuto ) ;
60
64
} ,
61
65
tourRemove : function ( ) {
62
- clearInterval ( this . playAuto ) ;
66
+ this . isAnimating = false ;
63
67
this . remove ( ) ;
64
68
}
65
69
} ) ;
0 commit comments