alongslide 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
- #
1
+ #
2
2
  # alongslide/scrolling.coffee: Skrollr wrapper.
3
- #
3
+ #
4
4
  # Copyright 2013 Canopy Canopy Canopy, Inc.
5
5
  # Authors Adam Florin & Anthony Tran
6
- #
6
+ #
7
7
  class Alongslide::Scrolling
8
8
 
9
9
  # For applyTransition.
10
- #
10
+ #
11
11
  TRANSITIONS:
12
12
  in: [-1..0]
13
13
  out: [0..1]
@@ -23,7 +23,7 @@ class Alongslide::Scrolling
23
23
  indexedTransitions: {}
24
24
 
25
25
  # For desktop scroll throttling.
26
- #
26
+ #
27
27
  wheelHistory: []
28
28
  lastAverageMagnitude: 0
29
29
  ignoreScroll: false
@@ -31,6 +31,9 @@ class Alongslide::Scrolling
31
31
 
32
32
  mouseDown: false
33
33
 
34
+ # browser history
35
+ stateData: {}
36
+
34
37
  constructor: (options= {}) ->
35
38
  {@frames} = options
36
39
 
@@ -39,7 +42,7 @@ class Alongslide::Scrolling
39
42
  horizontal: true
40
43
  edgeStrategy: 'set'
41
44
  render: @snap
42
- easing:
45
+ easing:
43
46
  easeInOutQuad: (p) ->
44
47
  if p < 0.5
45
48
  Math.pow(p*2, 1.5) / 2
@@ -58,15 +61,15 @@ class Alongslide::Scrolling
58
61
  @monitorMouse()
59
62
 
60
63
  # Init skrollr once content data attributes are populated.
61
- #
64
+ #
62
65
  # @param - frameAspect - percentage horizontal offset (0.-1.)
63
66
  # to factor in when applying scroll transitions
64
- #
67
+ #
65
68
  render: (@frameAspect, lastFramePosition) ->
66
69
  @applyTransitions(lastFramePosition)
67
70
  @skrollr.refresh()
68
71
 
69
- # TODO: write API that injects functions
72
+ # TODO: write API that injects functions
70
73
  # i.e. functionName(event, frame number, function) `('before', 3, animateTable)`
71
74
  events: =>
72
75
  @frames.on 'skrollrBefore', (e) -> e.target
@@ -74,11 +77,11 @@ class Alongslide::Scrolling
74
77
  @frames.on 'skrollrAfter', (e) -> e.target
75
78
 
76
79
  # Apply skrollr-style attrs based on Alongslide attrs.
77
- #
80
+ #
78
81
  #
79
82
  applyTransitions: (lastFramePosition) ->
80
83
  @indexedTransitions = {}
81
-
84
+
82
85
  @frames.find('.frame').each (index, frameEl) =>
83
86
  frame = $(frameEl)
84
87
 
@@ -111,23 +114,23 @@ class Alongslide::Scrolling
111
114
 
112
115
 
113
116
  # Write skrollr-style scroll transitions into jQuery DOM element.
114
- #
117
+ #
115
118
  # Note that, since a frame may enter and exit with different transitions,
116
119
  # the CSS snippets for each transition should zero out effects of other
117
120
  # transitions. (That's why the "slide" transition sets opacity.)
118
- #
121
+ #
119
122
  # Also, frames may scroll over a shorter distance ('scale') if they
120
123
  # are with horizontally pinned panels. The code below must be context-aware
121
124
  # enough to know when to do a normal-length scroll and when to shorten it.
122
- #
125
+ #
123
126
  # @param frame: jQuery object wrapping new DOM frame
124
127
  # @param options: hash containing:
125
128
  # - in: percentage of total page width when frame should enter
126
129
  # - out (optional): percentage of total page width when frame should exit
127
130
  # - lastFramePosition: last position of any frame in DOM.
128
- #
131
+ #
129
132
  # @return frame
130
- #
133
+ #
131
134
  applyTransition: (frame, options = {}) ->
132
135
  # fuzzy logic coefficient. see below.
133
136
  A_LITTLE_MORE = 2
@@ -149,7 +152,7 @@ class Alongslide::Scrolling
149
152
 
150
153
  # Set framescale for horizontal panels if there's another horizontal
