skrollr-rails 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b0711aeba31d3dfacb79fbe8b261990286913e5
4
- data.tar.gz: 1e037a545ae4cbe7fad4a922f86c9ddf48af51f7
3
+ metadata.gz: 66fe5b35160a73d4e2c206e315d823943d2e66b0
4
+ data.tar.gz: b97ea67a6a57614a746ebcfe1ae2d5995ba0aded
5
5
  SHA512:
6
- metadata.gz: b3846cc5e3288a4ef106d71a3eb3d23ca51565e91af38d7b7f94d130045249fea37af10d00e797da563aeb87955630946797693cd5c659bb27c221694db3aa96
7
- data.tar.gz: e4ab8a4af0572e44dc4d03ddf16e9040c851726462d40b23d8aa4e6fb031c4b024f0cfdc71fbc6e43bb66f4b9bbec5f06f6ea7b0dfe0c194693b92bc6ff1ac3e
6
+ metadata.gz: 80d7073ee02e87a92a17128638b6e47972a9c9a9a8470cded692756e5aa7d41d54a6df04636b029d785e81fd031ee2b1ba858f321bcb2c3941da0401c4b2ba4a
7
+ data.tar.gz: 63f1d21853374045bb7aae2142d4adaf1175e7a48096599dd594d3a0c558af3559695879f2587a8457f7375664af55b30268cf14ccd0652ca033989c09a63dc3
@@ -1,5 +1,5 @@
1
1
  module Skrollr
2
2
  module Rails
3
- VERSION = "0.6.18"
3
+ VERSION = "0.6.19"
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.17'
22
+ VERSION: '0.6.19'
23
23
  };
24
24
 
25
25
  //Minify optimization.
@@ -401,18 +401,20 @@
401
401
 
402
402
  var constant = match[1];
403
403
 
404
- //If there is a constant, get it's value or fall back to 0.
405
- constant = constant && _constants[constant.substr(1)] || 0;
404
+ if(constant) {
405
+ //Strip the underscore prefix.
406
+ kf.constant = constant.substr(1);
407
+ }
406
408
 
407
- //Parse key frame offset. If undefined will be casted to 0.
409
+ //Get the key frame offset.
408
410
  var offset = match[2];
409
411
 
410
412
  //Is it a percentage offset?
411
413
  if(/p$/.test(offset)) {
412
414
  kf.isPercentage = true;
413
- kf.offset = ((offset.slice(0, -1) | 0) + constant) / 100;
415
+ kf.offset = (offset.slice(0, -1) | 0) / 100;
414
416
  } else {
415
- kf.offset = (offset | 0) + constant;
417
+ kf.offset = (offset | 0);
416
418
  }
417
419
 
418
420
  var anchor1 = match[3];
@@ -430,9 +432,7 @@
430
432
  } else if(!kf.isPercentage) {
431
433
  //For data-start we can already set the key frame w/o calculations.
432
434
  //#59: "scale" options should only affect absolute mode.
433
- kf.frame = kf.offset * _scale;
434
-
435
- delete kf.offset;
435
+ kf.offset = kf.offset * _scale;
436
436
  }
437
437
  }
438
438
  //"relative" mode, where numbers are relative to anchors.
@@ -790,10 +790,13 @@
790
790
  };
791
791
 
792
792
  /**
793
- * Updates key frames which depend on others.
793
+ * Updates key frames which depend on others / need to be updated on resize.
794
794
  * That is "end" in "absolute" mode and all key frames in "relative" mode.
795
+ * Also handles constants, because they may change on resize.
795
796
  */
796
797
  var _updateDependentKeyFrames = function() {
798
+ var viewportHeight = documentElement.clientHeight;
799
+ var processedConstants = _processConstants();
797
800
  var skrollable;
798
801
  var element;
799
802
  var anchorTarget;
@@ -803,6 +806,8 @@
803
806
  var kf;
804
807
  var skrollableIndex;
805
808
  var skrollablesLength;
809
+ var offset;
810
+ var constantValue;
806
811
 
807
812
  //First process all relative-mode elements and find the max key frame.
808
813
  skrollableIndex = 0;
@@ -820,11 +825,14 @@
820
825
  for(; keyFrameIndex < keyFramesLength; keyFrameIndex++) {
821
826
  kf = keyFrames[keyFrameIndex];
822
827
 
823
- var offset = kf.offset;
828
+ offset = kf.offset;
829
+ constantValue = processedConstants[kf.constant] || 0;
830
+
831
+ kf.frame = offset;
824
832
 
825
833
  if(kf.isPercentage) {
826
834
  //Convert the offset to percentage of the viewport height.
827
- offset = offset * documentElement.clientHeight;
835
+ offset = offset * viewportHeight;
828
836
 
829
837
  //Absolute + percentage mode.
830
838
  kf.frame = offset;
@@ -838,6 +846,8 @@
838
846
  _reset(element, true);
839
847
  }
840
848
 
849
+ kf.frame += constantValue;
850
+
841
851
  //Only search for max key frame when forceHeight is enabled.
842
852
  if(_forceHeight) {
843
853
  //Find the max key frame, but don't use one of the data-end ones for comparison.
@@ -865,8 +875,10 @@
865
875
  for(; keyFrameIndex < keyFramesLength; keyFrameIndex++) {
866
876
  kf = keyFrames[keyFrameIndex];
867
877
 
878
+ constantValue = processedConstants[kf.constant] || 0;
879
+
868
880
  if(kf.isEnd) {
869
- kf.frame = _maxKeyFrame - kf.offset;
881
+ kf.frame = _maxKeyFrame - kf.offset + constantValue;
870
882
  }
871
883
  }
872
884
 
@@ -1447,6 +1459,32 @@
1447
1459
  _forceRender = true;
1448
1460
  };
1449
1461
 
1462
+ /*
1463
+ * Returns a copy of the constants object where all functions and strings have been evaluated.
1464
+ */
1465
+ var _processConstants = function() {
1466
+ var viewportHeight = documentElement.clientHeight;
1467
+ var copy = {};
1468
+ var prop;
1469
+ var value;
1470
+
1471
+ for(prop in _constants) {
1472
+ value = _constants[prop];
1473
+
1474
+ if(typeof value === 'function') {
1475
+ value = value.call(_instance);
1476
+ }
1477
+ //Percentage offset.
1478
+ else if((/p$/).test(value)) {
1479
+ value = (value.substr(0, -1) / 100) * viewportHeight;
1480
+ }
1481
+
1482
+ copy[prop] = value;
1483
+ }
1484
+
1485
+ return copy;
1486
+ };
1487
+
1450
1488
  /*
1451
1489
  * Returns the height of the document.
1452
1490
  */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skrollr-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.18
4
+ version: 0.6.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Reed