diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-09-17 13:27:16 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-09-17 13:27:16 +0200 |
commit | a8778dc23e60e65b47e2aae5d4cdf92660ee4c02 (patch) | |
tree | 09fd049dd660502b04b6a352ecb4ecca14c0fff6 | |
parent | d62dfd88d2519f84b418700bcf7e08f1a4081662 (diff) | |
download | wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.tar.gz wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.tar.zst wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.zip |
fix bug #105: Scroll position save / sync
-rw-r--r-- | tpl/js/restoreScroll.js | 25 | ||||
-rw-r--r-- | tpl/view.twig | 19 |
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 @@ | |||
1 | function supportsLocalStorage() { | ||
2 | try { | ||
3 | return 'localStorage' in window && window['localStorage'] !== null; | ||
4 | } catch (e) { | ||
5 | return false; | ||
6 | } | ||
7 | } | ||
8 | |||
9 | function savePercent(id, percent) { | ||
10 | if (!supportsLocalStorage()) { return false; } | ||
11 | localStorage["poche.article." + id + ".percent"] = percent; | ||
12 | return true; | ||
13 | } | ||
14 | |||
15 | function 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&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&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 |