151
154
  # panel at the opposite edge before AND after the transition.
152
- #
155
+ #
153
156
  if Math.abs(direction) > 0
154
157
  if frame.parent().hasClass('panels')
155
158
  panelAlignment = alongslide.layout.panelAlignment(frame)
@@ -162,8 +165,8 @@ class Alongslide::Scrolling
162
165
  frameScale = 0.495
163
166
 
164
167
  # In certain cases, we need more than one keypoint per direction.
165
- #
166
- keypoints =
168
+ #
169
+ keypoints =
167
170
  if frameScale?
168
171
  # if frameScale is set, use it--but add an additional keypoint
169
172
  # at 1.0 to make sure these closely-packed frames are out of
@@ -178,7 +181,7 @@ class Alongslide::Scrolling
178
181
  # Double keypoints in order to keep the frame out of the visible
179
182
  # window until absolutely necessary so that it doesn't sit atop
180
183
  # the visible frame (and consume link clicks).
181
- #
184
+ #
182
185
  [ {magnitude: magnitude, scale: scale * A_LITTLE_MORE},
183
186
  {magnitude: magnitude * 0.99, scale: scale}]
184
187
 
@@ -194,7 +197,7 @@ class Alongslide::Scrolling
194
197
  [{magnitude: direction, scale: 1.0}]
195
198
 
196
199
  # apply Skrollr transitions for each keypoint.
197
- #
200
+ #
198
201
  for keypoint in _.flatten(keypoints)
199
202
  {magnitude, scale} = keypoint
200
203
  position = options[transition] + magnitude
@@ -221,9 +224,9 @@ class Alongslide::Scrolling
221
224
 
222
225
  # Check frame's CSS classes for transition cues in the format
223
226
  # `*-in` or `*-out`.
224
- #
227
+ #
225
228
  # Currently defaults to "slide", and does no validation.
226
- #
229
+ #
227
230
  transitionOptions: (frame, options = {}) ->
228
231
  frameClass = frame.get(0).className
229
232
 
@@ -236,9 +239,9 @@ class Alongslide::Scrolling
236
239
  return options
237
240
 
238
241
  # If we're in the refractory period, extinguish all scroll events immediately.
239
- #
242
+ #
240
243
  # Desktop only.
241
- #
244
+ #
242
245
  throttleScrollEvents: ->
243
246
  $(window).on 'wheel mousewheel DOMMouseScroll MozMousePixelScroll', (e) =>
244
247
 
@@ -254,12 +257,12 @@ class Alongslide::Scrolling
254
257
  e.preventDefault()
255
258
 
256
259
  @lastAverageMagnitude = averageMagnitude
257
-
260
+
258
261
  # To gauge scroll inertia on desktop, need to constantly populate our
259
262
  # wheelHistory array with zeroes to mark time.
260
- #
263
+ #
261
264
  # Desktop only.
262
- #
265
+ #
263
266
  monitorScroll: ->
264
267
  # zero handler
265
268
  zeroHistory = => @lastAverageMagnitude = @updateWheelHistory(0)
@@ -269,11 +272,11 @@ class Alongslide::Scrolling
269
272
 
270
273
  # repeat forever.
271
274
  setInterval zeroHistory, 5
272
-
275
+
273
276
  # Add the latest delta to the running history, enforce max length.
274
- #
277
+ #
275
278
  # Returns average after updating.
276
- #
279
+ #
277
280
  updateWheelHistory: (delta) ->
278
281
  # add delta to history
279
282
  @wheelHistory.unshift(delta)
@@ -287,7 +290,7 @@ class Alongslide::Scrolling
287
290
  return Math.abs(average)
288
291
 
289
292
  # Monitor mousedown state on desktop to separate scrollbar from mousewheel
290
- #
293
+ #
291
294
  monitorMouse: ->
292
295
  $(document).mousedown =>
293
296
  @mouseDown = true
@@ -297,17 +300,17 @@ class Alongslide::Scrolling
297
300
  window.alongslide?.scrolling.scrollToPosition(requestedPosition)
298
301
 
299
302
  # Scroll to requested frame.
300
- #
303
+ #
301
304
  # Don't scroll below zero, and don't do redundant scrolls.
