X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app%2FResources%2Fstatic%2Fthemes%2Fbaggy%2Findex.js;h=27e3e3744425fd704a141731bd32e345929e9898;hb=5fe9aadc0e84bac277db7e6ab78b8731c2ba31fc;hp=39ad49aa6a8dc968269b5e05731cb0b7766757b9;hpb=46a54f5debe317ccb3a473ec4b54d3755fe6606c;p=github%2Fwallabag%2Fwallabag.git diff --git a/app/Resources/static/themes/baggy/index.js b/app/Resources/static/themes/baggy/index.js index 39ad49aa..27e3e374 100755 --- a/app/Resources/static/themes/baggy/index.js +++ b/app/Resources/static/themes/baggy/index.js @@ -9,6 +9,9 @@ import './js/shortcuts/entry'; /* Tools */ import toggleSaveLinkForm from './js/uiTools'; +import {savePercent, retrievePercent, throttle} from '../_global/js/tools'; + +global.jquery = $; /* Theme style */ import './css/index.scss'; @@ -50,6 +53,39 @@ $(document).ready(() => { }); } + /* ========================================================================== + Annotations & Remember position + ========================================================================== */ + + if ($('article').length) { + const app = new annotator.App(); + + app.include(annotator.ui.main, { + element: document.querySelector('article'), + }); + + const x = JSON.parse($('#annotationroutes').html()); + app.include(annotator.storage.http, x); + + app.start().then(() => { + app.annotations.load({ entry: x.entryId }); + }); + + window.addEventListener('unload', () => { + const scrollTop = $(window).scrollTop(); + const docHeight = $(document).height(); + const scrollPercent = (scrollTop) / (docHeight); + const scrollPercentRounded = Math.round(scrollPercent * 100) / 100; + savePercent(x.entryId, scrollPercentRounded); + }); + + retrievePercent(x.entryId); + + $(window).resize(() => { + retrievePercent(x.entryId); + }); + } + /** * Close window after adding entry if popup */