forked from leftypol/leftypol
Improve the mobile UX (#167)
Chunky PR Reviewed-on: https://git.leftypol.org/leftypol/leftypol/pulls/167 Co-authored-by: Zankaria <zankaria.auxa@skiff.com> Co-committed-by: Zankaria <zankaria.auxa@skiff.com>
This commit is contained in:
parent
31086b05d9
commit
f2ea90a2d0
28 changed files with 661 additions and 451 deletions
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
// From http://stackoverflow.com/a/14035162
|
||||
$.fn.scrollStopped = function(callback) {
|
||||
$.fn.scrollStopped = function(callback) {
|
||||
$(this).scroll(function(){
|
||||
var self = this, $this = $(self);
|
||||
if ($this.data('scrollTimeout')) {
|
||||
|
@ -73,7 +73,7 @@ $(document).ready(function(){
|
|||
|
||||
$('#auto_thread_desktop_notifications>input,#auto_thread_desktop_notifications_all>input').on('click', function() {
|
||||
if (!("Notification" in window)) return;
|
||||
|
||||
|
||||
var setting = $(this).parent().attr('id');
|
||||
if ($(this).is(':checked')) {
|
||||
Notification.requestPermission(function(permission){
|
||||
|
@ -132,7 +132,7 @@ $(document).ready(function(){
|
|||
|
||||
var new_posts = 0;
|
||||
var first_new_post = null;
|
||||
|
||||
|
||||
var title = document.title;
|
||||
|
||||
if (typeof update_title == "undefined") {
|
||||
|
@ -178,7 +178,7 @@ $(document).ready(function(){
|
|||
var decrement_timer = function() {
|
||||
poll_current_time = poll_current_time - 1000;
|
||||
$('#update_secs').text(poll_current_time/1000);
|
||||
|
||||
|
||||
if (poll_current_time <= 0) {
|
||||
poll(manualUpdate = false);
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ $(document).ready(function(){
|
|||
update_title();
|
||||
first_new_post = null;
|
||||
};
|
||||
|
||||
|
||||
// automatically updates the thread after a specified delay
|
||||
var auto_update = function(delay) {
|
||||
clearInterval(countdown_interval);
|
||||
|
@ -204,14 +204,14 @@ $(document).ready(function(){
|
|||
countdown_interval = setInterval(decrement_timer, 1000);
|
||||
$('#update_secs').text(poll_current_time/1000);
|
||||
}
|
||||
|
||||
|
||||
var stop_auto_update = function() {
|
||||
clearInterval(countdown_interval);
|
||||
}
|
||||
|
||||
var epoch = (new Date).getTime();
|
||||
var epochold = epoch;
|
||||
|
||||
|
||||
var timeDiff = function (delay) {
|
||||
if((epoch-epochold) > delay) {
|
||||
epochold = epoch = (new Date).getTime();
|
||||
|
@ -221,10 +221,15 @@ $(document).ready(function(){
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var poll = function(manualUpdate) {
|
||||
stop_auto_update();
|
||||
$('#update_secs').text(_("Updating..."));
|
||||
let isScreenSmall = window.matchMedia('(max-width: 48em)').matches;
|
||||
if (isScreenSmall) {
|
||||
$('#update_secs').text('...');
|
||||
} else {
|
||||
$('#update_secs').text(_('Updating...'));
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
cache: !manualUpdate,
|
||||
|
@ -259,14 +264,14 @@ $(document).ready(function(){
|
|||
});
|
||||
|
||||
time_loaded = Date.now(); // interop with watch.js
|
||||
|
||||
|
||||
if ($('#auto_update_status').is(':checked')) {
|
||||
// If there are no new posts, double the delay. Otherwise set it to the min.
|
||||
if(loaded_posts == 0) {
|
||||
// if the update was manual, don't increase the delay
|
||||
if (manualUpdate == false) {
|
||||
poll_interval_delay *= 2;
|
||||
|
||||
|
||||
// Don't increase the delay beyond the maximum
|
||||
if(poll_interval_delay > poll_interval_maxdelay) {
|
||||
poll_interval_delay = poll_interval_maxdelay;
|
||||
|
@ -275,7 +280,7 @@ $(document).ready(function(){
|
|||
} else {
|
||||
poll_interval_delay = poll_interval_mindelay;
|
||||
}
|
||||
|
||||
|
||||
auto_update(poll_interval_delay);
|
||||
} else {
|
||||
// Decide the message to show if auto update is disabled
|
||||
|
@ -300,7 +305,7 @@ $(document).ready(function(){
|
|||
} else {
|
||||
$('#update_secs').text(_("Unknown error"));
|
||||
}
|
||||
|
||||
|
||||
// Keep trying to update
|
||||
if ($('#auto_update_status').is(':checked')) {
|
||||
poll_interval_delay = poll_interval_errordelay;
|
||||
|
@ -308,7 +313,7 @@ $(document).ready(function(){
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
@ -318,7 +323,7 @@ $(document).ready(function(){
|
|||
|
||||
poll(manualUpdate = true);
|
||||
});
|
||||
|
||||
|
||||
$(window).scrollStopped(function() {
|
||||
// if the newest post is not visible
|
||||
if($(this).scrollTop() + $(this).height() <
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue