Add a spinner when loading during infinite scrolling.

updates #306
This commit is contained in:
JC Brand 2015-07-18 21:39:49 +02:00
parent ec02d34af9
commit 1a7a5e8054

View File

@ -1281,6 +1281,7 @@
if ($(ev.target).scrollTop() === 0) {
oldest = this.model.messages.where({'time': this.model.messages.pluck('time').sort()[0]});
if (oldest) {
this.$el.find('.chat-content').prepend('<span class="spinner"/>');
this.fetchArchivedMessages({
'before': oldest[0].get('archive_id'),
'with': this.model.get('jid'),
@ -1343,7 +1344,12 @@
* so that they are displayed inside it.
*/
API.archive.query(options,
_.partial(_.map, _, converse.chatboxes.onMessage.bind(converse.chatboxes)),
function (messages) {
this.clearSpinner();
if (messages.length) {
_.map(messages, converse.chatboxes.onMessage.bind(converse.chatboxes));
}
}.bind(this),
_.partial(converse.log, "Error while trying to fetch archived messages", "error")
);
},
@ -1379,6 +1385,13 @@
return this;
},
clearSpinner: function () {
var $content = this.$el.find('.chat-content');
if ($content.children(':first').is('span.spinner')) {
$content.children(':first').first().remove();
}
},
showMessage: function (msg_dict) {
var $content = this.$el.find('.chat-content'),
msg_time = moment(msg_dict.time) || moment,