@@ -4,17 +4,22 @@ defaults =
4
4
views : ' .view'
5
5
activeView : null
6
6
duration : $ .fx .speeds ._default
7
- easing : null
7
+ easing : if Zepto ? then ' ease-out ' else ' swing '
8
8
useTransformProps : Zepto?
9
9
use3D : Modernizr? and Modernizr .csstransforms3d
10
10
cssPrefix : if $ .fx .cssPrefix ? then $ .fx .cssPrefix else ' '
11
11
resizeHeight : true
12
12
heightDuration : null
13
13
deferHeightChange : Zepto?
14
+ scrollAfter : if $ .scrollTo ? then ' scrollTo' else false
14
15
dataAttrEvent : ' click'
15
16
dataAttr :
16
17
push : ' pushview'
17
18
pop : ' popview'
19
+ classNames :
20
+ container : ' SimpleSlideView-container'
21
+ view : ' SimpleSlideView-view'
22
+ activeView : ' SimpleSlideView-view-active'
18
23
eventNames :
19
24
viewChangeStart : ' viewChangeStart'
20
25
viewChangeEnd : ' viewChangeEnd'
@@ -38,10 +43,13 @@ class SimpleSlideView
38
43
@options = $ .extend true , {}, defaults, options
39
44
@options .heightDuration = @options .duration unless @options .heightDuration
40
45
@$container = $ element
41
- @$views = @ $container .find @options .views
46
+ @$views = if typeof @options . views is ' string ' then @ $container .find ( @options . views ) else $ ( @options .views )
42
47
@$activeView = if @options .activeView ? then $ (@options .activeView ) else @$views .first ()
43
48
44
49
on : () ->
50
+ @$container .addClass @options .classNames .container
51
+ @$views .addClass @options .classNames .view
52
+ @$activeView .addClass @options .classNames .activeView
45
53
@$views .not (@$activeView ).css ' display' , ' none'
46
54
if @options .dataAttrEvent ?
47
55
@$container .on @options .dataAttrEvent , ' [data-' + @options .dataAttr .push + ' ]' , (event ) =>
@@ -60,6 +68,9 @@ class SimpleSlideView
60
68
@ popView target
61
69
62
70
off : () ->
71
+ @$container .removeClass @options .classNames .container
72
+ @$views .removeClass @options .classNames .view + ' ' + @options .classNames .activeView
73
+ # @$activeView.removeClass @options.classNames.activeView
63
74
@$views .css ' display' , ' '
64
75
if @options .dataAttrEvent ?
65
76
@$container .off @options .dataAttrEvent , ' [data-' + @options .dataAttr .push + ' ]'
@@ -123,8 +134,18 @@ class SimpleSlideView
123
134
resetStyles ($targetView, resetProps)
124
135
animateHeight () if @options .deferHeightChange
125
136
137
+ if @options .scrollAfter
138
+ containerTop = @$container .position ().top
139
+ if $ (window ).scrollTop () > containerTop
140
+ if typeof @options .scrollAfter is ' string' and $[@options .scrollAfter ]?
141
+ $[@options .scrollAfter ] containerTop
142
+ else
143
+ window .scrollTo (0 , containerTop);
144
+
126
145
animateHeight () unless @options .deferHeightChange
127
146
147
+ @$activeView .removeClass @options .classNames .activeView
148
+ $targetView .addClass @options .classNames .activeView
128
149
@$activeView = $targetView
129
150
130
151
pushView : (targetView ) -> @ changeView targetView, true
0 commit comments