Comparing version 1.8.0 to 1.8.1
/*! | ||
* MoveTo - A lightweight scroll animation javascript library without any dependency. | ||
* Version 1.8.0 (14-01-2019 13:15) | ||
* Version 1.8.1 (07-05-2019 23:39) | ||
* Licensed under MIT | ||
@@ -8,8 +8,9 @@ * Copyright 2019 Hasan Aydoğdu <hsnaydd@gmail.com> | ||
'use strict'; | ||
"use strict"; | ||
var MoveTo = function () { | ||
/** | ||
* Defaults | ||
* @type {object} | ||
*/ | ||
* Defaults | ||
* @type {object} | ||
*/ | ||
var defaults = { | ||
@@ -20,13 +21,13 @@ tolerance: 0, | ||
container: window, | ||
callback: function callback() {} }; | ||
callback: function callback() {} | ||
}; | ||
/** | ||
* easeOutQuart Easing Function | ||
* @param {number} t - current time | ||
* @param {number} b - start value | ||
* @param {number} c - change in value | ||
* @param {number} d - duration | ||
* @return {number} - calculated value | ||
*/ | ||
/** | ||
* easeOutQuart Easing Function | ||
* @param {number} t - current time | ||
* @param {number} b - start value | ||
* @param {number} c - change in value | ||
* @param {number} d - duration | ||
* @return {number} - calculated value | ||
*/ | ||
function easeOutQuart(t, b, c, d) { | ||
@@ -37,10 +38,11 @@ t /= d; | ||
} | ||
/** | ||
* Merge two object | ||
* | ||
* @param {object} obj1 | ||
* @param {object} obj2 | ||
* @return {object} merged object | ||
*/ | ||
/** | ||
* Merge two object | ||
* | ||
* @param {object} obj1 | ||
* @param {object} obj2 | ||
* @return {object} merged object | ||
*/ | ||
function mergeObject(obj1, obj2) { | ||
@@ -51,3 +53,2 @@ var obj3 = {}; | ||
}); | ||
Object.keys(obj2).forEach(function (propertyName) { | ||
@@ -57,9 +58,11 @@ obj3[propertyName] = obj2[propertyName]; | ||
return obj3; | ||
}; | ||
} | ||
; | ||
/** | ||
* Converts camel case to kebab case | ||
* @param {string} val the value to be converted | ||
* @return {string} the converted value | ||
*/ | ||
* Converts camel case to kebab case | ||
* @param {string} val the value to be converted | ||
* @return {string} the converted value | ||
*/ | ||
function kebabCase(val) { | ||
@@ -69,9 +72,11 @@ return val.replace(/([A-Z])/g, function ($1) { | ||
}); | ||
}; | ||
} | ||
; | ||
/** | ||
* Count a number of item scrolled top | ||
* @param {Window|HTMLElement} container | ||
* @return {number} | ||
*/ | ||
* Count a number of item scrolled top | ||
* @param {Window|HTMLElement} container | ||
* @return {number} | ||
*/ | ||
function countScrollTop(container) { | ||
@@ -81,22 +86,32 @@ if (container instanceof HTMLElement) { | ||
} | ||
return container.pageYOffset; | ||
}; | ||
} | ||
; | ||
/** | ||
* MoveTo Constructor | ||
* @param {object} options Options | ||
* @param {object} easeFunctions Custom ease functions | ||
*/ | ||
function MoveTo() {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};var easeFunctions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
* MoveTo Constructor | ||
* @param {object} options Options | ||
* @param {object} easeFunctions Custom ease functions | ||
*/ | ||
function MoveTo() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var easeFunctions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.options = mergeObject(defaults, options); | ||
this.easeFunctions = mergeObject({ easeOutQuart: easeOutQuart }, easeFunctions); | ||
this.easeFunctions = mergeObject({ | ||
easeOutQuart: easeOutQuart | ||
}, easeFunctions); | ||
} | ||
/** | ||
* Register a dom element as trigger | ||
* @param {HTMLElement} dom Dom trigger element | ||
* @param {function} callback Callback function | ||
* @return {function|void} unregister function | ||
*/ | ||
/** | ||
* Register a dom element as trigger | ||
* @param {HTMLElement} dom Dom trigger element | ||
* @param {function} callback Callback function | ||
* @return {function|void} unregister function | ||
*/ | ||
MoveTo.prototype.registerTrigger = function (dom, callback) {var _this = this; | ||
MoveTo.prototype.registerTrigger = function (dom, callback) { | ||
var _this = this; | ||
if (!dom) { | ||
@@ -106,7 +121,5 @@ return; | ||
var href = dom.getAttribute('href') || dom.getAttribute('data-target'); | ||
// The element to be scrolled | ||
var target = href && href !== '#' ? | ||
document.getElementById(href.substring(1)) : | ||
document.body; | ||
var href = dom.getAttribute('href') || dom.getAttribute('data-target'); // The element to be scrolled | ||
var target = href && href !== '#' ? document.getElementById(href.substring(1)) : document.body; | ||
var options = mergeObject(this.options, _getOptionsFromTriggerDom(dom, this.options)); | ||
@@ -120,2 +133,3 @@ | ||
e.preventDefault(); | ||
_this.move(target, options); | ||
@@ -125,13 +139,19 @@ }; | ||
dom.addEventListener('click', listener, false); | ||
return function () {return dom.removeEventListener('click', listener, false);}; | ||
return function () { | ||
return dom.removeEventListener('click', listener, false); | ||
}; | ||
}; | ||
/** | ||
* Move | ||
* Scrolls to given element by using easeOutQuart function | ||
* @param {HTMLElement|number} target Target element to be scrolled or target position | ||
* @param {object} options Custom options | ||
*/ | ||
/** | ||
* Move | ||
* Scrolls to given element by using easeOutQuart function | ||
* @param {HTMLElement|number} target Target element to be scrolled or target position | ||
* @param {object} options Custom options | ||
*/ | ||
MoveTo.prototype.move = function (target) {var _this2 = this;var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
MoveTo.prototype.move = function (target) { | ||
var _this2 = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (target !== 0 && !target) { | ||
@@ -142,10 +162,8 @@ return; | ||
options = mergeObject(this.options, options); | ||
var distance = typeof target === 'number' ? target : target.getBoundingClientRect().top; | ||
var from = countScrollTop(options.container); | ||
var startTime = null; | ||
var lastYOffset = void 0; | ||
distance -= options.tolerance; | ||
var lastYOffset; | ||
distance -= options.tolerance; // rAF loop | ||
// rAF loop | ||
var loop = function loop(currentTime) { | ||
@@ -164,9 +182,7 @@ var currentYOffset = countScrollTop(_this2.options.container); | ||
if (lastYOffset) { | ||
if ( | ||
distance > 0 && lastYOffset > currentYOffset || | ||
distance < 0 && lastYOffset < currentYOffset) | ||
{ | ||
if (distance > 0 && lastYOffset > currentYOffset || distance < 0 && lastYOffset < currentYOffset) { | ||
return options.callback(target); | ||
} | ||
} | ||
lastYOffset = currentYOffset; | ||
@@ -188,23 +204,25 @@ | ||
}; | ||
/** | ||
* Adds custom ease function | ||
* @param {string} name Ease function name | ||
* @param {function} fn Ease function | ||
*/ | ||
/** | ||
* Adds custom ease function | ||
* @param {string} name Ease function name | ||
* @param {function} fn Ease function | ||
*/ | ||
MoveTo.prototype.addEaseFunction = function (name, fn) { | ||
this.easeFunctions[name] = fn; | ||
}; | ||
/** | ||
* Returns options which created from trigger dom element | ||
* @param {HTMLElement} dom Trigger dom element | ||
* @param {object} options The instance's options | ||
* @return {object} The options which created from trigger dom element | ||
*/ | ||
/** | ||
* Returns options which created from trigger dom element | ||
* @param {HTMLElement} dom Trigger dom element | ||
* @param {object} options The instance's options | ||
* @return {object} The options which created from trigger dom element | ||
*/ | ||
function _getOptionsFromTriggerDom(dom, options) { | ||
var domOptions = {}; | ||
Object.keys(options).forEach(function (key) { | ||
var value = dom.getAttribute("data-mt-".concat(kebabCase(key))); | ||
Object.keys(options).forEach(function (key) { | ||
var value = dom.getAttribute('data-mt-' + kebabCase(key)); | ||
if (value) { | ||
@@ -211,0 +229,0 @@ domOptions[key] = isNaN(value) ? value : parseInt(value, 10); |
/*! | ||
* MoveTo - A lightweight scroll animation javascript library without any dependency. | ||
* Version 1.8.0 (14-01-2019 13:15) | ||
* Version 1.8.1 (07-05-2019 23:39) | ||
* Licensed under MIT | ||
@@ -8,2 +8,2 @@ * Copyright 2019 Hasan Aydoğdu <hsnaydd@gmail.com> | ||
"use strict";var MoveTo=function(){var n={tolerance:0,duration:800,easing:"easeOutQuart",container:window,callback:function(){}};function o(t,e,n,o){return t/=o,-n*(--t*t*t*t-1)+e}function v(e,n){var o={};return Object.keys(e).forEach(function(t){o[t]=e[t]}),Object.keys(n).forEach(function(t){o[t]=n[t]}),o}function d(t){return t instanceof HTMLElement?t.scrollTop:t.pageYOffset}function t(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};this.options=v(n,t),this.easeFunctions=v({easeOutQuart:o},e)}return t.prototype.registerTrigger=function(t,e){var n=this;if(t){var o,i,r,a=t.getAttribute("href")||t.getAttribute("data-target"),c=a&&"#"!==a?document.getElementById(a.substring(1)):document.body,u=v(this.options,(o=t,i=this.options,r={},Object.keys(i).forEach(function(t){var e=o.getAttribute("data-mt-"+t.replace(/([A-Z])/g,function(t){return"-"+t.toLowerCase()}));e&&(r[t]=isNaN(e)?e:parseInt(e,10))}),r));"function"==typeof e&&(u.callback=e);var s=function(t){t.preventDefault(),n.move(c,u)};return t.addEventListener("click",s,!1),function(){return t.removeEventListener("click",s,!1)}}},t.prototype.move=function(r){var a=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(0===r||r){c=v(this.options,c);var u="number"==typeof r?r:r.getBoundingClientRect().top,s=d(c.container),f=null,l=void 0;u-=c.tolerance;window.requestAnimationFrame(function t(e){var n=d(a.options.container);f||(f=e-1);var o=e-f;if(l&&(0<u&&n<l||u<0&&l<n))return c.callback(r);l=n;var i=a.easeFunctions[c.easing](o,s,u,c.duration);c.container.scroll(0,i),o<c.duration?window.requestAnimationFrame(t):(c.container.scroll(0,u+s),c.callback(r))})}},t.prototype.addEaseFunction=function(t,e){this.easeFunctions[t]=e},t}();"undefined"!=typeof module?module.exports=MoveTo:window.MoveTo=MoveTo; | ||
"use strict";var MoveTo=function(){var e={tolerance:0,duration:800,easing:"easeOutQuart",container:window,callback:function(){}};function o(t,n,e,o){return t/=o,-e*(--t*t*t*t-1)+n}function v(n,e){var o={};return Object.keys(n).forEach(function(t){o[t]=n[t]}),Object.keys(e).forEach(function(t){o[t]=e[t]}),o}function d(t){return t instanceof HTMLElement?t.scrollTop:t.pageYOffset}function t(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};this.options=v(e,t),this.easeFunctions=v({easeOutQuart:o},n)}return t.prototype.registerTrigger=function(t,n){var e=this;if(t){var o=t.getAttribute("href")||t.getAttribute("data-target"),r=o&&"#"!==o?document.getElementById(o.substring(1)):document.body,i=v(this.options,function(e,t){var o={};return Object.keys(t).forEach(function(t){var n=e.getAttribute("data-mt-".concat(function(t){return t.replace(/([A-Z])/g,function(t){return"-"+t.toLowerCase()})}(t)));n&&(o[t]=isNaN(n)?n:parseInt(n,10))}),o}(t,this.options));"function"==typeof n&&(i.callback=n);var a=function(t){t.preventDefault(),e.move(r,i)};return t.addEventListener("click",a,!1),function(){return t.removeEventListener("click",a,!1)}}},t.prototype.move=function(i){var a=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(0===i||i){c=v(this.options,c);var u,s="number"==typeof i?i:i.getBoundingClientRect().top,f=d(c.container),l=null;s-=c.tolerance;window.requestAnimationFrame(function t(n){var e=d(a.options.container);l||(l=n-1);var o=n-l;if(u&&(0<s&&e<u||s<0&&u<e))return c.callback(i);u=e;var r=a.easeFunctions[c.easing](o,f,s,c.duration);c.container.scroll(0,r),o<c.duration?window.requestAnimationFrame(t):(c.container.scroll(0,s+f),c.callback(i))})}},t.prototype.addEaseFunction=function(t,n){this.easeFunctions[t]=n},t}();"undefined"!=typeof module?module.exports=MoveTo:window.MoveTo=MoveTo; |
@@ -34,3 +34,3 @@ 'use strict'; | ||
gulp.task('scripts:lint', (cb) => { | ||
return gulp.src('src/scripts/**/*.js') | ||
return gulp.src('src/**/*.js') | ||
.pipe($.eslint()) | ||
@@ -49,3 +49,3 @@ .pipe($.eslint.format()) | ||
return gulp.src('src/**/*.js') | ||
.pipe($.babel()) | ||
.pipe($.babel({presets: ['@babel/preset-env']})) | ||
.pipe($.header(banner)) | ||
@@ -52,0 +52,0 @@ .pipe(gulp.dest('dist')) |
{ | ||
"name": "moveto", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "A lightweight scroll animation javascript library without any dependency.", | ||
"main": "dist/moveTo.js", | ||
"scripts": { | ||
"test": "ava tests/**" | ||
"gulp": "gulp", | ||
"test": "ava tests/**", | ||
"lint": "gulp scripts:lint", | ||
"build": "yarn gulp build", | ||
"start": "yarn build && yarn gulp serve" | ||
}, | ||
@@ -30,11 +34,12 @@ "repository": { | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"babel-core": "^6.26.3", | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"ava": "^1.4.1", | ||
"babel-eslint": "^10.0.1", | ||
"babel-preset-es2015": "^6.22.0", | ||
"browser-sync": "^2.24.7", | ||
"del": "^4.1.1", | ||
"eslint": "^5.6.0", | ||
"eslint-config-google": "^0.10.0", | ||
"eslint-config-google": "^0.12.0", | ||
"gulp": "^3.9.1", | ||
"gulp-babel": "^7.0.1", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-eslint": "^5.0.0", | ||
@@ -46,17 +51,7 @@ "gulp-header": "^2.0.5", | ||
"gulp-util": "^3.0.8", | ||
"jsdom": "12.0.0", | ||
"jsdom": "15.0.0", | ||
"jsdom-global": "3.0.2", | ||
"lazypipe": "^1.0.1", | ||
"run-sequence": "^2.2.1" | ||
}, | ||
"ava": { | ||
"require": [ | ||
"babel-register" | ||
], | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
] | ||
} | ||
} | ||
} |
@@ -228,12 +228,24 @@ # MoveTo [![npm version](https://badge.fury.io/js/moveto.svg)](https://badge.fury.io/js/moveto) [![Bower version](https://badge.fury.io/bo/moveTo.svg)](https://badge.fury.io/bo/moveTo) [![CDNJS version](https://img.shields.io/cdnjs/v/moveTo.svg)](https://cdnjs.com/libraries/moveTo) [![Build Status](https://travis-ci.org/hsnaydd/moveTo.svg?branch=master)](https://travis-ci.org/hsnaydd/moveTo.js) | ||
$ gulp serve | ||
$ yarn start | ||
# Or so if using npm: | ||
$ npm run start | ||
# To lint your code run: | ||
$ gulp scripts:lint | ||
$ yarn lint | ||
# Or so if using npm: | ||
$ npm run lint | ||
# To make a full new build run: | ||
$ gulp build | ||
$ yarn build | ||
# Or so if using npm: | ||
$ npm run build | ||
# To run tests: | ||
@@ -240,0 +252,0 @@ |
@@ -134,3 +134,3 @@ | ||
const loop = (currentTime) => { | ||
let currentYOffset = countScrollTop(this.options.container); | ||
const currentYOffset = countScrollTop(this.options.container); | ||
@@ -190,3 +190,3 @@ if (!startTime) { | ||
Object.keys(options).forEach((key) => { | ||
let value = dom.getAttribute(`data-mt-${kebabCase(key)}`); | ||
const value = dom.getAttribute(`data-mt-${kebabCase(key)}`); | ||
if (value) { | ||
@@ -193,0 +193,0 @@ domOptions[key] = isNaN(value) ? value : parseInt(value, 10); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309041
19
700
266
20