Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-a-spinner-at-least-until-some-messages-are-shown #1126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,13 @@ class Hm_Output_loading_icon extends Hm_Output_Module {
* Sort of ugly loading icon animated with js/css
*/
protected function output() {
return '<div class="loading_icon"></div>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You renamed the class here: class="loading_bar" but it was refering to the module: Hm_Output_loading_icon you should keep it like that.

return '
<div class="loading_icon"></div>
<div class="loading_spinner text-center">
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>';
}
}

Expand Down
16 changes: 16 additions & 0 deletions modules/core/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ td {
height: 6px;
z-index: 1001;
}
.loading_spinner {
background-color: rgba(0, 0, 0, 0.6);
text-align: center;
display: none;
position: fixed;
right: 0px;
top: 0px;
left: 12%;
z-index: 1001;
min-height: 100%;
padding-top: 20%;
color: #ccc;
width: 100%;
z-index: 1001;
}

.logout {
margin: 2px;
margin-left: 5px;
Expand Down
66 changes: 35 additions & 31 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var Hm_Ajax = {
return;
},

request: function(args, callback, extra, no_icon, batch_callback, on_failure) {
request: function(args, callback, extra, on_loading = false, batch_callback, on_failure) {
var bcb = false;
if (typeof batch_callback != 'undefined' && $.inArray(batch_callback, this.batch_callbacks) === -1) {
bcb = batch_callback.toString();
Expand All @@ -127,34 +127,27 @@ var Hm_Ajax = {
Hm_Ajax.batch_callbacks[bcb] = 1;
}
}
var name = Hm_Ajax.get_ajax_hook_name(args);
var name = Hm_Ajax.get_ajax_hook_name(args)
var ajax = new Hm_Ajax_Request();
if (!no_icon) {
Hm_Ajax.show_loading_icon();
$('body').addClass('wait');
}
Hm_Ajax.active_reqs++;
return ajax.make_request(args, callback, extra, name, on_failure, batch_callback);
return ajax.make_request(args, callback, extra, name, on_failure, batch_callback, on_loading);
},

show_loading_icon: function() {
if (Hm_Ajax.icon_loading_id !== false) {
return;
}
var hm_loading_pos = $('.loading_icon').width()/40;
$('.loading_icon').show();
function move_background_image() {
hm_loading_pos = hm_loading_pos + 50;
$('.loading_icon').css('background-position', hm_loading_pos+'px 0');
Hm_Ajax.icon_loading_id = setTimeout(move_background_image, 100);
}
move_background_image();
Hm_Ajax.icon_loading_id = true;
$('.loading_bar').show();
$('.loading_spinner').show();
$('body').addClass('wait');
let width_nav_folder_cell= $('nav[class="folder_cell"]').css('width');
$('.loading_spinner').css('left', width_nav_folder_cell);

},

stop_loading_icon : function(loading_id) {
clearTimeout(loading_id);
$('.loading_icon').hide();
Hm_Ajax.icon_loading_id = false;
$('.loading_bar').hide();
$('.loading_spinner').hide();
$('body').removeClass('wait');
},

process_callback_hooks: function(name, res) {
Expand Down Expand Up @@ -188,27 +181,36 @@ var Hm_Ajax_Request = function() { return {
on_failure: false,
start_time: 0,

xhr_fetch: function(config) {
xhr_fetch: function(config, on_loading) {
var xhr = new XMLHttpRequest();
var data = '';
if (config.data) {
data = this.format_xhr_data(config.data);
}
xhr.open('POST', window.location.href)
Hm_Ajax.stop_loading_icon();
xhr.addEventListener('loadstart', function () {
if (!on_loading) {
Hm_Ajax.show_loading_icon();
}
});
xhr.addEventListener('load', function() {
config.callback.done(Hm_Utils.json_decode(xhr.response, true), xhr);
config.callback.always(Hm_Utils.json_decode(xhr.response, true));
});
xhr.addEventListener('error', function() {
Hm_Ajax.stop_loading_icon(Hm_Ajax.icon_loading_id);
Hm_Ajax.stop_loading_icon();
config.callback.fail(xhr);
config.callback.always(Hm_Utils.json_decode(xhr.response, true));
});
xhr.addEventListener('abort', function() {
Hm_Ajax.stop_loading_icon(Hm_Ajax.icon_loading_id);
Hm_Ajax.stop_loading_icon();
config.callback.always(Hm_Utils.json_decode(xhr.response, true));

});
xhr.addEventListener('loadend',function () {
Hm_Ajax.stop_loading_icon();
});
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('X-Requested-with', 'xmlhttprequest');
xhr.send(data);
Expand All @@ -222,7 +224,7 @@ var Hm_Ajax_Request = function() { return {
return res.join('&');
},

make_request: function(args, callback, extra, request_name, on_failure, batch_callback) {
make_request: function(args, callback, extra, request_name, on_failure, batch_callback, on_loading) {
var name;
var arg;
this.batch_callback = batch_callback;
Expand All @@ -248,7 +250,7 @@ var Hm_Ajax_Request = function() { return {
}
var dt = new Date();
this.start_time = dt.getTime();
this.xhr_fetch({url: '', data: args, callback: this});
this.xhr_fetch({url: '', data: args, callback: this},on_loading);
return false;
},

Expand Down Expand Up @@ -313,7 +315,7 @@ var Hm_Ajax_Request = function() { return {
if (this.batch_callback) {
if (typeof Hm_Ajax.batch_callbacks[this.batch_callback.toString()] != 'undefined') {
batch_count = --Hm_Ajax.batch_callbacks[this.batch_callback.toString()];
}
}
}
Hm_Message_List.set_row_events();
if (batch_count === 0) {
Expand All @@ -322,11 +324,11 @@ var Hm_Ajax_Request = function() { return {
Hm_Ajax.p_callbacks = [];
this.batch_callback(res);
this.batch_callback = false;
Hm_Ajax.stop_loading_icon(Hm_Ajax.icon_loading_id);
Hm_Ajax.stop_loading_icon();
$('body').removeClass('wait');
}
if (Hm_Ajax.active_reqs == 0) {
Hm_Ajax.stop_loading_icon(Hm_Ajax.icon_loading_id);
Hm_Ajax.stop_loading_icon();
$('body').removeClass('wait');
}
res = null;
Expand Down Expand Up @@ -1342,7 +1344,9 @@ var Hm_Folders = {
$('.search_terms').val(hm_search_terms());
}
$('.search_terms').on('search', function() {
Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_reset_search'}]);
Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_reset_search'}],function () {

},[],true);
});
},

Expand Down Expand Up @@ -1707,7 +1711,7 @@ var Hm_Utils = {
$('.offline').hide();
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_test'}],
false, [], false, false, false);
false, [], true, false, false);
},

is_element_visible: function (elem) {
Expand Down Expand Up @@ -2527,7 +2531,7 @@ function getServiceDetails(providerKey){
}
},
[],
false
true
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/feeds/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var feed_test_action = function(event) {
Hm_Ajax.request(
form.serializeArray(),
function() {},
{'feed_connect': 1}
{'feed_connect': 1},
true
);
};

Expand Down Expand Up @@ -40,7 +41,7 @@ var feeds_search_page_content = function(id) {
{'name': 'feed_server_ids', 'value': id}],
display_feeds_search_result,
[],
false,
true,
Hm_Message_List.set_search_state
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/github/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var load_github_data = function(id) {
};

var load_github_data_background = function(id) {
Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_github_data'}, {'name': 'github_unread', 'value': 1}, {'name': 'github_repo', 'value': id}], display_github_data_background);
Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_github_data'}, {'name': 'github_unread', 'value': 1}, {'name': 'github_repo', 'value': id}], display_github_data_background,[],true);
};

var display_github_data_background = function(res) {
Expand Down
7 changes: 4 additions & 3 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var imap_hide_action = function(form, server_id, hide) {
$('.hide_imap_connection', form).show();
}
Hm_Folders.reload_folders(true);
}
},[],true
);
};

Expand Down Expand Up @@ -110,7 +110,8 @@ var imap_test_action = function(event) {
Hm_Ajax.request(
form.serializeArray(),
false,
{'imap_connect': 1}
{'imap_connect': 1},
true
);
}

Expand Down Expand Up @@ -1064,7 +1065,7 @@ var imap_background_unread_content = function(id, folder) {
{'name': 'imap_server_ids', 'value': id}],
imap_background_unread_content_result,
[],
false,
true,
function() {
var cache = $('<tbody></tbody>').append($(Hm_Utils.get_from_local_storage('formatted_unread_data')));
Hm_Message_List.adjust_unread_total($('tr', cache).length, true);
Expand Down
4 changes: 3 additions & 1 deletion modules/nasa/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var nasa_connect = function(event) {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_nasa_connect'},
{'name': 'api_key', 'value': key}],
nasa_connect_result
nasa_connect_result,
[],
true
);
}
return false;
Expand Down
4 changes: 3 additions & 1 deletion modules/nux/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ var display_final_nux_step = function(res) {
{'name': 'imap_service_name', value: res.nux_service_name}],
function () {
Hm_Utils.redirect();
}
},
[],
true
);
} else {
Hm_Utils.redirect();
Expand Down
4 changes: 2 additions & 2 deletions modules/saved_searches/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var delete_search = function(event) {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_delete_search'},
{'name': 'search_name', 'value': name}],
search_delete_results
search_delete_results,[],true
);
}
return false;
Expand Down Expand Up @@ -55,7 +55,7 @@ var update_save_search_label = function(event) {
{'name': 'search_terms_label', 'value': $('.search_terms_label').val()},
{'name': 'old_search_terms_label', 'value': $('.old_search_terms_label').val()},
{'name': 'search_name', 'value': $('.search_terms').val()}],
update_save_search_label_results
update_save_search_label_results, [], true
);
}
return false;
Expand Down
Loading
Loading