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 /tpl/js/restoreScroll.js | |
parent | d62dfd88d2519f84b418700bcf7e08f1a4081662 (diff) | |
download | wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.tar.gz wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.tar.zst wallabag-a8778dc23e60e65b47e2aae5d4cdf92660ee4c02.zip |
fix bug #105: Scroll position save / sync
Diffstat (limited to 'tpl/js/restoreScroll.js')
-rw-r--r-- | tpl/js/restoreScroll.js | 25 |
1 files changed, 25 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 | ||