Skip to content

Commit cebbbdb

Browse files
committed
upgrade build system
1 parent 1cfd2c4 commit cebbbdb

File tree

5 files changed

+77
-87
lines changed

5 files changed

+77
-87
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

dist/jump.js

+60-74
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,83 @@
11
/*!
2-
* Jump.js 1.0.0 - A small, modern, dependency-free smooth scrolling library.
2+
* Jump.js 0.0.1 - A small, modern, dependency-free smooth scrolling library.
33
* Copyright (c) 2015 Michael Cavalea - https://github.com/callmecavs/jump.js
44
* License: MIT
55
*/
66

7-
(function (global, factory) {
8-
if (typeof define === 'function' && define.amd) {
9-
define('Jump', ['exports', 'module'], factory);
10-
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
11-
factory(exports, module);
12-
} else {
13-
var mod = {
14-
exports: {}
15-
};
16-
factory(mod.exports, mod);
17-
global.Jump = mod.exports;
18-
}
19-
})(this, function (exports, module) {
20-
'use strict';
7+
'use strict';
218

22-
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
9+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
2310

24-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
11+
Object.defineProperty(exports, "__esModule", {
12+
value: true
13+
});
2514

26-
var Jump = (function () {
27-
function Jump() {
28-
var defaults = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
15+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2916

30-
_classCallCheck(this, Jump);
17+
var Jump = (function () {
18+
function Jump() {
19+
_classCallCheck(this, Jump);
20+
}
3121

32-
this.duration = defaults.duration || 1000;
33-
this.offset = defaults.offset || 0;
34-
this.callback = defaults.callback || undefined;
22+
_createClass(Jump, [{
23+
key: 'jump',
24+
value: function jump(target) {
25+
var _this = this;
3526

36-
this.easing = defaults.easing || function (t, b, c, d) {
37-
// Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
38-
t /= d / 2;
39-
if (t < 1) return c / 2 * t * t + b;
40-
t--;
41-
return -c / 2 * (t * (t - 2) - 1) + b;
42-
};
43-
}
27+
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
4428

45-
_createClass(Jump, [{
46-
key: 'jump',
47-
value: function jump(target) {
48-
var _this = this;
29+
this.start = window.pageYOffset;
4930

50-
var overrides = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
51-
52-
this.jumpStart = window.pageYOffset;
31+
this.options = {
32+
duration: options.duration,
33+
offset: options.offset || 0,
34+
callback: options.callback || undefined
35+
};
5336

54-
this.jumpDuration = overrides.duration || this.duration;
55-
this.jumpOffset = overrides.offset || this.offset;
56-
this.jumpCallback = overrides.callback || this.callback;
57-
this.jumpEasing = overrides.easing || this.easing;
37+
this.distance = typeof target === 'string' ? this.options.offset + document.querySelector(target).getBoundingClientRect().top : target;
5838

59-
this.jumpDistance = target.nodeType === 1 ? this.jumpOffset + Math.round(target.getBoundingClientRect().top) : target;
39+
requestAnimationFrame(function (time) {
40+
return _this._loop(time);
41+
});
42+
}
43+
}, {
44+
key: '_loop',
45+
value: function _loop(time) {
46+
var _this2 = this;
6047

61-
requestAnimationFrame(function (time) {
62-
return _this._loop(time);
63-
});
48+
if (!this.timeStart) {
49+
this.timeStart = time;
6450
}
65-
}, {
66-
key: '_loop',
67-
value: function _loop(currentTime) {
68-
var _this2 = this;
6951

70-
if (!this.timeStart) {
71-
this.timeStart = currentTime;
72-
}
52+
this.timeElapsed = time - this.timeStart;
53+
this.next = this._easing(this.timeElapsed, this.start, this.distance, this.options.duration);
7354

74-
this.timeElapsed = currentTime - this.timeStart;
75-
this.jumpNext = this.jumpEasing(this.timeElapsed, this.jumpStart, this.jumpDistance, this.jumpDuration);
55+
window.scrollTo(0, this.next);
7656

77-
window.scrollTo(0, this.jumpNext);
78-
79-
this.timeElapsed < this.jumpDuration ? requestAnimationFrame(function (time) {
80-
return _this2._loop(time);
81-
}) : this._end();
82-
}
83-
}, {
84-
key: '_end',
85-
value: function _end() {
86-
window.scrollTo(0, this.jumpStart + this.jumpDistance);
57+
this.timeElapsed < this.options.duration ? requestAnimationFrame(function (time) {
58+
return _this2._loop(time);
59+
}) : this._end();
60+
}
61+
}, {
62+
key: '_end',
63+
value: function _end() {
64+
window.scrollTo(0, this.start + this.distance);
8765

88-
typeof this.jumpCallback === 'function' && this.jumpCallback.call();
89-
this.timeStart = false;
90-
}
91-
}]);
66+
typeof this.options.callback === 'function' && this.options.callback.call();
67+
this.timeStart = false;
68+
}
69+
}, {
70+
key: '_easing',
71+
value: function _easing(t, b, c, d) {
72+
// Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
73+
t /= d / 2;
74+
if (t < 1) return c / 2 * t * t + b;
75+
t--;
76+
return -c / 2 * (t * (t - 2) - 1) + b;
77+
}
78+
}]);
9279

93-
return Jump;
94-
})();
80+
return Jump;
81+
})();
9582

96-
module.exports = Jump;
97-
});
83+
exports.default = Jump;

dist/jump.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.babel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const attribution = [
2727
gulp.task('js', () => {
2828
return gulp.src('src/jump.js')
2929
.pipe(plumber({ errorHandler: onError }))
30-
.pipe(babel({ moduleId: 'Jump', modules: 'umd' }))
30+
.pipe(babel())
3131
.pipe(header(attribution, { pkg: packageJSON }))
3232
.pipe(gulp.dest('dist'))
3333
.pipe(uglify({ preserveComments: 'some' }))

package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jump.js",
3-
"version": "1.0.0",
3+
"version": "0.0.1",
44
"description": "A small, modern, dependency-free smooth scrolling library.",
55
"homepage": "https://github.com/callmecavs/jump.js",
66
"main": "dist/jump.js",
@@ -21,14 +21,15 @@
2121
],
2222

2323
"devDependencies": {
24-
"babel": "*",
25-
"gulp": "*",
26-
"gulp-babel": "*",
27-
"gulp-connect": "*",
28-
"gulp-header": "*",
29-
"gulp-plumber": "*",
30-
"gulp-rename": "*",
31-
"gulp-uglify": "*",
32-
"node-notifier": "*"
24+
"babel": "*",
25+
"babel-preset-es2015": "*",
26+
"gulp": "*",
27+
"gulp-babel": "*",
28+
"gulp-connect": "*",
29+
"gulp-header": "*",
30+
"gulp-plumber": "*",
31+
"gulp-rename": "*",
32+
"gulp-uglify": "*",
33+
"node-notifier": "*"
3334
}
3435
}

0 commit comments

Comments
 (0)