aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl
diff options
context:
space:
mode:
Diffstat (limited to 'tpl')
-rw-r--r--tpl/js/restoreScroll.js25
-rw-r--r--tpl/view.twig19
2 files changed, 44 insertions, 0 deletions
diff --git a/tpl/js/restoreScroll.js b/tpl/js/restoreScroll.js
new file mode 100644
index 00000000..331c9e19
--- /dev/null
+++ b/tpl/js/restoreScroll.js
@@ -0,0 +1,25 @@
1function supportsLocalStorage() {
2 try {
3 return 'localStorage' in window && window['localStorage'] !== null;
4 } catch (e) {
5 return false;
6 }
7}
8
9function savePercent(id, percent) {
10 if (!supportsLocalStorage()) { return false; }
11 localStorage["poche.article." + id + ".percent"] = percent;
12 return true;
13}
14
15function retrievePercent(id) {
16 if (!supportsLocalStorage()) { return false; }
17
18 var bheight = $(document).height();
19 var percent = localStorage["poche.article." + id + ".percent"];
20 var scroll = bheight * percent;
21
22 $('html,body').animate({scrollTop: scroll}, 'fast');
23
24 return true;
25} \ No newline at end of file
diff --git a/tpl/view.twig b/tpl/view.twig
index 2b6d91d5..f9405f45 100644
--- a/tpl/view.twig
+++ b/tpl/view.twig
@@ -37,4 +37,23 @@
37 <p>{% trans "this article appears wrong?" %} <a href="https://github.com/inthepoche/poche/issues/new">{% trans "create an issue" %}</a> {% trans "or" %} <a href="mailto:support@inthepoche.com?subject=Wrong%20display%20in%20poche&amp;body={{ entry.url|url_encode }}">{% trans "contact us by mail" %}</a></p> 37 <p>{% trans "this article appears wrong?" %} <a href="https://github.com/inthepoche/poche/issues/new">{% trans "create an issue" %}</a> {% trans "or" %} <a href="mailto:support@inthepoche.com?subject=Wrong%20display%20in%20poche&amp;body={{ entry.url|url_encode }}">{% trans "contact us by mail" %}</a></p>
38 </div> 38 </div>
39 </div> 39 </div>
40 <script src="./tpl/js/restoreScroll.js"></script>
41 <script type="text/javascript">
42 $(document).ready(function() {
43
44 $(window).scroll(function(e){
45 var scrollTop = $(window).scrollTop();
46 var docHeight = $(document).height();
47 var scrollPercent = (scrollTop) / (docHeight);
48 var scrollPercentRounded = Math.round(scrollPercent*100)/100;
49 savePercent({{ entry.id|e }}, scrollPercentRounded);
50 });
51
52 retrievePercent({{ entry.id|e }});
53
54 $(window).resize(function(){
55 retrievePercent({{ entry.id|e }});
56 });
57 });
58 </script>
40{% endblock %} \ No newline at end of file 59{% endblock %} \ No newline at end of file