2015-04-29 11:02:32 +02:00
|
|
|
'use strict';
|
2015-04-21 19:38:17 +02:00
|
|
|
|
2015-04-29 11:02:32 +02:00
|
|
|
var LocationActions = require('../actions/LocationActions');
|
2015-04-21 19:38:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A scroll behavior that attempts to imitate the default behavior
|
|
|
|
* of modern browsers.
|
|
|
|
*/
|
|
|
|
var ImitateBrowserBehavior = {
|
|
|
|
|
|
|
|
updateScrollPosition: function updateScrollPosition(position, actionType) {
|
|
|
|
switch (actionType) {
|
|
|
|
case LocationActions.PUSH:
|
|
|
|
case LocationActions.REPLACE:
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
break;
|
|
|
|
case LocationActions.POP:
|
|
|
|
if (position) {
|
|
|
|
window.scrollTo(position.x, position.y);
|
|
|
|
} else {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ImitateBrowserBehavior;
|