Merge branch 'MDL-64137-master' of git://github.com/bmbrands/moodle

This commit is contained in:
Jun Pataleta 2019-04-18 14:55:20 +08:00
commit da5a90a822
7 changed files with 37 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -612,6 +612,22 @@ function(
}
};
/**
* Highlight words in search results.
*
* @param {String} content HTML to search.
* @param {String} searchText Search text.
* @return {String} searchText with search wrapped in matchtext span.
*/
var highlightSearch = function(content, searchText) {
if (!content) {
return '';
}
var regex = new RegExp('(' + searchText + ')', 'gi');
return content.replace(regex, '<span class="matchtext">$1</span>');
};
/**
* Render contacts in the contacts search results.
*
@ -705,6 +721,18 @@ function(
var contactsCount = results.contacts.length;
var nonContactsCount = results.noncontacts.length;
if (contactsCount) {
results.contacts.forEach(function(contact) {
contact.highlight = highlightSearch(contact.fullname, text);
});
}
if (nonContactsCount) {
results.noncontacts.forEach(function(contact) {
contact.highlight = highlightSearch(contact.fullname, text);
});
}
return $.when(
contactsCount ? renderContacts(root, results.contacts) : true,
nonContactsCount ? renderNonContacts(root, results.noncontacts) : true
@ -759,6 +787,9 @@ function(
})
.then(function(messages) {
if (messages.length) {
messages.forEach(function(message) {
message.lastmessage = highlightSearch(message.lastmessage, text);
});
return renderMessages(root, messages)
.then(function() {
return messages.length;

View File

@ -67,7 +67,7 @@
{{#showonlinestatus}}
<span class="contact-status {{#isonline}}online{{/isonline}}"></span>
{{/showonlinestatus}}
<h6 class="ml-2 font-weight-bold" data-region="searchable">{{fullname}}</h6>
<h6 class="ml-2 font-weight-bold">{{#highlight}}{{{highlight}}}{{/highlight}}{{^highlight}}{{fullname}}{{/highlight}}</h6>
<div
class="ml-auto align-self-end {{^isblocked}}hidden{{/isblocked}}"
data-region="block-icon-container"

View File

@ -78,7 +78,7 @@
{{#str}} sender, core_message, {{.}} {{/str}}
{{/lastsendername}}
{{/sentfromcurrentuser}}
<span class='text-muted'>{{lastmessage}}</span>
<span class="text-muted">{{lastmessage}}</span>
</p>
</div>
<div class="d-flex align-self-stretch">

View File

@ -86,7 +86,7 @@
</div>
<p class="m-0 font-weight-light text-truncate" data-region="last-message">
{{#sentfromcurrentuser}}{{#str}} you, core_message {{/str}}{{/sentfromcurrentuser}}
{{lastmessage}}
<span>{{{lastmessage}}}</span>
</p>
</div>

View File

@ -62,7 +62,7 @@
aria-hidden="true"
style="height: 38px"
>
<h6 class="ml-2 font-weight-bold" data-region="searchable">{{fullname}}</h6>
<h6 class="ml-2 font-weight-bold">{{#highlight}}{{{highlight}}}{{/highlight}}{{^highlight}}{{fullname}}{{/highlight}}</h6>
{{#isblocked}}
<div class="ml-auto align-self-end">
{{#pix}} t/block, core, {{#str}} contactblocked, message {{/str}} {{/pix}}

View File

@ -61,7 +61,7 @@
{{#showonlinestatus}}
<span class="contact-status {{#isonline}}online{{/isonline}}"></span>
{{/showonlinestatus}}
<h6 class="ml-2" data-region="searchable">{{fullname}}</h6>
<h6 class="ml-2">{{fullname}}</h6>
<div
class="ml-auto align-self-end {{^isblocked}}hidden{{/isblocked}}"
data-region="block-icon-container"