skrollr-rails 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 638e39f1ee200fe4cb80c1fee9cb42b9a96acf34
4
- data.tar.gz: 645e9dee97c2c3cc5aabe6852f1cfa13cbdadd41
3
+ metadata.gz: d5626de761b7901972f19f4277355e76216f0618
4
+ data.tar.gz: 8c4c9c685a9401950575be87ad5fb6c42fb64790
5
5
  SHA512:
6
- metadata.gz: 47e93132b9598841503046b1ac48f64836eb138e99bd66761e1dae0289245609f36eac2ccf1b2e959fb512aaec8045ead94c8db9fb7587fb7665befa6470dd05
7
- data.tar.gz: 5b876404c7a083f84c82acab5a0f25edb0ce03aae20929ef7b906f342f86e729a71207e8b3dfd93ad39403ad543a909c7faf36f8b2bbd342a35de252131fdc50
6
+ metadata.gz: 76583ccee883c1694638fffa79ae619be25200559ece7d1fbe4807fb4764509e12bbf665edd8ca84bbcbf56645cd5025cda8a8b6f4743092f0c3568a88bc109d
7
+ data.tar.gz: d76f4d63911bb8d79cee67f12ab11aab2292ec14fcab0ded1105a961fe9e237bf57d45a708f23546863730a2b1af26d28405b9bf136316a9b56f929f5b20a721
@@ -1,5 +1,5 @@
1
1
  module Skrollr
2
2
  module Rails
3
- VERSION = "0.6.8"
3
+ VERSION = "0.6.9"
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@
19
19
  init: function(options) {
20
20
  return _instance || new Skrollr(options);
21
21
  },
22
- VERSION: '0.6.8'
22
+ VERSION: '0.6.9'
23
23
  };
24
24
 
25
25
  //Minify optimization.
@@ -147,7 +147,7 @@
147
147
  requestAnimFrame = function(callback) {
148
148
  //How long did it take to render?
149
149
  var deltaTime = _now() - lastTime;
150
- var delay = Math.max(0, 33 - deltaTime);
150
+ var delay = Math.max(0, 1000 / 60 - deltaTime);
151
151
 
152
152
  window.setTimeout(function() {
153
153
  lastTime = _now();
@@ -555,12 +555,6 @@
555
555
 
556
556
  if(_isMobile) {
557
557
  _mobileOffset = Math.min(Math.max(top, 0), _maxKeyFrame);
558
-
559
- //That's were we actually "scroll" on mobile.
560
- if(_skrollrBody) {
561
- //Set the transform ("scroll it").
562
- skrollr.setStyle(_skrollrBody, 'transform', 'translate(0, ' + -(_mobileOffset) + 'px) ' + _translateZ);
563
- }
564
558
  } else {
565
559
  window.scrollTo(0, top);
566
560
  }
@@ -622,6 +616,8 @@
622
616
  initialElement.blur();
623
617
  }
624
618
 
619
+ _instance.stopAnimateTo();
620
+
625
621
  initialElement = e.target;
626
622
  initialTouchY = lastTouchY = currentTouchY;
627
623
  initialTouchX = currentTouchX;
@@ -632,7 +628,7 @@
632
628
  deltaY = currentTouchY - lastTouchY;
633
629
  deltaTime = currentTouchTime - lastTouchTime;
634
630
 
635
- _instance.setScrollTop(_mobileOffset - deltaY);
631
+ _instance.setScrollTop(_mobileOffset - deltaY, true);
636
632
 
637
633
  lastTouchY = currentTouchY;
638
634
  lastTouchTime = currentTouchTime;
@@ -889,7 +885,7 @@
889
885
  renderTop = (_scrollAnimation.startTop + progress * _scrollAnimation.topDiff) | 0;
890
886
  }
891
887
 
892
- _instance.setScrollTop(renderTop);
888
+ _instance.setScrollTop(renderTop, true);
893
889
  }
894
890
  //Smooth scrolling only if there's no animation running and if we're not on mobile.
895
891
  else if(!_isMobile) {
@@ -915,6 +911,12 @@
915
911
  }
916
912
  }
917
913
 
914
+ //That's were we actually "scroll" on mobile.
915
+ if(_isMobile && _skrollrBody) {
916
+ //Set the transform ("scroll it").
917
+ skrollr.setStyle(_skrollrBody, 'transform', 'translate(0, ' + -(_mobileOffset) + 'px) ' + _translateZ);
918
+ }
919
+
918
920
  //Did the scroll position even change?
919
921
  if(_forceRender || _lastTop !== renderTop) {
920
922
  //Remember in which direction are we scrolling?
@@ -16,6 +16,8 @@
16
16
  var MENU_OFFSET_ATTR = 'data-menu-offset';
17
17
 
18
18
  var skrollr = window.skrollr;
19
+ var history = window.history;
20
+ var supportsHistory = !!history.pushState;
19
21
 
20
22
  /*
21
23
  Since we are using event bubbling, the element that has been clicked
@@ -52,12 +54,22 @@
52
54
  return;
53
55
  }
54
56
 
57
+ if(handleLink(link)) {
58
+ e.preventDefault();
59
+ }
60
+ };
61
+
62
+ /*
63
+ Handles the click on a link. May be called without an actual click event.
64
+ When the fake flag is set, the link won't change the url and the position won't be animated.
65
+ */
66
+ var handleLink = function(link, fake) {
55
67
  //Don't use the href property (link.href) because it contains the absolute url.
56
68
  var href = link.getAttribute('href');
57
69
 
58
70
  //Check if it's a hashlink.
59
71
  if(!/^#/.test(href)) {
60
- return;
72
+ return false;
61
73
  }
62
74
 
63
75
  //Now get the targetTop to scroll to.
@@ -73,7 +85,7 @@
73
85
 
74
86
  //Ignore the click if no target is found.
75
87
  if(!scrollTarget) {
76
- return;
88
+ return false;
77
89
  }
78
90
 
79
91
  targetTop = _skrollrInstance.relativeToAbsolute(scrollTarget, 'top', 'top');
@@ -85,17 +97,27 @@
85
97
  }
86
98
  }
87
99
 
100
+ if(supportsHistory && !fake) {
101
+ history.pushState({top: targetTop}, '', href);
102
+ }
103
+
88
104
  //Now finally scroll there.
89
- if(_animate) {
105
+ if(_animate && !fake) {
90
106
  _skrollrInstance.animateTo(targetTop, {
91
107
  duration: _duration,
92
108
  easing: _easing
93
109
  });
94
110
  } else {
95
- _skrollrInstance.setScrollTop(targetTop);
111
+ defer(function() {
112
+ _skrollrInstance.setScrollTop(targetTop);
113
+ });
96
114
  }
97
115
 
98
- e.preventDefault();
116
+ return true;
117
+ };
118
+
119
+ var defer = function(fn) {
120
+ window.setTimeout(fn, 1);
99
121
  };
100
122
 
101
123
  /*
@@ -113,6 +135,17 @@
113
135
 
114
136
  //Use event bubbling and attach a single listener to the document.
115
137
  skrollr.addEvent(document, 'click', handleClick);
138
+
139
+ if(supportsHistory) {
140
+ window.addEventListener('popstate', function(e) {
141
+ var state = e.state || {};
142
+ var top = state.top || 0;
143
+
144
+ defer(function() {
145
+ _skrollrInstance.setScrollTop(top);
146
+ });
147
+ }, false);
148
+ }
116
149
  };
117
150
 
118
151
  //Private reference to the initialized skrollr.
@@ -124,9 +157,17 @@
124
157
 
125
158
  //In case the page was opened with a hash, prevent jumping to it.
126
159
  //http://stackoverflow.com/questions/3659072/jquery-disable-anchor-jump-when-loading-a-page
127
- window.setTimeout(function() {
160
+ defer(function() {
128
161
  if(window.location.hash) {
129
162
  window.scrollTo(0, 0);
163
+
164
+ if(document.querySelector) {
165
+ var link = document.querySelector('a[href="' + window.location.hash + '"]');
166
+
167
+ if(link) {
168
+ handleLink(link, true);
169
+ }
170
+ }
130
171
  }
131
- }, 1);
172
+ });
132
173
  }(document, window));
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skrollr-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails