Skip to content

Commit

Permalink
Fixed bug w/ reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Wilkerson committed May 4, 2018
1 parent c7ac009 commit 8f23c8f
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 73 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(config) {

autoWatch: true,

browsers: ['Chrome']
browsers: ['PhantomJS']

});
};
96 changes: 51 additions & 45 deletions luna-scroll-tracking.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-tracking-google-analytics",
"version": "2.0.2",
"version": "2.0.3",
"description": "Plug-and-play context-aware scroll tracking with no dependencies.",
"main": "Gruntfile.js",
"scripts": {
Expand All @@ -17,6 +17,7 @@
"grunt-contrib-jshint": "~0.12.0",
"grunt-contrib-uglify": "^0.9.1",
"jasmine-core": "^2.8.0",
"js-beautify": "^1.7.5",
"karma": "^1.7.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.4",
Expand Down
7 changes: 4 additions & 3 deletions scroll-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@
ScrollTracker.prototype.reset = function() {

this._tracked = {};
delete this._marks;
this.marks = {};
this._marks = {};

this._update();

};

Expand Down Expand Up @@ -649,7 +650,7 @@

})(this);
/*
* v2.0.2
* v2.0.3
* Created by the Google Analytics consultants at http://www.lunametrics.com/
* Written by @notdanwilkerson
* Documentation: https://github.com/lunametrics/gascroll/
Expand Down
4 changes: 2 additions & 2 deletions scroll-tracker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/scroll-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@
ScrollTracker.prototype.reset = function() {

this._tracked = {};
delete this._marks;
this.marks = {};
this._marks = {};

this._update();

};

Expand Down
65 changes: 46 additions & 19 deletions test/scrollTracker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,32 @@ describe('scroll-tracker', function(){
"nested": {
".nested-every[0]": 0,
"10px": 10,
"10%": 40,
"10%": 39,
"90px": 90,
"25%": 100,
"25%": 98,
"100px": 100,
"50%": 200,
"50%": 197,
"200px": 200,
".nested-every[1]": 200,
"75%": 300,
"75%": 296,
"300px": 300,
"90%": 360,
"100%": 400,
"400px": 400
"90%": 355,
"100%": 395
},
"normal": {
"10px": 10,
"90px": 90,
"10%": 190,
"25%": 475,
"50%": 950,
"10%": 189,
"25%": 473,
"50%": 947,
"1000px": 1000,
".every[0]": 1000,
"#each": 1200,
".every[1]": 1300,
"75%": 1425,
"75%": 1421,
".every[2]": 1500,
"90%": 1710,
"100%": 1900
"90%": 1705,
"100%": 1895
}
};

Expand Down Expand Up @@ -130,12 +129,12 @@ describe('scroll-tracker', function(){
var passed = {};

var outcome = {
'10%': 100,
'25%': 250,
'50%': 500,
'75%': 750,
'90%': 900,
'100%': 1000
'10%': 99,
'25%': 248,
'50%': 497,
'75%': 746,
'90%': 895,
'100%': 995
};

tracker.on({
Expand Down Expand Up @@ -223,6 +222,33 @@ describe('scroll-tracker', function(){

});

describe('reset()', function() {

it ('should reset the internal marks', function() {

var tracker = ScrollTracker();
var events = [];

tracker.on({
percentages: {
each: [10]
}
}, function(evt) {

events.push(evt);

});

window.scrollTo(0, 1000);

expect(events.length).toBe(1);
tracker.reset();
expect(events.length).toBe(2);

});

});

describe('minHeight', function() {

it ('should not set marks because the min height is too small', function() {
Expand Down Expand Up @@ -332,6 +358,7 @@ describe('scroll-tracker', function(){

});


});

function noop () {}

0 comments on commit 8f23c8f

Please sign in to comment.