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: 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 (limited to 'tpl') 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 @@ +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 2b6d91d5..f9405f45 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 -- cgit v1.2.3