1
- // CodePen Evaluation License
2
- //
3
- // Copyright (c) 2013 Famous Industries, Inc.
4
- //
5
- // Non-sublicensable permission is hereby granted, free of charge, to any person obtaining a
6
- // copy of this software and associated documentation files directly from codepen.io (the
7
- // "Software"), solely to internally make and internally use copies of the Software to test,
8
- // explore, and evaluate the Software solely in such person’s non-commercial, non-
9
- // production environments, provided that the above copyright notice and this permission
10
- // notice shall be included in all copies or substantial portions of the Software.
11
- //
12
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
- // MERCHANTABILITY, FITNESS FOR A ARTICULAR PURPOSE AND
15
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
16
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
18
- // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
- //
21
-
22
-
23
- Famous ( function ( require , exports , module )
24
- {
25
- var Engine = require ( 'famous/Engine' ) ;
26
- var Modifier = require ( 'famous/Modifier' ) ;
27
-
28
- var FM = require ( 'famous/Matrix' ) ;
29
- var Easing = require ( 'famous-animation/Easing' ) ;
30
-
31
- var AppView = require ( './app/AppView' ) ;
1
+ //XXX figure out how to properly define components once Famo.us is released -- we added define manually for now
2
+
3
+ Famous ( function ( require ) {
4
+ //CoverView
5
+
6
+ var Surface = require ( "famous/Surface" ) ,
7
+ Modifier = require ( "famous/Modifier" ) ,
8
+ Matrix = require ( "famous/Matrix" ) ,
9
+ View = require ( "famous/View" ) ;
10
+
11
+ function CoverView ( ) {
12
+ View . apply ( this , arguments ) , this . profileImg = new Image , this . profileImg . src = this . options . img , this . profileImg . width = 320 , this . profileImg . style . webkitBoxReflect = "below" ;
13
+ var coverBackground = new Surface ( {
14
+ content : '<img width="320" src="covers/bg.png" />'
15
+ } ) ;
16
+
17
+ var coverBackgroundTransform = new Modifier ( {
18
+ transform : Matrix . translate ( 0 , 0 , .001 )
19
+ } ) ;
20
+ this . _add ( coverBackgroundTransform ) . link ( coverBackground ) ;
21
+
22
+ var profileImageSurface = new Surface ( {
23
+ size : [ this . options . size , this . options . size ] ,
24
+ content : this . profileImg
25
+ } ) ;
26
+ this . _add ( profileImageSurface ) ;
27
+ }
28
+
29
+ CoverView . prototype = Object . create ( View . prototype ) ;
30
+ CoverView . prototype . constructor = CoverView ;
31
+ CoverView . DEFAULT_OPTIONS = {
32
+ text : null ,
33
+ name : null ,
34
+ img : null
35
+ } ;
36
+
37
+ //StoriesView
38
+
39
+ var EventHandler = require ( "famous/EventHandler" ) ,
40
+ GenericSync = require ( "famous-sync/GenericSync" ) ,
41
+ Transitionable = require ( "famous/Transitionable" ) ,
42
+ SpringTransition = require ( "famous-physics/utils/SpringTransition" ) ,
43
+ Scrollview = require ( "famous-views/Scrollview" ) ,
44
+ ViewSequence = require ( "famous/ViewSequence" ) ,
45
+ Utility = require ( "famous/Utility" ) ,
46
+ Utils = require ( "famous-utils/Utils" ) ,
47
+ StoryData = require ( "app/Data/StoryData" ) ,
48
+ StoryView = require ( "app/StoryViews/StoryView" ) ,
49
+ PhotoStoryView = require ( "app/StoryViews/PhotoStoryView" ) ,
50
+ ArticleStoryView = require ( "app/StoryViews/ArticleStoryView" ) ;
51
+
52
+ function StoriesView ( ) {
53
+ View . apply ( this , arguments ) , S . call ( this ) , g . call ( this ) , w . call ( this ) , window . app = this
54
+ }
55
+
56
+ Transitionable . registerMethod ( "spring" , SpringTransition ) ;
57
+ StoriesView . prototype = Object . create ( View . prototype ) ;
58
+ StoriesView . prototype . constructor = StoriesView ;
59
+
60
+ StoriesView . DEFAULT_OPTIONS = {
61
+ velThreshold : .7 ,
62
+ spring : {
63
+ method : "spring" ,
64
+ period : 200 ,
65
+ dampingRatio : 1
66
+ } ,
67
+ curve : {
68
+ duration : 500 ,
69
+ curve : "easeOut"
70
+ } ,
71
+ cardScale : .445 ,
72
+ gutter : 2
73
+ } ;
74
+ StoriesView . DEFAULT_OPTIONS . cardWidth = StoriesView . DEFAULT_OPTIONS . cardScale * window . innerWidth ;
75
+ StoriesView . DEFAULT_OPTIONS . cardHeight = StoriesView . DEFAULT_OPTIONS . cardScale * window . innerHeight ;
76
+ StoriesView . DEFAULT_OPTIONS . initY = window . innerHeight - StoriesView . DEFAULT_OPTIONS . cardHeight ;
77
+ StoriesView . DEFAULT_OPTIONS . posThreshold = ( window . innerHeight - StoriesView . DEFAULT_OPTIONS . cardHeight ) / 2 ;
78
+ StoriesView . DEFAULT_OPTIONS . scrollOpts = {
79
+ direction : Utility . Direction . X ,
80
+ defaultItemSize : [ StoriesView . DEFAULT_OPTIONS . cardWidth , StoriesView . DEFAULT_OPTIONS . cardHeight ] ,
81
+ itemSpacing : 2 / StoriesView . DEFAULT_OPTIONS . cardScale ,
82
+ margin : 3 * window . innerWidth ,
83
+ pageSwitchSpeed : .1 ,
84
+ pagePeriod : 300 ,
85
+ pageDamp : 1 ,
86
+ speedLimit : 10 ,
87
+ drag : .001
88
+ } ;
89
+
90
+ var g = function ( ) {
91
+ this . storiesHandler = new EventHandler , this . scrollview = new Scrollview ( this . options . scrollOpts ) , this . stories = [ ] ;
92
+ for ( var t = 0 ; t < StoryData . length ; t ++ ) {
93
+ var i , e = {
94
+ profilePics : StoryData [ t ] . profilePics ,
95
+ name : StoryData [ t ] . name ,
96
+ text : StoryData [ t ] . text ,
97
+ time : StoryData [ t ] . time ,
98
+ likes : StoryData [ t ] . likes ,
99
+ comments : StoryData [ t ] . comments ,
100
+ scale : this . options . cardScale
101
+ } ;
102
+ StoryData [ t ] . article ? ( e . content = StoryData [ t ] . article , e . thumbSm = StoryData [ t ] . articleThumbSm , e . thumbLg = StoryData [ t ] . articleThumbLg , e . velThreshold = this . options . velThreshold , i = new ArticleStoryView ( e ) ) : ( e . photos = StoryData [ t ] . photos , i = StoryData [ t ] . photos && StoryData [ t ] . photos . length > 1 ? new PhotoStoryView ( e ) : new StoryView ( e ) ) , i . pipe ( this . storiesHandler ) , this . stories . push ( i ) , i . on ( "touchstart" , function ( t ) {
103
+ this . targetStory = t
104
+ } . bind ( this , i ) )
105
+ }
106
+ this . storiesHandler . pipe ( this . scrollview ) , this . storiesHandler . pipe ( this . ySync ) ;
107
+ var s = new ViewSequence ( this . stories , 0 , ! 0 ) ;
108
+ this . scrollview . sequenceFrom ( s ) , this . scrollview . on ( "paginate" , function ( ) {
109
+ this . targetStory . sequence && ( this . targetStory . sequence ( ) , this . targetStory . disableScroll ( ) )
110
+ } . bind ( this ) )
111
+ } ;
112
+
113
+ var S = function ( ) {
114
+ this . yPos = new Transitionable ( this . options . initY ) , this . ySync = new GenericSync ( function ( ) {
115
+ return [ 0 , this . yPos . get ( ) ]
116
+ } . bind ( this ) )
117
+ } ;
118
+
119
+ var w = function ( ) {
120
+ this . ySync . on ( "start" , function ( ) {
121
+ var t = this . yPos . get ( ) ;
122
+ this . direction = void 0 , 0 === t && this . targetStory . scrollable && this . targetStory . enableScroll ( ) , 0 === t && this . targetStory . flipable && this . targetStory . enableFlip ( ) , this . enableY = ! 1
123
+ } . bind ( this ) ) ;
124
+
125
+ this . ySync . on ( "update" , function ( t ) {
126
+ var i = this . yPos . get ( ) ;
127
+ this . direction || ( Math . abs ( t . v [ 1 ] ) > Math . abs ( t . v [ 0 ] ) ? this . direction = "y" : ( this . storiesHandler . unpipe ( this . ySync ) , this . direction = "x" ) ) , "y" === this . direction ? ( 0 !== i ? ( this . enableY = ! 0 , this . swipeY = ! 0 ) : ( this . targetStory . scrollable || this . targetStory . flipable || ( this . enableY = ! 0 ) , this . targetStory . scrollable && this . targetStory . top && t . v [ 1 ] > 0 && ( this . targetStory . disableScroll ( ) , this . enableY = ! 0 ) , this . targetStory . flipable && this . targetStory . closed && t . v [ 1 ] > 0 && ( this . targetStory . disableFlip ( ) , this . enableY = ! 0 ) ) , this . enableY && this . yPos . set ( Math . min ( this . options . initY + 75 , Math . max ( - 75 , t . p [ 1 ] ) ) ) ) : this . targetStory . scrollable && Math . abs ( this . targetStory . scrollview . getVelocity ( ) ) > .05 && this . storiesHandler . unpipe ( this . scrollview )
128
+ } . bind ( this ) ) ;
129
+
130
+ this . ySync . on ( "end" , function ( t ) {
131
+ this . storiesHandler . pipe ( this . scrollview ) , this . storiesHandler . pipe ( this . ySync ) ;
132
+ var i = t . v [ 1 ] . toFixed ( 2 ) ;
133
+ this . enableY && ( this . yPos . get ( ) < this . options . posThreshold ? i > this . options . velThreshold ? this . slideDown ( i ) : this . slideUp ( Math . abs ( i ) ) : i < - this . options . velThreshold ? this . slideUp ( Math . abs ( i ) ) : this . slideDown ( i ) )
134
+ } . bind ( this ) ) ;
135
+ } ;
136
+
137
+ StoriesView . prototype . slideUp = function ( t ) {
138
+ console . log ( "slide up" ) ;
139
+ var i = this . options . spring ;
140
+ i . velocity = t , this . options . scrollOpts . paginated = ! 0 , this . scrollview . setOptions ( this . options . scrollOpts ) , this . yPos . set ( 0 , i )
141
+ } ;
142
+
143
+ StoriesView . prototype . slideDown = function ( t ) {
144
+ console . log ( "slide down" ) ;
145
+ var i = this . options . spring ;
146
+ i . velocity = t , this . options . scrollOpts . paginated = ! 1 , this . scrollview . setOptions ( this . options . scrollOpts ) , this . yPos . set ( this . options . initY , i )
147
+ } ;
148
+
149
+ StoriesView . prototype . render = function ( ) {
150
+ var t = this . yPos . get ( ) ,
151
+ i = Utils . map ( t , 0 , this . options . initY , 1 , this . options . cardScale ) ;
152
+
153
+ this . progress = Utils . map ( t , this . options . initY , 0 , 0 , 1 , ! 0 ) ;
154
+
155
+ this . scrollview . sync . setOptions ( {
156
+ direction : GenericSync . DIRECTION_X ,
157
+ scale : 1 / i
158
+ } ) ;
159
+
160
+ for ( var e = 0 ; e < this . stories . length ; e ++ ) {
161
+ this . stories [ e ] . setProgress ( this . progress ) ;
162
+ }
163
+
164
+ this . spec = [ ] ;
165
+ this . spec . push ( {
166
+ origin : [ .5 , 1 ] ,
167
+ transform : Matrix . scale ( i , i , 1 ) ,
168
+ target : {
169
+ size : [ window . innerWidth , window . innerHeight ] ,
170
+ target : this . scrollview . render ( )
171
+ }
172
+ } ) ;
173
+
174
+ return this . spec ;
175
+ } ;
176
+
177
+ //AppView
178
+
179
+ var LightBox = require ( "famous-views/LightBox" ) ,
180
+ Time = require ( "famous-utils/Time" ) ;
181
+
182
+ var CoverData = [
183
+ {
184
+ text : "Objects in the mirror are unluckier than they appear." ,
185
+ img : "covers/sochi.jpg" ,
186
+ name : "Steve Kuzminski"
187
+ } ,
188
+ {
189
+ text : "Kylie Wilson changed her profile picture" ,
190
+ img : "covers/sochi.jpg" ,
191
+ name : "Kylie Wilson"
192
+ } ,
193
+ {
194
+ text : "Sick gifs from Sochi" ,
195
+ img : "covers/sochi.jpg" ,
196
+ name : "Chris Zimmerman"
197
+ }
198
+ ] ;
199
+
200
+ Transitionable . registerMethod ( "spring" , SpringTransition ) ;
201
+
202
+ //AppView
203
+ function AppView ( ) {
204
+ View . apply ( this , arguments ) ;
205
+ this . storiesView = new StoriesView ;
206
+
207
+ this . lightbox = new LightBox ( {
208
+ inTransform : Matrix . identity ,
209
+ inOpacity : 0 ,
210
+ inOrigin : [ .5 , .5 ] ,
211
+ outTransform : Matrix . identity ,
212
+ outOpacity : 0 ,
213
+ outOrigin : [ .5 , .5 ] ,
214
+ showTransform : Matrix . identity ,
215
+ showOpacity : 1 ,
216
+ showOrigin : [ .5 , .5 ] ,
217
+ inTransition : {
218
+ duration : 1e3
219
+ } ,
220
+ outTransition : {
221
+ duration : 1e3
222
+ } ,
223
+ overlap : ! 0
224
+ } ) ;
225
+
226
+ this . covers = [ ] ;
227
+
228
+ for ( var t = 0 ; t < CoverData . length ; t ++ ) {
229
+ var cover = new CoverView ( CoverData [ t ] ) ;
230
+ this . covers . push ( cover ) ;
231
+ }
232
+
233
+ this . lightbox . show ( this . covers [ 0 ] ) ;
234
+ var coverIndex = 0 ;
235
+ Time . setInterval ( function ( ) {
236
+ coverIndex ++ ;
237
+
238
+ if ( coverIndex === this . covers . length )
239
+ coverIndex = 0 ;
240
+
241
+ this . lightbox . show ( this . covers [ coverIndex ] ) ;
242
+ } . bind ( this ) , 4e3 ) ;
243
+
244
+ var e = new Modifier ( {
245
+ transform : Matrix . translate ( 0 , 0 , - .1 )
246
+ } ) ;
247
+
248
+ this . _add ( e ) . link ( this . lightbox ) ;
249
+ this . _add ( this . storiesView ) ;
250
+ }
251
+
252
+ AppView . prototype = Object . create ( View . prototype ) ;
253
+ AppView . prototype . constructor = AppView ;
254
+ AppView . DEFAULT_OPTIONS = { } ;
255
+
256
+ var Modifier = require ( 'famous/Modifier' ) ;
257
+
258
+ var Engine = require ( 'famous/Engine' ) ;
259
+
260
+ var FM = require ( 'famous/Matrix' ) ;
261
+ var Easing = require ( 'famous-animation/Easing' ) ;
262
+
263
+ // var AppView = require('./app/AppView');
264
+ // s.App.AppView = t("app/AppView"),
32
265
33
266
var Context = Engine . createContext ( ) ;
34
267
35
268
var appView = new AppView ( ) ;
36
269
37
270
Context . link ( appView ) ;
38
271
Context . setPerspective ( 2000 ) ;
39
- } ) ;
272
+ } ) ;
0 commit comments