mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
Merge branch 'MDL-57084_master' of git://github.com/markn86/moodle
This commit is contained in:
commit
0dcbbbaa7e
2 changed files with 45 additions and 12 deletions
File diff suppressed because one or more lines are too long
|
@ -242,13 +242,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||||
SELECTORS.LOADINGICON).remove();
|
SELECTORS.LOADINGICON).remove();
|
||||||
// Check if we got something to do.
|
// Check if we got something to do.
|
||||||
if (numberreceived > 0) {
|
if (numberreceived > 0) {
|
||||||
// Let's check if we can remove the block time.
|
var newHtml = $('<div>' + html + '</div>');
|
||||||
// First, get the block time that is currently being displayed.
|
if (this._hasMatchingBlockTime(this.messageArea.node, newHtml, true)) {
|
||||||
var blocktime = this.messageArea.node.find(SELECTORS.BLOCKTIME + ":first");
|
this.messageArea.node.find(SELECTORS.BLOCKTIME + ':first').remove();
|
||||||
var newblocktime = $(html).find(SELECTORS.BLOCKTIME + ":first").addBack();
|
|
||||||
if (blocktime.html() == newblocktime.html()) {
|
|
||||||
// Remove the block time as it's present above.
|
|
||||||
blocktime.remove();
|
|
||||||
}
|
}
|
||||||
// Get height before we add the messages.
|
// Get height before we add the messages.
|
||||||
var oldheight = this.messageArea.find(SELECTORS.MESSAGES)[0].scrollHeight;
|
var oldheight = this.messageArea.find(SELECTORS.MESSAGES)[0].scrollHeight;
|
||||||
|
@ -313,11 +309,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||||
}.bind(this)).then(function(html, js) {
|
}.bind(this)).then(function(html, js) {
|
||||||
// Check if we got something to do.
|
// Check if we got something to do.
|
||||||
if (numberreceived > 0) {
|
if (numberreceived > 0) {
|
||||||
html = $(html);
|
var newHtml = $('<div>' + html + '</div>');
|
||||||
// Remove the new block time as it's present above.
|
if (this._hasMatchingBlockTime(this.messageArea.node, newHtml, false)) {
|
||||||
html.find(SELECTORS.BLOCKTIME).remove();
|
newHtml.find(SELECTORS.BLOCKTIME + ':first').remove();
|
||||||
|
}
|
||||||
// Show the new content.
|
// Show the new content.
|
||||||
Templates.appendNodeContents(this.messageArea.find(SELECTORS.MESSAGES), html, js);
|
Templates.appendNodeContents(this.messageArea.find(SELECTORS.MESSAGES), newHtml, js);
|
||||||
// Scroll the new message into view.
|
// Scroll the new message into view.
|
||||||
if (shouldScrollBottom) {
|
if (shouldScrollBottom) {
|
||||||
this._scrollBottom();
|
this._scrollBottom();
|
||||||
|
@ -810,6 +807,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide the messaging area. This only applies on smaller screen resolutions.
|
* Hide the messaging area. This only applies on smaller screen resolutions.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
Messages.prototype._hideMessagingArea = function() {
|
Messages.prototype._hideMessagingArea = function() {
|
||||||
this.messageArea.find(SELECTORS.MESSAGINGAREA)
|
this.messageArea.find(SELECTORS.MESSAGINGAREA)
|
||||||
|
@ -817,6 +816,40 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||||
.addClass('hide-messages');
|
.addClass('hide-messages');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a day separator needs to be removed.
|
||||||
|
*
|
||||||
|
* Example - scrolling up and loading previous messages that belong to the
|
||||||
|
* same day as the last message that was previously shown, meaning we can
|
||||||
|
* remove the original separator.
|
||||||
|
*
|
||||||
|
* @param {jQuery} domHtml The HTML in the DOM.
|
||||||
|
* @param {jQuery} newHtml The HTML to compare to the DOM
|
||||||
|
* @param {boolean} loadingPreviousMessages Are we loading previous messages?
|
||||||
|
* @return {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Messages.prototype._hasMatchingBlockTime = function(domHtml, newHtml, loadingPreviousMessages) {
|
||||||
|
var blockTime, blockTimePos, newBlockTime, newBlockTimePos;
|
||||||
|
|
||||||
|
if (loadingPreviousMessages) {
|
||||||
|
blockTimePos = ':first';
|
||||||
|
newBlockTimePos = ':last';
|
||||||
|
} else {
|
||||||
|
blockTimePos = ':last';
|
||||||
|
newBlockTimePos = ':first';
|
||||||
|
}
|
||||||
|
|
||||||
|
blockTime = domHtml.find(SELECTORS.BLOCKTIME + blockTimePos);
|
||||||
|
newBlockTime = newHtml.find(SELECTORS.BLOCKTIME + newBlockTimePos);
|
||||||
|
|
||||||
|
if (blockTime.length && newBlockTime.length) {
|
||||||
|
return blockTime.data('blocktime') == newBlockTime.data('blocktime');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
return Messages;
|
return Messages;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue