mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-22 17:18:37 +00:00
Extract Scroll Storage controller
This commit is contained in:
parent
019d252446
commit
d515e11fe4
4 changed files with 22 additions and 50 deletions
19
assets/controllers/scroll_storage_controller.js
Normal file
19
assets/controllers/scroll_storage_controller.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static values = { entryId: Number };
|
||||
|
||||
connect() {
|
||||
window.scrollTo({
|
||||
top: window.innerHeight * localStorage[`wallabag.article.${this.entryIdValue}.percent`],
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
|
||||
saveScroll() {
|
||||
const scrollPercent = window.scrollY / window.innerHeight;
|
||||
const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
|
||||
|
||||
localStorage[`wallabag.article.${this.entryIdValue}.percent`] = scrollPercentRounded;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue