Comparing version 0.2.3 to 0.2.4
@@ -291,3 +291,3 @@ 'use strict'; | ||
link.setPath(event.delegateTarget.href); | ||
if (link.getPath() == this.currentUrl || link.getPath() == '') { | ||
if (link.getAddress() == this.currentUrl || link.getAddress() == '') { | ||
if (link.getHash() != '') { | ||
@@ -317,8 +317,8 @@ this.triggerEvent('samePageWithHash'); | ||
if (swupClass != null) { | ||
this.updateTransition(window.location.pathname, link.getPath(), event.delegateTarget.dataset.swupClass); | ||
this.updateTransition(window.location.pathname, link.getAddress(), event.delegateTarget.dataset.swupClass); | ||
document.documentElement.classList.add('to-' + swupClass); | ||
} else { | ||
this.updateTransition(window.location.pathname, link.getPath()); | ||
this.updateTransition(window.location.pathname, link.getAddress()); | ||
} | ||
this.loadPage(link.getPath(), false); | ||
this.loadPage(link.getAddress(), false); | ||
} | ||
@@ -338,5 +338,5 @@ } else { | ||
link.setPath(event.delegateTarget.href); | ||
if (link.getPath() != this.currentUrl && !this.cache.exists(link.getPath()) && this.preloadPromise == null) { | ||
if (link.getAddress() != this.currentUrl && !this.cache.exists(link.getAddress()) && this.preloadPromise == null) { | ||
this.preloadPromise = new Promise(function (resolve) { | ||
_this.getPage(link.getPath(), function (response) { | ||
_this.getPage(link.getAddress(), function (response) { | ||
if (response === null) { | ||
@@ -348,3 +348,3 @@ console.warn('Server error.'); | ||
var page = _this.getDataFromHtml(response); | ||
page.url = link.getPath(); | ||
page.url = link.getAddress(); | ||
_this.cache.cacheUrl(page, _this.options.debugMode); | ||
@@ -357,3 +357,3 @@ _this.triggerEvent('pagePreloaded'); | ||
}); | ||
this.preloadPromise.route = link.getPath(); | ||
this.preloadPromise.route = link.getAddress(); | ||
} | ||
@@ -373,3 +373,3 @@ } | ||
this.triggerEvent('popState'); | ||
this.loadPage(link.getPath(), event); | ||
this.loadPage(link.getAddress(), event); | ||
} | ||
@@ -376,0 +376,0 @@ }]); |
@@ -25,3 +25,3 @@ 'use strict'; | ||
key: 'getPath', | ||
value: function getPath(href) { | ||
value: function getPath() { | ||
var path = this.link.pathname; | ||
@@ -34,4 +34,13 @@ if (path[0] != '/') { | ||
}, { | ||
key: 'getAddress', | ||
value: function getAddress() { | ||
var path = this.link.pathname + this.link.search; | ||
if (path[0] != '/') { | ||
path = '/' + path; | ||
} | ||
return path; | ||
} | ||
}, { | ||
key: 'getHash', | ||
value: function getHash(href) { | ||
value: function getHash() { | ||
return this.link.hash; | ||
@@ -38,0 +47,0 @@ } |
@@ -16,4 +16,4 @@ 'use strict'; | ||
link.setPath(pathname); | ||
if (link.getPath() != _this.currentUrl && !_this.cache.exists(link.getPath()) && _this.preloadPromise == null) { | ||
_this.getPage(link.getPath(), function (response) { | ||
if (link.getAddress() != _this.currentUrl && !_this.cache.exists(link.getAddress()) && _this.preloadPromise == null) { | ||
_this.getPage(link.getAddress(), function (response) { | ||
if (response === null) { | ||
@@ -25,3 +25,3 @@ console.warn('Server error.'); | ||
var page = _this.getDataFromHtml(response); | ||
page.url = link.getPath(); | ||
page.url = link.getAddress(); | ||
_this.cache.cacheUrl(page, _this.options.debugMode); | ||
@@ -28,0 +28,0 @@ _this.triggerEvent('pagePreloaded'); |
@@ -6,15 +6,26 @@ 'use strict'; | ||
this.triggerEvent('scrollStart'); | ||
var start = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0), | ||
change = to - start, | ||
increment = 20; | ||
var body = document.body; | ||
var animateScroll = function animateScroll(elapsedTime) { | ||
elapsedTime += increment; | ||
var position = easeInOut(elapsedTime, start, change, duration); | ||
window.scrollTo(0, position); | ||
if (elapsedTime < duration) { | ||
setTimeout(function () { | ||
animateScroll(elapsedTime); | ||
}, increment); | ||
var UP = -1; | ||
var DOWN = 1; | ||
var friction = 0.7; | ||
var acceleration = 0.04; | ||
var positionY = 100; | ||
var velocityY = 0; | ||
var targetPositionY = 400; | ||
var raf = null; | ||
function getScrollTop() { | ||
return document.body.scrollTop || document.documentElement.scrollTop; | ||
} | ||
var animate = function animate() { | ||
var distance = update(); | ||
render(); | ||
if (Math.abs(distance) > 0.1) { | ||
raf = requestAnimationFrame(animate); | ||
} else { | ||
@@ -25,12 +36,45 @@ _this.triggerEvent('scrollDone'); | ||
animateScroll(0); | ||
function update() { | ||
var distance = targetPositionY - positionY; | ||
var attraction = distance * acceleration; | ||
function easeInOut(currentTime, start, change, duration) { | ||
currentTime /= duration / 2; | ||
if (currentTime < 1) { | ||
return change / 2 * currentTime * currentTime + start; | ||
applyForce(attraction); | ||
velocityY *= friction; | ||
positionY += velocityY; | ||
return distance; | ||
} | ||
var applyForce = function applyForce(force) { | ||
velocityY += force; | ||
}; | ||
var render = function render() { | ||
window.scrollTo(0, positionY); | ||
}; | ||
window.addEventListener('mousewheel', function (event) { | ||
if (raf) { | ||
cancelAnimationFrame(raf); | ||
raf = null; | ||
} | ||
currentTime -= 1; | ||
return -change / 2 * (currentTime * (currentTime - 2) - 1) + start; | ||
}, { | ||
passive: true | ||
}); | ||
var scrollTo = function scrollTo(offset, callback) { | ||
positionY = getScrollTop(); | ||
targetPositionY = offset; | ||
velocityY = 0; | ||
animate(); | ||
}; | ||
this.triggerEvent('scrollStart'); | ||
if (duration == 0) { | ||
window.scrollTo(0, 0); | ||
this.triggerEvent('scrollDone'); | ||
} else { | ||
scrollTo(to); | ||
} | ||
}; |
{ | ||
"name": "swup", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Animated page transitions with css - simple, quick and fun.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
772
107323