mirror of
https://github.com/moparisthebest/wallabag
synced 2024-11-27 11:22:17 -05:00
fix bug #105: Scroll position save / sync
This commit is contained in:
parent
d62dfd88d2
commit
a8778dc23e
25
tpl/js/restoreScroll.js
Normal file
25
tpl/js/restoreScroll.js
Normal file
@ -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;
|
||||||
|
}
|
@ -37,4 +37,23 @@
|
|||||||
<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>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="./tpl/js/restoreScroll.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
$(window).scroll(function(e){
|
||||||
|
var scrollTop = $(window).scrollTop();
|
||||||
|
var docHeight = $(document).height();
|
||||||
|
var scrollPercent = (scrollTop) / (docHeight);
|
||||||
|
var scrollPercentRounded = Math.round(scrollPercent*100)/100;
|
||||||
|
savePercent({{ entry.id|e }}, scrollPercentRounded);
|
||||||
|
});
|
||||||
|
|
||||||
|
retrievePercent({{ entry.id|e }});
|
||||||
|
|
||||||
|
$(window).resize(function(){
|
||||||
|
retrievePercent({{ entry.id|e }});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user