302
- #
305
+ #
303
306
  # @param position - ALS position (= frame number). May be floating point!
304
- #
307
+ #
305
308
  # @option skrollr - caller may pass in skrollr if our variable hasn't been
306
309
  # set yet
307
310
  # @option force - if true, force a corrective scroll, even if we think we're
308
311
  # at the position we think we're supposed to be at.
309
312
  # @option scrollMethod - is this a "scroll", a "touch", or "keys"?
310
- #
313
+ #
311
314
  scrollToPosition: (requestedPosition, options = {}) =>
312
315
  # use our stored copy of skrollr instance if available
313
316
  skrollr = @skrollr || options.skrollr
@@ -348,13 +351,13 @@ class Alongslide::Scrolling
348
351
  if (position * $(window).width()) isnt skrollr.getScrollPosition()
349
352
  scrollTo = @currentPosition
350
353
  duration = @FORCE_SLIDE_DURATION_MS
351
-
354
+
352
355
  @doScroll(scrollTo, skrollr, duration, options) if scrollTo?
353
356
 
354
357
  @lastRequestedPosition = requestedPosition
355
-
356
- #
357
- #
358
+
359
+ #
360
+ #
358
361
  doScroll: (scrollTo, skrollr, duration, options) ->
359
362
  scrollDelta = scrollTo - @currentPosition
360
363
  @currentPosition = scrollTo
@@ -368,7 +371,10 @@ class Alongslide::Scrolling
368
371
  skrollr.animateTo scrollTo * $(window).width(),
369
372
  duration: duration
370
373
  easing: 'easeOutQuad'
371
- done: (skrollr) ->
374
+ done: (skrollr) =>
375
+ @stateData =
376
+ index: @currentPosition
377
+ alongslide.state.update(@stateData)
372
378
 
373
379
  # For mobile, stage/unstage frames after transition
374
380
  if @skrollr.isMobile()
@@ -388,11 +394,11 @@ class Alongslide::Scrolling
388
394
 
389
395
  # Snap-to-content scrolling, implemented as a skrollr callback, called after
390
396
  # each frame in the animation loop.
391
- #
397
+ #
392
398
  # Bias the scroll so that it moves in the same direction as the user's input
393
399
  # (i.e., use floor()/ceil() rather than round(), so that scroll never
394
400
  # snaps BACK, which can feel disheartening as a user experience).
395
- #
401
+ #
396
402
  snap: (info) ->
397
403
 
398
404
  # don't do anything if skrollr is animating
@@ -410,7 +416,7 @@ class Alongslide::Scrolling
410
416
 
411
417
  # Listen to left/right arrow (unless modifier keys are pressed),
412
418
  # and scroll accordingly.
413
- #
419
+ #
414
420
  arrowKeys: ->
415
421
  $(document).keydown (event) =>
416
422
  if event.altKey or event.shiftKey or event.ctrlKey or event.metaKey
@@ -0,0 +1,32 @@
1
+ #
2
+ # state.coffee: update browser history
3
+ #
4
+ # Copyright 2013 Canopy Canopy Canopy, Inc.
5
+ #
6
+ class Alongslide::State
7
+
8
+ panelNames : {}
9
+ documentTitle: ''
10
+ hash : '#'
11
+
12
+ constructor: (options = {}) ->
13
+ History = window.History
14
+ if !History.enabled then return false
15
+ @documentTitle = document.getElementsByTagName('title')[0].innerHTML
16
+ @panelNames = options.panelNames
17
+
18
+ rewindStateIndex:(state) ->
19
+ state.index -= 1
20
+ @update(state);
21
+
22
+ update:(state)->
23
+ if @panelNames[state.index]
24
+ History.replaceState null, @documentTitle, @hash + @panelNames[state.index]
25
+ pageData =
26
+ index : state.index
27
+ hash : @panelNames[state.index]
28
+ $(document).triggerHandler 'alongslide.pagechange', pageData
29
+ else if !@panelNames[state.index] and state.index > -1
30
+ @rewindStateIndex(state)
31
+ else if state.index <= -1
32
+ return
@@ -1,13 +1,14 @@
1
- #
1
+ #
2
2
  # alongslide.js: Require Alongslide libraries.
3
- #
3
+ #
4
4
  # Vendor
