Skip to content

Commit

Permalink
Remember the position of the scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosuge committed Sep 19, 2015
1 parent 8c395f4 commit 9036e88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/renderer/timeline/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Timeline {
constructor() {
this.tweets = {};
this.windows = {};
this.currentWindowId = '';
}

showHomeTimeline() {
Expand All @@ -29,6 +30,9 @@ class Timeline {
this.switchTimeline(id);
}

currentWindow() {
return this.windows[this.currentWindowId];
}

createElement(id) {
let el = document.createElement("div");
Expand All @@ -39,12 +43,26 @@ class Timeline {
}

switchTimeline(id) {
let nextWindow = this.windows[id];
let el = document.getElementById('tweets');
if (this.currentWindow()) {
this.currentWindow().scrollTop = el.scrollTop;
}

let tweets = document.getElementsByClassName('tweets');
Array.prototype.forEach.call(tweets, (node) =>{
node.style.display = 'none';
});

let tl = document.querySelector(`div[data-timeline-id="${id}"]`);
tl.style.display = '';

if (nextWindow.scrollTop) {
el.scrollTop = nextWindow.scrollTop;
} else {
el.scrollTop = el.scrollHeight;
}
this.currentWindowId = id;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/timeline/tweets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export default class Tweets {
this.node = node;
this.template = Hogan.compile(this.template());
this.statusIds = [];
this.scrollTop = 0;
this.autoScroll = false;
}

pushTweet(tweet) {
Expand Down

0 comments on commit 9036e88

Please sign in to comment.