From 5fe9aadc0e84bac277db7e6ab78b8731c2ba31fc Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 31 Mar 2017 14:54:34 +0200 Subject: Set progress --- app/Resources/static/themes/material/index.js | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'app/Resources/static/themes/material/index.js') diff --git a/app/Resources/static/themes/material/index.js b/app/Resources/static/themes/material/index.js index d6afbb8a..408528ea 100755 --- a/app/Resources/static/themes/material/index.js +++ b/app/Resources/static/themes/material/index.js @@ -75,4 +75,37 @@ $(document).ready(() => { const scrollPercent = (s / (d - c)) * 100; $('.progress .determinate').css('width', `${scrollPercent}%`); }); + +/* ========================================================================== + Annotations & Remember position + ========================================================================== */ + + if ($('article').length) { + const app = new annotator.App(); + const x = JSON.parse($('#annotationroutes').html()); + + app.include(annotator.ui.main, { + element: document.querySelector('article'), + }); + + 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); + }); + } }); -- cgit v1.2.3