5
5
  #= require regionFlow
6
6
  #= require skrollr
7
7
  #= require tether
8
8
  #= require prefix
9
9
  #= require jquery.fitvids
10
- #
10
+ #= require jquery.history
11
+ #
11
12
  # Utility
12
13
  #= require ./styles
13
14
  #= require ./fixedAspect
@@ -17,7 +18,8 @@
17
18
  #= require alongslide/parser
18
19
  #= require alongslide/layout
19
20
  #= require alongslide/scrolling
20
- #
21
+ #= require alongslide/state
22
+ #
21
23
  # Copyright 2013 Canopy Canopy Canopy, Inc.
22
24
  # Authors Adam Florin & Anthony Tran
23
- #
25
+ #
@@ -2,11 +2,11 @@
2
2
  // alongslide.sass: Set up CSS Regions and basic scrolling mechanism.
3
3
  //
4
4
  // Copyright 2013 Canopy Canopy Canopy, Inc.
5
- //
5
+ //
6
6
 
7
- //
7
+ //
8
8
  // FIXED pixel-based values from comps.
9
- //
9
+ //
10
10
  $fixed-frame-width: 980px
11
11
  $fixed-frame-height: 612.5px
12
12
 
@@ -31,9 +31,9 @@ $fixed-three-column-width: fixed-width-in-bars($wide: 5, $narrow: 6)
31
31
  $fixed-2-column-inner-margin: fixed-width-in-bars($wide: 1, $narrow: 2)
32
32
  $fixed-3-column-inner-margin: fixed-width-in-bars($wide: 1, $narrow: 0)
33
33
 
34
- //
34
+ //
35
35
  // PERCENTAGE-based values based on fixed values above
36
- //
36
+ //
37
37
  $full-bleed: 100%
38
38
  $outer-margin-width: percentage($fixed-column-outer-margin / $fixed-frame-width)
39
39
  $outer-margin-height: percentage($fixed-column-outer-margin / $fixed-frame-height)
@@ -43,23 +43,23 @@ $vertical-grid-unit: percentage($fixed-vertical-grid-unit / $fixed-frame-height)
43
43
  $width-2-column: ($full-bleed - 2 * $outer-margin-width - $inner-margin-2-column) / 2
44
44
  $width-3-column: ($full-bleed - 2 * $outer-margin-width - 2 * $inner-margin-3-column) / 3
45
45
 
46
- $white-bg: #fbfbfb
46
+ $white-bg: #ffffff
47
47
 
48
48
 
49
49
  // skrollr elements must all be fixed.
50
- //
50
+ //
51
51
  @mixin scrollable
52
52
  position: fixed
53
53
  &.unstaged
54
54
  position: static
55
55
 
56
56
  // Hide Alongslide directives.
57
- //
57
+ //
58
58
  .alongslide
59
59
  display: none
60
60
 
61
61
  // Horizontally-scrolling content viewer.
62
- //
62
+ //
63
63
  #frames
64
64
  height: $full-bleed
65
65
  background-color: $white-bg
@@ -71,29 +71,29 @@ $white-bg: #fbfbfb
71
71
  line-height: 1em
72
72
 
73
73
  // One frame is one screen's worth.
74
- //
74
+ //
75
75
  // Panels, flow, backgrounds (front-to-back order) all contain frames.
76
- //
76
+ //
77
77
  .frame
78
78
  width: $full-bleed
79
79
  height: $full-bleed
80
80
  @include scrollable
81
81
 
82
82
  // Columns
83
- //
83
+ //
84
84
  // Flowing text laid out by CSS Regions.
85
- //
85
+ //
86
86
  // Column dimensions are all defined in percentages. FixedAspect then overwites
87
87
  // the dimensions of `#frames > .flow > .frame`, and the contained columns
88
88
  // fit accordingly.
89
- //
89
+ //
90
90
  // Contrast with what FixedAspect does with panels below.
91
- //
91
+ //
92
92
  .flow
93
93
  .frame
94
94
 
95
95
  // One text column
96
- //
96
+ //
97
97
  .column
98
98
  width: $width-2-column
99
99
  height: 45 * $vertical-grid-unit
@@ -107,17 +107,17 @@ $white-bg: #fbfbfb
107
107
  text-indent: 0 !important
