From a8778dc23e60e65b47e2aae5d4cdf92660ee4c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 17 Sep 2013 13:27:16 +0200 Subject: [PATCH] fix bug #105: Scroll position save / sync --- tpl/js/restoreScroll.js | 25 +++++++++++++++++++++++++ tpl/view.twig | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tpl/js/restoreScroll.js diff --git a/tpl/js/restoreScroll.js b/tpl/js/restoreScroll.js new file mode 100644 index 0000000..331c9e1 --- /dev/null +++ b/tpl/js/restoreScroll.js @@ -0,0 +1,25 @@ +function supportsLocalStorage() { + try { + return 'localStorage' in window && window['localStorage'] !== null; + } catch (e) { + return false; + } +} + +function savePercent(id, percent) { + if (!supportsLocalStorage()) { return false; } + localStorage["poche.article." + id + ".percent"] = percent; + return true; +} + +function retrievePercent(id) { + if (!supportsLocalStorage()) { return false; } + + var bheight = $(document).height(); + var percent = localStorage["poche.article." + id + ".percent"]; + var scroll = bheight * percent; + + $('html,body').animate({scrollTop: scroll}, 'fast'); + + return true; +} \ No newline at end of file diff --git a/tpl/view.twig b/tpl/view.twig index 2b6d91d..f9405f4 100644 --- a/tpl/view.twig +++ b/tpl/view.twig @@ -37,4 +37,23 @@

{% trans "this article appears wrong?" %} {% trans "create an issue" %} {% trans "or" %} {% trans "contact us by mail" %}

+ + {% endblock %} \ No newline at end of file