108
108
 
109
109
  // Left/right columns
110
- //
110
+ //
111
111
  &:nth-child(1)
112
112
  left: $outer-margin-width
113
113
  &:nth-child(2)
114
114
  right: $outer-margin-width
115
115
 
116
116
  // With pinned panel: top/bottom
117
- //
117
+ //
118
118
  // All column values assume 'half' size by default and treat
119
119
  // 'one-third' and 'two-thirds' as overwrites.
120
- //
120
+ //
121
121
  &.with-panel-pinned-bottom
122
122
  .column
123
123
  height: 19 * $vertical-grid-unit
@@ -138,7 +138,7 @@ $white-bg: #fbfbfb
138
138
  height: 11 * $vertical-grid-unit
139
139
 
140
140
  // With pinned panel: left/right
141
- //
141
+ //
142
142
  &.with-panel-pinned-left, &.with-panel-pinned-right
143
143
  .column
144
144
  width: $width-2-column
@@ -156,7 +156,7 @@ $white-bg: #fbfbfb
156
156
  left: $outer-margin-width + 2 * ($width-3-column + $inner-margin-3-column)
157
157
 
158
158
  // Three column layout
159
- //
159
+ //
160
160
  &.three-columns
161
161
  .column
162
162
  width: $width-3-column
@@ -180,21 +180,21 @@ $white-bg: #fbfbfb
180
180
  left: $outer-margin-width + 2 * ($width-3-column + $inner-margin-3-column)
181
181
 
182
182
  // Panels
183
- //
183
+ //
184
184
  // Contrary to columns above, all values are defined in pixels, which
185
185
  // FixedAspect uses to re-apply percentages in JS. It then overwrites
186
186
  // the below pixel-based values with percentage values based on aspect.
187
- //
187
+ //
188
188
  // The reason is that JS can't access the CSS percentage values anyway,
189
189
  // so, to maintain floating point precision, we may as well do the
190
190
  // math in JS--rather than go from pixels to percentages in SASS, and then
191
191
  // re-derive the percentages in JS, which will be rounded to integers
192
192
  // (and therefore exhibit sampling inaccuracy).
193
- //
193
+ //
194
194
  // The rule is:
195
195
  // - `.panel` is the content area, defined in fixed pixel widths
196
196
  // - `.panel .contents` is relative to the content area
197
- //
197
+ //
198
198
  .panels
199
199
  .panel
200
200
  width: $fixed-frame-width
@@ -212,7 +212,7 @@ $white-bg: #fbfbfb
212
212
  overflow: visible
213
213
 
214
214
  // Class for inner padding. This one _is_ percentage-based.
215
- //
215
+ //
216
216
  .inner
217
217
  width: 100%
218
218
  height: 100%
@@ -220,15 +220,15 @@ $white-bg: #fbfbfb
220
220
  z-index: 101
221
221
 
222
222
  // Responsive images
223
- img
223
+ img
224
224
  max-width: 100%
225
225
  height: auto
226
-
226
+
227
227
  // Pinned
228
- //
228
+ //
229
229
  // As with columns, default size is 'half'.
230
230
  // 'one-third' and 'two-thirds' overwrite.
231
- //
231
+ //
232
232
  &.pin
233
233
  background-color: $white-bg
234
234
  &.top
@@ -308,7 +308,7 @@ $white-bg: #fbfbfb
308
308
  left: percentage($fixed-panel-margin-two-thirds / $fixed-panel-width-two-thirds)
309
309
 
310
310
  // Section backgrounds
311
- //
311
+ //
312
312
  .backgrounds
313
313
  .background
314
314
  width: $full-bleed
@@ -345,7 +345,7 @@ $white-bg: #fbfbfb
345
345
  margin-left: 1%
346
346
 
347
347
  // DEBUG GRID
348
- //
348
+ //
349
349
  #als-debug-grid
350
350
  position: fixed
351
351
  width: 100%
@@ -432,7 +432,7 @@ $white-bg: #fbfbfb
432
432
  top: 0
433
433
  width: 100%
434
434
  height: 100%
435
- background: #fbfbfb
435
+ background: #ffffff
436
436
  h1
437
437
  font-size: 54px
438
438
  line-height: 1em